Search in sources :

Example 76 with AccessibilityServiceInfo

use of android.accessibilityservice.AccessibilityServiceInfo in project platform_frameworks_base by android.

the class UiAutomationConnection method registerUiTestAutomationServiceLocked.

private void registerUiTestAutomationServiceLocked(IAccessibilityServiceClient client, int flags) {
    IAccessibilityManager manager = IAccessibilityManager.Stub.asInterface(ServiceManager.getService(Context.ACCESSIBILITY_SERVICE));
    final 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 | AccessibilityServiceInfo.FLAG_FORCE_DIRECT_BOOT_AWARE;
    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, flags);
        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)

Example 77 with AccessibilityServiceInfo

use of android.accessibilityservice.AccessibilityServiceInfo in project platform_frameworks_base by android.

the class AccessibilityManagerServiceTest method testSendAccessibilityEvent_OneService_NotifivationAfterTimeout.

@LargeTest
public void testSendAccessibilityEvent_OneService_NotifivationAfterTimeout() throws Exception {
    // 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();
    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_CURRENT);
    mManagerService.sendAccessibilityEvent(secondEvent, UserHandle.USER_CURRENT);
    // 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 78 with AccessibilityServiceInfo

use of android.accessibilityservice.AccessibilityServiceInfo in project platform_frameworks_base by android.

the class AccessibilityManagerServiceTest method testGetAccessibilityServicesList.

@LargeTest
public void testGetAccessibilityServicesList() throws Exception {
    boolean firstMockServiceInstalled = false;
    boolean secondMockServiceInstalled = false;
    String packageName = getContext().getPackageName();
    String firstMockServiceClassName = MyFirstMockAccessibilityService.class.getName();
    String secondMockServiceClassName = MySecondMockAccessibilityService.class.getName();
    // look for the two mock services
    for (AccessibilityServiceInfo info : mManagerService.getInstalledAccessibilityServiceList(UserHandle.USER_CURRENT)) {
        ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo;
        if (packageName.equals(serviceInfo.packageName)) {
            if (firstMockServiceClassName.equals(serviceInfo.name)) {
                firstMockServiceInstalled = true;
            } else if (secondMockServiceClassName.equals(serviceInfo.name)) {
                secondMockServiceInstalled = true;
            }
        }
    }
    // check expected result
    assertTrue("First mock service must be installed", firstMockServiceInstalled);
    assertTrue("Second mock service must be installed", secondMockServiceInstalled);
}
Also used : AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) ServiceInfo(android.content.pm.ServiceInfo) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 79 with AccessibilityServiceInfo

use of android.accessibilityservice.AccessibilityServiceInfo in project platform_frameworks_base by android.

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 = new AccessibilityServiceInfo();
    accessibilityServiceInfo.packageNames = new String[] { "foo.bar" };
    expectedServices.add(accessibilityServiceInfo);
    // configure the mock service behavior
    when(mMockService.getInstalledAccessibilityServiceList(anyInt())).thenReturn(expectedServices);
    // invoke the method under test
    AccessibilityManager manager = createManager(true);
    List<AccessibilityServiceInfo> receivedServices = manager.getInstalledAccessibilityServiceList();
    verify(mMockService).getInstalledAccessibilityServiceList(UserHandle.USER_CURRENT);
    // check expected result (list equals() compares it contents as well)
    assertEquals("All expected services must be returned", expectedServices, receivedServices);
}
Also used : AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) AccessibilityManager(android.view.accessibility.AccessibilityManager) IAccessibilityManager(android.view.accessibility.IAccessibilityManager) ArrayList(java.util.ArrayList) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 80 with AccessibilityServiceInfo

use of android.accessibilityservice.AccessibilityServiceInfo in project platform_frameworks_base by android.

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_ANNOUNCEMENT;
    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)

Aggregations

AccessibilityServiceInfo (android.accessibilityservice.AccessibilityServiceInfo)123 ComponentName (android.content.ComponentName)30 Point (android.graphics.Point)30 ServiceInfo (android.content.pm.ServiceInfo)29 ArrayList (java.util.ArrayList)26 LargeTest (android.test.suitebuilder.annotation.LargeTest)25 ResolveInfo (android.content.pm.ResolveInfo)20 AccessibilityEvent (android.view.accessibility.AccessibilityEvent)20 AccessibilityManager (android.view.accessibility.AccessibilityManager)19 IAccessibilityManager (android.view.accessibility.IAccessibilityManager)17 AccessibilityService (android.accessibilityservice.AccessibilityService)13 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)13 RemoteException (android.os.RemoteException)7 PendingIntent (android.app.PendingIntent)6 Intent (android.content.Intent)6 UserInfo (android.content.pm.UserInfo)6 ParcelableString (com.android.internal.util.ParcelableString)6 IOException (java.io.IOException)6 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)6 UserManager (android.os.UserManager)5