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

Commit 4d3eec41 authored by Phil Weaver's avatar Phil Weaver
Browse files

Keep services updated of added views.

We were marking subtree events as not important for
accessibility based on the root view, but that doesn't
take into account the fact that important children may have
changed. In particular, adding a View to the hierarchy was
sometimes marked as not important because the layout it was
attached to was not important.

Also fixing an issue with UiAutomation where it called out
to the test filter with a lock held.

Also fixing an issue where nodes that are the source of
accessibility events are always marked as important for
accessibility.

Bug: 31226561
Change-Id: Ib619948ba1bbcfd00aef1d10726152f6cf2dfccd
parent 155374e8
Loading
Loading
Loading
Loading
+36 −27
Original line number Diff line number Diff line
@@ -580,14 +580,18 @@ public final class UiAutomation {
        command.run();

        // Acquire the lock and wait for the event.
        synchronized (mLock) {
        try {
            // Wait for the event.
            final long startTimeMillis = SystemClock.uptimeMillis();
            while (true) {
                List<AccessibilityEvent> localEvents = new ArrayList<>();
                synchronized (mLock) {
                    localEvents.addAll(mEventQueue);
                    mEventQueue.clear();
                }
                // Drain the event queue
                    while (!mEventQueue.isEmpty()) {
                        AccessibilityEvent event = mEventQueue.remove(0);
                while (!localEvents.isEmpty()) {
                    AccessibilityEvent event = localEvents.remove(0);
                    // Ignore events from previous interactions.
                    if (event.getEventTime() < executionStartTimeMillis) {
                        continue;
@@ -604,13 +608,18 @@ public final class UiAutomation {
                    throw new TimeoutException("Expected event not received within: "
                            + timeoutMillis + " ms.");
                }
                synchronized (mLock) {
                    if (mEventQueue.isEmpty()) {
                        try {
                            mLock.wait(remainingTimeMillis);
                        } catch (InterruptedException ie) {
                            /* ignore */
                        }
                    }
                }
            }
        } finally {
            synchronized (mLock) {
                mWaitingForEventDelivery = false;
                mEventQueue.clear();
                mLock.notifyAll();
+1 −7
Original line number Diff line number Diff line
@@ -6928,13 +6928,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        info.setVisibleToUser(isVisibleToUser());
        if ((mAttachInfo != null) && ((mAttachInfo.mAccessibilityFetchFlags
                & AccessibilityNodeInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS) != 0)) {
        info.setImportantForAccessibility(isImportantForAccessibility());
        } else {
            info.setImportantForAccessibility(true);
        }
        info.setPackageName(mContext.getPackageName());
        info.setClassName(getAccessibilityClassName());
        info.setContentDescription(getContentDescription());
+20 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.util.Pools.SynchronizedPool;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
@@ -3144,6 +3145,25 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        }
    }

    /** @hide */
    @Override
    public void notifySubtreeAccessibilityStateChangedIfNeeded() {
        if (!AccessibilityManager.getInstance(mContext).isEnabled() || mAttachInfo == null) {
            return;
        }
        // If something important for a11y is happening in this subtree, make sure it's dispatched
        // from a view that is important for a11y so it doesn't get lost.
        if ((getImportantForAccessibility() != IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS)
                && !isImportantForAccessibility() && (getChildCount() > 0)) {
            ViewParent a11yParent = getParentForAccessibility();
            if (a11yParent instanceof View) {
                ((View) a11yParent).notifySubtreeAccessibilityStateChangedIfNeeded();
                return;
            }
        }
        super.notifySubtreeAccessibilityStateChangedIfNeeded();
    }

    @Override
    void resetSubtreeAccessibilityStateChanged() {
        super.resetSubtreeAccessibilityStateChanged();
+1 −0
Original line number Diff line number Diff line
@@ -3282,6 +3282,7 @@ public class AccessibilityNodeInfo implements Parcelable {
        builder.append("; enabled: ").append(isEnabled());
        builder.append("; password: ").append(isPassword());
        builder.append("; scrollable: ").append(isScrollable());
        builder.append("; importantForAccessibility: ").append(isImportantForAccessibility());
        builder.append("; actions: ").append(mActions);

        return builder.toString();