Fixing some tests

> Adding retry to fallback recents tests
> Fixing provider test after provider name change
> Fixing AllApps icon detection when there is no more scroll available

Bug: 141390432
Bug: 141523101
Bug: 141517004
Bug: 141524555
Bug: 141522764
Change-Id: I425638d20c053206134835dabde819f16160f035
diff --git a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java
index 986f845..3697230 100644
--- a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java
+++ b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java
@@ -53,6 +53,7 @@
 import com.android.launcher3.tapl.OverviewTask;
 import com.android.launcher3.tapl.TestHelpers;
 import com.android.launcher3.testcomponent.TestCommandReceiver;
+import com.android.launcher3.util.Wait;
 import com.android.launcher3.util.rule.FailureWatcher;
 import com.android.launcher3.util.rule.SimpleActivityRule;
 import com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch;
@@ -147,16 +148,25 @@
         mLauncher.getBackground().switchToOverview();
     }
 
-    protected void executeOnRecents(Consumer<RecentsActivity> f) throws Exception {
+    protected void executeOnRecents(Consumer<RecentsActivity> f) {
         getFromRecents(r -> {
             f.accept(r);
-            return null;
+            return true;
         });
     }
 
-    protected <T> T getFromRecents(Function<RecentsActivity, T> f) throws Exception {
+    protected <T> T getFromRecents(Function<RecentsActivity, T> f) {
         if (!TestHelpers.isInLauncherProcess()) return null;
-        return MAIN_EXECUTOR.submit(() -> f.apply(mActivityMonitor.getActivity())).get();
+        Object[] result = new Object[1];
+        Wait.atMost("Failed to get from recents", () -> MAIN_EXECUTOR.submit(() -> {
+            RecentsActivity activity = mActivityMonitor.getActivity();
+            if (activity == null) {
+                return false;
+            }
+            result[0] = f.apply(activity);
+            return true;
+        }).get(), DEFAULT_UI_TIMEOUT);
+        return (T) result[0];
     }
 
     private BaseOverview pressHomeAndGoToOverview() {
@@ -166,7 +176,7 @@
 
     @NavigationModeSwitch
     @Test
-    public void testOverview() throws Exception {
+    public void testOverview() {
         startAppFast(getAppPackageName());
         startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
         startTestActivity(2);
diff --git a/tests/src/com/android/launcher3/ui/DefaultLayoutProviderTest.java b/tests/src/com/android/launcher3/ui/DefaultLayoutProviderTest.java
index a76b4a4..3d4e17b 100644
--- a/tests/src/com/android/launcher3/ui/DefaultLayoutProviderTest.java
+++ b/tests/src/com/android/launcher3/ui/DefaultLayoutProviderTest.java
@@ -30,7 +30,7 @@
 import androidx.test.runner.AndroidJUnit4;
 
 import com.android.launcher3.LauncherAppWidgetProviderInfo;
-import com.android.launcher3.testcomponent.TestCommandReceiver;
+import com.android.launcher3.testcomponent.TestCommandProvider;
 import com.android.launcher3.util.LauncherLayoutBuilder;
 import com.android.launcher3.util.rule.ShellCommandRule;
 
@@ -63,7 +63,7 @@
 
         PackageManager pm = mTargetContext.getPackageManager();
         ProviderInfo pi = pm.getProviderInfo(new ComponentName(mContext,
-                TestCommandReceiver.class), 0);
+                TestCommandProvider.class), 0);
         mAuthority = pi.authority;
     }
 
diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java
index 0359ff7..7754b5e 100644
--- a/tests/tapl/com/android/launcher3/tapl/AllApps.java
+++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java
@@ -54,7 +54,7 @@
     }
 
     private boolean hasClickableIcon(UiObject2 allAppsContainer, UiObject2 appListRecycler,
-            BySelector appIconSelector, int bottomOffset) {
+            BySelector appIconSelector, int displayBottom) {
         final UiObject2 icon = appListRecycler.findObject(appIconSelector);
         if (icon == null) {
             LauncherInstrumentation.log("hasClickableIcon: icon not visible");
@@ -66,7 +66,7 @@
             LauncherInstrumentation.log("hasClickableIcon: icon center is under search box");
             return false;
         }
-        if (iconBounds.bottom > bottomOffset) {
+        if (iconBounds.bottom > displayBottom) {
             LauncherInstrumentation.log("hasClickableIcon: icon center bellow bottom offset");
             return false;
         }
@@ -97,7 +97,8 @@
 
             int bottomGestureMargin = ResourceUtils.getNavbarSize(
                     ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE, mLauncher.getResources()) + 1;
-            int bottomOffset = mLauncher.getDevice().getDisplayHeight() - bottomGestureMargin;
+            int deviceHeight = mLauncher.getDevice().getDisplayHeight();
+            int displayBottom = deviceHeight - bottomGestureMargin;
             allAppsContainer.setGestureMargins(
                     0,
                     getSearchBox(allAppsContainer).getVisibleBounds().bottom + 1,
@@ -105,13 +106,13 @@
                     bottomGestureMargin);
             final BySelector appIconSelector = AppIcon.getAppIconSelector(appName, mLauncher);
             if (!hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector,
-                    bottomOffset)) {
+                    displayBottom)) {
                 scrollBackToBeginning();
                 int attempts = 0;
                 int scroll = getAllAppsScroll();
                 try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("scrolled")) {
                     while (!hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector,
-                            bottomOffset)) {
+                            displayBottom)) {
                         mLauncher.scroll(allAppsContainer, Direction.DOWN, 0.8f, null, 50);
                         final int newScroll = getAllAppsScroll();
                         if (newScroll == scroll) break;
@@ -126,9 +127,11 @@
                 verifyActiveContainer();
             }
 
+            // Ignore bottom offset selection here as there might not be any scroll more scroll
+            // region available.
             mLauncher.assertTrue("Unable to scroll to a clickable icon: " + appName,
                     hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector,
-                            bottomOffset));
+                            deviceHeight));
 
             final UiObject2 appIcon = mLauncher.waitForObjectInContainer(appListRecycler,
                     appIconSelector);