Merge "Disabling horizontal swipes if the app has draggable content at the bottom" into ub-launcher3-qt-dev
diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java
index 18a8f27..d03035a 100644
--- a/tests/tapl/com/android/launcher3/tapl/AllApps.java
+++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java
@@ -20,8 +20,10 @@
 
 import android.graphics.Point;
 import android.graphics.Rect;
+import android.widget.TextView;
 
 import androidx.annotation.NonNull;
+import androidx.test.uiautomator.By;
 import androidx.test.uiautomator.BySelector;
 import androidx.test.uiautomator.Direction;
 import androidx.test.uiautomator.UiObject2;
@@ -42,6 +44,10 @@
         super(launcher);
         final UiObject2 allAppsContainer = verifyActiveContainer();
         mHeight = allAppsContainer.getVisibleBounds().height();
+        final UiObject2 appListRecycler = mLauncher.waitForObjectInContainer(allAppsContainer,
+                "apps_list_view");
+        // Wait for the recycler to populate.
+        mLauncher.waitForObjectInContainer(appListRecycler, By.clazz(TextView.class));
     }
 
     @Override
@@ -115,7 +121,7 @@
                 verifyActiveContainer();
             }
 
-            final UiObject2 appIcon = mLauncher.getObjectInContainer(allAppsContainer,
+            final UiObject2 appIcon = mLauncher.getObjectInContainer(appListRecycler,
                     appIconSelector);
             ensureIconVisible(appIcon, allAppsContainer, appListRecycler);
             return new AppIcon(mLauncher, appIcon);
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index f7befd1..443bc1a 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -21,9 +21,9 @@
 import static android.content.pm.PackageManager.MATCH_ALL;
 import static android.content.pm.PackageManager.MATCH_DISABLED_COMPONENTS;
 
+import static com.android.launcher3.tapl.TestHelpers.getOverviewPackageName;
 import static com.android.launcher3.testing.TestProtocol.BACKGROUND_APP_STATE_ORDINAL;
 import static com.android.launcher3.testing.TestProtocol.NORMAL_STATE_ORDINAL;
-import static com.android.launcher3.tapl.TestHelpers.getOverviewPackageName;
 
 import android.app.ActivityManager;
 import android.app.Instrumentation;
@@ -570,6 +570,16 @@
         return object;
     }
 
+    @NonNull
+    UiObject2 waitForObjectInContainer(UiObject2 container, BySelector selector) {
+        final UiObject2 object = container.wait(
+                Until.findObject(selector),
+                WAIT_TIME_MS);
+        assertNotNull("Can't find a launcher object id: " + selector + " in container: " +
+                container.getResourceName(), object);
+        return object;
+    }
+
     @Nullable
     private boolean hasLauncherObject(String resId) {
         return mDevice.hasObject(getLauncherObjectSelector(resId));
@@ -581,11 +591,6 @@
     }
 
     @NonNull
-    UiObject2 waitForLauncherObjectByClass(String clazz) {
-        return waitForObjectBySelector(getLauncherObjectSelectorByClass(clazz));
-    }
-
-    @NonNull
     UiObject2 waitForFallbackLauncherObject(String resName) {
         return waitForObjectBySelector(getFallbackLauncherObjectSelector(resName));
     }
@@ -600,10 +605,6 @@
         return By.res(getLauncherPackageName(), resName);
     }
 
-    BySelector getLauncherObjectSelectorByClass(String clazz) {
-        return By.pkg(getLauncherPackageName()).clazz(clazz);
-    }
-
     BySelector getFallbackLauncherObjectSelector(String resName) {
         return By.res(getOverviewPackageName(), resName);
     }