1 /* 2 * Copyright 2020 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.hdmicec.cts; 18 19 import com.android.tradefed.device.DeviceNotAvailableException; 20 import com.android.tradefed.device.ITestDevice; 21 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; 22 23 import java.util.HashMap; 24 import java.util.Map; 25 26 /** Helper class to call tests in the HdmiCecControlManagerHelper app */ 27 public class HdmiControlManagerUtility { 28 /** The package name of the APK. */ 29 private static final String TEST_PKG = "android.hdmicec.app"; 30 31 /** The class name of the main activity in the APK. */ 32 private static final String TEST_CLS = "android.hdmicec.app.HdmiControlManagerHelper"; 33 34 /** The method name of the set active source case. */ 35 private static final String SELECT_DEVICE = "deviceSelect"; 36 37 /** The method name of the set active source case. */ 38 private static final String SEND_INTERRUPTED_LONG_PRESS = "interruptedLongPress"; 39 40 /** The method name of the set active source case. */ 41 private static final String VENDOR_CMD_LISTENER_WITHOUT_ID = "vendorCmdListenerWithoutId"; 42 43 /** The method name of the set active source case. */ 44 private static final String VENDOR_CMD_LISTENER_WITH_ID = "vendorCmdListenerWithId"; 45 46 /** The key of the set active source case arguments. */ 47 private static final String LOGICAL_ADDR = "ARG_LOGICAL_ADDR"; 48 49 /** The timeout of the test. */ 50 private static final long TEST_TIMEOUT_MS = 10 * 60 * 1000L; 51 52 /** 53 * Method to make a device the active source. Will only work if the DUT is TV. 54 * 55 * @param host Reference to the JUnit4 host test class 56 * @param device Reference to the DUT 57 * @param logicalAddress The logical address of the device that should be made the active source 58 */ selectDevice(BaseHostJUnit4Test host, ITestDevice device, String logicalAddress)59 public static void selectDevice(BaseHostJUnit4Test host, ITestDevice device, 60 String logicalAddress) throws DeviceNotAvailableException { 61 Map<String, String> args = new HashMap<>(); 62 args.put(LOGICAL_ADDR, logicalAddress); 63 host.runDeviceTests(device, null, TEST_PKG, TEST_CLS, SELECT_DEVICE, null, 64 TEST_TIMEOUT_MS, TEST_TIMEOUT_MS, 0L, true, false, args); 65 } 66 67 /** 68 * Sends a long press keyevent (KEYCODE_UP) followed by a short press of another keyevent 69 * (KEYCODE_DOWN). 70 */ sendLongPressKeyevent(BaseHostJUnit4Test host)71 public static void sendLongPressKeyevent(BaseHostJUnit4Test host) throws DeviceNotAvailableException { 72 host.runDeviceTests(TEST_PKG, TEST_CLS, SEND_INTERRUPTED_LONG_PRESS); 73 } 74 75 /** Registers a vendor command listener without a vendor ID. */ registerVendorCmdListenerWithoutId(BaseHostJUnit4Test host)76 public static void registerVendorCmdListenerWithoutId(BaseHostJUnit4Test host) 77 throws DeviceNotAvailableException { 78 host.runDeviceTests(TEST_PKG, TEST_CLS, VENDOR_CMD_LISTENER_WITHOUT_ID); 79 } 80 81 /** Registers a vendor command listener with vendor ID. */ registerVendorCmdListenerWithId(BaseHostJUnit4Test host)82 public static void registerVendorCmdListenerWithId(BaseHostJUnit4Test host) 83 throws DeviceNotAvailableException { 84 host.runDeviceTests(TEST_PKG, TEST_CLS, VENDOR_CMD_LISTENER_WITH_ID); 85 } 86 } 87