Snap for 7798846 from 6ab0d1e7be9e4a6fa10381f506aadce04532dafe to sc-v2-release

Change-Id: I82e13e0d5bb36ba07731d4f0c1f4dc852b97fdaf
diff --git a/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java b/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java
index 12fba0d..6ccb152 100644
--- a/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java
+++ b/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java
@@ -53,14 +53,14 @@
                         Bundle::putInt, PortraitStatesTouchController::getHotseatTop);
             }
 
-            case TestProtocol.REQUEST_GET_FOCUSED_TASK_WIDTH_FOR_TABLET: {
+            case TestProtocol.REQUEST_GET_FOCUSED_TASK_HEIGHT_FOR_TABLET: {
                 if (!mDeviceProfile.isTablet) {
                     return null;
                 }
                 Rect focusedTaskRect = new Rect();
                 LauncherActivityInterface.INSTANCE.calculateTaskSize(mContext, mDeviceProfile,
                         focusedTaskRect);
-                response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, focusedTaskRect.width());
+                response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, focusedTaskRect.height());
                 return response;
             }
         }
diff --git a/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java b/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java
index e9a695d..1dae2c8 100644
--- a/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java
+++ b/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java
@@ -163,10 +163,8 @@
                                 if (mSuccessCallback != null) {
                                     mSuccessCallback.accept(true);
                                 }
+                                resetState();
                             }));
-
-            // After successful launch, call resetState
-            resetState();
         }
 
         @Override
@@ -175,9 +173,8 @@
                 if (mSuccessCallback != null) {
                     mSuccessCallback.accept(false);
                 }
+                resetState();
             });
-
-            resetState();
         }
     }
 
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index e1a3895..796caa0 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -409,7 +409,7 @@
     private final float mFastFlingVelocity;
     private final int mScrollHapticMinGapMillis;
     private final RecentsModel mModel;
-    private final int mGridSideMargin;
+    private final int mSplitPlaceholderSize;
     private final ClearAllButton mClearAllButton;
     private final Rect mClearAllButtonDeadZoneRect = new Rect();
     private final Rect mTaskViewDeadZoneRect = new Rect();
@@ -660,7 +660,8 @@
 
         mIsRtl = mOrientationHandler.getRecentsRtlSetting(getResources());
         setLayoutDirection(mIsRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR);
-        mGridSideMargin = getResources().getDimensionPixelSize(R.dimen.overview_grid_side_margin);
+        mSplitPlaceholderSize = getResources().getDimensionPixelSize(
+                R.dimen.split_placeholder_size);
         mSquaredTouchSlop = squaredTouchSlop(context);
 
         mEmptyIcon = context.getDrawable(R.drawable.ic_empty_recents);
