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

Commit 0b0a41d8 authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

Not visible view should not be announced or interacted with.

1. Some invisible views' text was reported by accessibility events.

2. Accessibility actions could have been perfromed on invisible views.

bug:5264355

Change-Id: I68184fb436a3e10e947ec6f1eae02aa3d0d1cb7f
parent 08b997c7
Loading
Loading
Loading
Loading
+16 −13
Original line number Diff line number Diff line
@@ -4529,7 +4529,7 @@ public final class ViewRootImpl extends Handler implements ViewParent,
                predicate.init(accessibilityId);
                View root = ViewRootImpl.this.mView;
                View target = root.findViewByPredicate(predicate);
                if (target != null && target.isShown()) {
                if (target != null && target.getVisibility() == View.VISIBLE) {
                    info = target.createAccessibilityNodeInfo();
                }
            } finally {
@@ -4572,7 +4572,7 @@ public final class ViewRootImpl extends Handler implements ViewParent,
            try {
                View root = ViewRootImpl.this.mView;
                View target = root.findViewById(viewId);
                if (target != null && target.isShown()) {
                if (target != null && target.getVisibility() == View.VISIBLE) {
                    info = target.createAccessibilityNodeInfo();
                }
            } finally {
@@ -4623,14 +4623,14 @@ public final class ViewRootImpl extends Handler implements ViewParent,
                ArrayList<View> foundViews = mAttachInfo.mFocusablesTempList;
                foundViews.clear();

                View root;
                View root = null;
                if (accessibilityViewId != View.NO_ID) {
                    root = findViewByAccessibilityId(accessibilityViewId);
                } else {
                    root = ViewRootImpl.this.mView;
                }

                if (root == null || !root.isShown()) {
                if (root == null || root.getVisibility() != View.VISIBLE) {
                    return;
                }

@@ -4645,7 +4645,7 @@ public final class ViewRootImpl extends Handler implements ViewParent,
                final int viewCount = foundViews.size();
                for (int i = 0; i < viewCount; i++) {
                    View foundView = foundViews.get(i);
                    if (foundView.isShown()) {
                    if (foundView.getVisibility() == View.VISIBLE) {
                        infos.add(foundView.createAccessibilityNodeInfo());
                    }
                 }
@@ -4718,7 +4718,7 @@ public final class ViewRootImpl extends Handler implements ViewParent,

        private boolean performActionFocus(int accessibilityId) {
            View target = findViewByAccessibilityId(accessibilityId);
            if (target == null) {
            if (target == null || target.getVisibility() != View.VISIBLE) {
                return false;
            }
            // Get out of touch mode since accessibility wants to move focus around.
@@ -4728,7 +4728,7 @@ public final class ViewRootImpl extends Handler implements ViewParent,

        private boolean performActionClearFocus(int accessibilityId) {
            View target = findViewByAccessibilityId(accessibilityId);
            if (target == null) {
            if (target == null || target.getVisibility() != View.VISIBLE) {
                return false;
            }
            if (!target.isFocused()) {
@@ -4740,7 +4740,7 @@ public final class ViewRootImpl extends Handler implements ViewParent,

        private boolean performActionSelect(int accessibilityId) {
            View target = findViewByAccessibilityId(accessibilityId);
            if (target == null) {
            if (target == null || target.getVisibility() != View.VISIBLE) {
                return false;
            }
            if (target.isSelected()) {
@@ -4752,7 +4752,7 @@ public final class ViewRootImpl extends Handler implements ViewParent,

        private boolean performActionClearSelection(int accessibilityId) {
            View target = findViewByAccessibilityId(accessibilityId);
            if (target == null) {
            if (target == null || target.getVisibility() != View.VISIBLE) {
                return false;
            }
            if (!target.isSelected()) {
@@ -4769,18 +4769,21 @@ public final class ViewRootImpl extends Handler implements ViewParent,
            }
            mFindByAccessibilityIdPredicate.init(accessibilityId);
            View foundView = root.findViewByPredicate(mFindByAccessibilityIdPredicate);
            return (foundView != null && foundView.isShown()) ? foundView : null;
            if (foundView == null || foundView.getVisibility() != View.VISIBLE) {
                return null;
            }
            return foundView;
        }

        private final class FindByAccessibilitytIdPredicate implements Predicate<View> {
            public int mSerchedId;
            public int mSearchedId;

            public void init(int searchedId) {
                mSerchedId = searchedId;
                mSearchedId = searchedId;
            }

            public boolean apply(View view) {
                return (view.getAccessibilityViewId() == mSerchedId);
                return (view.getAccessibilityViewId() == mSearchedId);
            }
        }
    }
+6 −7
Original line number Diff line number Diff line
@@ -886,9 +886,11 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
            event.setEventType(AccessibilityEvent.TYPE_VIEW_SELECTED);
        }

        View selectedView = getSelectedView();
        if (selectedView != null && selectedView.getVisibility() == VISIBLE) {
            // We first get a chance to populate the event.
            onPopulateAccessibilityEvent(event);

        }
        return false;
    }

@@ -896,10 +898,7 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
    public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
        // We send selection events only from AdapterView to avoid
        // generation of such event for each child.
        View selectedView = getSelectedView();
        if (selectedView != null) {
            selectedView.dispatchPopulateAccessibilityEvent(event);
        }
        getSelectedView().dispatchPopulateAccessibilityEvent(event);
    }

    @Override
+2 −1
Original line number Diff line number Diff line
@@ -961,7 +961,8 @@ public class RelativeLayout extends ViewGroup {
        }

        for (View view : mTopToBottomLeftToRightSet) {
            if (view.dispatchPopulateAccessibilityEvent(event)) {
            if (view.getVisibility() == View.VISIBLE
                    && view.dispatchPopulateAccessibilityEvent(event)) {
                mTopToBottomLeftToRightSet.clear();
                return true;
            }
+4 −1
Original line number Diff line number Diff line
@@ -405,7 +405,10 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
        onPopulateAccessibilityEvent(event);
        // Dispatch only to the selected tab.
        if (mSelectedTab != -1) {
            return getChildTabViewAt(mSelectedTab).dispatchPopulateAccessibilityEvent(event);
            View tabView = getChildTabViewAt(mSelectedTab);
            if (tabView != null && tabView.getVisibility() == VISIBLE) {
                return tabView.dispatchPopulateAccessibilityEvent(event);
            }
        }
        return false;
    }