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

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

Apply desktop specific bounds when moving background task to desktop

When moving a background task to desktop, calculate desktop initial
bounds and apply to task via activity options.

Flag: EXEMPT bug fix
Test: m && atest WMShellUnitTests:DesktopTasksControllerTest
Bug: 408092956

Change-Id: I6ae94af4b79cc71396079bd0ed8bd80159ee5822
parent b3477a65
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
+7 −2
Original line number Diff line number Diff line
@@ -1074,6 +1074,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)
@@ -1092,7 +1094,10 @@ class DesktopTasksController(
        wct.startTask(
            taskId,
            ActivityOptions.makeBasic()
                .apply { launchWindowingMode = WINDOWING_MODE_FREEFORM }
                .apply {
                    launchWindowingMode = WINDOWING_MODE_FREEFORM
                    launchBounds = getInitialBounds(displayLayout, task, deskId)
                }
                .toBundle(),
        )

@@ -3750,7 +3755,7 @@ class DesktopTasksController(

    private fun getInitialBounds(
        displayLayout: DisplayLayout,
        taskInfo: RunningTaskInfo,
        taskInfo: TaskInfo,
        deskId: Int,
    ): Rect {
        val bounds =