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

Commit 48f483b8 authored by Jorge Gil's avatar Jorge Gil Committed by Android (Google) Code Review
Browse files

Merge changes I4c6066ae,I21c3c7c8,Iff6475b6 into main

* changes:
  [30/N] Desks: Track desk deactivation on moves to fullscreen
  [29/N] Desks: Add #addMoveTaskToDeskChanges
  [28/N] Desks: Always use prepareMoveTaskToDesk
parents 6e63524c 6ad54c34
Loading
Loading
Loading
Loading
+88 −83
Original line number Original line Diff line number Diff line
@@ -677,11 +677,7 @@ class DesktopTasksController(
                // Bring other apps to front first.
                // Bring other apps to front first.
                bringDesktopAppsToFrontBeforeShowingNewTask(displayId, wct, task.taskId)
                bringDesktopAppsToFrontBeforeShowingNewTask(displayId, wct, task.taskId)
            }
            }
        if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
        addMoveToDeskTaskChanges(wct = wct, task = task, deskId = deskId)
            prepareMoveTaskToDesk(wct, task, deskId)
        } else {
            addMoveToDesktopChanges(wct, task)
        }
        return taskIdToMinimize
        return taskIdToMinimize
    }
    }


@@ -1260,6 +1256,8 @@ class DesktopTasksController(
     * Move [task] to display with [displayId].
     * Move [task] to display with [displayId].
     *
     *
     * No-op if task is already on that display per [RunningTaskInfo.displayId].
     * No-op if task is already on that display per [RunningTaskInfo.displayId].
     *
     * TODO: b/399411604 - split this up into smaller functions.
     */
     */
    private fun moveToDisplay(task: RunningTaskInfo, displayId: Int) {
    private fun moveToDisplay(task: RunningTaskInfo, displayId: Int) {
        logV("moveToDisplay: taskId=%d displayId=%d", task.taskId, displayId)
        logV("moveToDisplay: taskId=%d displayId=%d", task.taskId, displayId)
@@ -1315,16 +1313,20 @@ class DesktopTasksController(


        // TODO: b/393977830 and b/397437641 - do not assume that freeform==desktop.
        // TODO: b/393977830 and b/397437641 - do not assume that freeform==desktop.
        if (!task.isFreeform) {
        if (!task.isFreeform) {
            addMoveToDesktopChanges(wct, task, displayId)
            addMoveToDeskTaskChanges(wct = wct, task = task, deskId = destinationDeskId)
        } else if (Flags.enableMoveToNextDisplayShortcut()) {
        } else {
            if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
                desksOrganizer.moveTaskToDesk(wct, destinationDeskId, task)
            }
            if (Flags.enableMoveToNextDisplayShortcut()) {
                applyFreeformDisplayChange(wct, task, displayId)
                applyFreeformDisplayChange(wct, task, displayId)
            }
            }
        }


        if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
        if (!DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
            desksOrganizer.moveTaskToDesk(wct, destinationDeskId, task)
        } else {
            wct.reparent(task.token, displayAreaInfo.token, /* onTop= */ true)
            wct.reparent(task.token, displayAreaInfo.token, /* onTop= */ true)
        }
        }

        addDeskActivationChanges(destinationDeskId, wct)
        addDeskActivationChanges(destinationDeskId, wct)
        val activationRunnable: RunOnTransitStart = { transition ->
        val activationRunnable: RunOnTransitStart = { transition ->
            desksTransitionObserver.addPendingTransition(
            desksTransitionObserver.addPendingTransition(
@@ -2062,12 +2064,13 @@ class DesktopTasksController(
            triggerTask?.let { task ->
            triggerTask?.let { task ->
                when {
                when {
                    // Check if freeform task launch during recents should be handled
                    // Check if freeform task launch during recents should be handled
                    shouldHandleMidRecentsFreeformLaunch -> handleMidRecentsFreeformTaskLaunch(task)
                    shouldHandleMidRecentsFreeformLaunch ->
                        handleMidRecentsFreeformTaskLaunch(task, transition)
                    // Check if the closing task needs to be handled
                    // Check if the closing task needs to be handled
                    TransitionUtil.isClosingType(request.type) ->
                    TransitionUtil.isClosingType(request.type) ->
                        handleTaskClosing(task, transition, request.type)
                        handleTaskClosing(task, transition, request.type)
                    // Check if the top task shouldn't be allowed to enter desktop mode
                    // Check if the top task shouldn't be allowed to enter desktop mode
                    isIncompatibleTask(task) -> handleIncompatibleTaskLaunch(task)
                    isIncompatibleTask(task) -> handleIncompatibleTaskLaunch(task, transition)
                    // Check if fullscreen task should be updated
                    // Check if fullscreen task should be updated
                    task.isFullscreen -> handleFullscreenTaskLaunch(task, transition)
                    task.isFullscreen -> handleFullscreenTaskLaunch(task, transition)
                    // Check if freeform task should be updated
                    // Check if freeform task should be updated
@@ -2306,10 +2309,12 @@ class DesktopTasksController(
     * This is a special case where we want to launch the task in fullscreen instead of freeform.
     * This is a special case where we want to launch the task in fullscreen instead of freeform.
     */
     */
    private fun handleMidRecentsFreeformTaskLaunch(
    private fun handleMidRecentsFreeformTaskLaunch(
        task: RunningTaskInfo
        task: RunningTaskInfo,
        transition: IBinder,
    ): WindowContainerTransaction? {
    ): WindowContainerTransaction? {
        logV("DesktopTasksController: handleMidRecentsFreeformTaskLaunch")
        logV("DesktopTasksController: handleMidRecentsFreeformTaskLaunch")
        val wct = WindowContainerTransaction()
        val wct = WindowContainerTransaction()
        val runOnTransitStart =
            addMoveToFullscreenChanges(
            addMoveToFullscreenChanges(
                wct = wct,
                wct = wct,
                taskInfo = task,
                taskInfo = task,
@@ -2320,6 +2325,7 @@ class DesktopTasksController(
                        forceExitDesktop = true,
                        forceExitDesktop = true,
                    ),
                    ),
            )
            )
        runOnTransitStart?.invoke(transition)
        wct.reorder(task.token, true)
        wct.reorder(task.token, true)
        return wct
        return wct
    }
    }
@@ -2343,6 +2349,7 @@ class DesktopTasksController(
                // launched. We should make this task go to fullscreen instead of freeform. Note
                // launched. We should make this task go to fullscreen instead of freeform. Note
                // that this means any re-launch of a freeform window outside of desktop will be in
                // that this means any re-launch of a freeform window outside of desktop will be in
                // fullscreen as long as default-desktop flag is disabled.
                // fullscreen as long as default-desktop flag is disabled.
                val runOnTransitStart =
                    addMoveToFullscreenChanges(
                    addMoveToFullscreenChanges(
                        wct = wct,
                        wct = wct,
                        taskInfo = task,
                        taskInfo = task,
@@ -2353,6 +2360,7 @@ class DesktopTasksController(
                                forceExitDesktop = true,
                                forceExitDesktop = true,
                            ),
                            ),
                    )
                    )
                runOnTransitStart?.invoke(transition)
                return wct
                return wct
            }
            }
            bringDesktopAppsToFrontBeforeShowingNewTask(task.displayId, wct, task.taskId)
            bringDesktopAppsToFrontBeforeShowingNewTask(task.displayId, wct, task.taskId)
@@ -2416,7 +2424,8 @@ class DesktopTasksController(
        if (shouldFullscreenTaskLaunchSwitchToDesktop(task)) {
        if (shouldFullscreenTaskLaunchSwitchToDesktop(task)) {
            logD("Switch fullscreen task to freeform on transition: taskId=%d", task.taskId)
            logD("Switch fullscreen task to freeform on transition: taskId=%d", task.taskId)
            return WindowContainerTransaction().also { wct ->
            return WindowContainerTransaction().also { wct ->
                addMoveToDesktopChanges(wct, task)
                val deskId = getDefaultDeskId(task.displayId)
                addMoveToDeskTaskChanges(wct = wct, task = task, deskId = deskId)
                // In some launches home task is moved behind new task being launched. Make sure
                // In some launches home task is moved behind new task being launched. Make sure
                // that's not the case for launches in desktop. Also, if this launch is the first
                // that's not the case for launches in desktop. Also, if this launch is the first
                // one to trigger the desktop mode (e.g., when [forceEnterDesktop()]), activate the
                // one to trigger the desktop mode (e.g., when [forceEnterDesktop()]), activate the
@@ -2447,7 +2456,8 @@ class DesktopTasksController(
            // If a freeform task receives a request for a fullscreen launch, apply the same
            // If a freeform task receives a request for a fullscreen launch, apply the same
            // changes we do for similar transitions. The task not having WINDOWING_MODE_UNDEFINED
            // changes we do for similar transitions. The task not having WINDOWING_MODE_UNDEFINED
            // set when needed can interfere with future split / multi-instance transitions.
            // set when needed can interfere with future split / multi-instance transitions.
            return WindowContainerTransaction().also { wct ->
            val wct = WindowContainerTransaction()
            val runOnTransitStart =
                addMoveToFullscreenChanges(
                addMoveToFullscreenChanges(
                    wct = wct,
                    wct = wct,
                    taskInfo = task,
                    taskInfo = task,
@@ -2458,7 +2468,8 @@ class DesktopTasksController(
                            forceExitDesktop = true,
                            forceExitDesktop = true,
                        ),
                        ),
                )
                )
            }
            runOnTransitStart?.invoke(transition)
            return wct
        }
        }
        return null
        return null
    }
    }
@@ -2473,7 +2484,10 @@ class DesktopTasksController(
     * If a task is not compatible with desktop mode freeform, it should always be launched in
     * If a task is not compatible with desktop mode freeform, it should always be launched in
     * fullscreen.
     * fullscreen.
     */
     */
    private fun handleIncompatibleTaskLaunch(task: RunningTaskInfo): WindowContainerTransaction? {
    private fun handleIncompatibleTaskLaunch(
        task: RunningTaskInfo,
        transition: IBinder,
    ): WindowContainerTransaction? {
        logV("handleIncompatibleTaskLaunch")
        logV("handleIncompatibleTaskLaunch")
        if (!isDesktopModeShowing(task.displayId) && !forceEnterDesktop(task.displayId)) return null
        if (!isDesktopModeShowing(task.displayId) && !forceEnterDesktop(task.displayId)) return null
        // Only update task repository for transparent task.
        // Only update task repository for transparent task.
@@ -2485,7 +2499,8 @@ class DesktopTasksController(
        }
        }
        // Already fullscreen, no-op.
        // Already fullscreen, no-op.
        if (task.isFullscreen) return null
        if (task.isFullscreen) return null
        return WindowContainerTransaction().also { wct ->
        val wct = WindowContainerTransaction()
        val runOnTransitStart =
            addMoveToFullscreenChanges(
            addMoveToFullscreenChanges(
                wct = wct,
                wct = wct,
                taskInfo = task,
                taskInfo = task,
@@ -2496,7 +2511,8 @@ class DesktopTasksController(
                        forceExitDesktop = true,
                        forceExitDesktop = true,
                    ),
                    ),
            )
            )
        }
        runOnTransitStart?.invoke(transition)
        return wct
    }
    }


    /**
    /**
@@ -2543,21 +2559,32 @@ class DesktopTasksController(
    }
    }


    /**
    /**
     * Apply all changes required when task is first added to desktop. Uses the task's current
     * Applies the [wct] changes needed when a task is first moving to a desk.
     * display by default to apply initial bounds and placement relative to the display. Use a
     *
     * different [displayId] if the task should be moved to a different display.
     * Note that this recalculates the initial bounds of the task, so it should not be used when
     * transferring a task between desks.
     *
     * TODO: b/362720497 - this should be improved to be reusable by desk-to-desk CUJs where
     *   [DesksOrganizer.moveTaskToDesk] needs to be called and even cross-display CUJs where
     *   [applyFreeformDisplayChange] needs to be called. Potentially by comparing source vs
     *   destination desk ids and display ids, or adding extra arguments to the function.
     */
     */
    @VisibleForTesting
    fun addMoveToDeskTaskChanges(
    @Deprecated("Deprecated with multiple desks", ReplaceWith("prepareMoveTaskToDesk()"))
    fun addMoveToDesktopChanges(
        wct: WindowContainerTransaction,
        wct: WindowContainerTransaction,
        taskInfo: RunningTaskInfo,
        task: RunningTaskInfo,
        displayId: Int = taskInfo.displayId,
        deskId: Int,
    ) {
    ) {
        val displayLayout = displayController.getDisplayLayout(displayId) ?: return
        val targetDisplayId = taskRepository.getDisplayForDesk(deskId)
        val tdaInfo = rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(displayId)!!
        val displayLayout = displayController.getDisplayLayout(targetDisplayId) ?: return
        val initialBounds = getInitialBounds(displayLayout, task, targetDisplayId)
        if (canChangeTaskPosition(task)) {
            wct.setBounds(task.token, initialBounds)
        }
        if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
            desksOrganizer.moveTaskToDesk(wct = wct, deskId = deskId, task = task)
        } else {
            val tdaInfo = rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(targetDisplayId)!!
            val tdaWindowingMode = tdaInfo.configuration.windowConfiguration.windowingMode
            val tdaWindowingMode = tdaInfo.configuration.windowConfiguration.windowingMode
        // TODO: b/397437641 - reconsider the windowing mode choice when multiple desks is enabled.
            val targetWindowingMode =
            val targetWindowingMode =
                if (tdaWindowingMode == WINDOWING_MODE_FREEFORM) {
                if (tdaWindowingMode == WINDOWING_MODE_FREEFORM) {
                    // Display windowing is freeform, set to undefined and inherit it
                    // Display windowing is freeform, set to undefined and inherit it
@@ -2565,33 +2592,11 @@ class DesktopTasksController(
                } else {
                } else {
                    WINDOWING_MODE_FREEFORM
                    WINDOWING_MODE_FREEFORM
                }
                }
        val initialBounds = getInitialBounds(displayLayout, taskInfo, displayId)
            wct.setWindowingMode(task.token, targetWindowingMode)

            wct.reorder(task.token, /* onTop= */ true)
        if (canChangeTaskPosition(taskInfo)) {
            wct.setBounds(taskInfo.token, initialBounds)
        }
        wct.setWindowingMode(taskInfo.token, targetWindowingMode)
        wct.reorder(taskInfo.token, /* onTop= */ true)
        if (useDesktopOverrideDensity()) {
            wct.setDensityDpi(taskInfo.token, DESKTOP_DENSITY_OVERRIDE)
        }
    }

    private fun prepareMoveTaskToDesk(
        wct: WindowContainerTransaction,
        taskInfo: RunningTaskInfo,
        deskId: Int,
    ) {
        if (!DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) return
        val displayId = taskRepository.getDisplayForDesk(deskId)
        val displayLayout = displayController.getDisplayLayout(displayId) ?: return
        val initialBounds = getInitialBounds(displayLayout, taskInfo, displayId)
        if (canChangeTaskPosition(taskInfo)) {
            wct.setBounds(taskInfo.token, initialBounds)
        }
        }
        desksOrganizer.moveTaskToDesk(wct, deskId = deskId, task = taskInfo)
        if (useDesktopOverrideDensity()) {
        if (useDesktopOverrideDensity()) {
            wct.setDensityDpi(taskInfo.token, DESKTOP_DENSITY_OVERRIDE)
            wct.setDensityDpi(task.token, DESKTOP_DENSITY_OVERRIDE)
        }
        }
    }
    }


+132 −44

File changed.

Preview size limit exceeded, changes collapsed.