Loading services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java +4 −10 Original line number Diff line number Diff line Loading @@ -205,9 +205,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { private final UserManager mUserManager; private final LockPatternUtils mLockPatternUtils; private int mCurrentUserId = UserHandle.USER_OWNER; private int mCurrentUserId = UserHandle.USER_SYSTEM; //TODO: Remove this hack private boolean mInitialized; Loading @@ -230,7 +228,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE); mSecurityPolicy = new SecurityPolicy(); mMainHandler = new MainHandler(mContext.getMainLooper()); mLockPatternUtils = new LockPatternUtils(context); registerBroadcastReceivers(); new AccessibilityContentObserver(mMainHandler).register( context.getContentResolver()); Loading Loading @@ -866,17 +863,18 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { } // Called only during settings restore; currently supports only the owner user // TODO: http://b/22388012 void restoreEnabledAccessibilityServicesLocked(String oldSetting, String newSetting) { readComponentNamesFromStringLocked(oldSetting, mTempComponentNameSet, false); readComponentNamesFromStringLocked(newSetting, mTempComponentNameSet, true); UserState userState = getUserStateLocked(UserHandle.USER_OWNER); UserState userState = getUserStateLocked(UserHandle.USER_SYSTEM); userState.mEnabledServices.clear(); userState.mEnabledServices.addAll(mTempComponentNameSet); persistComponentNamesToSettingLocked( Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, userState.mEnabledServices, UserHandle.USER_OWNER); UserHandle.USER_SYSTEM); onUserStateChangedLocked(userState); } Loading Loading @@ -1646,10 +1644,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { DisplayAdjustmentUtils.applyAdjustments(mContext, userState.mUserId); } private boolean hasRunningServicesLocked(UserState userState) { return !userState.mBoundServices.isEmpty() || !userState.mBindingServices.isEmpty(); } private MagnificationSpec getCompatibleMagnificationSpecLocked(int windowId) { IBinder windowToken = mGlobalWindowTokens.get(windowId); if (windowToken == null) { Loading services/tests/servicestests/src/com/android/server/AccessibilityManagerServiceTest.java +68 −52 Original line number Diff line number Diff line Loading @@ -54,7 +54,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { * Timeout in which we are waiting for the system to start the mock * accessibility services. */ private static final long TIMEOUT_START_MOCK_ACCESSIBILITY_SERVICES = 300; private static final long TIMEOUT_START_MOCK_ACCESSIBILITY_SERVICES = 1000; /** * Timeout used for testing that a service is notified only upon a Loading @@ -67,6 +67,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { */ private IAccessibilityManager mManagerService; @Override protected void setUp() throws Exception { // Reset the state. ensureOnlyMockServicesEnabled(getContext(), false, false); } @Override public void setContext(Context context) { super.setContext(context); Loading @@ -92,6 +98,9 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testAddClient_AccessibilityDisabledThenEnabled() throws Exception { // at least some service must be enabled, otherwise accessibility will always be disabled. ensureOnlyMockServicesEnabled(mContext, true, false); // make sure accessibility is disabled ensureAccessibilityEnabled(mContext, false); Loading @@ -99,7 +108,8 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { MyMockAccessibilityManagerClient mockClient = new MyMockAccessibilityManagerClient(); // invoke the method under test final int stateFlagsDisabled = mManagerService.addClient(mockClient, UserHandle.USER_OWNER); final int stateFlagsDisabled = mManagerService.addClient(mockClient, UserHandle.USER_CURRENT); boolean enabledAccessibilityDisabled = (stateFlagsDisabled & AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED) != 0; Loading @@ -111,11 +121,11 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { ensureAccessibilityEnabled(mContext, true); // invoke the method under test final int stateFlagsEnabled = mManagerService.addClient(mockClient, UserHandle.USER_OWNER); final int stateFlagsEnabled = mManagerService.addClient(mockClient, UserHandle.USER_CURRENT); boolean enabledAccessibilityEnabled = (stateFlagsEnabled & AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED) != 0; // check expected result assertTrue("The client must be enabled since accessibility is enabled.", enabledAccessibilityEnabled); Loading @@ -123,6 +133,9 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testAddClient_AccessibilityEnabledThenDisabled() throws Exception { // at least some service must be enabled, otherwise accessibility will always be disabled. ensureOnlyMockServicesEnabled(mContext, true, false); // enable accessibility before registering the client ensureAccessibilityEnabled(mContext, true); Loading @@ -130,7 +143,8 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { MyMockAccessibilityManagerClient mockClient = new MyMockAccessibilityManagerClient(); // invoke the method under test final int stateFlagsEnabled = mManagerService.addClient(mockClient, UserHandle.USER_OWNER); final int stateFlagsEnabled = mManagerService.addClient(mockClient, UserHandle.USER_CURRENT); boolean enabledAccessibilityEnabled = (stateFlagsEnabled & AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED) != 0; Loading @@ -142,7 +156,8 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { ensureAccessibilityEnabled(mContext, false); // invoke the method under test final int stateFlagsDisabled = mManagerService.addClient(mockClient, UserHandle.USER_OWNER); final int stateFlagsDisabled = mManagerService.addClient(mockClient, UserHandle.USER_CURRENT); boolean enabledAccessibilityDisabled = (stateFlagsDisabled & AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED) != 0; Loading @@ -162,7 +177,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { // look for the two mock services for (AccessibilityServiceInfo info : mManagerService.getInstalledAccessibilityServiceList( UserHandle.USER_OWNER)) { UserHandle.USER_CURRENT)) { ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo; if (packageName.equals(serviceInfo.packageName)) { if (firstMockServiceClassName.equals(serviceInfo.name)) { Loading @@ -181,12 +196,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testSendAccessibilityEvent_OneService_MatchingPackageAndEventType() throws Exception { // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // enable the mock accessibility service ensureOnlyMockServicesEnabled(mContext, true, false); // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // configure the mock service MockAccessibilityService service = MyFirstMockAccessibilityService.sInstance; service.setServiceInfo(MockAccessibilityService.createDefaultInfo()); Loading @@ -203,7 +218,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { service.replay(); // send the event mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_OWNER); mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_CURRENT); // verify if all expected methods have been called assertMockServiceVerifiedWithinTimeout(service); Loading @@ -211,12 +226,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testSendAccessibilityEvent_OneService_NotMatchingPackage() throws Exception { // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // enable the mock accessibility service ensureOnlyMockServicesEnabled(mContext, true, false); // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // configure the mock service MockAccessibilityService service = MyFirstMockAccessibilityService.sInstance; service.setServiceInfo(MockAccessibilityService.createDefaultInfo()); Loading @@ -233,7 +248,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { service.replay(); // send the event mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_OWNER); mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_CURRENT); // verify if all expected methods have been called assertMockServiceVerifiedWithinTimeout(service); Loading @@ -241,12 +256,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testSendAccessibilityEvent_OneService_NotMatchingEventType() throws Exception { // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // enable the mock accessibility service ensureOnlyMockServicesEnabled(mContext, true, false); // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // configure the mock service MockAccessibilityService service = MyFirstMockAccessibilityService.sInstance; service.setServiceInfo(MockAccessibilityService.createDefaultInfo()); Loading @@ -263,7 +278,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { service.replay(); // send the event mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_OWNER); mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_CURRENT); // verify if all expected methods have been called assertMockServiceVerifiedWithinTimeout(service); Loading @@ -271,12 +286,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testSendAccessibilityEvent_OneService_NotifivationAfterTimeout() throws Exception { // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // enable the mock accessibility service ensureOnlyMockServicesEnabled(mContext, true, false); // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // configure the mock service MockAccessibilityService service = MyFirstMockAccessibilityService.sInstance; AccessibilityServiceInfo info = MockAccessibilityService.createDefaultInfo(); Loading @@ -299,8 +314,8 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { service.replay(); // send the events mManagerService.sendAccessibilityEvent(firstEvent, UserHandle.USER_OWNER); mManagerService.sendAccessibilityEvent(secondEvent, UserHandle.USER_OWNER); mManagerService.sendAccessibilityEvent(firstEvent, UserHandle.USER_CURRENT); mManagerService.sendAccessibilityEvent(secondEvent, UserHandle.USER_CURRENT); // wait for #sendAccessibilityEvent to reach the backing service Thread.sleep(TIMEOUT_BINDER_CALL); Loading @@ -322,12 +337,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType_DiffFeedback() throws Exception { // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // enable the mock accessibility services ensureOnlyMockServicesEnabled(mContext, true, true); // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // configure the first mock service MockAccessibilityService firstService = MyFirstMockAccessibilityService.sInstance; AccessibilityServiceInfo firstInfo = MockAccessibilityService.createDefaultInfo(); Loading Loading @@ -356,7 +371,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { secondService.replay(); // send the event mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_OWNER); mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_CURRENT); // verify if all expected methods have been called assertMockServiceVerifiedWithinTimeout(firstService); Loading @@ -366,12 +381,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType() throws Exception { // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // enable the mock accessibility services ensureOnlyMockServicesEnabled(mContext, true, true); // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // configure the first mock service MockAccessibilityService firstService = MyFirstMockAccessibilityService.sInstance; firstService.setServiceInfo(MockAccessibilityService.createDefaultInfo()); Loading @@ -395,7 +410,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { secondService.replay(); // send the event mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_OWNER); mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_CURRENT); // verify if all expected methods have been called assertMockServiceVerifiedWithinTimeout(firstService); Loading @@ -405,12 +420,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType_OneDefault() throws Exception { // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // enable the mock accessibility services ensureOnlyMockServicesEnabled(mContext, true, true); // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // configure the first mock service MockAccessibilityService firstService = MyFirstMockAccessibilityService.sInstance; AccessibilityServiceInfo firstInfo = MyFirstMockAccessibilityService.createDefaultInfo(); Loading @@ -436,7 +451,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { secondService.replay(); // send the event mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_OWNER); mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_CURRENT); // verify if all expected methods have been called assertMockServiceVerifiedWithinTimeout(firstService); Loading @@ -446,12 +461,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType_TwoDefault() throws Exception { // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // enable the mock accessibility services ensureOnlyMockServicesEnabled(mContext, true, true); // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // configure the first mock service MockAccessibilityService firstService = MyFirstMockAccessibilityService.sInstance; AccessibilityServiceInfo firstInfo = MyFirstMockAccessibilityService.createDefaultInfo(); Loading Loading @@ -479,7 +494,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { secondService.replay(); // send the event mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_OWNER); mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_CURRENT); // verify if all expected methods have been called assertMockServiceVerifiedWithinTimeout(firstService); Loading @@ -488,12 +503,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testInterrupt() throws Exception { // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // enable the mock accessibility services ensureOnlyMockServicesEnabled(mContext, true, true); // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // configure the first mock service MockAccessibilityService firstService = MyFirstMockAccessibilityService.sInstance; firstService.setServiceInfo(MockAccessibilityService.createDefaultInfo()); Loading @@ -514,7 +529,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { secondService.replay(); // call the method under test mManagerService.interrupt(UserHandle.USER_OWNER); mManagerService.interrupt(UserHandle.USER_CURRENT); // verify if all expected methods have been called assertMockServiceVerifiedWithinTimeout(firstService); Loading @@ -534,7 +549,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { sentEvent.setContentDescription("ContentDescription"); sentEvent.setCurrentItemIndex(1); sentEvent.setEnabled(true); sentEvent.setEventType(AccessibilityEvent.TYPE_VIEW_CLICKED); sentEvent.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT); sentEvent.setEventTime(1000); sentEvent.setFromIndex(1); sentEvent.setFullScreen(true); Loading Loading @@ -568,8 +583,8 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { * @throws Exception If any error occurs. */ private void ensureAccessibilityEnabled(Context context, boolean enabled) throws Exception { boolean isEnabled = (Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1 ? true : false); boolean isEnabled = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1; if (isEnabled == enabled) { return; Loading Loading @@ -608,13 +623,14 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { servicesToEnable.append(MySecondMockAccessibilityService.sComponentName).append(":"); } Settings.Secure.putString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, servicesToEnable.toString()); // Optimization. If things will not change, we don't have to do anything. if (servicesToEnable.equals(enabledServices)) { return; } Settings.Secure.putString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, servicesToEnable.toString()); // we have enabled the services of interest and need to wait until they // are instantiated and started (if needed) and the system binds to them boolean firstMockServiceOK = false; Loading Loading @@ -664,13 +680,13 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { throws Exception { Exception lastVerifyException = null; long beginTime = SystemClock.uptimeMillis(); long pollTmeout = TIMEOUT_BINDER_CALL / 5; long pollTimeout = TIMEOUT_BINDER_CALL / 5; // poll until the timeout has elapsed while (SystemClock.uptimeMillis() - beginTime < TIMEOUT_BINDER_CALL) { // sleep first since immediate call will always fail try { Thread.sleep(pollTmeout); Thread.sleep(pollTimeout); } catch (InterruptedException ie) { /* ignore */ } Loading services/tests/servicestests/src/com/android/server/MockAccessibilityService.java +1 −1 Original line number Diff line number Diff line Loading @@ -62,7 +62,7 @@ public abstract class MockAccessibilityService extends AccessibilityService { */ public static AccessibilityServiceInfo createDefaultInfo() { AccessibilityServiceInfo defaultInfo = new AccessibilityServiceInfo(); defaultInfo.eventTypes = AccessibilityEvent.TYPE_VIEW_CLICKED; defaultInfo.eventTypes = AccessibilityEvent.TYPE_ANNOUNCEMENT; defaultInfo.feedbackType = AccessibilityServiceInfo.FEEDBACK_AUDIBLE; defaultInfo.flags = 0; defaultInfo.notificationTimeout = 0; Loading Loading
services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java +4 −10 Original line number Diff line number Diff line Loading @@ -205,9 +205,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { private final UserManager mUserManager; private final LockPatternUtils mLockPatternUtils; private int mCurrentUserId = UserHandle.USER_OWNER; private int mCurrentUserId = UserHandle.USER_SYSTEM; //TODO: Remove this hack private boolean mInitialized; Loading @@ -230,7 +228,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE); mSecurityPolicy = new SecurityPolicy(); mMainHandler = new MainHandler(mContext.getMainLooper()); mLockPatternUtils = new LockPatternUtils(context); registerBroadcastReceivers(); new AccessibilityContentObserver(mMainHandler).register( context.getContentResolver()); Loading Loading @@ -866,17 +863,18 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { } // Called only during settings restore; currently supports only the owner user // TODO: http://b/22388012 void restoreEnabledAccessibilityServicesLocked(String oldSetting, String newSetting) { readComponentNamesFromStringLocked(oldSetting, mTempComponentNameSet, false); readComponentNamesFromStringLocked(newSetting, mTempComponentNameSet, true); UserState userState = getUserStateLocked(UserHandle.USER_OWNER); UserState userState = getUserStateLocked(UserHandle.USER_SYSTEM); userState.mEnabledServices.clear(); userState.mEnabledServices.addAll(mTempComponentNameSet); persistComponentNamesToSettingLocked( Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, userState.mEnabledServices, UserHandle.USER_OWNER); UserHandle.USER_SYSTEM); onUserStateChangedLocked(userState); } Loading Loading @@ -1646,10 +1644,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { DisplayAdjustmentUtils.applyAdjustments(mContext, userState.mUserId); } private boolean hasRunningServicesLocked(UserState userState) { return !userState.mBoundServices.isEmpty() || !userState.mBindingServices.isEmpty(); } private MagnificationSpec getCompatibleMagnificationSpecLocked(int windowId) { IBinder windowToken = mGlobalWindowTokens.get(windowId); if (windowToken == null) { Loading
services/tests/servicestests/src/com/android/server/AccessibilityManagerServiceTest.java +68 −52 Original line number Diff line number Diff line Loading @@ -54,7 +54,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { * Timeout in which we are waiting for the system to start the mock * accessibility services. */ private static final long TIMEOUT_START_MOCK_ACCESSIBILITY_SERVICES = 300; private static final long TIMEOUT_START_MOCK_ACCESSIBILITY_SERVICES = 1000; /** * Timeout used for testing that a service is notified only upon a Loading @@ -67,6 +67,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { */ private IAccessibilityManager mManagerService; @Override protected void setUp() throws Exception { // Reset the state. ensureOnlyMockServicesEnabled(getContext(), false, false); } @Override public void setContext(Context context) { super.setContext(context); Loading @@ -92,6 +98,9 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testAddClient_AccessibilityDisabledThenEnabled() throws Exception { // at least some service must be enabled, otherwise accessibility will always be disabled. ensureOnlyMockServicesEnabled(mContext, true, false); // make sure accessibility is disabled ensureAccessibilityEnabled(mContext, false); Loading @@ -99,7 +108,8 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { MyMockAccessibilityManagerClient mockClient = new MyMockAccessibilityManagerClient(); // invoke the method under test final int stateFlagsDisabled = mManagerService.addClient(mockClient, UserHandle.USER_OWNER); final int stateFlagsDisabled = mManagerService.addClient(mockClient, UserHandle.USER_CURRENT); boolean enabledAccessibilityDisabled = (stateFlagsDisabled & AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED) != 0; Loading @@ -111,11 +121,11 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { ensureAccessibilityEnabled(mContext, true); // invoke the method under test final int stateFlagsEnabled = mManagerService.addClient(mockClient, UserHandle.USER_OWNER); final int stateFlagsEnabled = mManagerService.addClient(mockClient, UserHandle.USER_CURRENT); boolean enabledAccessibilityEnabled = (stateFlagsEnabled & AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED) != 0; // check expected result assertTrue("The client must be enabled since accessibility is enabled.", enabledAccessibilityEnabled); Loading @@ -123,6 +133,9 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testAddClient_AccessibilityEnabledThenDisabled() throws Exception { // at least some service must be enabled, otherwise accessibility will always be disabled. ensureOnlyMockServicesEnabled(mContext, true, false); // enable accessibility before registering the client ensureAccessibilityEnabled(mContext, true); Loading @@ -130,7 +143,8 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { MyMockAccessibilityManagerClient mockClient = new MyMockAccessibilityManagerClient(); // invoke the method under test final int stateFlagsEnabled = mManagerService.addClient(mockClient, UserHandle.USER_OWNER); final int stateFlagsEnabled = mManagerService.addClient(mockClient, UserHandle.USER_CURRENT); boolean enabledAccessibilityEnabled = (stateFlagsEnabled & AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED) != 0; Loading @@ -142,7 +156,8 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { ensureAccessibilityEnabled(mContext, false); // invoke the method under test final int stateFlagsDisabled = mManagerService.addClient(mockClient, UserHandle.USER_OWNER); final int stateFlagsDisabled = mManagerService.addClient(mockClient, UserHandle.USER_CURRENT); boolean enabledAccessibilityDisabled = (stateFlagsDisabled & AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED) != 0; Loading @@ -162,7 +177,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { // look for the two mock services for (AccessibilityServiceInfo info : mManagerService.getInstalledAccessibilityServiceList( UserHandle.USER_OWNER)) { UserHandle.USER_CURRENT)) { ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo; if (packageName.equals(serviceInfo.packageName)) { if (firstMockServiceClassName.equals(serviceInfo.name)) { Loading @@ -181,12 +196,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testSendAccessibilityEvent_OneService_MatchingPackageAndEventType() throws Exception { // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // enable the mock accessibility service ensureOnlyMockServicesEnabled(mContext, true, false); // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // configure the mock service MockAccessibilityService service = MyFirstMockAccessibilityService.sInstance; service.setServiceInfo(MockAccessibilityService.createDefaultInfo()); Loading @@ -203,7 +218,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { service.replay(); // send the event mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_OWNER); mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_CURRENT); // verify if all expected methods have been called assertMockServiceVerifiedWithinTimeout(service); Loading @@ -211,12 +226,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testSendAccessibilityEvent_OneService_NotMatchingPackage() throws Exception { // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // enable the mock accessibility service ensureOnlyMockServicesEnabled(mContext, true, false); // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // configure the mock service MockAccessibilityService service = MyFirstMockAccessibilityService.sInstance; service.setServiceInfo(MockAccessibilityService.createDefaultInfo()); Loading @@ -233,7 +248,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { service.replay(); // send the event mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_OWNER); mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_CURRENT); // verify if all expected methods have been called assertMockServiceVerifiedWithinTimeout(service); Loading @@ -241,12 +256,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testSendAccessibilityEvent_OneService_NotMatchingEventType() throws Exception { // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // enable the mock accessibility service ensureOnlyMockServicesEnabled(mContext, true, false); // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // configure the mock service MockAccessibilityService service = MyFirstMockAccessibilityService.sInstance; service.setServiceInfo(MockAccessibilityService.createDefaultInfo()); Loading @@ -263,7 +278,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { service.replay(); // send the event mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_OWNER); mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_CURRENT); // verify if all expected methods have been called assertMockServiceVerifiedWithinTimeout(service); Loading @@ -271,12 +286,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testSendAccessibilityEvent_OneService_NotifivationAfterTimeout() throws Exception { // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // enable the mock accessibility service ensureOnlyMockServicesEnabled(mContext, true, false); // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // configure the mock service MockAccessibilityService service = MyFirstMockAccessibilityService.sInstance; AccessibilityServiceInfo info = MockAccessibilityService.createDefaultInfo(); Loading @@ -299,8 +314,8 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { service.replay(); // send the events mManagerService.sendAccessibilityEvent(firstEvent, UserHandle.USER_OWNER); mManagerService.sendAccessibilityEvent(secondEvent, UserHandle.USER_OWNER); mManagerService.sendAccessibilityEvent(firstEvent, UserHandle.USER_CURRENT); mManagerService.sendAccessibilityEvent(secondEvent, UserHandle.USER_CURRENT); // wait for #sendAccessibilityEvent to reach the backing service Thread.sleep(TIMEOUT_BINDER_CALL); Loading @@ -322,12 +337,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType_DiffFeedback() throws Exception { // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // enable the mock accessibility services ensureOnlyMockServicesEnabled(mContext, true, true); // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // configure the first mock service MockAccessibilityService firstService = MyFirstMockAccessibilityService.sInstance; AccessibilityServiceInfo firstInfo = MockAccessibilityService.createDefaultInfo(); Loading Loading @@ -356,7 +371,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { secondService.replay(); // send the event mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_OWNER); mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_CURRENT); // verify if all expected methods have been called assertMockServiceVerifiedWithinTimeout(firstService); Loading @@ -366,12 +381,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType() throws Exception { // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // enable the mock accessibility services ensureOnlyMockServicesEnabled(mContext, true, true); // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // configure the first mock service MockAccessibilityService firstService = MyFirstMockAccessibilityService.sInstance; firstService.setServiceInfo(MockAccessibilityService.createDefaultInfo()); Loading @@ -395,7 +410,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { secondService.replay(); // send the event mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_OWNER); mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_CURRENT); // verify if all expected methods have been called assertMockServiceVerifiedWithinTimeout(firstService); Loading @@ -405,12 +420,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType_OneDefault() throws Exception { // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // enable the mock accessibility services ensureOnlyMockServicesEnabled(mContext, true, true); // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // configure the first mock service MockAccessibilityService firstService = MyFirstMockAccessibilityService.sInstance; AccessibilityServiceInfo firstInfo = MyFirstMockAccessibilityService.createDefaultInfo(); Loading @@ -436,7 +451,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { secondService.replay(); // send the event mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_OWNER); mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_CURRENT); // verify if all expected methods have been called assertMockServiceVerifiedWithinTimeout(firstService); Loading @@ -446,12 +461,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType_TwoDefault() throws Exception { // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // enable the mock accessibility services ensureOnlyMockServicesEnabled(mContext, true, true); // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // configure the first mock service MockAccessibilityService firstService = MyFirstMockAccessibilityService.sInstance; AccessibilityServiceInfo firstInfo = MyFirstMockAccessibilityService.createDefaultInfo(); Loading Loading @@ -479,7 +494,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { secondService.replay(); // send the event mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_OWNER); mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_CURRENT); // verify if all expected methods have been called assertMockServiceVerifiedWithinTimeout(firstService); Loading @@ -488,12 +503,12 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @LargeTest public void testInterrupt() throws Exception { // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // enable the mock accessibility services ensureOnlyMockServicesEnabled(mContext, true, true); // set the accessibility setting value ensureAccessibilityEnabled(mContext, true); // configure the first mock service MockAccessibilityService firstService = MyFirstMockAccessibilityService.sInstance; firstService.setServiceInfo(MockAccessibilityService.createDefaultInfo()); Loading @@ -514,7 +529,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { secondService.replay(); // call the method under test mManagerService.interrupt(UserHandle.USER_OWNER); mManagerService.interrupt(UserHandle.USER_CURRENT); // verify if all expected methods have been called assertMockServiceVerifiedWithinTimeout(firstService); Loading @@ -534,7 +549,7 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { sentEvent.setContentDescription("ContentDescription"); sentEvent.setCurrentItemIndex(1); sentEvent.setEnabled(true); sentEvent.setEventType(AccessibilityEvent.TYPE_VIEW_CLICKED); sentEvent.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT); sentEvent.setEventTime(1000); sentEvent.setFromIndex(1); sentEvent.setFullScreen(true); Loading Loading @@ -568,8 +583,8 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { * @throws Exception If any error occurs. */ private void ensureAccessibilityEnabled(Context context, boolean enabled) throws Exception { boolean isEnabled = (Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1 ? true : false); boolean isEnabled = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1; if (isEnabled == enabled) { return; Loading Loading @@ -608,13 +623,14 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { servicesToEnable.append(MySecondMockAccessibilityService.sComponentName).append(":"); } Settings.Secure.putString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, servicesToEnable.toString()); // Optimization. If things will not change, we don't have to do anything. if (servicesToEnable.equals(enabledServices)) { return; } Settings.Secure.putString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, servicesToEnable.toString()); // we have enabled the services of interest and need to wait until they // are instantiated and started (if needed) and the system binds to them boolean firstMockServiceOK = false; Loading Loading @@ -664,13 +680,13 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { throws Exception { Exception lastVerifyException = null; long beginTime = SystemClock.uptimeMillis(); long pollTmeout = TIMEOUT_BINDER_CALL / 5; long pollTimeout = TIMEOUT_BINDER_CALL / 5; // poll until the timeout has elapsed while (SystemClock.uptimeMillis() - beginTime < TIMEOUT_BINDER_CALL) { // sleep first since immediate call will always fail try { Thread.sleep(pollTmeout); Thread.sleep(pollTimeout); } catch (InterruptedException ie) { /* ignore */ } Loading
services/tests/servicestests/src/com/android/server/MockAccessibilityService.java +1 −1 Original line number Diff line number Diff line Loading @@ -62,7 +62,7 @@ public abstract class MockAccessibilityService extends AccessibilityService { */ public static AccessibilityServiceInfo createDefaultInfo() { AccessibilityServiceInfo defaultInfo = new AccessibilityServiceInfo(); defaultInfo.eventTypes = AccessibilityEvent.TYPE_VIEW_CLICKED; defaultInfo.eventTypes = AccessibilityEvent.TYPE_ANNOUNCEMENT; defaultInfo.feedbackType = AccessibilityServiceInfo.FEEDBACK_AUDIBLE; defaultInfo.flags = 0; defaultInfo.notificationTimeout = 0; Loading