Search in sources :

Example 6 with AccessibilityServiceInfo

use of android.accessibilityservice.AccessibilityServiceInfo in project android_frameworks_base by ParanoidAndroid.

the class AccessibilityManagerServiceTest method testSendAccessibilityEvent_OneService_NotifivationAfterTimeout.

@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);
    // configure the mock service
    MockAccessibilityService service = MyFirstMockAccessibilityService.sInstance;
    AccessibilityServiceInfo info = MockAccessibilityService.createDefaultInfo();
    info.notificationTimeout = TIMEOUT_TEST_NOTIFICATION_TIMEOUT;
    service.setServiceInfo(info);
    // wait for the binder call to #setService to complete
    Thread.sleep(TIMEOUT_BINDER_CALL);
    // create and populate the first event to be sent
    AccessibilityEvent firstEvent = AccessibilityEvent.obtain();
    fullyPopulateDefaultAccessibilityEvent(firstEvent);
    // create and populate the second event to be sent
    AccessibilityEvent secondEvent = AccessibilityEvent.obtain();
    fullyPopulateDefaultAccessibilityEvent(secondEvent);
    // set expectations
    service.expectEvent(secondEvent);
    service.replay();
    // send the events
    mManagerService.sendAccessibilityEvent(firstEvent, UserHandle.USER_OWNER);
    mManagerService.sendAccessibilityEvent(secondEvent, UserHandle.USER_OWNER);
    // wait for #sendAccessibilityEvent to reach the backing service
    Thread.sleep(TIMEOUT_BINDER_CALL);
    try {
        service.verify();
        fail("No events must be dispatched before the expiration of the notification timeout.");
    } catch (IllegalStateException ise) {
    /* expected */
    }
    // wait for the configured notification timeout to expire
    Thread.sleep(TIMEOUT_TEST_NOTIFICATION_TIMEOUT);
    // verify if all expected methods have been called
    assertMockServiceVerifiedWithinTimeout(service);
}
Also used : AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 7 with AccessibilityServiceInfo

use of android.accessibilityservice.AccessibilityServiceInfo in project android_frameworks_base by ParanoidAndroid.

the class AccessibilityManagerServiceTest method testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType_TwoDefault.

@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);
    // configure the first mock service
    MockAccessibilityService firstService = MyFirstMockAccessibilityService.sInstance;
    AccessibilityServiceInfo firstInfo = MyFirstMockAccessibilityService.createDefaultInfo();
    firstInfo.flags = AccessibilityServiceInfo.DEFAULT;
    firstService.setServiceInfo(firstInfo);
    // configure the second mock service
    MockAccessibilityService secondService = MySecondMockAccessibilityService.sInstance;
    AccessibilityServiceInfo secondInfo = MyFirstMockAccessibilityService.createDefaultInfo();
    secondInfo.flags = AccessibilityServiceInfo.DEFAULT;
    secondService.setServiceInfo(firstInfo);
    // wait for the binder calls to #setService to complete
    Thread.sleep(TIMEOUT_BINDER_CALL);
    // create and populate an event to be sent
    AccessibilityEvent sentEvent = AccessibilityEvent.obtain();
    fullyPopulateDefaultAccessibilityEvent(sentEvent);
    // set expectations for the first mock service
    firstService.expectEvent(sentEvent);
    firstService.replay();
    // set expectations for the second mock service
    secondService.replay();
    // send the event
    mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_OWNER);
    // verify if all expected methods have been called
    assertMockServiceVerifiedWithinTimeout(firstService);
    assertMockServiceVerifiedWithinTimeout(secondService);
}
Also used : AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 8 with AccessibilityServiceInfo

use of android.accessibilityservice.AccessibilityServiceInfo in project android_frameworks_base by ParanoidAndroid.

the class AccessibilityManagerTest method testGetAccessibilityServiceList.

