UI test automation cannot get the root node and gets null children.

1. The AccessibilityInteractionController was using an incorrect
   looper i.e. not the UI thread looper which was causing getting
   the root node to fail.

2. The AccessibilityNodeInfo was populated by a ViewGroup with the
   children for accessibility without checking whether these children
   are really displayed.

bug:6362875

Change-Id: I7906d89571eb9d57d10f971639f88632926dd077
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index ab3413e..ce02113 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -4680,6 +4680,23 @@
     }
 
     /**
+     * Computes whether this view is visible on the screen.
+     *
+     * @return Whether the view is visible on the screen.
+     */
+    boolean isDisplayedOnScreen() {
+        // The first two checks are made also made by isShown() which
+        // however traverses the tree up to the parent to catch that.
+        // Therefore, we do some fail fast check to minimize the up
+        // tree traversal.
+        return (mAttachInfo != null
+                && mAttachInfo.mWindowVisibility == View.VISIBLE
+                && getAlpha() > 0
+                && isShown()
+                && getGlobalVisibleRect(mAttachInfo.mTmpInvalRect));
+    }
+
+    /**
      * Sets a delegate for implementing accessibility support via compositon as
      * opposed to inheritance. The delegate's primary use is for implementing
      * backwards compatible widgets. For more details see {@link AccessibilityDelegate}.
@@ -6301,9 +6318,9 @@
     boolean includeForAccessibility() {
         if (mAttachInfo != null) {
             if (!mAttachInfo.mIncludeNotImportantViews) {
-                return isImportantForAccessibility();
+                return isImportantForAccessibility() && isDisplayedOnScreen();
             } else {
-                return true;
+                return isDisplayedOnScreen();
             }
         }
         return false;