1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.server.wm; 18 19 import android.content.ComponentName; 20 import android.content.Context; 21 import android.content.Intent; 22 23 /** 24 * A class that sends log data to {@link TestLogService}. 25 */ 26 public class TestLogClient { 27 28 public static final String EXTRA_LOG_TAG = "logtag"; 29 public static final String EXTRA_KEY = "key"; 30 public static final String EXTRA_VALUE = "value"; 31 32 private static final String TEST_LOGGER_PACKAGE_NAME = "android.server.wm.cts"; 33 private static final String TEST_LOGGER_SERVICE_NAME = "android.server.wm.TestLogService"; 34 35 private final Context mContext; 36 private final String mLogTag; 37 TestLogClient(Context context, String logtag)38 public TestLogClient(Context context, String logtag) { 39 mContext = context; 40 mLogTag = logtag; 41 } 42 record(String key, String value)43 public void record(String key, String value) { 44 Intent intent = new Intent(); 45 intent.setComponent( 46 new ComponentName(TEST_LOGGER_PACKAGE_NAME, TEST_LOGGER_SERVICE_NAME)); 47 intent.putExtra(EXTRA_LOG_TAG, mLogTag); 48 intent.putExtra(EXTRA_KEY, key); 49 intent.putExtra(EXTRA_VALUE, value); 50 mContext.startService(intent); 51 } 52 } 53