@MediumTest
public void testGetAccessibilityServiceList() throws Exception {
    // create a list of installed accessibility services the mock service returns
    List<AccessibilityServiceInfo> expectedServices = new ArrayList<AccessibilityServiceInfo>();
    AccessibilityServiceInfo accessibilityServiceInfo = new AccessibilityServiceInfo();
    accessibilityServiceInfo.packageNames = new String[] { "foo.bar" };
    expectedServices.add(accessibilityServiceInfo);
    // configure the mock service behavior
    IAccessibilityManager mockServiceInterface = mMockServiceInterface;
    expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient(), UserHandle.USER_OWNER)).andReturn(AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED);
    expect(mockServiceInterface.getInstalledAccessibilityServiceList(UserHandle.USER_OWNER)).andReturn(expectedServices);
    replay(mockServiceInterface);
    // invoke the method under test
    AccessibilityManager manager = new AccessibilityManager(mContext, mockServiceInterface, UserHandle.USER_OWNER);
    List<AccessibilityServiceInfo> receivedServices = manager.getInstalledAccessibilityServiceList();
    // check expected result (list equals() compares it contents as well)
    assertEquals("All expected services must be returned", receivedServices, expectedServices);
    // verify the mock service was properly called
    verify(mockServiceInterface);
}
Also used : AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) IAccessibilityManager(android.view.accessibility.IAccessibilityManager) AccessibilityManager(android.view.accessibility.AccessibilityManager) IAccessibilityManager(android.view.accessibility.IAccessibilityManager) ArrayList(java.util.ArrayList) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 9 with AccessibilityServiceInfo

use of android.accessibilityservice.AccessibilityServiceInfo in project android_frameworks_base by ParanoidAndroid.

the class MockAccessibilityService method createDefaultInfo.

/**
     * Creates an {@link AccessibilityServiceInfo} populated with default
     * values.
     *
     * @return The default info.
     */
public static AccessibilityServiceInfo createDefaultInfo() {
    AccessibilityServiceInfo defaultInfo = new AccessibilityServiceInfo();
    defaultInfo.eventTypes = AccessibilityEvent.TYPE_VIEW_CLICKED;
    defaultInfo.feedbackType = AccessibilityServiceInfo.FEEDBACK_AUDIBLE;
    defaultInfo.flags = 0;
    defaultInfo.notificationTimeout = 0;
    defaultInfo.packageNames = new String[] { "foo.bar.baz" };
    return defaultInfo;
}
Also used : AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo)

Example 10 with AccessibilityServiceInfo

use of android.accessibilityservice.AccessibilityServiceInfo in project android_frameworks_base by ParanoidAndroid.

the class UiAutomationConnection method registerUiTestAutomationServiceLocked.

private void registerUiTestAutomationServiceLocked(IAccessibilityServiceClient client) {
    IAccessibilityManager manager = IAccessibilityManager.Stub.asInterface(ServiceManager.getService(Context.ACCESSIBILITY_SERVICE));
    AccessibilityServiceInfo info = new AccessibilityServiceInfo();
    info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
    info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
    info.flags |= AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS | AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS;
    info.setCapabilities(AccessibilityServiceInfo.CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT | AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION | AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITY | AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS);
    try {
        // Calling out with a lock held is fine since if the system
        // process is gone the client calling in will be killed.
        manager.registerUiTestAutomationService(mToken, client, info);
        mClient = client;
    } catch (RemoteException re) {
        throw new IllegalStateException("Error while registering UiTestAutomationService.", re);
    }
}
Also used : IAccessibilityManager(android.view.accessibility.IAccessibilityManager) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) RemoteException(android.os.RemoteException)

Aggregations

AccessibilityServiceInfo (android.accessibilityservice.AccessibilityServiceInfo)210 ServiceInfo (android.content.pm.ServiceInfo)69 ComponentName (android.content.ComponentName)64 AccessibilityManager (android.view.accessibility.AccessibilityManager)54 ArrayList (java.util.ArrayList)50 ResolveInfo (android.content.pm.ResolveInfo)45 Point (android.graphics.Point)30 LargeTest (android.test.suitebuilder.annotation.LargeTest)25 AccessibilityEvent (android.view.accessibility.AccessibilityEvent)20 Bundle (android.os.Bundle)17 IAccessibilityManager (android.view.accessibility.IAccessibilityManager)17 AccessibilityService (android.accessibilityservice.AccessibilityService)13 Drawable (android.graphics.drawable.Drawable)13 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)13 Intent (android.content.Intent)12 HashSet (java.util.HashSet)12 RemoteException (android.os.RemoteException)9 EnforcedAdmin (com.android.settingslib.RestrictedLockUtils.EnforcedAdmin)8 RestrictedPreference (com.android.settingslib.RestrictedPreference)8 IOException (java.io.IOException)8