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

Commit 79f9734d authored by Daichi Hirono's avatar Daichi Hirono
Browse files

Remove task from desktop repo when moved to unsupported display

When a task active in the desktop is moved to a display that does not
support desktop mode, it becomes a non-freeform task. This change
ensures that we remove it from the `DesktopRepository` to prevent stale
state.

Bug: 424748132
Test: DesktopTaskChangeListenerTest
Flag: com.android.window.flags.move_to_next_display_shortcut_with_projected_mode
Change-Id: I67933c0367357e00de1e559568222e657f767e88
parent ec76e65d
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -91,6 +91,10 @@ class DesktopTaskChangeListener(
    }

    override fun onTaskChanging(taskInfo: RunningTaskInfo) {
        val desktopRepository: DesktopRepository =
            desktopUserRepositories.getProfile(taskInfo.userId)
        val isFreeformTask = taskInfo.isFreeform
        val isActiveTask = desktopRepository.isActiveTask(taskInfo.taskId)
        if (
            !desktopState.isDesktopModeSupportedOnDisplay(taskInfo.displayId) &&
                DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue
@@ -100,12 +104,20 @@ class DesktopTaskChangeListener(
                taskInfo.taskId,
                taskInfo.displayId,
            )
            if (
                DesktopExperienceFlags.MOVE_TO_NEXT_DISPLAY_SHORTCUT_WITH_PROJECTED_MODE.isTrue &&
                    !isFreeformTask &&
                    isActiveTask
            ) {
                logD(
                    "Removing previous desktop task moved to non-desktop display",
                    taskInfo.taskId,
                    taskInfo.displayId,
                )
                removeTask(desktopRepository, taskInfo.taskId, isClosingTask = false)
            }
            return
        }
        val desktopRepository: DesktopRepository =
            desktopUserRepositories.getProfile(taskInfo.userId)
        val isFreeformTask = taskInfo.isFreeform
        val isActiveTask = desktopRepository.isActiveTask(taskInfo.taskId)
        logD(
            "onTaskChanging for taskId=%d, displayId=%d userId=%s currentUserId=%d " +
                "parentTaskId=%d isFreeform=%b isActive=%b",
+17 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import androidx.test.filters.SmallTest
import com.android.server.am.Flags.FLAG_PERCEPTIBLE_TASKS
import com.android.window.flags.Flags.FLAG_ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION
import com.android.window.flags.Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND
import com.android.window.flags.Flags.FLAG_MOVE_TO_NEXT_DISPLAY_SHORTCUT_WITH_PROJECTED_MODE
import com.android.wm.shell.MockToken
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.TestRunningTaskInfoBuilder
@@ -264,6 +265,22 @@ class DesktopTaskChangeListenerTest : ShellTestCase() {
            )
    }

    @Test
    @EnableFlags(
        FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND,
        FLAG_MOVE_TO_NEXT_DISPLAY_SHORTCUT_WITH_PROJECTED_MODE,
    )
    fun onTaskChanging_taskMovedToUnsupportedDisplay_removesTaskFromRepo() {
        val task = createFullscreenTask()
        whenever(desktopUserRepositories.current.isActiveTask(task.taskId)).thenReturn(true)
        // Task is no longer freeform as it moved to a display that does not support it.
        task.displayId = UNSUPPORTED_DISPLAY_ID

        desktopTaskChangeListener.onTaskChanging(task)

        verify(desktopUserRepositories.current).removeTask(task.taskId)
    }

    @Test
    fun onTaskMovingToFront_fullscreenTask_activeTaskInDesktopRepo_removesTaskFromRepo() {
        val task = createFullscreenTask().apply { isVisible = true }