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

Commit 34a1159d authored by Eghosa Ewansiha-Vlachavas's avatar Eghosa Ewansiha-Vlachavas Committed by Android (Google) Code Review
Browse files

Merge changes Id105ec21,I6ae94af4 into main

* changes:
  Check for recents task info in cascading if running returns null
  Apply desktop specific bounds when moving background task to desktop
parents 48f9868e a36fc150
Loading
Loading
Loading
Loading
+8 −9
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ fun calculateDefaultDesktopTaskBounds(displayLayout: DisplayLayout): Rect {
@JvmOverloads
fun calculateInitialBounds(
    displayLayout: DisplayLayout,
    taskInfo: RunningTaskInfo,
    taskInfo: TaskInfo,
    scale: Float = DESKTOP_MODE_INITIAL_BOUNDS_SCALE,
    captionInsets: Int = 0,
    requestedScreenOrientation: Int? = null,
@@ -78,7 +78,7 @@ fun calculateInitialBounds(
    // Instead default to the desired initial bounds.
    val stableBounds = Rect()
    displayLayout.getStableBoundsForDesktopMode(stableBounds)
    if (hasFullscreenOverride(taskInfo)) {
    if (taskInfo.hasFullscreenOverride()) {
        // If the activity has a fullscreen override applied, it should be treated as
        // resizeable and match the device orientation. Thus the ideal size can be
        // applied.
@@ -197,7 +197,7 @@ fun calculateMaximizeBounds(displayLayout: DisplayLayout, taskInfo: RunningTaskI
 * ratio.
 */
fun maximizeSizeGivenAspectRatio(
    taskInfo: RunningTaskInfo,
    taskInfo: TaskInfo,
    targetArea: Size,
    aspectRatio: Float,
    captionInsets: Int = 0,
@@ -233,7 +233,7 @@ fun maximizeSizeGivenAspectRatio(
}

/** Calculates the aspect ratio of an activity from its fullscreen bounds. */
fun calculateAspectRatio(taskInfo: RunningTaskInfo): Float {
fun calculateAspectRatio(taskInfo: TaskInfo): Float {
    if (taskInfo.appCompatTaskInfo.topNonResizableActivityAspectRatio > 0) {
        return taskInfo.appCompatTaskInfo.topNonResizableActivityAspectRatio
    }
@@ -286,7 +286,7 @@ fun isTaskBoundsEqual(taskBounds: Rect, stableBounds: Rect): Boolean {
fun getInheritedExistingTaskBounds(
    taskRepository: DesktopRepository,
    shellTaskOrganizer: ShellTaskOrganizer,
    task: RunningTaskInfo,
    task: TaskInfo,
    deskId: Int,
): Rect? {
    if (!DesktopModeFlags.INHERIT_TASK_BOUNDS_FOR_TRAMPOLINE_TASK_LAUNCHES.isTrue) return null
@@ -392,7 +392,6 @@ private fun TaskInfo.hasPortraitTopActivity(screenOrientation: Int?): Boolean {
    }
}

private fun hasFullscreenOverride(taskInfo: RunningTaskInfo): Boolean {
    return taskInfo.appCompatTaskInfo.isUserFullscreenOverrideEnabled ||
        taskInfo.appCompatTaskInfo.isSystemFullscreenOverrideEnabled
}
private fun TaskInfo.hasFullscreenOverride(): Boolean =
    appCompatTaskInfo.isUserFullscreenOverrideEnabled ||
        appCompatTaskInfo.isSystemFullscreenOverrideEnabled
+29 −12
Original line number Diff line number Diff line
@@ -1106,6 +1106,8 @@ class DesktopTasksController(
        remoteTransition: RemoteTransition? = null,
        callback: IMoveToDesktopCallback? = null,
    ): Boolean {
        val targetDisplayId = taskRepository.getDisplayForDesk(deskId)
        val displayLayout = displayController.getDisplayLayout(targetDisplayId) ?: return false
        val task = recentTasksController?.findTaskInBackground(taskId)
        if (task == null) {
            logW("moveBackgroundTaskToDesktop taskId=%d not found", taskId)
@@ -1124,7 +1126,10 @@ class DesktopTasksController(
        wct.startTask(
            taskId,
            ActivityOptions.makeBasic()
                .apply { launchWindowingMode = WINDOWING_MODE_FREEFORM }
                .apply {
                    launchWindowingMode = WINDOWING_MODE_FREEFORM
                    launchBounds = getInitialBounds(displayLayout, task, deskId)
                }
                .toBundle(),
        )

@@ -3807,7 +3812,7 @@ class DesktopTasksController(

    private fun getInitialBounds(
        displayLayout: DisplayLayout,
        taskInfo: RunningTaskInfo,
        taskInfo: TaskInfo,
        deskId: Int,
    ): Rect {
        val bounds =
@@ -3899,17 +3904,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
@@ -194,6 +194,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
@@ -2026,6 +2027,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() {
@@ -11480,7 +11511,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