Merge "Defer some heavy work from final frame of app -> home transition" into sc-dev
diff --git a/quickstep/src/com/android/launcher3/uioverrides/BaseRecentsViewStateController.java b/quickstep/src/com/android/launcher3/uioverrides/BaseRecentsViewStateController.java
index 2eb19ec..814cf93 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/BaseRecentsViewStateController.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/BaseRecentsViewStateController.java
@@ -99,6 +99,8 @@
                 config.getInterpolator(ANIM_OVERVIEW_TRANSLATE_X, LINEAR));
         setter.setFloat(mRecentsView, ADJACENT_PAGE_VERTICAL_OFFSET, scaleAndOffset[2],
                 config.getInterpolator(ANIM_OVERVIEW_TRANSLATE_Y, LINEAR));
+        setter.setFloat(mRecentsView, TASK_SECONDARY_TRANSLATION, 0f,
+                config.getInterpolator(ANIM_OVERVIEW_TRANSLATE_Y, LINEAR));
         PagedOrientationHandler orientationHandler =
                 ((RecentsView) mLauncher.getOverviewPanel()).getPagedOrientationHandler();
         FloatProperty taskViewsFloat = orientationHandler.getSplitSelectTaskOffset(
diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
index bcf6687..afe989d 100644
--- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
+++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
@@ -1521,7 +1521,6 @@
 
     private void setupLauncherUiAfterSwipeUpToRecentsAnimation() {
         endLauncherTransitionController();
-        mActivityInterface.onSwipeUpToRecentsComplete();
         mRecentsView.onSwipeUpAnimationSuccess();
         if (LIVE_TILE.get()) {
             mTaskAnimationManager.setLiveTileCleanUpHandler(mInputConsumerProxy::destroy);
diff --git a/quickstep/src/com/android/quickstep/BaseActivityInterface.java b/quickstep/src/com/android/quickstep/BaseActivityInterface.java
index b60b1be..c8865c4 100644
--- a/quickstep/src/com/android/quickstep/BaseActivityInterface.java
+++ b/quickstep/src/com/android/quickstep/BaseActivityInterface.java
@@ -99,16 +99,8 @@
             DeviceProfile dp, Context context, Rect outRect,
             PagedOrientationHandler orientationHandler);
 
-    public void onSwipeUpToRecentsComplete() {
-        // Re apply state in case we did something funky during the transition.
-        ACTIVITY_TYPE activity = getCreatedActivity();
-        if (activity == null) {
-            return;
-        }
-        activity.getStateManager().reapplyState();
-    }
-
-    public abstract void onSwipeUpToHomeComplete(RecentsAnimationDeviceState deviceState);
+    /** Called when the animation to home has fully settled. */
+    public void onSwipeUpToHomeComplete(RecentsAnimationDeviceState deviceState) {}
 
     public abstract void onAssistantVisibilityChanged(float visibility);
 
diff --git a/quickstep/src/com/android/quickstep/FallbackActivityInterface.java b/quickstep/src/com/android/quickstep/FallbackActivityInterface.java
index 3c81d1b..4ee4398 100644
--- a/quickstep/src/com/android/quickstep/FallbackActivityInterface.java
+++ b/quickstep/src/com/android/quickstep/FallbackActivityInterface.java
@@ -65,12 +65,6 @@
         }
     }
 
-    /** 4 */
-    @Override
-    public void onSwipeUpToHomeComplete(RecentsAnimationDeviceState deviceState) {
-        onSwipeUpToRecentsComplete();
-    }
-
     /** 5 */
     @Override
     public void onAssistantVisibilityChanged(float visibility) {
diff --git a/quickstep/src/com/android/quickstep/LauncherActivityInterface.java b/quickstep/src/com/android/quickstep/LauncherActivityInterface.java
index c43d3c9..5217c3b 100644
--- a/quickstep/src/com/android/quickstep/LauncherActivityInterface.java
+++ b/quickstep/src/com/android/quickstep/LauncherActivityInterface.java
@@ -21,6 +21,7 @@
 import static com.android.launcher3.LauncherState.QUICK_SWITCH;
 import static com.android.launcher3.anim.AnimatorListeners.forEndCallback;
 import static com.android.launcher3.anim.Interpolators.LINEAR;
+import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_IME_SHOWING;
 
 import android.animation.Animator;
@@ -84,9 +85,13 @@
         if (launcher == null) {
             return;
         }
-        // Ensure recents is at the correct position for NORMAL state. For example, when we detach
-        // recents, we assume the first task is invisible, making translation off by one task.
-        launcher.getStateManager().reapplyState();
+        // When going to home, the state animator we use has SKIP_OVERVIEW because we assume that
+        // setRecentsAttachedToAppWindow() will handle animating Overview instead. Thus, at the end
+        // of the animation, we should ensure recents is at the correct position for NORMAL state.
+        // For example, when doing a long swipe to home, RecentsView may be scaled down. This is
+        // relatively expensive, so do it on the next frame instead of critical path.
+        MAIN_EXECUTOR.getHandler().post(launcher.getStateManager()::reapplyState);
+
         launcher.getRootView().setForceHideBackArrow(false);
         notifyRecentsOfOrientation(deviceState.getRotationTouchHelper());
     }
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index 7d19f6c..21100c4 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -1585,12 +1585,16 @@
         mLiveTileParams.setTargetSet(null);
         mLiveTileTaskViewSimulator.setDrawsBelowRecents(true);
 
-        unloadVisibleTaskData(TaskView.FLAG_UPDATE_ALL);
-        setCurrentPage(0);
-        LayoutUtils.setViewEnabled(mActionsView, true);
-        if (mOrientationState.setGestureActive(false)) {
-            updateOrientationHandler();
-        }
+        // These are relatively expensive and don't need to be done this frame (RecentsView isn't
+        // visible anyway), so defer by a frame to get off the critical path, e.g. app to home.
+        post(() -> {
+            unloadVisibleTaskData(TaskView.FLAG_UPDATE_ALL);
+            setCurrentPage(0);
+            LayoutUtils.setViewEnabled(mActionsView, true);
+            if (mOrientationState.setGestureActive(false)) {
+                updateOrientationHandler();
+            }
+        });
     }
 
     public int getRunningTaskId() {