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

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

Merge "[31/N] Desks: Consolidate desk activation utils" into main

parents 6dae38a7 939036d4
Loading
Loading
Loading
Loading
+30 −65
Original line number Diff line number Diff line
@@ -537,8 +537,7 @@ class DesktopTasksController(
            return false
        }
        logV("moveBackgroundTaskToDesktop with taskId=%d", taskId)
        val taskIdToMinimize =
            bringDesktopAppsToFrontBeforeShowingNewTask(task.displayId, wct, taskId)
        val taskIdToMinimize = bringDesktopAppsToFront(task.displayId, wct, taskId)
        val exitResult =
            desktopImmersiveController.exitImmersiveIfApplicable(
                wct = wct,
@@ -603,13 +602,7 @@ class DesktopTasksController(
                reason = DesktopImmersiveController.ExitReason.TASK_LAUNCH,
            )

        val taskIdToMinimize =
            prepareMoveTaskToDeskAndActivate(
                wct = wct,
                displayId = displayId,
                deskId = deskId,
                task = task,
            )
        val taskIdToMinimize = addDeskActivationWithMovingTaskChanges(deskId, wct, task)

        val transition: IBinder
        if (remoteTransition != null) {
@@ -643,44 +636,6 @@ class DesktopTasksController(
        return true
    }

    /**
     * Applies the necessary changes and operations to [wct] to move a task into a desk and
     * activating that desk. This includes showing pre-existing tasks of that desk behind the new
     * task (but minimizing one of them if needed) and showing Home and the desktop wallpaper.
     *
     * @return the id of the task that is being minimized, if any.
     */
    private fun prepareMoveTaskToDeskAndActivate(
        wct: WindowContainerTransaction,
        displayId: Int,
        deskId: Int,
        task: RunningTaskInfo,
    ): Int? {
        val taskIdToMinimize =
            if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
                // Activate the desk first.
                prepareForDeskActivation(displayId, wct)
                desksOrganizer.activateDesk(wct, deskId)
                if (DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_PERSISTENCE.isTrue()) {
                    // TODO: b/362720497 - do non-running tasks need to be restarted with
                    // |wct#startTask|?
                }
                taskbarDesktopTaskListener?.onTaskbarCornerRoundingUpdate(
                    doesAnyTaskRequireTaskbarRounding(displayId)
                )
                // TODO: b/362720497 - activating a desk with the intention to move a new task to
                //  it means we may need to minimize something in the activating desk. Do so here
                //  similar to how it's done in #bringDesktopAppsToFrontBeforeShowingNewTask
                //  instead of returning null.
                null
            } else {
                // Bring other apps to front first.
                bringDesktopAppsToFrontBeforeShowingNewTask(displayId, wct, task.taskId)
            }
        addMoveToDeskTaskChanges(wct = wct, task = task, deskId = deskId)
        return taskIdToMinimize
    }

    private fun invokeCallbackToOverview(transition: IBinder, callback: IMoveToDesktopCallback?) {
        // TODO: b/333524374 - Remove this later.
        // This is a temporary implementation for adding CUJ end and
@@ -738,13 +693,7 @@ class DesktopTasksController(
                moveHomeTask(context.displayId, wct)
            }
        }
        val taskIdToMinimize =
            prepareMoveTaskToDeskAndActivate(
                wct = wct,
                displayId = taskInfo.displayId,
                deskId = deskId,
                task = taskInfo,
            )
        val taskIdToMinimize = addDeskActivationWithMovingTaskChanges(deskId, wct, taskInfo)
        val exitResult =
            desktopImmersiveController.exitImmersiveIfApplicable(
                wct = wct,
@@ -1733,12 +1682,6 @@ class DesktopTasksController(
        }
    }

    private fun bringDesktopAppsToFrontBeforeShowingNewTask(
        displayId: Int,
        wct: WindowContainerTransaction,
        newTaskIdInFront: Int,
    ): Int? = bringDesktopAppsToFront(displayId, wct, newTaskIdInFront)

    @Deprecated("Use activeDesk() instead.", ReplaceWith("activateDesk()"))
    private fun bringDesktopAppsToFront(
        displayId: Int,
@@ -2363,7 +2306,7 @@ class DesktopTasksController(
                runOnTransitStart?.invoke(transition)
                return wct
            }
            bringDesktopAppsToFrontBeforeShowingNewTask(task.displayId, wct, task.taskId)
            bringDesktopAppsToFront(task.displayId, wct, task.taskId)
            wct.reorder(task.token, true)
            return wct
        }
@@ -2434,7 +2377,7 @@ class DesktopTasksController(
                    task.baseIntent.flags.and(Intent.FLAG_ACTIVITY_TASK_ON_HOME) != 0 ||
                        !isDesktopModeShowing(task.displayId)
                ) {
                    bringDesktopAppsToFrontBeforeShowingNewTask(task.displayId, wct, task.taskId)
                    bringDesktopAppsToFront(task.displayId, wct, task.taskId)
                    wct.reorder(task.token, true)
                }

@@ -2558,6 +2501,20 @@ class DesktopTasksController(
        return if (wct.isEmpty) null else wct
    }

    /**
     * Applies the [wct] changes need when a task is first moving to a desk and the desk needs to be
     * activated.
     */
    private fun addDeskActivationWithMovingTaskChanges(
        deskId: Int,
        wct: WindowContainerTransaction,
        task: RunningTaskInfo,
    ): Int? {
        val taskIdToMinimize = addDeskActivationChanges(deskId, wct, task)
        addMoveToDeskTaskChanges(wct = wct, task = task, deskId = deskId)
        return taskIdToMinimize
    }

    /**
     * Applies the [wct] changes needed when a task is first moving to a desk.
     *
@@ -2827,9 +2784,13 @@ class DesktopTasksController(
    }

    /** Activates the given desk but without starting a transition. */
    fun addDeskActivationChanges(deskId: Int, wct: WindowContainerTransaction) {
    fun addDeskActivationChanges(
        deskId: Int,
        wct: WindowContainerTransaction,
        newTask: RunningTaskInfo? = null,
    ): Int? {
        val displayId = taskRepository.getDisplayForDesk(deskId)
        if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
        return if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
            prepareForDeskActivation(displayId, wct)
            desksOrganizer.activateDesk(wct, deskId)
            if (DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_PERSISTENCE.isTrue()) {
@@ -2838,8 +2799,12 @@ class DesktopTasksController(
            taskbarDesktopTaskListener?.onTaskbarCornerRoundingUpdate(
                doesAnyTaskRequireTaskbarRounding(displayId)
            )
            // TODO: b/362720497 - activating a desk with the intention to move a new task to
            //  it means we may need to minimize something in the activating desk. Do so here
            //  similar to how it's done in #bringDesktopAppsToFront instead of returning null.
            null
        } else {
            bringDesktopAppsToFront(displayId, wct)
            bringDesktopAppsToFront(displayId, wct, newTask?.taskId)
        }
    }