Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3359ab54 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Allow SplitScreenController to explicitly request a new instance." into main

parents 0fa7cec6 19b80216
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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 -> {
+15 −4
Original line number Diff line number Diff line
@@ -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,7 +808,8 @@ 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
        final ActivityManager.RecentTaskInfo taskInfo = forceLaunchNewTask ? null :
                mRecentTasksOptional
                        .map(recentTasks -> recentTasks.findTaskInBackground(component, userId1,
                        hideTaskToken))
                .orElse(null);
+3 −2
Original line number Diff line number Diff line
@@ -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)
+22 −0
Original line number Diff line number Diff line
@@ -296,6 +296,28 @@ public class SplitScreenControllerTests extends ShellTestCase {
        verify(mStageCoordinator).switchSplitPosition(anyString());
    }

    @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";