Merge "Separate code paths to launch split from existing pair vs new pair" into udc-dev
diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java
index 79a301a..95c2326 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java
@@ -1282,7 +1282,8 @@
                             getActivityLaunchOptions(taskView, null).options));
             return;
         }
-        mSplitSelectStateController.launchTasks(
+        mSplitSelectStateController.launchExistingSplitPair(
+                null /* launchingTaskView */,
                 groupTask.task1.key.id,
                 groupTask.task2.key.id,
                 SplitConfigurationOptions.STAGE_POSITION_TOP_OR_LEFT,
diff --git a/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java b/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java
index da81410..ee51af7 100644
--- a/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java
+++ b/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java
@@ -298,36 +298,6 @@
     }
 
     /**
-     * To be called when we want to launch split pairs from an existing GroupedTaskView.
-     */
-    public void launchTasks(GroupedTaskView groupedTaskView, Consumer<Boolean> callback,
-            boolean freezeTaskList) {
-        mLaunchingTaskView = groupedTaskView;
-        TaskView.TaskIdAttributeContainer[] taskIdAttributeContainers =
-                groupedTaskView.getTaskIdAttributeContainers();
-        launchTasks(taskIdAttributeContainers[0].getTask().key.id,
-                taskIdAttributeContainers[1].getTask().key.id,
-                taskIdAttributeContainers[0].getStagePosition(), callback, freezeTaskList,
-                groupedTaskView.getSplitRatio());
-    }
-
-    /**
-     * To be called when we want to launch split pairs from Overview when split is initiated from
-     * Overview.
-     */
-    public void launchTasks(int taskId1, int taskId2, @StagePosition int stagePosition,
-            Consumer<Boolean> callback, boolean freezeTaskList, float splitRatio) {
-        if (FeatureFlags.ENABLE_SPLIT_LAUNCH_DATA_REFACTOR.get()) {
-            mSplitSelectDataHolder.setInitialTaskSelect(null /*intent*/,
-                    stagePosition, null /*itemInfo*/, null /*splitEvent*/,
-                    taskId1);
-            mSplitSelectDataHolder.setSecondTask(taskId2);
-        }
-        launchTasks(taskId1, null /* intent1 */, taskId2, null /* intent2 */, stagePosition,
-                callback, freezeTaskList, splitRatio, null);
-    }
-
-    /**
      * To be called when we want to launch split pairs from Overview. Split can be initiated from
      * either Overview or home, or all apps. Either both taskIds are set, or a pending intent + a
      * fill in intent with a taskId2 are set.
@@ -510,6 +480,47 @@
         }
     }
 
+    /**
+     * Used to launch split screen from a split pair that already exists (usually accessible through
+     * Overview). This is different than
+     * {@link #launchTasks(int, Intent, int, Intent, int, Consumer, boolean, float, InstanceId)} in
+     * that this only launches split screen that are existing tasks. This doesn't determine which
+     * API should be used (i.e. launching split with existing tasks vs intents vs shortcuts, etc).
+     *
+     * <p/>
+     * NOTE: This is not to be used to launch AppPairs.
+     */
+    public void launchExistingSplitPair(@Nullable GroupedTaskView groupedTaskView,
+            int firstTaskId, int secondTaskId, @StagePosition int stagePosition,
+            Consumer<Boolean> callback, boolean freezeTaskList, float splitRatio) {
+        mLaunchingTaskView = groupedTaskView;
+        final ActivityOptions options1 = ActivityOptions.makeBasic();
+        if (freezeTaskList) {
+            options1.setFreezeRecentTasksReordering();
+        }
+        Bundle optionsBundle = options1.toBundle();
+
+        if (TaskAnimationManager.ENABLE_SHELL_TRANSITIONS) {
+            final RemoteSplitLaunchTransitionRunner animationRunner =
+                    new RemoteSplitLaunchTransitionRunner(firstTaskId, secondTaskId, callback);
+            final RemoteTransition remoteTransition = new RemoteTransition(animationRunner,
+                    ActivityThread.currentActivityThread().getApplicationThread(),
+                    "LaunchSplitPair");
+            mSystemUiProxy.startTasks(firstTaskId, optionsBundle, secondTaskId,
+                    null /* options2 */, stagePosition, splitRatio,
+                    remoteTransition, null /*shellInstanceId*/);
+        } else {
+            final RemoteSplitLaunchAnimationRunner animationRunner =
+                    new RemoteSplitLaunchAnimationRunner(firstTaskId, secondTaskId, callback);
+            final RemoteAnimationAdapter adapter = new RemoteAnimationAdapter(
+                    animationRunner, 300, 150,
+                    ActivityThread.currentActivityThread().getApplicationThread());
+            mSystemUiProxy.startTasksWithLegacyTransition(firstTaskId, optionsBundle,
+                    secondTaskId, null /* options2 */, stagePosition,
+                    splitRatio, adapter, null /*shellInstanceId*/);
+        }
+    }
+
     private void launchIntentOrShortcut(Intent intent, UserHandle user, ActivityOptions options1,
             int taskId, @StagePosition int stagePosition, float splitRatio,
             RemoteTransition remoteTransition, @Nullable InstanceId shellInstanceId) {
diff --git a/quickstep/src/com/android/quickstep/views/GroupedTaskView.java b/quickstep/src/com/android/quickstep/views/GroupedTaskView.java
index c6c84bd..c91b183 100644
--- a/quickstep/src/com/android/quickstep/views/GroupedTaskView.java
+++ b/quickstep/src/com/android/quickstep/views/GroupedTaskView.java
@@ -223,13 +223,11 @@
         // Callbacks run from remote animation when recents animation not currently running
         InteractionJankMonitorWrapper.begin(this,
                 InteractionJankMonitorWrapper.CUJ_SPLIT_SCREEN_ENTER, "Enter form GroupedTaskView");
-        recentsView.getSplitSelectController().launchTasks(this /*groupedTaskView*/,
-                success -> {
-                    endCallback.executeAllAndDestroy();
-                    InteractionJankMonitorWrapper.end(
-                            InteractionJankMonitorWrapper.CUJ_SPLIT_SCREEN_ENTER);
-                },
-                false /* freezeTaskList */);
+        launchTask(success -> {
+            endCallback.executeAllAndDestroy();
+            InteractionJankMonitorWrapper.end(
+                    InteractionJankMonitorWrapper.CUJ_SPLIT_SCREEN_ENTER);
+        }, false /* freezeTaskList */);
 
         // Callbacks get run from recentsView for case when recents animation already running
         recentsView.addSideTaskLaunchCallback(endCallback);
@@ -238,9 +236,9 @@
 
     @Override
     public void launchTask(@NonNull Consumer<Boolean> callback, boolean isQuickswitch) {
-        getRecentsView().getSplitSelectController().launchTasks(mTask.key.id, mSecondaryTask.key.id,
-                SplitConfigurationOptions.STAGE_POSITION_TOP_OR_LEFT, callback, isQuickswitch,
-                getSplitRatio());
+        getRecentsView().getSplitSelectController().launchExistingSplitPair(this, mTask.key.id,
+                mSecondaryTask.key.id, SplitConfigurationOptions.STAGE_POSITION_TOP_OR_LEFT,
+                callback, isQuickswitch, getSplitRatio());
     }
 
     @Override