diff options
4 files changed, 42 insertions, 7 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt index e078c7e14bd4..4440778a5a45 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt @@ -1225,7 +1225,8 @@ class DesktopTasksController( .determineNewInstancePosition(callingTaskInfo) splitScreenController.startIntent( launchIntent, context.userId, fillIn, splitPosition, - options.toBundle(), null /* hideTaskToken */ + options.toBundle(), null /* hideTaskToken */, + true /* forceLaunchNewTask */ ) } WINDOWING_MODE_FREEFORM -> { 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 9e39f440915c..a23b576beebc 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 @@ -772,15 +772,25 @@ public class SplitScreenController implements SplitDragPolicy.Starter, instanceId); } + @Override + public void startIntent(PendingIntent intent, int userId1, @Nullable Intent fillInIntent, + @SplitPosition int position, @Nullable Bundle options, + @Nullable WindowContainerToken hideTaskToken) { + startIntent(intent, userId1, fillInIntent, position, options, hideTaskToken, + false /* forceLaunchNewTask */); + } + /** * Starts the given intent into split. + * * @param hideTaskToken If non-null, a task matching this token will be moved to back in the * same window container transaction as the starting of the intent. + * @param forceLaunchNewTask If true, this method will skip the check for a background task + * matching the intent and launch a new task. */ - @Override public void startIntent(PendingIntent intent, int userId1, @Nullable Intent fillInIntent, @SplitPosition int position, @Nullable Bundle options, - @Nullable WindowContainerToken hideTaskToken) { + @Nullable WindowContainerToken hideTaskToken, boolean forceLaunchNewTask) { ProtoLog.v(ShellProtoLogGroup.WM_SHELL_SPLIT_SCREEN, "startIntent(): intent=%s user=%d fillInIntent=%s position=%d", intent, userId1, fillInIntent, position); @@ -798,8 +808,9 @@ public class SplitScreenController implements SplitDragPolicy.Starter, // To prevent accumulating large number of instances in the background, reuse task // in the background. If we don't explicitly reuse, new may be created even if the app // isn't multi-instance because WM won't automatically remove/reuse the previous instance - final ActivityManager.RecentTaskInfo taskInfo = mRecentTasksOptional - .map(recentTasks -> recentTasks.findTaskInBackground(component, userId1, + final ActivityManager.RecentTaskInfo taskInfo = forceLaunchNewTask ? null : + mRecentTasksOptional + .map(recentTasks -> recentTasks.findTaskInBackground(component, userId1, hideTaskToken)) .orElse(null); if (taskInfo != null) { diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt index 6531e2a04ada..f9376570dc83 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt @@ -2902,7 +2902,8 @@ class DesktopTasksControllerTest : ShellTestCase() { runOpenNewWindow(task) verify(splitScreenController) .startIntent(any(), anyInt(), any(), any(), - optionsCaptor.capture(), anyOrNull()) + optionsCaptor.capture(), anyOrNull(), eq(true) + ) assertThat(ActivityOptions.fromBundle(optionsCaptor.value).launchWindowingMode) .isEqualTo(WINDOWING_MODE_MULTI_WINDOW) } @@ -2917,7 +2918,7 @@ class DesktopTasksControllerTest : ShellTestCase() { verify(splitScreenController) .startIntent( any(), anyInt(), any(), any(), - optionsCaptor.capture(), anyOrNull() + optionsCaptor.capture(), anyOrNull(), eq(true) ) assertThat(ActivityOptions.fromBundle(optionsCaptor.value).launchWindowingMode) .isEqualTo(WINDOWING_MODE_MULTI_WINDOW) diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/SplitScreenControllerTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/SplitScreenControllerTests.java index 9260a07fd945..ef3af8e7bdac 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/SplitScreenControllerTests.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/SplitScreenControllerTests.java @@ -297,6 +297,28 @@ public class SplitScreenControllerTests extends ShellTestCase { } @Test + public void startIntent_forceLaunchNewTaskTrue_skipsBackgroundTasks() { + Intent startIntent = createStartIntent("startActivity"); + PendingIntent pendingIntent = + PendingIntent.getActivity(mContext, 0, startIntent, FLAG_IMMUTABLE); + mSplitScreenController.startIntent(pendingIntent, mContext.getUserId(), null, + SPLIT_POSITION_TOP_OR_LEFT, null /* options */, null /* hideTaskToken */, + true /* forceLaunchNewTask */); + verify(mRecentTasks, never()).findTaskInBackground(any(), anyInt(), any()); + } + + @Test + public void startIntent_forceLaunchNewTaskFalse_checksBackgroundTasks() { + Intent startIntent = createStartIntent("startActivity"); + PendingIntent pendingIntent = + PendingIntent.getActivity(mContext, 0, startIntent, FLAG_IMMUTABLE); + mSplitScreenController.startIntent(pendingIntent, mContext.getUserId(), null, + SPLIT_POSITION_TOP_OR_LEFT, null /* options */, null /* hideTaskToken */, + false /* forceLaunchNewTask */); + verify(mRecentTasks).findTaskInBackground(any(), anyInt(), any()); + } + + @Test public void testSwitchSplitPosition_checksIsSplitScreenVisible() { final String reason = "test"; when(mSplitScreenController.isSplitScreenVisible()).thenReturn(true, false); |