1 /* 2 * Copyright (C) 2018 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 package android.angle.cts; 17 18 import com.android.tradefed.device.ITestDevice; 19 import com.android.tradefed.device.PackageInfo; 20 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; 21 22 import java.util.HashMap; 23 import java.util.Map; 24 25 class CtsAngleCommon { 26 // General 27 static final int NUM_ATTEMPTS = 5; 28 static final int REATTEMPT_SLEEP_MSEC = 5000; 29 30 // Settings.Global 31 static final String SETTINGS_GLOBAL_ALL_USE_ANGLE = "angle_gl_driver_all_angle"; 32 static final String SETTINGS_GLOBAL_DRIVER_PKGS = "angle_gl_driver_selection_pkgs"; 33 static final String SETTINGS_GLOBAL_DRIVER_VALUES = "angle_gl_driver_selection_values"; 34 static final String SETTINGS_GLOBAL_ALLOWLIST = "angle_allowlist"; 35 static final String SETTINGS_GLOBAL_ANGLE_IN_USE_DIALOG_BOX = "show_angle_in_use_dialog_box"; 36 37 // System Properties 38 static final String PROPERTY_TEMP_RULES_FILE = "debug.angle.rules"; 39 40 // Rules File 41 static final String DEVICE_TEMP_RULES_FILE_DIRECTORY = "/data/local/tmp"; 42 static final String DEVICE_TEMP_RULES_FILE_FILENAME = "a4a_rules.json"; 43 static final String DEVICE_TEMP_RULES_FILE_PATH = DEVICE_TEMP_RULES_FILE_DIRECTORY + "/" + DEVICE_TEMP_RULES_FILE_FILENAME; 44 45 // ANGLE 46 static final String ANGLE_PACKAGE_NAME = "com.android.angle"; 47 static final String ANGLE_DRIVER_TEST_PKG = "com.android.angleIntegrationTest.driverTest"; 48 static final String ANGLE_DRIVER_TEST_SEC_PKG = "com.android.angleIntegrationTest.driverTestSecondary"; 49 static final String ANGLE_DRIVER_TEST_CLASS = "AngleDriverTestActivity"; 50 static final String ANGLE_DRIVER_TEST_DEFAULT_METHOD = "testUseDefaultDriver"; 51 static final String ANGLE_DRIVER_TEST_ANGLE_METHOD = "testUseAngleDriver"; 52 static final String ANGLE_DRIVER_TEST_NATIVE_METHOD = "testUseNativeDriver"; 53 static final String ANGLE_DRIVER_TEST_APP = "CtsAngleDriverTestCases.apk"; 54 static final String ANGLE_DRIVER_TEST_SEC_APP = "CtsAngleDriverTestCasesSecondary.apk"; 55 static final String ANGLE_DRIVER_TEST_ACTIVITY = 56 ANGLE_DRIVER_TEST_PKG + "/com.android.angleIntegrationTest.common.AngleIntegrationTestActivity"; 57 static final String ANGLE_DRIVER_TEST_SEC_ACTIVITY = 58 ANGLE_DRIVER_TEST_SEC_PKG + "/com.android.angleIntegrationTest.common.AngleIntegrationTestActivity"; 59 60 enum OpenGlDriverChoice { 61 DEFAULT, 62 NATIVE, 63 ANGLE 64 } 65 66 static final Map<OpenGlDriverChoice, String> sDriverGlobalSettingMap = buildDriverGlobalSettingMap(); buildDriverGlobalSettingMap()67 static Map<OpenGlDriverChoice, String> buildDriverGlobalSettingMap() { 68 Map<OpenGlDriverChoice, String> map = new HashMap<>(); 69 map.put(OpenGlDriverChoice.DEFAULT, "default"); 70 map.put(OpenGlDriverChoice.ANGLE, "angle"); 71 map.put(OpenGlDriverChoice.NATIVE, "native"); 72 73 return map; 74 } 75 76 static final Map<OpenGlDriverChoice, String> sDriverTestMethodMap = buildDriverTestMethodMap(); buildDriverTestMethodMap()77 static Map<OpenGlDriverChoice, String> buildDriverTestMethodMap() { 78 Map<OpenGlDriverChoice, String> map = new HashMap<>(); 79 map.put(OpenGlDriverChoice.DEFAULT, ANGLE_DRIVER_TEST_DEFAULT_METHOD); 80 map.put(OpenGlDriverChoice.ANGLE, ANGLE_DRIVER_TEST_ANGLE_METHOD); 81 map.put(OpenGlDriverChoice.NATIVE, ANGLE_DRIVER_TEST_NATIVE_METHOD); 82 83 return map; 84 } 85 getGlobalSetting(ITestDevice device, String globalSetting)86 static String getGlobalSetting(ITestDevice device, String globalSetting) throws Exception { 87 return device.getSetting("global", globalSetting); 88 } 89 setGlobalSetting(ITestDevice device, String globalSetting, String value)90 static void setGlobalSetting(ITestDevice device, String globalSetting, String value) throws Exception { 91 device.setSetting("global", globalSetting, value); 92 device.executeShellCommand("am refresh-settings-cache"); 93 } 94 clearSettings(ITestDevice device)95 static void clearSettings(ITestDevice device) throws Exception { 96 // Cached Activity Manager settings 97 setGlobalSetting(device, SETTINGS_GLOBAL_ALL_USE_ANGLE, "0"); 98 setGlobalSetting(device, SETTINGS_GLOBAL_ANGLE_IN_USE_DIALOG_BOX, "0"); 99 setGlobalSetting(device, SETTINGS_GLOBAL_DRIVER_PKGS, "\"\""); 100 setGlobalSetting(device, SETTINGS_GLOBAL_DRIVER_VALUES, "\"\""); 101 setGlobalSetting(device, SETTINGS_GLOBAL_ALLOWLIST, "\"\""); 102 103 // Properties 104 setProperty(device, PROPERTY_TEMP_RULES_FILE, "\"\""); 105 } 106 isAngleInstalled(ITestDevice device)107 static boolean isAngleInstalled(ITestDevice device) throws Exception { 108 PackageInfo info = device.getAppPackageInfo(ANGLE_PACKAGE_NAME); 109 110 return (info != null); 111 } 112 isNativeDriverAngle(ITestDevice device)113 static boolean isNativeDriverAngle(ITestDevice device) throws Exception { 114 String driverProp = device.getProperty("ro.hardware.egl"); 115 116 return (driverProp != null) && (driverProp.equals("angle")); 117 } 118 stopPackage(ITestDevice device, String pkgName)119 static void stopPackage(ITestDevice device, String pkgName) throws Exception { 120 device.executeShellCommand("am force-stop " + pkgName); 121 } 122 123 /** 124 * Work around the fact that INativeDevice.enableAdbRoot() is not supported. 125 */ setProperty(ITestDevice device, String property, String value)126 static void setProperty(ITestDevice device, String property, String value) throws Exception { 127 device.executeShellCommand("setprop " + property + " " + value); 128 } 129 } 130