Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c783066 authored by Svetoslav's avatar Svetoslav Committed by Android (Google) Code Review
Browse files

Merge "Fixing bugs exposed when moving accessibility CTS tests to UiAutomation." into jb-mr2-dev

parents 952b3102 db7da0eb
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -375,6 +375,23 @@ public class AccessibilityServiceInfo implements Parcelable {
        /* do nothing */
    }

    /**
     * Creates a new instance.
     *
     * @param isAutomation Whether this is a test automation service.
     *
     * @hide
     */
    public AccessibilityServiceInfo(boolean isAutomation) {
        // Automation service can do anything.
        if (isAutomation) {
            mCapabilities |= CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT
                    | CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION
                    | CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITY
                    | CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS;
        }
    }

    /**
     * Creates a new instance.
     *
+13 −6
Original line number Diff line number Diff line
@@ -443,18 +443,25 @@ public final class UiAutomation {
     */
    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.
        // 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();
@@ -463,7 +470,7 @@ public final class UiAutomation {
                    while (!mEventQueue.isEmpty()) {
                        AccessibilityEvent event = mEventQueue.remove(0);
                        // Ignore events from previous interactions.
                        if (event.getEventTime() <= executionStartTimeMillis) {
                        if (event.getEventTime() < executionStartTimeMillis) {
                            continue;
                        }
                        if (filter.accept(event)) {
+1 −1
Original line number Diff line number Diff line
@@ -158,7 +158,7 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub {
    private void registerUiTestAutomationServiceLocked(IAccessibilityServiceClient client) {
        IAccessibilityManager manager = IAccessibilityManager.Stub.asInterface(
                ServiceManager.getService(Context.ACCESSIBILITY_SERVICE));
        AccessibilityServiceInfo info = new AccessibilityServiceInfo();
        AccessibilityServiceInfo info = new AccessibilityServiceInfo(true);
        info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
        info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
        info.flags |= AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS
+1 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ public class AccessibilityNodeInfoCache {
                } break;
                case AccessibilityEvent.TYPE_VIEW_FOCUSED:
                case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED:
                case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED:
                case AccessibilityEvent.TYPE_VIEW_SELECTED:
                case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED:
                case AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED: {
+7 −21
Original line number Diff line number Diff line
@@ -8042,7 +8042,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            info.setEditable(true);
        }

        if (TextUtils.isEmpty(getContentDescription()) && !TextUtils.isEmpty(mText)) {
        if (!TextUtils.isEmpty(mText)) {
            info.addAction(AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY);
            info.addAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY);
            info.setMovementGranularities(AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER
@@ -8051,6 +8051,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                    | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH
                    | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
        }

        if (isFocused()) {
            if (canSelectText()) {
                info.addAction(AccessibilityNodeInfo.ACTION_SET_SELECTION);
@@ -8655,14 +8656,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     */
    @Override
    public CharSequence getIterableTextForAccessibility() {
        if (!TextUtils.isEmpty(mText)) {
        if (!(mText instanceof Spannable)) {
            setText(mText, BufferType.SPANNABLE);
        }
        return mText;
    }
        return super.getIterableTextForAccessibility();
    }

    /**
     * @hide
@@ -8697,13 +8695,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     */
    @Override
    public int getAccessibilitySelectionStart() {
        if (TextUtils.isEmpty(getContentDescription())) {
            final int selectionStart = getSelectionStart();
            if (selectionStart >= 0) {
                return selectionStart;
            }
        }
        return ACCESSIBILITY_CURSOR_POSITION_UNDEFINED;
        return getSelectionStart();
    }

    /**
@@ -8718,13 +8710,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     */
    @Override
    public int getAccessibilitySelectionEnd() {
        if (TextUtils.isEmpty(getContentDescription())) {
            final int selectionEnd = getSelectionEnd();
            if (selectionEnd >= 0) {
                return selectionEnd;
            }
        }
        return ACCESSIBILITY_CURSOR_POSITION_UNDEFINED;
        return getSelectionEnd();
    }

    /**
Loading