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

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

Merge changes I0d636306,I00c0ff07 into main

* changes:
  [18/N] Desks: Deactive desk on core-started task close
  [16/N] Desks: Create minimization root for each desk
parents e9485079 f875abfb
Loading
Loading
Loading
Loading
+29 −22
Original line number Diff line number Diff line
@@ -332,29 +332,22 @@ class DesktopRepository(
        return false
    }

    /**
     * Adds given task to the closing task list for [displayId]'s active desk.
     *
     * TODO: b/389960283 - add explicit [deskId] argument.
     */
    fun addClosingTask(displayId: Int, taskId: Int) {
        val activeDesk =
            desktopData.getActiveDesk(displayId)
                ?: error("Expected active desk in display: $displayId")
        if (activeDesk.closingTasks.add(taskId)) {
            logD(
                "Added closing task=%d displayId=%d deskId=%d",
                taskId,
                displayId,
                activeDesk.deskId,
            )
    /** Adds given task to the closing task list of its desk. */
    fun addClosingTask(displayId: Int, deskId: Int?, taskId: Int) {
        val desk =
            deskId?.let { desktopData.getDesk(it) }
                ?: checkNotNull(desktopData.getActiveDesk(displayId)) {
                    "Expected active desk in display: $displayId"
                }
        if (desk.closingTasks.add(taskId)) {
            logD("Added closing task=%d displayId=%d deskId=%d", taskId, displayId, desk.deskId)
        } else {
            // If the task hasn't been removed from closing list after it disappeared.
            logW(
                "Task with taskId=%d displayId=%d deskId=%d is already closing",
                taskId,
                displayId,
                activeDesk.deskId,
                desk.deskId,
            )
        }
    }
@@ -392,7 +385,8 @@ class DesktopRepository(
     * Checks if a task is the only visible, non-closing, non-minimized task on the active desk of
     * the given display, or any display's active desk if [displayId] is [INVALID_DISPLAY].
     *
     * TODO: b/389960283 - add explicit [deskId] argument.
     * TODO: b/389960283 - consider forcing callers to use [isOnlyVisibleNonClosingTaskInDesk] with
     *   an explicit desk id instead of using this function and defaulting to the active one.
     */
    fun isOnlyVisibleNonClosingTask(taskId: Int, displayId: Int = INVALID_DISPLAY): Boolean {
        val activeDesks =
@@ -402,12 +396,25 @@ class DesktopRepository(
                desktopData.getAllActiveDesks()
            }
        return activeDesks.any { desk ->
            desk.visibleTasks
            isOnlyVisibleNonClosingTaskInDesk(
                taskId = taskId,
                deskId = desk.deskId,
                displayId = desk.displayId,
            )
        }
    }

    /**
     * Checks if a task is the only visible, non-closing, non-minimized task on the given desk of
     * the given display.
     */
    fun isOnlyVisibleNonClosingTaskInDesk(taskId: Int, deskId: Int, displayId: Int): Boolean {
        val desk = desktopData.getDesk(deskId) ?: return false
        return desk.visibleTasks
            .subtract(desk.closingTasks)
            .subtract(desk.minimizedTasks)
            .singleOrNull() == taskId
    }
    }

    /**
     * Returns the active tasks in the given display's active desk.
+55 −19
Original line number Diff line number Diff line
@@ -802,6 +802,9 @@ class DesktopTasksController(
    ): ((IBinder) -> Unit) {
        val taskId = taskInfo.taskId
        val deskId = taskRepository.getDeskIdForTask(taskInfo.taskId)
        if (deskId == null && DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
            error("Did not find desk for task: $taskId")
        }
        snapEventHandler.removeTaskIfTiled(displayId, taskId)
        val shouldExitDesktop =
            willExitDesktop(
@@ -819,7 +822,7 @@ class DesktopTasksController(
                shouldEndUpAtHome = true,
            )

        taskRepository.addClosingTask(displayId, taskId)
        taskRepository.addClosingTask(displayId = displayId, deskId = deskId, taskId = taskId)
        taskbarDesktopTaskListener?.onTaskbarCornerRoundingUpdate(
            doesAnyTaskRequireTaskbarRounding(displayId, taskId)
        )
@@ -871,6 +874,10 @@ class DesktopTasksController(
    private fun minimizeTaskInner(taskInfo: RunningTaskInfo, minimizeReason: MinimizeReason) {
        val taskId = taskInfo.taskId
        val deskId = taskRepository.getDeskIdForTask(taskInfo.taskId)
        if (deskId == null && DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
            logW("minimizeTaskInner: desk not found for task: ${taskInfo.taskId}")
            return
        }
        val displayId = taskInfo.displayId
        val wct = WindowContainerTransaction()

@@ -891,10 +898,26 @@ class DesktopTasksController(
                taskInfo = taskInfo,
                reason = DesktopImmersiveController.ExitReason.MINIMIZED,
            )

        wct.reorder(taskInfo.token, false)
        val isLastTask = taskRepository.isOnlyVisibleNonClosingTask(taskId, displayId)
        val transition: IBinder =
        if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
            desksOrganizer.minimizeTask(
                wct = wct,
                deskId = checkNotNull(deskId) { "Expected non-null deskId" },
                task = taskInfo,
            )
        } else {
            wct.reorder(taskInfo.token, /* onTop= */ false)
        }
        val isLastTask =
            if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
                taskRepository.isOnlyVisibleNonClosingTaskInDesk(
                    taskId = taskId,
                    deskId = checkNotNull(deskId) { "Expected non-null deskId" },
                    displayId = displayId,
                )
            } else {
                taskRepository.isOnlyVisibleNonClosingTask(taskId = taskId, displayId = displayId)
            }
        val transition =
            freeformTaskTransitionStarter.startMinimizedModeTransition(wct, taskId, isLastTask)
        desktopTasksLimiter.ifPresent {
            it.addPendingMinimizeChange(
@@ -1232,9 +1255,9 @@ class DesktopTasksController(
        //  home.
        if (Flags.enablePerDisplayDesktopWallpaperActivity()) {
            performDesktopExitCleanupIfNeeded(
                task.taskId,
                task.displayId,
                wct,
                taskId = task.taskId,
                displayId = task.displayId,
                wct = wct,
                forceToFullscreen = false,
                // TODO: b/371096166 - Temporary turing home relaunch off to prevent home stealing
                // display focus. Remove shouldEndUpAtHome = false when home focus handling
@@ -1801,6 +1824,7 @@ class DesktopTasksController(

    private fun performDesktopExitCleanupIfNeeded(
        taskId: Int,
        deskId: Int? = null,
        displayId: Int,
        wct: WindowContainerTransaction,
        forceToFullscreen: Boolean,
@@ -1814,13 +1838,14 @@ class DesktopTasksController(
        //  |RunOnTransitStart| when the transition is started.
        return performDesktopExitCleanUp(
            wct = wct,
            deskId = null,
            deskId = deskId,
            displayId = displayId,
            willExitDesktop = true,
            shouldEndUpAtHome = shouldEndUpAtHome,
        )
    }

    /** TODO: b/394268248 - update [deskId] to be non-null. */
    private fun performDesktopExitCleanUp(
        wct: WindowContainerTransaction,
        deskId: Int?,
@@ -2373,17 +2398,28 @@ class DesktopTasksController(
    ): WindowContainerTransaction? {
        logV("handleTaskClosing")
        if (!isDesktopModeShowing(task.displayId)) return null
        val deskId = taskRepository.getDeskIdForTask(task.taskId)
        if (deskId == null && DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
            return null
        }

        val wct = WindowContainerTransaction()
        val deactivationRunnable =
            performDesktopExitCleanupIfNeeded(
            task.taskId,
            task.displayId,
            wct,
                taskId = task.taskId,
                deskId = deskId,
                displayId = task.displayId,
                wct = wct,
                forceToFullscreen = false,
            )
        deactivationRunnable?.invoke(transition)

        if (!DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION.isTrue()) {
            taskRepository.addClosingTask(task.displayId, task.taskId)
            taskRepository.addClosingTask(
                displayId = task.displayId,
                deskId = deskId,
                taskId = task.taskId,
            )
            snapEventHandler.removeTaskIfTiled(task.displayId, task.taskId)
        }

@@ -2587,9 +2623,9 @@ class DesktopTasksController(
        wct.setDensityDpi(taskInfo.token, getDefaultDensityDpi())

        performDesktopExitCleanupIfNeeded(
            taskInfo.taskId,
            taskInfo.displayId,
            wct,
            taskId = taskInfo.taskId,
            displayId = taskInfo.displayId,
            wct = wct,
            forceToFullscreen = false,
            shouldEndUpAtHome = false,
        )
+10 −0
Original line number Diff line number Diff line
@@ -40,9 +40,19 @@ interface DesksOrganizer {
        task: ActivityManager.RunningTaskInfo,
    )

    /** Minimizes the given task of the given deskId. */
    fun minimizeTask(
        wct: WindowContainerTransaction,
        deskId: Int,
        task: ActivityManager.RunningTaskInfo,
    )

    /** Whether the change is for the given desk id. */
    fun isDeskChange(change: TransitionInfo.Change, deskId: Int): Boolean

    /** Whether the change is for a known desk. */
    fun isDeskChange(change: TransitionInfo.Change): Boolean

    /**
     * Returns the desk id in which the task in the given change is located at the end of a
     * transition, if any.
+240 −45

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -333,7 +333,7 @@ class DesktopRepositoryTest(flags: FlagsParameterization) : ShellTestCase() {
    @Test
    fun isOnlyVisibleNonClosingTask_singleVisibleClosingTask() {
        repo.updateTask(DEFAULT_DISPLAY, taskId = 1, isVisible = true)
        repo.addClosingTask(DEFAULT_DISPLAY, 1)
        repo.addClosingTask(displayId = DEFAULT_DISPLAY, deskId = 0, taskId = 1)

        // A visible task that's closing
        assertThat(repo.isVisibleTask(1)).isTrue()
Loading