From 6cc4627d88932c93ce4c8821a5714b5382cd0425 Mon Sep 17 00:00:00 2001 From: Svetoslav Date: Wed, 3 Jun 2015 11:38:30 -0700 Subject: [PATCH] Fix finding views by accessibility id. 1. If a view has a node provider, then the latter takes over representation of the view tree. Hence, find by accessibility id should not return children of a view with a provider. 2. Views can change their importantce for accessibility, so an accessibility service may get a node and try to act on it but the node became not important in the meantime. Hence, find by accessibility id should respect importance. Change-Id: Ib4d738c00f46c91300605a2928550f40705ea47b --- core/java/android/view/View.java | 6 +++++- core/java/android/view/ViewGroup.java | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index cfd504d3f5b4a..e3ad3cf18f41a 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -18291,7 +18291,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, if (accessibilityId < 0) { return null; } - return findViewByAccessibilityIdTraversal(accessibilityId); + View view = findViewByAccessibilityIdTraversal(accessibilityId); + if (view != null) { + return view.includeForAccessibility() ? view : null; + } + return null; } /** diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index e015c0419e9ec..dd32f854e26d2 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -1173,6 +1173,11 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager if (foundView != null) { return foundView; } + + if (getAccessibilityNodeProvider() != null) { + return null; + } + final int childrenCount = mChildrenCount; final View[] children = mChildren; for (int i = 0; i < childrenCount; i++) { @@ -1182,6 +1187,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager return foundView; } } + return null; }