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

Commit 01ca704c authored by Matt Sziklay's avatar Matt Sziklay
Browse files

Allow freeform openInstance to handle non-freeform running tasks.

openInstance has been functioning on the assumption that when the calling task is freeform and the requested task is not freeform, the requested task must be in the background. This is not necessarily the case and leads to incorrect bounds on launch. This CL routes the logic through moveTaskToDesk to correct this assumption.

Bug: 395975053
Test: Manual
Flag: com.android.window.flags.enable_desktop_windowing_multi_instance_features
Change-Id: I03ebc4e0d446db7401bfb1d06318fa789b8a5d1d
parent e09cce99
Loading
Loading
Loading
Loading
+12 −17
Original line number Diff line number Diff line
@@ -450,10 +450,7 @@ class DesktopTasksController(
        }
        // TODO(342378842): Instead of using default display, support multiple displays
        val displayId = runningTask?.displayId ?: DEFAULT_DISPLAY
        val deskId =
            checkNotNull(taskRepository.getDefaultDeskId(displayId)) {
                "Expected a default desk to exist"
            }
        val deskId = getDefaultDeskId(displayId)
        return moveTaskToDesk(
            taskId = taskId,
            deskId = deskId,
@@ -697,10 +694,7 @@ class DesktopTasksController(
     * [startDragToDesktop].
     */
    private fun finalizeDragToDesktop(taskInfo: RunningTaskInfo) {
        val deskId =
            checkNotNull(taskRepository.getDefaultDeskId(taskInfo.displayId)) {
                "Expected a default desk to exist"
            }
        val deskId = getDefaultDeskId(taskInfo.displayId)
        ProtoLog.v(
            WM_SHELL_DESKTOP_MODE,
            "DesktopTasksController: finalizeDragToDesktop taskId=%d deskId=%d",
@@ -1976,8 +1970,10 @@ class DesktopTasksController(
                    unminimizeReason = UnminimizeReason.APP_HANDLE_MENU_BUTTON,
                )
            } else {
                moveBackgroundTaskToDesktop(
                val deskId = getDefaultDeskId(callingTask.displayId)
                moveTaskToDesk(
                    requestedTaskId,
                    deskId,
                    WindowContainerTransaction(),
                    DesktopModeTransitionSource.APP_HANDLE_MENU_BUTTON,
                )
@@ -2534,10 +2530,7 @@ class DesktopTasksController(
        displayId: Int,
        remoteTransition: RemoteTransition? = null,
    ) {
        val deskId =
            checkNotNull(taskRepository.getDefaultDeskId(displayId)) {
                "Expected a default desk to exist"
            }
        val deskId = getDefaultDeskId(displayId)
        activateDesk(deskId, remoteTransition)
    }

@@ -2584,13 +2577,15 @@ class DesktopTasksController(
    /** Removes the default desk in the given display. */
    @Deprecated("Deprecated with multi-desks.", ReplaceWith("removeDesk()"))
    fun removeDefaultDeskInDisplay(displayId: Int) {
        val deskId =
            checkNotNull(taskRepository.getDefaultDeskId(displayId)) {
                "Expected a default desk to exist"
            }
        val deskId = getDefaultDeskId(displayId)
        removeDesk(displayId = displayId, deskId = deskId)
    }

    private fun getDefaultDeskId(displayId: Int) =
        checkNotNull(taskRepository.getDefaultDeskId(displayId)) {
            "Expected a default desk to exist in display: $displayId"
        }

    /** Removes the given desk. */
    fun removeDesk(deskId: Int) {
        val displayId = taskRepository.getDisplayForDesk(deskId)