1 /* 2 * Copyright (C) 2012 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 com.android.cts.tradefed.testtype; 18 19 import com.android.cts.util.AbiUtils; 20 import com.android.ddmlib.Log; 21 import com.android.tradefed.device.DeviceNotAvailableException; 22 import com.android.tradefed.result.ITestInvocationListener; 23 import com.android.tradefed.util.FileUtil; 24 25 import junit.framework.TestCase; 26 27 import java.io.File; 28 29 /** 30 * Running the accessibility tests requires modification of secure 31 * settings. Secure settings cannot be changed from device CTS tests 32 * since system signature permission is required. Such settings can 33 * be modified by the shell user, so a host side test is used for 34 * installing a package with a delegating accessibility service, enabling 35 * this service, running these tests, disabling the service, and removing 36 * the delegating accessibility service package. 37 * 38 * @deprecated This class is not required in current CTS builds. Still 39 * maintained so cts-tradefed can run against older CTS builds that still 40 * require this class. 41 */ 42 @Deprecated 43 public class AccessibilityServiceTestRunner extends CtsInstrumentationApkTest { 44 45 private static final String LOG_TAG = AccessibilityServiceTestRunner.class.getSimpleName(); 46 47 private static final String DELEGATING_ACCESSIBLITY_SERVICE_PACKAGE_NAME = 48 "android.accessibilityservice.delegate"; 49 50 private static final String DELEGATING_ACCESSIBLITY_SERVICE_NAME = 51 "android.accessibilityservice.delegate.DelegatingAccessibilityService"; 52 53 private static final String DELEGATING_ACCESSIBLITY_SERVICE_APK = 54 "CtsDelegatingAccessibilityService.apk"; 55 56 @Override run(ITestInvocationListener listener)57 public void run(ITestInvocationListener listener) throws DeviceNotAvailableException { 58 beforeTest(); 59 super.run(listener); 60 afterTest(); 61 } 62 beforeTest()63 private void beforeTest() throws DeviceNotAvailableException { 64 installApkAndAssert(DELEGATING_ACCESSIBLITY_SERVICE_APK); 65 enableAccessibilityAndDelegatingService(); 66 } 67 afterTest()68 private void afterTest() throws DeviceNotAvailableException { 69 AccessibilityTestRunner.disableAccessibilityAndServices(getDevice()); 70 uninstallAndAssert(DELEGATING_ACCESSIBLITY_SERVICE_PACKAGE_NAME); 71 } 72 installApkAndAssert(String apkName)73 private void installApkAndAssert(String apkName) throws DeviceNotAvailableException { 74 File file = FileUtil.getFileForPath(mCtsBuild.getTestCasesDir(), apkName); 75 String[] options = {AbiUtils.createAbiFlag(mAbi.getName())}; 76 String errorMessage = getDevice().installPackage(file, true, options); 77 TestCase.assertNull("Error installing: " + apkName, errorMessage); 78 } 79 uninstallAndAssert(String packageName)80 private void uninstallAndAssert(String packageName) throws DeviceNotAvailableException { 81 String errorMessage = getDevice().uninstallPackage(packageName); 82 TestCase.assertNull("Error uninstalling: " + packageName, errorMessage); 83 } 84 enableAccessibilityAndDelegatingService()85 private void enableAccessibilityAndDelegatingService() throws DeviceNotAvailableException { 86 String componentName = DELEGATING_ACCESSIBLITY_SERVICE_PACKAGE_NAME + "/" 87 + DELEGATING_ACCESSIBLITY_SERVICE_NAME; 88 AccessibilityTestRunner.enableAccessibilityAndServices(getDevice(), 89 componentName); 90 } 91 } 92