Search in sources :

Example 11 with AccessibilityEvent

use of android.view.accessibility.AccessibilityEvent in project platform_frameworks_base by android.

the class AccessibilityManagerServiceTest method testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType_TwoDefault.

@LargeTest
public void testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType_TwoDefault() throws Exception {
    // 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();
    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_CURRENT);
    // 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 12 with AccessibilityEvent

use of android.view.accessibility.AccessibilityEvent in project platform_frameworks_base by android.

the class AccessibilityManagerServiceTest method testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType_DiffFeedback.

@LargeTest
public void testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType_DiffFeedback() throws Exception {
    // 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();
    firstInfo.feedbackType = AccessibilityServiceInfo.FEEDBACK_AUDIBLE;
    firstService.setServiceInfo(firstInfo);
    // configure the second mock service
    MockAccessibilityService secondService = MySecondMockAccessibilityService.sInstance;
    AccessibilityServiceInfo secondInfo = MockAccessibilityService.createDefaultInfo();
    secondInfo.feedbackType = AccessibilityServiceInfo.FEEDBACK_HAPTIC;
    secondService.setServiceInfo(secondInfo);
    // 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.expectEvent(sentEvent);
    secondService.replay();
    // send the event
    mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_CURRENT);
    // 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 13 with AccessibilityEvent

use of android.view.accessibility.AccessibilityEvent in project platform_frameworks_base by android.

the class AccessibilityManagerServiceTest method testSendAccessibilityEvent_OneService_MatchingPackageAndEventType.

@LargeTest
public void testSendAccessibilityEvent_OneService_MatchingPackageAndEventType() 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;
    service.setServiceInfo(MockAccessibilityService.createDefaultInfo());
    // wait for the binder call 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
    service.expectEvent(sentEvent);
    service.replay();
    // send the event
    mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_CURRENT);
    // verify if all expected methods have been called
    assertMockServiceVerifiedWithinTimeout(service);
}
Also used : AccessibilityEvent(android.view.accessibility.AccessibilityEvent) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 14 with AccessibilityEvent

use of android.view.accessibility.AccessibilityEvent in project platform_frameworks_base by android.

the class AccessibilityManagerServiceTest method testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType_OneDefault.

@LargeTest
public void testSendAccessibilityEvent_TwoServices_MatchingPackageAndEventType_OneDefault() throws Exception {
    // 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();
    firstInfo.flags = AccessibilityServiceInfo.DEFAULT;
    firstService.setServiceInfo(firstInfo);
    // configure the second mock service
    MockAccessibilityService secondService = MySecondMockAccessibilityService.sInstance;
    secondService.setServiceInfo(MySecondMockAccessibilityService.createDefaultInfo());
    // 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.replay();
    // set expectations for the second mock service
    secondService.expectEvent(sentEvent);
    secondService.replay();
    // send the event
    mManagerService.sendAccessibilityEvent(sentEvent, UserHandle.USER_CURRENT);
    // 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 15 with AccessibilityEvent

use of android.view.accessibility.AccessibilityEvent in project ZI by yixia.

the class Manager method announceForAccessibilityCompat.

/**
   * Generates and dispatches an SDK-specific spoken announcement.
   * <p>
   * For backwards compatibility, we're constructing an event from scratch
   * using the appropriate event type. If your application only targets SDK
   * 16+, you can just call View.announceForAccessibility(CharSequence).
   * </p>
   * <p/>
   * note: AccessibilityManager is only available from API lvl 4.
   * <p/>
   * Adapted from https://http://eyes-free.googlecode.com/files/accessibility_codelab_demos_v2_src.zip
   * via https://github.com/coreform/android-formidable-validation
   *
   * @param context
   *   Used to get {@link AccessibilityManager}
   * @param text
   *   The text to announce.
   */
public static void announceForAccessibilityCompat(Context context, CharSequence text) {
    if (Build.VERSION.SDK_INT >= 4) {
        AccessibilityManager accessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
        if (!accessibilityManager.isEnabled()) {
            return;
        }
        // Prior to SDK 16, announcements could only be made through FOCUSED
        // events. Jelly Bean (SDK 16) added support for speaking text verbatim
        // using the ANNOUNCEMENT event type.
        final int eventType;
        if (Build.VERSION.SDK_INT < 16) {
            eventType = AccessibilityEvent.TYPE_VIEW_FOCUSED;
        } else {
            eventType = AccessibilityEventCompat.TYPE_ANNOUNCEMENT;
        }
        // Construct an accessibility event with the minimum recommended
        // attributes. An event without a class name or package may be dropped.
        final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
        event.getText().add(text);
        event.setClassName(Manager.class.getName());
        event.setPackageName(context.getPackageName());
        // Sends the event directly through the accessibility manager. If your
        // application only targets SDK 14+, you should just call
        // getParent().requestSendAccessibilityEvent(this, event);
        accessibilityManager.sendAccessibilityEvent(event);
    }
}
Also used : AccessibilityManager(android.view.accessibility.AccessibilityManager) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) AccessibilityManager(android.view.accessibility.AccessibilityManager)

Aggregations

AccessibilityEvent (android.view.accessibility.AccessibilityEvent)234 AccessibilityManager (android.view.accessibility.AccessibilityManager)47 LargeTest (android.test.suitebuilder.annotation.LargeTest)40 AccessibilityServiceInfo (android.accessibilityservice.AccessibilityServiceInfo)20 ViewParent (android.view.ViewParent)13 TimeoutException (java.util.concurrent.TimeoutException)11 MediumTest (android.test.suitebuilder.annotation.MediumTest)10 IAccessibilityManager (android.view.accessibility.IAccessibilityManager)10 Notification (android.app.Notification)7 ITransientNotification (android.app.ITransientNotification)6 RemoteException (android.os.RemoteException)6 StatusBarNotification (android.service.notification.StatusBarNotification)6 SuppressLint (android.annotation.SuppressLint)5 AccessibilityEventFilter (android.app.UiAutomation.AccessibilityEventFilter)5 OnAccessibilityEventListener (android.app.UiAutomation.OnAccessibilityEventListener)5 ViewGroup (android.view.ViewGroup)5 UiAutomationShellWrapper (com.android.uiautomator.core.UiAutomationShellWrapper)5 SimpleDateFormat (java.text.SimpleDateFormat)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5