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

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

Cascade based on desk tasks not display tasks

Calculate cascading position based on task in active desk instead of
tasks in current display.

Flag: com.android.window.flags.enable_cascading_windows
Test: atest WMShellUnitTests:DesktopTasksControllerTest
Fixes: 402252345
Change-Id: Idc2dad2c693855d53f1d5d21f9e4e17f85182bfa
parent fb008518
Loading
Loading
Loading
Loading
+20 −19
Original line number Diff line number Diff line
@@ -1460,8 +1460,9 @@ class DesktopTasksController(
        val wct = WindowContainerTransaction()
        val displayLayout = displayController.getDisplayLayout(displayId) ?: return
        val bounds = calculateDefaultDesktopTaskBounds(displayLayout)
        val deskId = getOrCreateDefaultDeskId(displayId) ?: return
        if (DesktopModeFlags.ENABLE_CASCADING_WINDOWS.isTrue) {
            cascadeWindow(bounds, displayLayout, displayId)
            cascadeWindow(bounds, displayLayout, deskId)
        }
        val pendingIntent =
            PendingIntent.getActivityAsUser(
@@ -1486,7 +1487,6 @@ class DesktopTasksController(
            }

        wct.sendPendingIntent(pendingIntent, intent, ops.toBundle())
        val deskId = getOrCreateDefaultDeskId(displayId) ?: return
        startLaunchTransition(
            TRANSIT_OPEN,
            wct,
@@ -1545,7 +1545,7 @@ class DesktopTasksController(
            if (bounds != null) {
                wct.setBounds(task.token, bounds)
            } else if (Flags.enableMoveToNextDisplayShortcut()) {
                applyFreeformDisplayChange(wct, task, displayId)
                applyFreeformDisplayChange(wct, task, displayId, destinationDeskId)
            }
        }

@@ -2430,6 +2430,7 @@ class DesktopTasksController(

    /** Open an existing instance of an app. */
    fun openInstance(callingTask: RunningTaskInfo, requestedTaskId: Int) {
        val deskId = getOrCreateDefaultDeskId(callingTask.displayId) ?: return
        if (callingTask.isFreeform) {
            val requestedTaskInfo = shellTaskOrganizer.getRunningTaskInfo(requestedTaskId)
            if (requestedTaskInfo?.isFreeform == true) {
@@ -2439,7 +2440,6 @@ class DesktopTasksController(
                    unminimizeReason = UnminimizeReason.APP_HANDLE_MENU_BUTTON,
                )
            } else {
                val deskId = getOrCreateDefaultDeskId(callingTask.displayId) ?: return
                moveTaskToDesk(
                    requestedTaskId,
                    deskId,
@@ -2448,7 +2448,7 @@ class DesktopTasksController(
                )
            }
        } else {
            val options = createNewWindowOptions(callingTask)
            val options = createNewWindowOptions(callingTask, deskId)
            val splitPosition = splitScreenController.determineNewInstancePosition(callingTask)
            splitScreenController.startTask(
                requestedTaskId,
@@ -2483,7 +2483,11 @@ class DesktopTasksController(
                /* options= */ null,
                userHandle,
            )
        val options = createNewWindowOptions(callingTaskInfo)
        val deskId =
            taskRepository.getDeskIdForTask(callingTaskInfo.taskId)
                ?: getOrCreateDefaultDeskId(callingTaskInfo.displayId)
                ?: return
        val options = createNewWindowOptions(callingTaskInfo, deskId)
        when (options.launchWindowingMode) {
            WINDOWING_MODE_MULTI_WINDOW -> {
                val splitPosition =
@@ -2508,10 +2512,6 @@ class DesktopTasksController(
            WINDOWING_MODE_FREEFORM -> {
                val wct = WindowContainerTransaction()
                wct.sendPendingIntent(launchIntent, fillIn, options.toBundle())
                val deskId =
                    taskRepository.getDeskIdForTask(callingTaskInfo.taskId)
                        ?: getOrCreateDefaultDeskId(callingTaskInfo.displayId)
                        ?: return
                startLaunchTransition(
                    transitionType = TRANSIT_OPEN,
                    wct = wct,
@@ -2523,7 +2523,7 @@ class DesktopTasksController(
        }
    }

    private fun createNewWindowOptions(callingTask: RunningTaskInfo): ActivityOptions {
    private fun createNewWindowOptions(callingTask: RunningTaskInfo, deskId: Int): ActivityOptions {
        val newTaskWindowingMode =
            when {
                callingTask.isFreeform -> {
@@ -2540,7 +2540,7 @@ class DesktopTasksController(
            when (newTaskWindowingMode) {
                WINDOWING_MODE_FREEFORM -> {
                    displayController.getDisplayLayout(callingTask.displayId)?.let {
                        getInitialBounds(it, callingTask, callingTask.displayId)
                        getInitialBounds(it, callingTask, deskId)
                    }
                }
                WINDOWING_MODE_MULTI_WINDOW -> {
@@ -2694,7 +2694,7 @@ class DesktopTasksController(
            val displayLayout = displayController.getDisplayLayout(task.displayId)
            if (displayLayout != null) {
                val initialBounds = Rect(task.configuration.windowConfiguration.bounds)
                cascadeWindow(initialBounds, displayLayout, task.displayId)
                cascadeWindow(initialBounds, displayLayout, deskId)
                wct.setBounds(task.token, initialBounds)
            }
        }
@@ -2975,7 +2975,7 @@ class DesktopTasksController(
            // cascading positions.
            wct.setBounds(task.token, inheritedTaskBounds)
        } else {
            val initialBounds = getInitialBounds(displayLayout, task, targetDisplayId)
            val initialBounds = getInitialBounds(displayLayout, task, deskId)
            if (canChangeTaskPosition(task)) {
                wct.setBounds(task.token, initialBounds)
            }
@@ -3008,6 +3008,7 @@ class DesktopTasksController(
        wct: WindowContainerTransaction,
        taskInfo: RunningTaskInfo,
        destDisplayId: Int,
        destDeskId: Int,
    ) {
        val sourceLayout = displayController.getDisplayLayout(taskInfo.displayId) ?: return
        val destLayout = displayController.getDisplayLayout(destDisplayId) ?: return
@@ -3039,7 +3040,7 @@ class DesktopTasksController(
                    )
                }
            } else {
                getInitialBounds(destLayout, taskInfo, destDisplayId)
                getInitialBounds(destLayout, taskInfo, destDeskId)
            }
        wct.setBounds(taskInfo.token, boundsWithinDisplay)
    }
@@ -3047,7 +3048,7 @@ class DesktopTasksController(
    private fun getInitialBounds(
        displayLayout: DisplayLayout,
        taskInfo: RunningTaskInfo,
        displayId: Int,
        deskId: Int,
    ): Rect {
        val bounds =
            if (ENABLE_WINDOWING_DYNAMIC_INITIAL_BOUNDS.isTrue) {
@@ -3066,7 +3067,7 @@ class DesktopTasksController(
            }

        if (DesktopModeFlags.ENABLE_CASCADING_WINDOWS.isTrue) {
            cascadeWindow(bounds, displayLayout, displayId)
            cascadeWindow(bounds, displayLayout, deskId)
        }
        return bounds
    }
@@ -3117,11 +3118,11 @@ class DesktopTasksController(
        )
    }

    private fun cascadeWindow(bounds: Rect, displayLayout: DisplayLayout, displayId: Int) {
    private fun cascadeWindow(bounds: Rect, displayLayout: DisplayLayout, deskId: Int) {
        val stableBounds = Rect()
        displayLayout.getStableBoundsForDesktopMode(stableBounds)

        val activeTasks = taskRepository.getExpandedTasksOrdered(displayId)
        val activeTasks = taskRepository.getExpandedTasksIdsInDeskOrdered(deskId)
        activeTasks.firstOrNull()?.let { activeTask ->
            shellTaskOrganizer.getRunningTaskInfo(activeTask)?.let {
                cascadeWindow(
+25 −0
Original line number Diff line number Diff line
@@ -1244,6 +1244,31 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            .isEqualTo(DesktopTaskPosition.BottomRight)
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_CASCADING_WINDOWS, Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun handleRequest_newFreeformTaskLaunch_newDesk_desksCascadeIndependently() {
        setUpLandscapeDisplay()
        val stableBounds = Rect()
        displayLayout.getStableBoundsForDesktopMode(stableBounds)

        // Launch freeform tasks in default desk.
        setUpFreeformTask(bounds = DEFAULT_LANDSCAPE_BOUNDS)
        val freeformTask = setUpFreeformTask(bounds = DEFAULT_LANDSCAPE_BOUNDS, active = false)
        controller.handleRequest(Binder(), createTransition(freeformTask))

        // Create new active desk and launch new task.
        taskRepository.addDesk(DEFAULT_DISPLAY, deskId = 2)
        taskRepository.setActiveDesk(displayId = DEFAULT_DISPLAY, deskId = 2)
        val newDeskTask = setUpFullscreenTask(displayId = DEFAULT_DISPLAY)
        val wct = controller.handleRequest(Binder(), createTransition(newDeskTask))

        // New task should be cascaded independently of tasks in other desks.
        assertNotNull(wct, "should handle request")
        val finalBounds = findBoundsChange(wct, newDeskTask)
        assertThat(stableBounds.getDesktopTaskPosition(finalBounds!!))
            .isEqualTo(DesktopTaskPosition.Center)
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_CASCADING_WINDOWS)
    fun handleRequest_freeformTaskAlreadyExistsInDesktopMode_cascadeNotApplied() {