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

Commit e1d182b8 authored by Jorge Gil's avatar Jorge Gil
Browse files

Desks: Incompatible Tasks (2/2) - Adjust launch WCT for desks

Makes a couple of adjustments to the WCT in
handleIncompatibleTaskLaunch() when multiple-desks is enabled:
1) to-transparent-fullscren task tracking isn't needed - instead, when
   one of these tasks launches, the desk is kept in an active state.
2) Even if the task is already fullscreen, ensure
   addMoveToFullscreenChanges runs, so the task is reparented to the TDA
   and the desktop state is cleaned up
3) Set |forceExitDesktop| to true|false based on task transparency:
   opaque tasks always force-exit the desktop, transparent tasks always
   keep the desktop active.

Flag: com.android.window.flags.enable_multiple_desktops_backend
Bug: 398295550
Test: while in desktop, launch incompatible tasks and check opaque ones
go fullscreen and exit the desktop, while transparent ones go fullscreen
but keep the desktop active.

Change-Id: I720a6477511fcafa8e914f5703d57e43e1f1c4e8
parent b0ed62e4
Loading
Loading
Loading
Loading
+8 −15
Original line number Diff line number Diff line
@@ -751,12 +751,10 @@ class DesktopRepository(
    fun getTaskInFullImmersiveState(displayId: Int): Int? =
        desktopData.getActiveDesk(displayId)?.fullImmersiveTaskId

    /**
     * Sets the top transparent fullscreen task id for a given display's active desk.
     *
     * TODO: b/389960283 - add explicit [deskId] argument.
     */
    /** Sets the top transparent fullscreen task id for a given display's active desk. */
    @Deprecated("Deprecated with multiple desks")
    fun setTopTransparentFullscreenTaskId(displayId: Int, taskId: Int) {
        if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) return
        logD(
            "Top transparent fullscreen task set for display: taskId=%d, displayId=%d",
            taskId,
@@ -765,23 +763,18 @@ class DesktopRepository(
        desktopData.getActiveDesk(displayId)?.topTransparentFullscreenTaskId = taskId
    }

    /**
     * Returns the top transparent fullscreen task id for a given display, or null.
     *
     * TODO: b/389960283 - add explicit [deskId] argument.
     */
    /** Returns the top transparent fullscreen task id for a given display, or null. */
    @Deprecated("Deprecated with multiple desks")
    fun getTopTransparentFullscreenTaskId(displayId: Int): Int? =
        desktopData
            .desksSequence(displayId)
            .mapNotNull { it.topTransparentFullscreenTaskId }
            .firstOrNull()

    /**
     * Clears the top transparent fullscreen task id info for a given display's active desk.
     *
     * TODO: b/389960283 - add explicit [deskId] argument.
     */
    /** Clears the top transparent fullscreen task id info for a given display's active desk. */
    @Deprecated("Deprecated with multiple desks")
    fun clearTopTransparentFullscreenTaskId(displayId: Int) {
        if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) return
        logD(
            "Top transparent fullscreen task cleared for display: taskId=%d, displayId=%d",
            desktopData.getActiveDesk(displayId)?.topTransparentFullscreenTaskId,
+51 −20
Original line number Diff line number Diff line
@@ -2497,14 +2497,25 @@ class DesktopTasksController(
        task: RunningTaskInfo,
        transition: IBinder,
    ): WindowContainerTransaction? {
        logV("handleIncompatibleTaskLaunch")
        if (!isAnyDeskActive(task.displayId) && !forceEnterDesktop(task.displayId)) return null
        // Only update task repository for transparent task.
        val taskId = task.taskId
        val displayId = task.displayId
        val inDesktop = isAnyDeskActive(displayId)
        val isTransparentTask = desktopModeCompatPolicy.isTransparentTask(task)
        logV(
            "handleIncompatibleTaskLaunch taskId=%d displayId=%d isTransparent=%b inDesktop=%b",
            taskId,
            displayId,
            isTransparentTask,
            inDesktop,
        )
        if (!DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
            if (!inDesktop && !forceEnterDesktop(displayId)) return null
            if (
                DesktopModeFlags.INCLUDE_TOP_TRANSPARENT_FULLSCREEN_TASK_IN_DESKTOP_HEURISTIC
                .isTrue() && desktopModeCompatPolicy.isTransparentTask(task)
                    .isTrue && isTransparentTask
            ) {
            taskRepository.setTopTransparentFullscreenTaskId(task.displayId, task.taskId)
                // Only update task repository for transparent task.
                taskRepository.setTopTransparentFullscreenTaskId(displayId, taskId)
            }
            // Already fullscreen, no-op.
            if (task.isFullscreen) return null
@@ -2515,14 +2526,37 @@ class DesktopTasksController(
                    taskInfo = task,
                    willExitDesktop =
                        willExitDesktop(
                        triggerTaskId = task.taskId,
                        displayId = task.displayId,
                            triggerTaskId = taskId,
                            displayId = displayId,
                            forceExitDesktop = true,
                        ),
                )
            runOnTransitStart?.invoke(transition)
            return wct
        }
        if (!inDesktop) {
            logD("handleIncompatibleTaskLaunch not in desktop, nothing to do")
            return null
        }
        // Both opaque and transparent incompatible tasks need to be forced to fullscreen, but
        // opaque ones force-exit the desktop while transparent ones are just shown on top of the
        // desktop while keeping it active.
        val willExitDesktop = !isTransparentTask
        if (willExitDesktop) {
            logD("handleIncompatibleTaskLaunch forcing task to fullscreen and exiting desktop")
        } else {
            logD("handleIncompatibleTaskLaunch forcing task to fullscreen and staying in desktop")
        }
        val wct = WindowContainerTransaction()
        val runOnTransitStart =
            addMoveToFullscreenChanges(
                wct = wct,
                taskInfo = task,
                willExitDesktop = willExitDesktop,
            )
        runOnTransitStart?.invoke(transition)
        return wct
    }

    /**
     * Handle task closing by removing wallpaper activity if it's the last active task.
@@ -2702,10 +2736,7 @@ class DesktopTasksController(
        return bounds
    }

    /**
     * Applies the changes needed to enter fullscreen and returns the id of the desk that needs to
     * be deactivated.
     */
    /** Applies the changes needed to enter fullscreen and clean up the desktop if needed. */
    private fun addMoveToFullscreenChanges(
        wct: WindowContainerTransaction,
        taskInfo: RunningTaskInfo,
+3 −2
Original line number Diff line number Diff line
@@ -84,8 +84,9 @@ class DesktopTasksTransitionObserver(
    ) {
        // TODO: b/332682201 Update repository state
        if (
            DesktopModeFlags.INCLUDE_TOP_TRANSPARENT_FULLSCREEN_TASK_IN_DESKTOP_HEURISTIC
                .isTrue() && DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_MODALS_POLICY.isTrue()
            DesktopModeFlags.INCLUDE_TOP_TRANSPARENT_FULLSCREEN_TASK_IN_DESKTOP_HEURISTIC.isTrue &&
                DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_MODALS_POLICY.isTrue &&
                !DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue
        ) {
            updateTopTransparentFullscreenTaskId(info)
        }
+2 −0
Original line number Diff line number Diff line
@@ -1163,6 +1163,7 @@ class DesktopRepositoryTest(flags: FlagsParameterization) : ShellTestCase() {
    }

    @Test
    @DisableFlags(FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun setTaskIdAsTopTransparentFullscreenTaskId_savesTaskId() {
        repo.setTopTransparentFullscreenTaskId(displayId = DEFAULT_DISPLAY, taskId = 1)

@@ -1170,6 +1171,7 @@ class DesktopRepositoryTest(flags: FlagsParameterization) : ShellTestCase() {
    }

    @Test
    @DisableFlags(FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun clearTaskIdAsTopTransparentFullscreenTaskId_clearsTaskId() {
        repo.setTopTransparentFullscreenTaskId(displayId = DEFAULT_DISPLAY, taskId = 1)

+5 −1
Original line number Diff line number Diff line
@@ -4708,7 +4708,10 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODALS_POLICY,
        Flags.FLAG_INCLUDE_TOP_TRANSPARENT_FULLSCREEN_TASK_IN_DESKTOP_HEURISTIC,
    )
    @DisableFlags(Flags.FLAG_ENABLE_MODALS_FULLSCREEN_WITH_PERMISSION)
    @DisableFlags(
        Flags.FLAG_ENABLE_MODALS_FULLSCREEN_WITH_PERMISSION,
        Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND,
    )
    fun handleRequest_topActivityTransparentWithDisplay_savedToDesktopRepository() {
        val freeformTask = setUpFreeformTask(displayId = DEFAULT_DISPLAY)
        markTaskVisible(freeformTask)
@@ -4899,6 +4902,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
    }

    @Test
    @DisableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun handleRequest_systemUIActivityWithDisplay_returnSwitchToFullscreenWCT_enforcedDesktop() {
        taskRepository.setDeskInactive(deskId = 0)
        whenever(DesktopModeStatus.enterDesktopByDefaultOnFreeformDisplay(context)).thenReturn(true)
Loading