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

Commit 875d5aee authored by Eghosa Ewansiha-Vlachavas's avatar Eghosa Ewansiha-Vlachavas Committed by Android (Google) Code Review
Browse files

Merge "Don't inherit task bounds if task belong to different user" into main

parents 685092b9 a61b7c93
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
@@ -1286,7 +1287,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))
@@ -1294,6 +1295,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        val launchingTask =
            setUpFullscreenTask().apply {
                topActivityInfo = ActivityInfo().apply { launchMode = LAUNCH_SINGLE_INSTANCE }
                userId = DEFAULT_USER_ID
            }
        launchingTask.topActivity = testComponent

@@ -1307,6 +1309,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() {
@@ -1334,6 +1365,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
@@ -348,6 +348,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
@@ -543,6 +543,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)