@@ -126,6 +126,16 @@ private void clear() {
126126 }
127127 }
128128
129+ private boolean isShown (View view ) {
130+ // The first two checks are made also made by isShown() which
131+ // however traverses the tree up to the parent to catch that.
132+ // Therefore, we do some fail fast check to minimize the up
133+ // tree traversal.
134+ return (view .mAttachInfo != null
135+ && view .mAttachInfo .mWindowVisibility == View .VISIBLE
136+ && view .isShown ());
137+ }
138+
129139 public void findAccessibilityNodeInfoByAccessibilityIdClientThread (
130140 long accessibilityNodeId , int interactionId ,
131141 IAccessibilityInteractionConnectionCallback callback , int flags , int interrogatingPid ,
@@ -174,7 +184,7 @@ private void findAccessibilityNodeInfoByAccessibilityIdUiThread(Message message)
174184 } else {
175185 root = findViewByAccessibilityId (accessibilityViewId );
176186 }
177- if (root != null && root . isDisplayedOnScreen ( )) {
187+ if (root != null && isShown ( root )) {
178188 mPrefetcher .prefetchAccessibilityNodeInfos (root , virtualDescendantId , flags , infos );
179189 }
180190 } finally {
@@ -236,7 +246,7 @@ private void findAccessibilityNodeInfoByViewIdUiThread(Message message) {
236246 }
237247 if (root != null ) {
238248 View target = root .findViewById (viewId );
239- if (target != null && target . isDisplayedOnScreen ( )) {
249+ if (target != null && isShown ( target )) {
240250 info = target .createAccessibilityNodeInfo ();
241251 }
242252 }
@@ -298,7 +308,7 @@ private void findAccessibilityNodeInfosByTextUiThread(Message message) {
298308 } else {
299309 root = mViewRootImpl .mView ;
300310 }
301- if (root != null && root . isDisplayedOnScreen ( )) {
311+ if (root != null && isShown ( root )) {
302312 AccessibilityNodeProvider provider = root .getAccessibilityNodeProvider ();
303313 if (provider != null ) {
304314 infos = provider .findAccessibilityNodeInfosByText (text ,
@@ -315,7 +325,7 @@ private void findAccessibilityNodeInfosByTextUiThread(Message message) {
315325 final int viewCount = foundViews .size ();
316326 for (int i = 0 ; i < viewCount ; i ++) {
317327 View foundView = foundViews .get (i );
318- if (foundView . isDisplayedOnScreen ( )) {
328+ if (isShown ( foundView )) {
319329 provider = foundView .getAccessibilityNodeProvider ();
320330 if (provider != null ) {
321331 List <AccessibilityNodeInfo > infosFromProvider =
@@ -390,7 +400,7 @@ private void findFocusUiThread(Message message) {
390400 } else {
391401 root = mViewRootImpl .mView ;
392402 }
393- if (root != null && root . isDisplayedOnScreen ( )) {
403+ if (root != null && isShown ( root )) {
394404 switch (focusType ) {
395405 case AccessibilityNodeInfo .FOCUS_ACCESSIBILITY : {
396406 View host = mViewRootImpl .mAccessibilityFocusedHost ;
@@ -411,7 +421,7 @@ private void findFocusUiThread(Message message) {
411421 case AccessibilityNodeInfo .FOCUS_INPUT : {
412422 // Input focus cannot go to virtual views.
413423 View target = root .findFocus ();
414- if (target != null && target . isDisplayedOnScreen ( )) {
424+ if (target != null && isShown ( target )) {
415425 focused = target .createAccessibilityNodeInfo ();
416426 }
417427 } break ;
@@ -477,7 +487,7 @@ private void focusSearchUiThread(Message message) {
477487 } else {
478488 root = mViewRootImpl .mView ;
479489 }
480- if (root != null && root . isDisplayedOnScreen ( )) {
490+ if (root != null && isShown ( root )) {
481491 if ((direction & View .FOCUS_ACCESSIBILITY ) == View .FOCUS_ACCESSIBILITY ) {
482492 AccessibilityNodeProvider provider = root .getAccessibilityNodeProvider ();
483493 if (provider != null ) {
@@ -565,7 +575,7 @@ private void perfromAccessibilityActionUiThread(Message message) {
565575 } else {
566576 target = mViewRootImpl .mView ;
567577 }
568- if (target != null && target . isDisplayedOnScreen ( )) {
578+ if (target != null && isShown ( target )) {
569579 AccessibilityNodeProvider provider = target .getAccessibilityNodeProvider ();
570580 if (provider != null ) {
571581 succeeded = provider .performAction (virtualDescendantId , action ,
@@ -590,7 +600,7 @@ private View findViewByAccessibilityId(int accessibilityId) {
590600 return null ;
591601 }
592602 View foundView = root .findViewByAccessibilityId (accessibilityId );
593- if (foundView != null && !foundView . isDisplayedOnScreen ( )) {
603+ if (foundView != null && !isShown ( foundView )) {
594604 return null ;
595605 }
596606 return foundView ;
@@ -670,7 +680,7 @@ private void prefetchSiblingsOfRealNode(View current,
670680 }
671681 View child = children .getChildAt (i );
672682 if (child .getAccessibilityViewId () != current .getAccessibilityViewId ()
673- && child . isDisplayedOnScreen ( )) {
683+ && isShown ( child )) {
674684 AccessibilityNodeInfo info = null ;
675685 AccessibilityNodeProvider provider = child .getAccessibilityNodeProvider ();
676686 if (provider == null ) {
@@ -706,7 +716,7 @@ private void prefetchDescendantsOfRealNode(View root,
706716 return ;
707717 }
708718 View child = children .getChildAt (i );
709- if (child . isDisplayedOnScreen ( )) {
719+ if (isShown ( child )) {
710720 AccessibilityNodeProvider provider = child .getAccessibilityNodeProvider ();
711721 if (provider == null ) {
712722 AccessibilityNodeInfo info = child .createAccessibilityNodeInfo ();
0 commit comments