Fix PermissionsHostTest failures for automotive builds.

Some permissions are not on screen due to the display size. As a result, accessibility info was not populated as expected causing failures when granting / revoking permissions within long lists.

testGrantPreviouslyRevokedWithPrejudiceShowsPrompt23 is flaky, but from local testing, increasing the idle timeout seems to improve the success rate.

Bug: 123429708
Fixes: 120901390

Test: cts-tradefed run cts-dev -a arm64-v8a -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.PermissionsHostTest
Multiple runs on device and emulator

Change-Id: I4c12ba014ac6aa2113b633c34b2163c599cba596
Merged-In: Ie891f96b527ab2724c0274e8547fb5e2e511b4d6
diff --git a/hostsidetests/appsecurity/test-apps/UsePermissionApp23/src/com/android/cts/usepermission/BasePermissionsTest.java b/hostsidetests/appsecurity/test-apps/UsePermissionApp23/src/com/android/cts/usepermission/BasePermissionsTest.java
index 62a05c8..a54b9b5 100755
--- a/hostsidetests/appsecurity/test-apps/UsePermissionApp23/src/com/android/cts/usepermission/BasePermissionsTest.java
+++ b/hostsidetests/appsecurity/test-apps/UsePermissionApp23/src/com/android/cts/usepermission/BasePermissionsTest.java
@@ -64,8 +64,8 @@
 public abstract class BasePermissionsTest {
     private static final String PLATFORM_PACKAGE_NAME = "android";
 
-    private static final long IDLE_TIMEOUT_MILLIS = 500;
-    private static final long GLOBAL_TIMEOUT_MILLIS = 5000;
+    private static final long IDLE_TIMEOUT_MILLIS = 1000;
+    private static final long GLOBAL_TIMEOUT_MILLIS = 10000;
 
     private static final long RETRY_TIMEOUT = 3 * GLOBAL_TIMEOUT_MILLIS;
     private static final String LOG_TAG = "BasePermissionsTest";
@@ -557,7 +557,9 @@
             throws Exception {
         AccessibilityNodeInfo result = current;
         while (result != null) {
-            if (result.getCollectionItemInfo() != null) {
+            // Nodes that are in the hierarchy but not yet on screen may not have collection item
+            // info populated. Use a parent with collection info as an indicator in those cases.
+            if (result.getCollectionItemInfo() != null || hasCollectionAsParent(result)) {
                 return result;
             }
             result = result.getParent();
@@ -565,6 +567,10 @@
         return null;
     }
 
+    private static boolean hasCollectionAsParent(AccessibilityNodeInfo node) {
+        return node.getParent() != null && node.getParent().getCollectionInfo() != null;
+    }
+
     private static AccessibilityNodeInfo findSwitch(AccessibilityNodeInfo root) throws Exception {
         if (Switch.class.getName().equals(root.getClassName().toString())) {
             return root;