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

Commit 3567b980 authored by Daniel Norman's avatar Daniel Norman
Browse files

Dispatch A11yEvents regardless of the AccessibilityDataPrivate property.

AccessibilityEvents should always be dispatched for otherwise-included
views, regardless of the source node's AccessibilityDataPrivate property.
Event filtering is performed later when AMS sends events to a11y services.

Fix: 265899846
Test: atest AccessibilityEndToEndTest
Test: Use TalkBack to explore by touch in the Security and Privacy
      section of the Settings app.
Change-Id: Ic54b09902bce8c4c161a66614b9510b2bce48dfb
parent 48ae0d86
Loading
Loading
Loading
Loading
+45 −18
Original line number Diff line number Diff line
@@ -14078,7 +14078,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        // working solution.
        View source = this;
        while (true) {
            if (source.includeForAccessibility()) {
            if (source.includeForAccessibility(false)) {
                source.sendAccessibilityEvent(eventType);
                return;
            }
@@ -14432,11 +14432,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            // importance, since we'll need to check it later to make sure.
            final boolean maySkipNotify = oldMode == IMPORTANT_FOR_ACCESSIBILITY_AUTO
                    || mode == IMPORTANT_FOR_ACCESSIBILITY_AUTO;
            final boolean oldIncludeForAccessibility = maySkipNotify && includeForAccessibility();
            final boolean oldIncludeForAccessibility =
                    maySkipNotify && includeForAccessibility(false);
            mPrivateFlags2 &= ~PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK;
            mPrivateFlags2 |= (mode << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT)
                    & PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK;
            if (!maySkipNotify || oldIncludeForAccessibility != includeForAccessibility()) {
            if (!maySkipNotify || oldIncludeForAccessibility != includeForAccessibility(false)) {
                notifySubtreeAccessibilityStateChangedIfNeeded();
            } else {
                notifyViewAccessibilityStateChangedIfNeeded(
@@ -14568,29 +14569,54 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    }
    /**
     * Whether to regard this view for accessibility. A view is regarded for
     * accessibility if it is important for accessibility or the querying
     * accessibility service has explicitly requested that view not
     * important for accessibility are regarded.
     *
     * @return Whether to regard the view for accessibility.
     *
     * @see #includeForAccessibility(boolean)
     * @hide
     */
    @UnsupportedAppUsage
    public boolean includeForAccessibility() {
        if (mAttachInfo != null) {
        return includeForAccessibility(true);
    }
    /**
     * Whether to regard this view for accessibility.
     *
     * <p>
     * If this decision is used for generating the accessibility node tree then this returns false
     * for {@link #isAccessibilityDataPrivate()} views queried by non-accessibility tools.
     * </p>
     * <p>
     * Otherwise, a view is regarded for accessibility if:
     * <li>the view returns true for {@link #isImportantForAccessibility()}, or</li>
     * <li>the querying accessibility service has explicitly requested that views not important for
     * accessibility are regarded by setting
     * {@link android.accessibilityservice.AccessibilityServiceInfo#FLAG_INCLUDE_NOT_IMPORTANT_VIEWS}</li>
     * </p>
     *
     * @param forNodeTree True if the result of this function will be used for generating a node
     *                    tree, otherwise false (like when sending {@link AccessibilityEvent}s).
     * @return Whether to regard the view for accessibility.
     * @hide
     */
    public boolean includeForAccessibility(boolean forNodeTree) {
        if (mAttachInfo == null) {
            return false;
        }
        if (forNodeTree) {
            // The AccessibilityDataPrivate property should not effect whether this View is
            // included for consideration when sending AccessibilityEvents. Events copy their
            // source View's AccessibilityDataPrivate value, and then filtering is done when
            // AccessibilityManagerService propagates events to each recipient AccessibilityService.
            if (!AccessibilityManager.getInstance(mContext).isRequestFromAccessibilityTool()
                    && isAccessibilityDataPrivate()) {
                return false;
            }
        }
        return (mAttachInfo.mAccessibilityFetchFlags
                & AccessibilityNodeInfo.FLAG_SERVICE_REQUESTS_INCLUDE_NOT_IMPORTANT_VIEWS) != 0
                || isImportantForAccessibility();
    }
        return false;
    }
    /**
     * Whether this view should restrict accessibility service access only to services that have the
@@ -17137,7 +17163,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    void setFlags(int flags, int mask) {
        final boolean accessibilityEnabled =
                AccessibilityManager.getInstance(mContext).isEnabled();
        final boolean oldIncludeForAccessibility = accessibilityEnabled && includeForAccessibility();
        final boolean oldIncludeForAccessibility =
                accessibilityEnabled && includeForAccessibility(false);
        int old = mViewFlags;
        mViewFlags = (mViewFlags & ~mask) | (flags & mask);
@@ -17363,7 +17390,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            if ((changed & FOCUSABLE) != 0 || (changed & VISIBILITY_MASK) != 0
                    || (changed & CLICKABLE) != 0 || (changed & LONG_CLICKABLE) != 0
                    || (changed & CONTEXT_CLICKABLE) != 0) {
                if (oldIncludeForAccessibility != includeForAccessibility()) {
                if (oldIncludeForAccessibility != includeForAccessibility(false)) {
                    notifySubtreeAccessibilityStateChangedIfNeeded();
                } else {
                    notifyViewAccessibilityStateChangedIfNeeded(
+1 −1
Original line number Diff line number Diff line
@@ -3532,7 +3532,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
    @Override
    public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
        boolean handled = false;
        if (includeForAccessibility()) {
        if (includeForAccessibility(false)) {
            handled = super.dispatchPopulateAccessibilityEventInternal(event);
            if (handled) {
                return handled;