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

Commit a36fc150 authored by Eghosa Ewansiha-Vlachavas's avatar Eghosa Ewansiha-Vlachavas
Browse files

Check for recents task info in cascading if running returns null

When launching into desktop following a restart, all existing tasks are
in recents and not running yet. Currently cascading only checks for
running taskInfo so no cascading is applied. Updated cascading to check
for recents taskInfo if not running taskInfo is found.

Flag: com.android.window.flags.enable_cascading_windows
Test: atest WMShellUnitTests:DesktopTasksControllerTest
Bug: 408092956

Change-Id: Id105ec21f87e1b63ec9cc24909119e87fd06571e
parent ca75abb2
Loading
Loading
Loading
Loading
+22 −10
Original line number Diff line number Diff line
@@ -3847,17 +3847,29 @@ class DesktopTasksController(
            displayLayout.getStableBoundsForDesktopMode(stableBounds)
        }

        val activeTasks = taskRepository.getExpandedTasksIdsInDeskOrdered(deskId)
        activeTasks
        val expandedTasks = taskRepository.getExpandedTasksIdsInDeskOrdered(deskId)
        expandedTasks
            .firstOrNull { !taskRepository.isClosingTask(it) }
            ?.let { activeTask ->
                shellTaskOrganizer.getRunningTaskInfo(activeTask)?.let {
                    cascadeWindow(
                        context.resources,
                        stableBounds,
                        it.configuration.windowConfiguration.bounds,
                        bounds,
                    )
            ?.let { taskId: Int ->
                val taskInfo =
                    shellTaskOrganizer.getRunningTaskInfo(taskId)
                        ?: recentTasksController?.findTaskInBackground(taskId)
                taskInfo?.let {
                    val taskBounds = it.configuration.windowConfiguration.bounds
                    if (!taskBounds.isEmpty()) {
                        cascadeWindow(context.resources, stableBounds, taskBounds, bounds)
                        return@let
                    }
                    // RecentsTaskInfo might not have configuration bounds populated yet so use
                    // task lastNonFullscreenBounds if available. If null or empty bounds are found
                    // do not cascade.
                    if (it is RecentTaskInfo) {
                        it.lastNonFullscreenBounds?.let {
                            if (!it.isEmpty()) {
                                cascadeWindow(context.resources, stableBounds, it, bounds)
                            }
                        }
                    }
                }
            }
    }
+32 −1
Original line number Diff line number Diff line
@@ -193,6 +193,7 @@ import org.junit.Assume.assumeTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.AdditionalMatchers.not
import org.mockito.ArgumentMatchers.isA
import org.mockito.ArgumentMatchers.isNull
import org.mockito.Mock
@@ -2025,6 +2026,36 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
                .onEnterDesktopModeTransitionStarted(TO_DESKTOP_ANIM_DURATION)
        }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_CASCADING_WINDOWS)
    fun moveToDesk_existingDeskTasksInBackground_cascadeApplied() {
        val stableBounds =
            Rect(0, 0, DISPLAY_DIMENSION_LONG, DISPLAY_DIMENSION_SHORT - TASKBAR_FRAME_HEIGHT)
        whenever(displayLayout.getStableBounds(any())).thenAnswer { i ->
            (i.arguments.first() as Rect).set(stableBounds)
        }
        setUpLandscapeDisplay()

        val freeformTask = setUpFreeformTask(bounds = DEFAULT_LANDSCAPE_BOUNDS, background = true)
        val recentsFreeformTask =
            createRecentTaskInfo(taskId = freeformTask.taskId, displayId = freeformTask.displayId)
        recentsFreeformTask.lastNonFullscreenBounds = DEFAULT_LANDSCAPE_BOUNDS
        whenever(recentTasksController.findTaskInBackground(anyInt()))
            .thenReturn(recentsFreeformTask)
        val fullscreenTask = setUpFullscreenTask()

        controller.moveTaskToDefaultDeskAndActivate(
            fullscreenTask.taskId,
            transitionSource = UNKNOWN,
        )

        val wct = getLatestEnterDesktopWct()
        assertNotNull(wct, "should move to desk")
        val finalBounds = findBoundsChange(wct, fullscreenTask)
        assertThat(stableBounds.getDesktopTaskPosition(finalBounds!!))
            .isEqualTo(DesktopTaskPosition.BottomRight)
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun moveTaskToDesk_nonDefaultDesk_movesTaskToDesk() {
@@ -11481,7 +11512,7 @@ private fun WindowContainerTransaction?.anyWindowingModeChange(
    } ?: false
}

private fun createRecentTaskInfo(taskId: Int, displayId: Int = DEFAULT_DISPLAY) =
private fun createRecentTaskInfo(taskId: Int, displayId: Int = DEFAULT_DISPLAY): RecentTaskInfo =
    RecentTaskInfo().apply {
        this.taskId = taskId
        this.displayId = displayId