From 8e89deb7610d3a757ff68b077706e6553af1504c Mon Sep 17 00:00:00 2001 From: Chilun Huang Date: Wed, 14 Sep 2022 14:16:20 +0800 Subject: Reuse tasks in background in priority for split screen When dragging the same app to the other side, we will try to reuse the task in background instead of directly launching a new instance. Bug: 241181313 Test: atest WMShellUnitTests Change-Id: Ifd1329ae0b634d8b27a6960e4500458a09cf69f4 --- .../wm/shell/recents/RecentTasksController.java | 23 ++++++++++++++++++++++ .../shell/splitscreen/SplitScreenController.java | 13 +++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) (limited to 'libs') diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasksController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasksController.java index ff4b2edb7310..f8799945134f 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasksController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasksController.java @@ -24,6 +24,7 @@ import static com.android.wm.shell.common.ExecutorUtils.executeRemoteCallWithTas import android.app.ActivityManager; import android.app.ActivityTaskManager; import android.app.TaskInfo; +import android.content.ComponentName; import android.content.Context; import android.os.RemoteException; import android.util.Slog; @@ -327,6 +328,28 @@ public class RecentTasksController implements TaskStackListenerCallback, return recentTasks; } + /** + * Find the background task that match the given component. + */ + @Nullable + public ActivityManager.RecentTaskInfo findTaskInBackground(ComponentName componentName) { + if (componentName == null) { + return null; + } + List tasks = getRawRecentTasks(Integer.MAX_VALUE, + ActivityManager.RECENT_IGNORE_UNAVAILABLE, ActivityManager.getCurrentUser()); + for (int i = 0; i < tasks.size(); i++) { + final ActivityManager.RecentTaskInfo task = tasks.get(i); + if (task.isVisible) { + continue; + } + if (componentName.equals(task.baseIntent.getComponent())) { + return task; + } + } + return null; + } + public void dump(@NonNull PrintWriter pw, String prefix) { final String innerPrefix = prefix + " "; pw.println(prefix + TAG); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java index 3758471664cc..088ee7f483bf 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java @@ -371,6 +371,9 @@ public class SplitScreenController implements DragAndDropPolicy.Starter, } @Override public void onAnimationCancelled(boolean isKeyguardOccluded) { + final WindowContainerTransaction evictWct = new WindowContainerTransaction(); + mStageCoordinator.prepareEvictInvisibleChildTasks(evictWct); + mSyncQueue.queue(evictWct); } }; options = mStageCoordinator.resolveStartStage(STAGE_TYPE_UNDEFINED, position, options, @@ -458,8 +461,16 @@ public class SplitScreenController implements DragAndDropPolicy.Starter, fillInIntent.addFlags(FLAG_ACTIVITY_NO_USER_ACTION); // Flag with MULTIPLE_TASK if this is launching the same activity into both sides of the - // split. + // split and there is no reusable background task. if (shouldAddMultipleTaskFlag(intent.getIntent(), position)) { + final ActivityManager.RecentTaskInfo taskInfo = mRecentTasksOptional.isPresent() + ? mRecentTasksOptional.get().findTaskInBackground( + intent.getIntent().getComponent()) + : null; + if (taskInfo != null) { + startTask(taskInfo.taskId, position, options); + return; + } fillInIntent.addFlags(FLAG_ACTIVITY_MULTIPLE_TASK); ProtoLog.v(ShellProtoLogGroup.WM_SHELL_SPLIT_SCREEN, "Adding MULTIPLE_TASK"); } -- cgit v1.2.3-59-g8ed1b