Merge "Remove all Android Security tests that require root from CTS." into oc-mr1-dev-plus-aosp
diff --git a/tests/tests/widget/src/android/widget/cts/ListPopupWindowTest.java b/tests/tests/widget/src/android/widget/cts/ListPopupWindowTest.java
index 70f9661..88f3450 100644
--- a/tests/tests/widget/src/android/widget/cts/ListPopupWindowTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ListPopupWindowTest.java
@@ -528,15 +528,19 @@
         assertTrue(promptView.isShown());
         assertEquals(ListPopupWindow.POSITION_PROMPT_ABOVE, mPopupWindow.getPromptPosition());
 
-        final int[] promptViewOnScreenXY = new int[2];
-        promptView.getLocationOnScreen(promptViewOnScreenXY);
-
         final ListView listView = mPopupWindow.getListView();
         WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, listView, null);
 
-        final View firstListChild = listView.getChildAt(0);
+        final int[] promptViewOnScreenXY = new int[2];
         final int[] firstChildOnScreenXY = new int[2];
-        firstListChild.getLocationOnScreen(firstChildOnScreenXY);
+
+        mActivityRule.runOnUiThread(()-> {
+            promptView.getLocationOnScreen(promptViewOnScreenXY);
+
+            final View firstListChild = listView.getChildAt(0);
+            firstListChild.getLocationOnScreen(firstChildOnScreenXY);
+        });
+        mInstrumentation.waitForIdleSync();
 
         assertTrue(promptViewOnScreenXY[1] + promptView.getHeight() <= firstChildOnScreenXY[1]);
     }
@@ -560,11 +564,15 @@
         WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, listView, null);
 
         final int[] promptViewOnScreenXY = new int[2];
-        promptView.getLocationOnScreen(promptViewOnScreenXY);
-
-        final View lastListChild = listView.getChildAt(listView.getChildCount() - 1);
         final int[] lastChildOnScreenXY = new int[2];
-        lastListChild.getLocationOnScreen(lastChildOnScreenXY);
+
+        mActivityRule.runOnUiThread(()-> {
+            promptView.getLocationOnScreen(promptViewOnScreenXY);
+
+            final View lastListChild = listView.getChildAt(listView.getChildCount() - 1);
+            lastListChild.getLocationOnScreen(lastChildOnScreenXY);
+        });
+        mInstrumentation.waitForIdleSync();
 
         // The child is above the prompt. They may overlap, as in the case
         // when the list items do not all fit on screen, but this is still