Skip to content

Commit 0b0a41d

Browse files
committed
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
1 parent 08b997c commit 0b0a41d

File tree

4 files changed

+28
-22
lines changed

4 files changed

+28
-22
lines changed

core/java/android/view/ViewRootImpl.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4529,7 +4529,7 @@ public void findAccessibilityNodeInfoByAccessibilityIdUiThread(Message message)
45294529
predicate.init(accessibilityId);
45304530
View root = ViewRootImpl.this.mView;
45314531
View target = root.findViewByPredicate(predicate);
4532-
if (target != null && target.isShown()) {
4532+
if (target != null && target.getVisibility() == View.VISIBLE) {
45334533
info = target.createAccessibilityNodeInfo();
45344534
}
45354535
} finally {
@@ -4572,7 +4572,7 @@ public void findAccessibilityNodeInfoByViewIdUiThread(Message message) {
45724572
try {
45734573
View root = ViewRootImpl.this.mView;
45744574
View target = root.findViewById(viewId);
4575-
if (target != null && target.isShown()) {
4575+
if (target != null && target.getVisibility() == View.VISIBLE) {
45764576
info = target.createAccessibilityNodeInfo();
45774577
}
45784578
} finally {
@@ -4623,14 +4623,14 @@ public void findAccessibilityNodeInfosByViewTextUiThread(Message message) {
46234623
ArrayList<View> foundViews = mAttachInfo.mFocusablesTempList;
46244624
foundViews.clear();
46254625

4626-
View root;
4626+
View root = null;
46274627
if (accessibilityViewId != View.NO_ID) {
46284628
root = findViewByAccessibilityId(accessibilityViewId);
46294629
} else {
46304630
root = ViewRootImpl.this.mView;
46314631
}
46324632

4633-
if (root == null || !root.isShown()) {
4633+
if (root == null || root.getVisibility() != View.VISIBLE) {
46344634
return;
46354635
}
46364636

@@ -4645,7 +4645,7 @@ public void findAccessibilityNodeInfosByViewTextUiThread(Message message) {
46454645
final int viewCount = foundViews.size();
46464646
for (int i = 0; i < viewCount; i++) {
46474647
View foundView = foundViews.get(i);
4648-
if (foundView.isShown()) {
4648+
if (foundView.getVisibility() == View.VISIBLE) {
46494649
infos.add(foundView.createAccessibilityNodeInfo());
46504650
}
46514651
}
@@ -4718,7 +4718,7 @@ public void perfromAccessibilityActionUiThread(Message message) {
47184718

47194719
private boolean performActionFocus(int accessibilityId) {
47204720
View target = findViewByAccessibilityId(accessibilityId);
4721-
if (target == null) {
4721+
if (target == null || target.getVisibility() != View.VISIBLE) {
47224722
return false;
47234723
}
47244724
// Get out of touch mode since accessibility wants to move focus around.
@@ -4728,7 +4728,7 @@ private boolean performActionFocus(int accessibilityId) {
47284728

47294729
private boolean performActionClearFocus(int accessibilityId) {
47304730
View target = findViewByAccessibilityId(accessibilityId);
4731-
if (target == null) {
4731+
if (target == null || target.getVisibility() != View.VISIBLE) {
47324732
return false;
47334733
}
47344734
if (!target.isFocused()) {
@@ -4740,7 +4740,7 @@ private boolean performActionClearFocus(int accessibilityId) {
47404740

47414741
private boolean performActionSelect(int accessibilityId) {
47424742
View target = findViewByAccessibilityId(accessibilityId);
4743-
if (target == null) {
4743+
if (target == null || target.getVisibility() != View.VISIBLE) {
47444744
return false;
47454745
}
47464746
if (target.isSelected()) {
@@ -4752,7 +4752,7 @@ private boolean performActionSelect(int accessibilityId) {
47524752

47534753
private boolean performActionClearSelection(int accessibilityId) {
47544754
View target = findViewByAccessibilityId(accessibilityId);
4755-
if (target == null) {
4755+
if (target == null || target.getVisibility() != View.VISIBLE) {
47564756
return false;
47574757
}
47584758
if (!target.isSelected()) {
@@ -4769,18 +4769,21 @@ private View findViewByAccessibilityId(int accessibilityId) {
47694769
}
47704770
mFindByAccessibilityIdPredicate.init(accessibilityId);
47714771
View foundView = root.findViewByPredicate(mFindByAccessibilityIdPredicate);
4772-
return (foundView != null && foundView.isShown()) ? foundView : null;
4772+
if (foundView == null || foundView.getVisibility() != View.VISIBLE) {
4773+
return null;
4774+
}
4775+
return foundView;
47734776
}
47744777

47754778
private final class FindByAccessibilitytIdPredicate implements Predicate<View> {
4776-
public int mSerchedId;
4779+
public int mSearchedId;
47774780

47784781
public void init(int searchedId) {
4779-
mSerchedId = searchedId;
4782+
mSearchedId = searchedId;
47804783
}
47814784

47824785
public boolean apply(View view) {
4783-
return (view.getAccessibilityViewId() == mSerchedId);
4786+
return (view.getAccessibilityViewId() == mSearchedId);
47844787
}
47854788
}
47864789
}

core/java/android/widget/AdapterView.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -886,20 +886,19 @@ public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
886886
event.setEventType(AccessibilityEvent.TYPE_VIEW_SELECTED);
887887
}
888888

889-
// We first get a chance to populate the event.
890-
onPopulateAccessibilityEvent(event);
891-
889+
View selectedView = getSelectedView();
890+
if (selectedView != null && selectedView.getVisibility() == VISIBLE) {
891+
// We first get a chance to populate the event.
892+
onPopulateAccessibilityEvent(event);
893+
}
892894
return false;
893895
}
894896

895897
@Override
896898
public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
897899
// We send selection events only from AdapterView to avoid
898900
// generation of such event for each child.
899-
View selectedView = getSelectedView();
900-
if (selectedView != null) {
901-
selectedView.dispatchPopulateAccessibilityEvent(event);
902-
}
901+
getSelectedView().dispatchPopulateAccessibilityEvent(event);
903902
}
904903

905904
@Override

core/java/android/widget/RelativeLayout.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,8 @@ public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
961961
}
962962

963963
for (View view : mTopToBottomLeftToRightSet) {
964-
if (view.dispatchPopulateAccessibilityEvent(event)) {
964+
if (view.getVisibility() == View.VISIBLE
965+
&& view.dispatchPopulateAccessibilityEvent(event)) {
965966
mTopToBottomLeftToRightSet.clear();
966967
return true;
967968
}

core/java/android/widget/TabWidget.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,10 @@ public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
405405
onPopulateAccessibilityEvent(event);
406406
// Dispatch only to the selected tab.
407407
if (mSelectedTab != -1) {
408-
return getChildTabViewAt(mSelectedTab).dispatchPopulateAccessibilityEvent(event);
408+
View tabView = getChildTabViewAt(mSelectedTab);
409+
if (tabView != null && tabView.getVisibility() == VISIBLE) {
410+
return tabView.dispatchPopulateAccessibilityEvent(event);
411+
}
409412
}
410413
return false;
411414
}

0 commit comments

Comments
 (0)