Merge "Fix integration tests with multi-desks on" into main
diff --git a/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java b/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java
index d80c05b..147033f 100644
--- a/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java
+++ b/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java
@@ -104,6 +104,13 @@
                         launcher -> launcher.<RecentsView>getOverviewPanel().getCurrentPage());
             }
 
+            case TestProtocol.REQUEST_GET_OVERVIEW_FIRST_TASKVIEW_INDEX: {
+                return getLauncherUIProperty(Bundle::putInt,
+                        launcher ->
+                                launcher.<RecentsView<?, ?>>getOverviewPanel()
+                                        .getFirstTaskViewIndex());
+            }
+
             case TestProtocol.REQUEST_HAS_TIS: {
                 response.putBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD, true);
                 return response;
diff --git a/quickstep/src/com/android/quickstep/views/RecentsDismissUtils.kt b/quickstep/src/com/android/quickstep/views/RecentsDismissUtils.kt
index 1dd0ac9..c26fef4 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsDismissUtils.kt
+++ b/quickstep/src/com/android/quickstep/views/RecentsDismissUtils.kt
@@ -1046,7 +1046,7 @@
                     pageToSnapTo = indexOfChild(clearAllButton)
                 } else if (isClearAllHidden) {
                     // Snap to focused task if clear all is hidden.
-                    pageToSnapTo = indexOfChild(firstTaskView)
+                    pageToSnapTo = firstTaskViewIndex
                 }
             } else {
                 val snappedTaskView = currentPageTaskView
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index 2672b1d..767aba9 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -879,6 +879,10 @@
         return mUtils.getFirstTaskView();
     }
 
+    public int getFirstTaskViewIndex() {
+        return indexOfChild(getFirstTaskView());
+    }
+
     public RecentsView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
         super(context, attrs, defStyleAttr);
         setEnableFreeScroll(true);
@@ -4079,7 +4083,7 @@
                                 pageToSnapTo = indexOfChild(mClearAllButton);
                             } else if (isClearAllHidden) {
                                 // Snap to focused task if clear all is hidden.
-                                pageToSnapTo = indexOfChild(getFirstTaskView());
+                                pageToSnapTo = getFirstTaskViewIndex();
                             }
                         } else {
                             // Get the id of the task view we will snap to based on the current
@@ -4097,7 +4101,7 @@
                                     } else {
                                         // Won't focus next task in split select, so snap to the
                                         // first task.
-                                        pageToSnapTo = indexOfChild(getFirstTaskView());
+                                        pageToSnapTo = getFirstTaskViewIndex();
                                         calculateScrollDiff = false;
                                     }
                                 } else {
diff --git a/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java b/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java
index 844719f..763f9ae 100644
--- a/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java
+++ b/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java
@@ -119,16 +119,14 @@
 
         // Test flinging forward and backward.
         runOnRecentsView(recentsView -> assertEquals("Current task in Overview is not first",
-                recentsView.indexOfChild(recentsView.getFirstTaskView()),
-                recentsView.getCurrentPage()));
+                recentsView.getFirstTaskViewIndex(), recentsView.getCurrentPage()));
 
         overview.flingForward();
         assertIsInState("Launcher internal state is not Overview", LauncherState.OVERVIEW);
         final Integer currentTaskAfterFlingForward =
                 getFromRecentsView(RecentsView::getCurrentPage);
-        runOnRecentsView(recentsView -> assertTrue("Current task in Overview is still 0",
-                currentTaskAfterFlingForward > recentsView.indexOfChild(
-                        recentsView.getFirstTaskView())));
+        runOnRecentsView(recentsView -> assertTrue("Current task in Overview is still first",
+                currentTaskAfterFlingForward > recentsView.getFirstTaskViewIndex()));
 
         overview.flingBackward();
         assertIsInState("Launcher internal state is not Overview", LauncherState.OVERVIEW);
@@ -390,8 +388,7 @@
         overview.scrollCurrentTaskOffScreen();
         assertIsInState("Launcher internal state is not Overview", LauncherState.OVERVIEW);
         runOnRecentsView(recentsView -> assertTrue("Current task in Overview is still first",
-                recentsView.getCurrentPage() > recentsView.indexOfChild(
-                        recentsView.getFirstTaskView())));
+                recentsView.getCurrentPage() > recentsView.getFirstTaskViewIndex()));
 
         // Test opening the task.
         overview.getCurrentTask().open();
@@ -407,8 +404,7 @@
         assertIsInState(
                 "Launcher internal state is not Overview", LauncherState.OVERVIEW);
         runOnRecentsView(recentsView -> assertTrue("Current task in Overview is still first",
-                recentsView.getCurrentPage() > recentsView.indexOfChild(
-                        recentsView.getFirstTaskView())));
+                recentsView.getCurrentPage() > recentsView.getFirstTaskViewIndex()));
 
         // Test dismissing the later task.
         final Integer numTasks = getFromRecentsView(RecentsView::getTaskViewCount);
diff --git a/shared/src/com/android/launcher3/testing/shared/TestProtocol.java b/shared/src/com/android/launcher3/testing/shared/TestProtocol.java
index cdeab95..84f8039 100644
--- a/shared/src/com/android/launcher3/testing/shared/TestProtocol.java
+++ b/shared/src/com/android/launcher3/testing/shared/TestProtocol.java
@@ -156,6 +156,8 @@
     public static final String REQUEST_GET_OVERVIEW_PAGE_SPACING = "get-overview-page-spacing";
     public static final String REQUEST_GET_OVERVIEW_CURRENT_PAGE_INDEX =
             "get-overview-current-page-index";
+    public static final String REQUEST_GET_OVERVIEW_FIRST_TASKVIEW_INDEX =
+            "get-overview-first-taskview-index";
     public static final String REQUEST_GET_SPLIT_SELECTION_ACTIVE = "get-split-selection-active";
     public static final String REQUEST_ENABLE_ROTATION = "enable_rotation";
     public static final String REQUEST_MODEL_QUEUE_CLEARED = "model-queue-cleared";
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index 6f2e8ef..72c5c54 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -448,6 +448,11 @@
                 .getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD);
     }
 
+    public int getOverviewFirstTaskViewIndex() {
+        return getTestInfo(TestProtocol.REQUEST_GET_OVERVIEW_FIRST_TASKVIEW_INDEX).getInt(
+                TEST_INFO_RESPONSE_FIELD);
+    }
+
     float getExactScreenCenterX() {
         return getRealDisplaySize().x / 2f;
     }