Search in sources :

Example 61 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 62 with AccessibilityEvent

use of android.view.accessibility.AccessibilityEvent in project XobotOS by xamarin.

the class AdapterView method onRequestSendAccessibilityEvent.

@Override
public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
    if (super.onRequestSendAccessibilityEvent(child, event)) {
        // Add a record for ourselves as well.
        AccessibilityEvent record = AccessibilityEvent.obtain();
        onInitializeAccessibilityEvent(record);
        // Populate with the text of the requesting child.
        child.dispatchPopulateAccessibilityEvent(record);
        event.appendRecord(record);
        return true;
    }
    return false;
}
Also used : AccessibilityEvent(android.view.accessibility.AccessibilityEvent)

Example 63 with AccessibilityEvent

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

the class UiAutomation method executeAndWaitForEvent.

/**
     * Executes a command and waits for a specific accessibility event up to a
     * given wait timeout. To detect a sequence of events one can implement a
     * filter that keeps track of seen events of the expected sequence and
     * returns true after the last event of that sequence is received.
     * <p>
     * <strong>Note:</strong> It is caller's responsibility to recycle the returned event.
     * </p>
     * @param command The command to execute.
     * @param filter Filter that recognizes the expected event.
     * @param timeoutMillis The wait timeout in milliseconds.
     *
     * @throws TimeoutException If the expected event is not received within the timeout.
     */
public AccessibilityEvent executeAndWaitForEvent(Runnable command, AccessibilityEventFilter filter, long timeoutMillis) throws TimeoutException {
    // Acquire the lock and prepare for receiving events.
    synchronized (mLock) {
        throwIfNotConnectedLocked();
        mEventQueue.clear();
        // Prepare to wait for an event.
        mWaitingForEventDelivery = true;
    }
    // Note: We have to release the lock since calling out with this lock held
    // can bite. We will correctly filter out events from other interactions,
    // so starting to collect events before running the action is just fine.
    // We will ignore events from previous interactions.
    final long executionStartTimeMillis = SystemClock.uptimeMillis();
    // Execute the command *without* the lock being held.
    command.run();
    // Acquire the lock and wait for the event.
    synchronized (mLock) {
        try {
            // Wait for the event.
            final long startTimeMillis = SystemClock.uptimeMillis();
            while (true) {
                // Drain the event queue
                while (!mEventQueue.isEmpty()) {
                    AccessibilityEvent event = mEventQueue.remove(0);
                    // Ignore events from previous interactions.
                    if (event.getEventTime() < executionStartTimeMillis) {
                        continue;
                    }
                    if (filter.accept(event)) {
                        return event;
                    }
                    event.recycle();
                }
                // Check if timed out and if not wait.
                final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
                final long remainingTimeMillis = timeoutMillis - elapsedTimeMillis;
                if (remainingTimeMillis <= 0) {
                    throw new TimeoutException("Expected event not received within: " + timeoutMillis + " ms.");
                }
                try {
                    mLock.wait(remainingTimeMillis);
                } catch (InterruptedException ie) {
                /* ignore */
                }
            }
        } finally {
            mWaitingForEventDelivery = false;
            mEventQueue.clear();
            mLock.notifyAll();
        }
    }
}
Also used : AccessibilityEvent(android.view.accessibility.AccessibilityEvent) TimeoutException(java.util.concurrent.TimeoutException)

Example 64 with AccessibilityEvent

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

the class TextView method sendAccessibilityEventTypeViewTextChanged.

void sendAccessibilityEventTypeViewTextChanged(CharSequence beforeText, int fromIndex, int removedCount, int addedCount) {
    AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED);
    event.setFromIndex(fromIndex);
    event.setRemovedCount(removedCount);
    event.setAddedCount(addedCount);
    event.setBeforeText(beforeText);
    sendAccessibilityEventUnchecked(event);
}
Also used : AccessibilityEvent(android.view.accessibility.AccessibilityEvent)

Example 65 with AccessibilityEvent

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

the class ExploreByTouchHelper method createEventForChild.

/**
     * Constructs and returns an {@link AccessibilityEvent} populated with
     * information about the specified item.
     *
     * @param virtualViewId The virtual view id for the item for which to
     *            construct an event.
     * @param eventType The type of event to construct.
     * @return An {@link AccessibilityEvent} populated with information about
     *         the specified item.
     */
private AccessibilityEvent createEventForChild(int virtualViewId, int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.setEnabled(true);
    event.setClassName(DEFAULT_CLASS_NAME);
    // Allow the client to populate the event.
    onPopulateEventForVirtualView(virtualViewId, event);
    // Make sure the developer is following the rules.
    if (event.getText().isEmpty() && (event.getContentDescription() == null)) {
        throw new RuntimeException("Callbacks must add text or a content description in " + "populateEventForVirtualViewId()");
    }
    // Don't allow the client to override these properties.
    event.setPackageName(mView.getContext().getPackageName());
    event.setSource(mView, virtualViewId);
    return event;
}
Also used : AccessibilityEvent(android.view.accessibility.AccessibilityEvent)

Aggregations

AccessibilityEvent (android.view.accessibility.AccessibilityEvent)241 AccessibilityManager (android.view.accessibility.AccessibilityManager)49 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 Context (android.content.Context)6 RemoteException (android.os.RemoteException)6 StatusBarNotification (android.service.notification.StatusBarNotification)6 AccessibilityRecordCompat (android.support.v4.view.accessibility.AccessibilityRecordCompat)6 ViewGroup (android.view.ViewGroup)6 Test (org.junit.Test)6 SuppressLint (android.annotation.SuppressLint)5 AccessibilityEventFilter (android.app.UiAutomation.AccessibilityEventFilter)5 OnAccessibilityEventListener (android.app.UiAutomation.OnAccessibilityEventListener)5 UiAutomationShellWrapper (com.android.uiautomator.core.UiAutomationShellWrapper)5