@@ -3918,7 +3919,6 @@
 
     /** TODO(b/181707736) More gracefully handle exiting split selection state */
     private void resetFromSplitSelectionState() {
-        mSplitHiddenTaskView.setTranslationY(0);
         if (!showAsGrid()) {
             int pageToSnapTo = mCurrentPage;
             if (mSplitHiddenTaskViewIndex <= pageToSnapTo) {
@@ -3930,9 +3930,12 @@
         }
         onLayout(false /*  changed */, getLeft(), getTop(), getRight(), getBottom());
         resetTaskVisuals();
-        mSplitHiddenTaskView.setVisibility(VISIBLE);
-        mSplitHiddenTaskView = null;
         mSplitHiddenTaskViewIndex = -1;
+        if (mSplitHiddenTaskView != null) {
+            mSplitHiddenTaskView.setTranslationY(0);
+            mSplitHiddenTaskView.setVisibility(VISIBLE);
+            mSplitHiddenTaskView = null;
+        }
         if (mFirstFloatingTaskView != null) {
             mActivity.getRootView().removeView(mFirstFloatingTaskView);
             mFirstFloatingTaskView = null;
@@ -4236,13 +4239,19 @@
             return;
         }
 
-        if (mSyncTransactionApplier != null) {
-            recentsAnimationTargets.addReleaseCheck(mSyncTransactionApplier);
-        }
-
         RemoteTargetGluer gluer = new RemoteTargetGluer(getContext(), getSizeStrategy());
         mRemoteTargetHandles = gluer.assignTargetsForSplitScreen(recentsAnimationTargets);
         mSplitBoundsConfig = gluer.getStagedSplitBounds();
+        if (mSyncTransactionApplier != null) {
+            // Add release check to the targets from the RemoteTargetGluer and not the targets
+            // passed in because in the event we're in split screen, we use the passed in targets
+            // to create new RemoteAnimationTargets in assignTargetsForSplitScreen(), and the
+            // mSyncTransactionApplier doesn't get transferred over
+            runActionOnRemoteHandles(remoteTargetHandle -> remoteTargetHandle
+                    .getTransformParams().getTargetSet()
+                    .addReleaseCheck(mSyncTransactionApplier));
+        }
+
         TaskView runningTaskView = getRunningTaskView();
         if (runningTaskView instanceof GroupedTaskView) {
             // We initially create a GroupedTaskView in showCurrentTask() before launcher even
@@ -4349,16 +4358,24 @@
     @Override
     protected int computeMinScroll() {
         if (getTaskViewCount() > 0) {
+            int minScroll;
             if (mIsRtl) {
                 // If we aren't showing the clear all button, use the rightmost task as the min
                 // scroll.
-                return getScrollForPage(mDisallowScrollToClearAll ? indexOfChild(
+                minScroll = getScrollForPage(mDisallowScrollToClearAll ? indexOfChild(
                         getTaskViewAt(getTaskViewCount() - 1)) : indexOfChild(mClearAllButton));
+                if (showAsGrid() && isSplitSelectionActive()
+                        && mSplitSelectStateController.getActiveSplitStagePosition()
+                        == SplitConfigurationOptions.STAGE_POSITION_BOTTOM_OR_RIGHT) {
+                    minScroll -= mSplitPlaceholderSize;
+                }
             } else {
                 TaskView focusedTaskView = mShowAsGridLastOnLayout ? getFocusedTaskView() : null;
-                return getScrollForPage(focusedTaskView != null ? indexOfChild(focusedTaskView)
+                minScroll = getScrollForPage(focusedTaskView != null ? indexOfChild(focusedTaskView)
                         : 0);
+                // TODO(b/200537659): Adjust according to mSplitPlaceholderSize.
             }
+            return minScroll;
         }
         return super.computeMinScroll();
     }
@@ -4366,16 +4383,24 @@
     @Override
     protected int computeMaxScroll() {
         if (getTaskViewCount() > 0) {
+            int maxScroll;
             if (mIsRtl) {
                 TaskView focusedTaskView = mShowAsGridLastOnLayout ? getFocusedTaskView() : null;
-                return getScrollForPage(focusedTaskView != null ? indexOfChild(focusedTaskView)
+                maxScroll = getScrollForPage(focusedTaskView != null ? indexOfChild(focusedTaskView)
                         : 0);
+                if (showAsGrid() && isSplitSelectionActive()
+                        && mSplitSelectStateController.getActiveSplitStagePosition()
+                        == SplitConfigurationOptions.STAGE_POSITION_TOP_OR_LEFT) {
+                    maxScroll += mSplitPlaceholderSize;
+                }
             } else {
                 // If we aren't showing the clear all button, use the leftmost task as the min
                 // scroll.
-                return getScrollForPage(mDisallowScrollToClearAll ? indexOfChild(
+                maxScroll = getScrollForPage(mDisallowScrollToClearAll ? indexOfChild(
                         getTaskViewAt(getTaskViewCount() - 1)) : indexOfChild(mClearAllButton));
+                // TODO(b/200537659): Adjust according to mSplitPlaceholderSize.
             }
+            return maxScroll;
         }
         return super.computeMaxScroll();
     }
diff --git a/src/com/android/launcher3/model/BaseLoaderResults.java b/src/com/android/launcher3/model/BaseLoaderResults.java
index e9feb1c..3cae1e1 100644
--- a/src/com/android/launcher3/model/BaseLoaderResults.java
+++ b/src/com/android/launcher3/model/BaseLoaderResults.java
@@ -178,7 +178,7 @@
                 Log.d(TestProtocol.NULL_INT_SET, "bind (1) currentScreenIds: "
                         + currentScreenIds
                         + ", mCallBacks: "
-                        + mCallbacks.getClass().getSimpleName());
+                        + mCallbacks.getClass().getName());
             }
             filterCurrentWorkspaceItems(currentScreenIds, mWorkspaceItems, currentWorkspaceItems,
                     otherWorkspaceItems);
diff --git a/src/com/android/launcher3/testing/TestProtocol.java b/src/com/android/launcher3/testing/TestProtocol.java
index ce01d4e..f67bac6 100644
--- a/src/com/android/launcher3/testing/TestProtocol.java
+++ b/src/com/android/launcher3/testing/TestProtocol.java
@@ -102,8 +102,8 @@
     public static final String REQUEST_GET_ACTIVITIES_CREATED_COUNT =
             "get-activities-created-count";
     public static final String REQUEST_GET_ACTIVITIES = "get-activities";
-    public static final String REQUEST_GET_FOCUSED_TASK_WIDTH_FOR_TABLET =
-            "get-focused-task-width-for-tablet";
+    public static final String REQUEST_GET_FOCUSED_TASK_HEIGHT_FOR_TABLET =
+            "get-focused-task-height-for-tablet";
 
     public static Long sForcePauseTimeout;
     public static final String REQUEST_SET_FORCE_PAUSE_TIMEOUT = "set-force-pause-timeout";
diff --git a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java
index 7137c00..20366aa 100644
--- a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java
+++ b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java
@@ -138,6 +138,10 @@
         }
     }
 
+    int getTaskCount() {
+        return getTasks().size();
+    }
+
     /**
      * Returns whether Overview has tasks.
      */
@@ -169,7 +173,7 @@
         }
         try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
                 "want to assert overview actions view visibility")) {
-            if (mLauncher.isTablet() && !isOverviewSnappedToFocusedTask()) {
+            if (mLauncher.isTablet() && !isOverviewSnappedToFocusedTaskForTablet()) {
                 mLauncher.waitUntilLauncherObjectGone("action_buttons");
             } else {
                 mLauncher.waitForLauncherObject("action_buttons");
@@ -178,14 +182,10 @@
     }
 
     /**
-     * Returns if focused task is currently snapped task in overview.
+     * Returns if focused task is currently snapped task in tablet grid overview.
      */
-    private boolean isOverviewSnappedToFocusedTask() {
-        if (!mLauncher.isTablet()) {
-            // Focused task only exists in tablet's grid-overview
-            return false;
-        }
-        UiObject2 focusedTask = getFocusedTask();
+    private boolean isOverviewSnappedToFocusedTaskForTablet() {
+        UiObject2 focusedTask = getFocusedTaskForTablet();
         if (focusedTask == null) {
             return false;
         }
@@ -197,14 +197,14 @@
     /**
      * Returns Overview focused task if it exists.
      */
-    private UiObject2 getFocusedTask() {
+    UiObject2 getFocusedTaskForTablet() {
         final List<UiObject2> taskViews = getTasks();
         if (taskViews.size() == 0) {
             return null;
         }
-        int focusedTaskWidth = mLauncher.getFocusedTaskWidth();
+        int focusedTaskHeight = mLauncher.getFocusedTaskHeightForTablet();
         for (UiObject2 task : taskViews) {
-            if (task.getVisibleBounds().width() == focusedTaskWidth) {
+            if (task.getVisibleBounds().height() == focusedTaskHeight) {
                 return task;
             }
         }
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index f83c031..55fb2c1 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -321,8 +321,8 @@
                 .getBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD);
     }
 
-    int getFocusedTaskWidth() {
-        return getTestInfo(TestProtocol.REQUEST_GET_FOCUSED_TASK_WIDTH_FOR_TABLET).getInt(
+    int getFocusedTaskHeightForTablet() {
+        return getTestInfo(TestProtocol.REQUEST_GET_FOCUSED_TASK_HEIGHT_FOR_TABLET).getInt(
                 TestProtocol.TEST_INFO_RESPONSE_FIELD);
     }
 
diff --git a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java
index 71c0abb..9419839 100644
--- a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java
+++ b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java
@@ -47,29 +47,53 @@
         mOverview.verifyActiveContainer();
     }
 
+    private int getVisibleHeight() {
+        return mTask.getVisibleBounds().height();
+    }
+
     /**
-     * Swipes the task up.
+     * Dismisses the task by swiping up.
      */
     public void dismiss() {
         try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck();
              LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
-                     "want to dismiss a task")) {
+                     "want to dismiss an overview task")) {
             verifyActiveContainer();
-            // Dismiss the task via flinging it up.
-            final Rect taskBounds = mLauncher.getVisibleBounds(mTask);
-            final int centerX = taskBounds.centerX();
-            final int centerY = taskBounds.centerY();
-            mLauncher.executeAndWaitForLauncherEvent(
-                    () -> mLauncher.linearGesture(centerX, centerY, centerX, 0, 10, false,
-                            LauncherInstrumentation.GestureScope.INSIDE),
-                    event -> TestProtocol.DISMISS_ANIMATION_ENDS_MESSAGE.equals(
-                            event.getClassName()),
-                    () -> "Didn't receive a dismiss animation ends message: " + centerX + ", "
-                            + centerY,
-                    "swiping to dismiss");
+            int taskCountBeforeDismiss = mOverview.getTaskCount();
+            mLauncher.assertNotEquals("Unable to find a task", 0, taskCountBeforeDismiss);
+            if (taskCountBeforeDismiss == 1) {
+                dismissBySwipingUp();
+                return;
+            }
+
+            boolean taskWasFocused = mLauncher.isTablet() && getVisibleHeight() == mLauncher
+                    .getFocusedTaskHeightForTablet();
+
+            dismissBySwipingUp();
+
+            try (LauncherInstrumentation.Closable c2 = mLauncher.addContextLayer("dismissed")) {
+                if (taskWasFocused) {
+                    mLauncher.assertNotNull("No task became focused",
+                            mOverview.getFocusedTaskForTablet());
+                }
+            }
         }
     }
 
+    private void dismissBySwipingUp() {
+        verifyActiveContainer();
+        // Dismiss the task via flinging it up.
+        final Rect taskBounds = mLauncher.getVisibleBounds(mTask);
+        final int centerX = taskBounds.centerX();
+        final int centerY = taskBounds.centerY();
+        mLauncher.executeAndWaitForLauncherEvent(
+                () -> mLauncher.linearGesture(centerX, centerY, centerX, 0, 10, false,
+                        LauncherInstrumentation.GestureScope.INSIDE),
+                event -> TestProtocol.DISMISS_ANIMATION_ENDS_MESSAGE.equals(event.getClassName()),
+                () -> "Didn't receive a dismiss animation ends message: " + centerX + ", "
+                        + centerY, "swiping to dismiss");
+    }
+
     /**
      * Clicks at the task.
      */