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

Commit a61b7c93 authored by Eghosa Ewansiha-Vlachavas's avatar Eghosa Ewansiha-Vlachavas
Browse files

Don't inherit task bounds if task belong to different user

Flag: com.android.window.flags.inherit_task_bounds_for_trampoline_task_launches
Fixes: 409520023
Test: Manual - open chrome instance from work profile while default user
instance running. Windows should not overlap.
atest WMShellUnitTests:DesktopTasksControllerTest,
atest WmTests:DesktopModeLaunchParamsModifierTests

Change-Id: Ic732e5c649f166360d290ae1bd84840e7759d4d1
parent 2cbbe4a1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -304,6 +304,8 @@ fun getInheritedExistingTaskBounds(
        currentTaskTopActivity == null -> null
        // Top task is not an instance of the launching activity, do not inherit its bounds.
        lastTaskTopActivity.packageName != currentTaskTopActivity.packageName -> null
        // Tasks belong to different users, do not inherit.
        task.userId != lastTask.userId -> null
        // Top task is an instance of launching activity. Activity will be launching in a new
        // task with the existing task also being closed. Inherit existing task bounds to
        // prevent new task jumping.
+59 −1
Original line number Diff line number Diff line
@@ -124,6 +124,7 @@ import com.android.wm.shell.desktopmode.DesktopModeEventLogger.Companion.Unminim
import com.android.wm.shell.desktopmode.DesktopTasksController.DesktopModeEntryExitTransitionListener
import com.android.wm.shell.desktopmode.DesktopTasksController.SnapPosition
import com.android.wm.shell.desktopmode.DesktopTasksController.TaskbarDesktopTaskListener
import com.android.wm.shell.desktopmode.DesktopTestHelpers.DEFAULT_USER_ID
import com.android.wm.shell.desktopmode.DesktopTestHelpers.createFreeformTask
import com.android.wm.shell.desktopmode.DesktopTestHelpers.createFullscreenTask
import com.android.wm.shell.desktopmode.DesktopTestHelpers.createHomeTask
@@ -1284,7 +1285,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
    @EnableFlags(Flags.FLAG_INHERIT_TASK_BOUNDS_FOR_TRAMPOLINE_TASK_LAUNCHES)
    fun addMoveToDeskTaskChanges_newTaskInstance_inheritsClosingInstanceBounds() {
        // Setup existing task.
        val existingTask = setUpFreeformTask(active = true)
        val existingTask = setUpFreeformTask(active = true).apply { userId = DEFAULT_USER_ID }
        val testComponent = ComponentName(/* package */ "test.package", /* class */ "test.class")
        existingTask.topActivity = testComponent
        existingTask.configuration.windowConfiguration.setBounds(Rect(0, 0, 500, 500))
@@ -1292,6 +1293,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        val launchingTask =
            setUpFullscreenTask().apply {
                topActivityInfo = ActivityInfo().apply { launchMode = LAUNCH_SINGLE_INSTANCE }
                userId = DEFAULT_USER_ID
            }
        launchingTask.topActivity = testComponent

@@ -1305,6 +1307,35 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            .isEqualTo(existingTask.configuration.windowConfiguration.bounds)
    }

    @Test
    @EnableFlags(Flags.FLAG_INHERIT_TASK_BOUNDS_FOR_TRAMPOLINE_TASK_LAUNCHES)
    fun addMoveToDeskTaskChanges_newTaskInstanceInDifferentUser_doesntInheritBounds() {
        // Setup existing task.
        val existingTask = setUpFreeformTask(active = true)
        val testComponent = ComponentName(/* package */ "test.package", /* class */ "test.class")
        existingTask.topActivity = testComponent
        existingTask.configuration.windowConfiguration.setBounds(Rect(0, 0, 500, 500))
        // Set up new instance of already existing task in a different user.
        val launchingTask =
            setUpFullscreenTask().apply {
                topActivityInfo =
                    ActivityInfo().apply {
                        launchMode = LAUNCH_SINGLE_INSTANCE
                        applicationInfo = ApplicationInfo()
                    }
                userId = 100
            }
        launchingTask.topActivity = testComponent

        // Move new instance to desktop.
        val wct = WindowContainerTransaction()
        controller.addMoveToDeskTaskChanges(wct, launchingTask, deskId = 0)

        // New instance should not inherit task bounds of old instance.
        assertThat(findBoundsChange(wct, launchingTask))
            .isNotEqualTo(existingTask.configuration.windowConfiguration.bounds)
    }

    @Test
    @EnableFlags(Flags.FLAG_INHERIT_TASK_BOUNDS_FOR_TRAMPOLINE_TASK_LAUNCHES)
    fun handleRequest_newTaskInstance_inheritsClosingInstanceBounds() {
@@ -1332,6 +1363,33 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        assertThat(finalBounds).isEqualTo(existingTask.configuration.windowConfiguration.bounds)
    }

    @Test
    @EnableFlags(Flags.FLAG_INHERIT_TASK_BOUNDS_FOR_TRAMPOLINE_TASK_LAUNCHES)
    fun handleRequest_newTaskInstanceInDifferentUser_doesntInheritBounds() {
        setUpLandscapeDisplay()
        // Setup existing task.
        val existingTask = setUpFreeformTask(active = true)
        val testComponent = ComponentName(/* package */ "test.package", /* class */ "test.class")
        existingTask.topActivity = testComponent
        existingTask.configuration.windowConfiguration.setBounds(Rect(0, 0, 500, 500))
        // Set up new instance of already existing task.
        val launchingTask =
            setUpFreeformTask(active = false).apply {
                topActivityInfo = ActivityInfo().apply { launchMode = LAUNCH_SINGLE_INSTANCE }
                userId = 100
            }
        taskRepository.removeTask(launchingTask.taskId)
        launchingTask.topActivity = testComponent

        // Move new instance to desktop.
        val wct = controller.handleRequest(Binder(), createTransition(launchingTask))

        assertNotNull(wct, "should handle request")
        val finalBounds = findBoundsChange(wct, launchingTask)
        // New instance should not inherit task bounds of old instance.
        assertThat(finalBounds).isNotEqualTo(existingTask.configuration.windowConfiguration.bounds)
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_CASCADING_WINDOWS)
    fun handleRequest_newFreeformTaskLaunch_cascadeApplied() {
+1 −0
Original line number Diff line number Diff line
@@ -337,6 +337,7 @@ class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
            @NonNull Task launchingTask) {
        if (existingTaskActivity == null || launchingActivity == null) return false;
        return (Objects.equals(existingTaskActivity.packageName, launchingActivity.packageName))
                && (existingTaskActivity.mUserId == launchingTask.mUserId)
                && isLaunchingNewSingleTask(launchingActivity.launchMode)
                && isClosingExitingInstance(launchingTask.getBaseIntent().getFlags());
    }
+32 −0
Original line number Diff line number Diff line
@@ -453,6 +453,38 @@ public class DesktopModeLaunchParamsModifierTests extends
        assertEquals(existingFreeformTask.getBounds(), mResult.mBounds);
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE,
            Flags.FLAG_INHERIT_TASK_BOUNDS_FOR_TRAMPOLINE_TASK_LAUNCHES})
    public void testDontInheritTaskBoundsFromExistingInstanceIfDifferentUser() {
        setupDesktopModeLaunchParamsModifier();

        final String packageName = "com.same.package";
        // Setup existing task.
        final DisplayContent dc = spy(createNewDisplay());
        final Task existingFreeformTask = new TaskBuilder(mSupervisor).setCreateActivity(true)
                .setWindowingMode(WINDOWING_MODE_FREEFORM).setPackage(packageName).build();
        existingFreeformTask.topRunningActivity().launchMode = LAUNCH_SINGLE_INSTANCE;
        existingFreeformTask.setBounds(
                /* left */ 0,
                /* top */ 0,
                /* right */ 500,
                /* bottom */ 500);
        doReturn(existingFreeformTask.getRootActivity()).when(dc)
                .getTopMostVisibleFreeformActivity();
        // Set up new instance of already existing task.
        final Task launchingTask = new TaskBuilder(mSupervisor).setPackage(packageName)
                .setCreateActivity(true).setUserId(100).build();
        launchingTask.topRunningActivity().launchMode = LAUNCH_SINGLE_INSTANCE;
        launchingTask.onDisplayChanged(dc);


        new CalculateRequestBuilder().setTask(launchingTask)
                .setActivity(launchingTask.getRootActivity()).calculate();
        // New instance should not inherit task bounds of old instance.
        assertNotEquals(existingFreeformTask.getBounds(), mResult.mBounds);
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE)
    @DisableFlags(Flags.FLAG_ENABLE_WINDOWING_DYNAMIC_INITIAL_BOUNDS)