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

Commit f34ef4fc authored by Pragya Bajoria's avatar Pragya Bajoria Committed by Android (Google) Code Review
Browse files

Merge "1. Rename desktopModeTaskRepository to taskRepository in...

Merge "1. Rename desktopModeTaskRepository to taskRepository in DesktopTasksController 2. Update log utils to reduce verbosity in the code." into main
parents 4744da87 3ac48cc9
Loading
Loading
Loading
Loading
+71 −147
Original line number Original line Diff line number Diff line
@@ -121,7 +121,7 @@ class DesktopTasksController(
    private val exitDesktopTaskTransitionHandler: ExitDesktopTaskTransitionHandler,
    private val exitDesktopTaskTransitionHandler: ExitDesktopTaskTransitionHandler,
    private val toggleResizeDesktopTaskTransitionHandler: ToggleResizeDesktopTaskTransitionHandler,
    private val toggleResizeDesktopTaskTransitionHandler: ToggleResizeDesktopTaskTransitionHandler,
    private val dragToDesktopTransitionHandler: DragToDesktopTransitionHandler,
    private val dragToDesktopTransitionHandler: DragToDesktopTransitionHandler,
    private val desktopModeTaskRepository: DesktopModeTaskRepository,
    private val taskRepository: DesktopModeTaskRepository,
    private val desktopModeLoggerTransitionObserver: DesktopModeLoggerTransitionObserver,
    private val desktopModeLoggerTransitionObserver: DesktopModeLoggerTransitionObserver,
    private val launchAdjacentController: LaunchAdjacentController,
    private val launchAdjacentController: LaunchAdjacentController,
    private val recentsTransitionHandler: RecentsTransitionHandler,
    private val recentsTransitionHandler: RecentsTransitionHandler,
@@ -181,7 +181,7 @@ class DesktopTasksController(
    }
    }


    private fun onInit() {
    private fun onInit() {
        ProtoLog.d(WM_SHELL_DESKTOP_MODE, "Initialize DesktopTasksController")
        logD("onInit")
        shellCommandHandler.addDumpCallback(this::dump, this)
        shellCommandHandler.addDumpCallback(this::dump, this)
        shellCommandHandler.addCommandCallback("desktopmode", desktopModeShellCommandHandler, this)
        shellCommandHandler.addCommandCallback("desktopmode", desktopModeShellCommandHandler, this)
        shellController.addExternalInterface(
        shellController.addExternalInterface(
@@ -190,16 +190,12 @@ class DesktopTasksController(
            this
            this
        )
        )
        transitions.addHandler(this)
        transitions.addHandler(this)
        desktopModeTaskRepository.addVisibleTasksListener(taskVisibilityListener, mainExecutor)
        taskRepository.addVisibleTasksListener(taskVisibilityListener, mainExecutor)
        dragToDesktopTransitionHandler.setDragToDesktopStateListener(dragToDesktopStateListener)
        dragToDesktopTransitionHandler.setDragToDesktopStateListener(dragToDesktopStateListener)
        recentsTransitionHandler.addTransitionStateListener(
        recentsTransitionHandler.addTransitionStateListener(
            object : RecentsTransitionStateListener {
            object : RecentsTransitionStateListener {
                override fun onAnimationStateChanged(running: Boolean) {
                override fun onAnimationStateChanged(running: Boolean) {
                    ProtoLog.v(
                    logV("Recents animation state changed running=%b", running)
                        WM_SHELL_DESKTOP_MODE,
                        "DesktopTasksController: recents animation state changed running=%b",
                        running
                    )
                    recentsAnimationRunning = running
                    recentsAnimationRunning = running
                }
                }
            }
            }
@@ -227,7 +223,7 @@ class DesktopTasksController(
    /** Returns the transition type for the given remote transition. */
    /** Returns the transition type for the given remote transition. */
    private fun transitionType(remoteTransition: RemoteTransition?): Int {
    private fun transitionType(remoteTransition: RemoteTransition?): Int {
        if (remoteTransition == null) {
        if (remoteTransition == null) {
            ProtoLog.v(WM_SHELL_DESKTOP_MODE, "DesktopTasksController: remoteTransition is null")
            logV("RemoteTransition is null")
            return TRANSIT_NONE
            return TRANSIT_NONE
        }
        }
        return TRANSIT_TO_FRONT
        return TRANSIT_TO_FRONT
@@ -235,7 +231,7 @@ class DesktopTasksController(


    /** Show all tasks, that are part of the desktop, on top of launcher */
    /** Show all tasks, that are part of the desktop, on top of launcher */
    fun showDesktopApps(displayId: Int, remoteTransition: RemoteTransition? = null) {
    fun showDesktopApps(displayId: Int, remoteTransition: RemoteTransition? = null) {
        ProtoLog.v(WM_SHELL_DESKTOP_MODE, "DesktopTasksController: showDesktopApps")
        logV("showDesktopApps")
        val wct = WindowContainerTransaction()
        val wct = WindowContainerTransaction()
        bringDesktopAppsToFront(displayId, wct)
        bringDesktopAppsToFront(displayId, wct)


@@ -255,7 +251,7 @@ class DesktopTasksController(


    /** Gets number of visible tasks in [displayId]. */
    /** Gets number of visible tasks in [displayId]. */
    fun visibleTaskCount(displayId: Int): Int =
    fun visibleTaskCount(displayId: Int): Int =
        desktopModeTaskRepository.getVisibleTaskCount(displayId)
        taskRepository.getVisibleTaskCount(displayId)


    /** Returns true if any tasks are visible in Desktop Mode. */
    /** Returns true if any tasks are visible in Desktop Mode. */
    fun isDesktopModeShowing(displayId: Int): Boolean = visibleTaskCount(displayId) > 0
    fun isDesktopModeShowing(displayId: Int): Boolean = visibleTaskCount(displayId) > 0
@@ -286,14 +282,8 @@ class DesktopTasksController(
                    // Fullscreen case where we move the current focused task.
                    // Fullscreen case where we move the current focused task.
                    moveToDesktop(allFocusedTasks[0].taskId, transitionSource = transitionSource)
                    moveToDesktop(allFocusedTasks[0].taskId, transitionSource = transitionSource)
                }
                }
                else -> {
                else -> logW("Cannot enter desktop, expected < 3 focused tasks, found %d",
                    ProtoLog.w(
                    allFocusedTasks.size)
                        WM_SHELL_DESKTOP_MODE,
                        "DesktopTasksController: Cannot enter desktop, expected less " +
                            "than 3 focused tasks but found %d",
                        allFocusedTasks.size
                    )
                }
            }
            }
        }
        }
    }
    }
@@ -317,11 +307,7 @@ class DesktopTasksController(
        transitionSource: DesktopModeTransitionSource,
        transitionSource: DesktopModeTransitionSource,
    ): Boolean {
    ): Boolean {
        recentTasksController?.findTaskInBackground(taskId)?.let {
        recentTasksController?.findTaskInBackground(taskId)?.let {
            ProtoLog.v(
            logV("moveToDesktopFromNonRunningTask with taskId=%d, displayId=%d", taskId)
                WM_SHELL_DESKTOP_MODE,
                "DesktopTasksController: moveToDesktopFromNonRunningTask taskId=%d",
                taskId
            )
            // TODO(342378842): Instead of using default display, support multiple displays
            // TODO(342378842): Instead of using default display, support multiple displays
            val taskToMinimize =
            val taskToMinimize =
                bringDesktopAppsToFrontBeforeShowingNewTask(DEFAULT_DISPLAY, wct, taskId)
                bringDesktopAppsToFrontBeforeShowingNewTask(DEFAULT_DISPLAY, wct, taskId)
@@ -351,18 +337,10 @@ class DesktopTasksController(
    ) {
    ) {
        if (DesktopModeFlags.MODALS_POLICY.isEnabled(context)
        if (DesktopModeFlags.MODALS_POLICY.isEnabled(context)
            && isTopActivityExemptFromDesktopWindowing(context, task)) {
            && isTopActivityExemptFromDesktopWindowing(context, task)) {
            ProtoLog.w(
            logW("Cannot enter desktop for taskId %d, ineligible top activity found", task.taskId)
                WM_SHELL_DESKTOP_MODE,
                "DesktopTasksController: Cannot enter desktop, " +
                        "ineligible top activity found."
            )
            return
            return
        }
        }
        ProtoLog.v(
        logV("moveToDesktop taskId=%d", task.taskId)
            WM_SHELL_DESKTOP_MODE,
            "DesktopTasksController: moveToDesktop taskId=%d",
            task.taskId
        )
        exitSplitIfApplicable(wct, task)
        exitSplitIfApplicable(wct, task)
        // Bring other apps to front first
        // Bring other apps to front first
        val taskToMinimize =
        val taskToMinimize =
@@ -386,11 +364,7 @@ class DesktopTasksController(
        dragToDesktopValueAnimator: MoveToDesktopAnimator,
        dragToDesktopValueAnimator: MoveToDesktopAnimator,
        taskSurface: SurfaceControl,
        taskSurface: SurfaceControl,
    ) {
    ) {
        ProtoLog.v(
        logV("startDragToDesktop taskId=%d", taskInfo.taskId)
            WM_SHELL_DESKTOP_MODE,
            "DesktopTasksController: startDragToDesktop taskId=%d",
            taskInfo.taskId
        )
        interactionJankMonitor.begin(taskSurface, context,
        interactionJankMonitor.begin(taskSurface, context,
            CUJ_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG_HOLD)
            CUJ_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG_HOLD)
        dragToDesktopTransitionHandler.startDragToDesktopTransition(
        dragToDesktopTransitionHandler.startDragToDesktopTransition(
@@ -442,10 +416,10 @@ class DesktopTasksController(
     * @param taskId task id of the window that's being closed
     * @param taskId task id of the window that's being closed
     */
     */
    fun onDesktopWindowClose(wct: WindowContainerTransaction, displayId: Int, taskId: Int) {
    fun onDesktopWindowClose(wct: WindowContainerTransaction, displayId: Int, taskId: Int) {
        if (desktopModeTaskRepository.isOnlyVisibleNonClosingTask(taskId)) {
        if (taskRepository.isOnlyVisibleNonClosingTask(taskId)) {
            removeWallpaperActivity(wct)
            removeWallpaperActivity(wct)
        }
        }
        desktopModeTaskRepository.addClosingTask(displayId, taskId)
        taskRepository.addClosingTask(displayId, taskId)
    }
    }


    /** Move a task with given `taskId` to fullscreen */
    /** Move a task with given `taskId` to fullscreen */
@@ -464,11 +438,7 @@ class DesktopTasksController(


    /** Move a desktop app to split screen. */
    /** Move a desktop app to split screen. */
    fun moveToSplit(task: RunningTaskInfo) {
    fun moveToSplit(task: RunningTaskInfo) {
        ProtoLog.v(
        logV( "moveToSplit taskId=%s", task.taskId)
            WM_SHELL_DESKTOP_MODE,
            "DesktopTasksController: moveToSplit taskId=%d",
            task.taskId
        )
        val wct = WindowContainerTransaction()
        val wct = WindowContainerTransaction()
        wct.setBounds(task.token, Rect())
        wct.setBounds(task.token, Rect())
        // Rather than set windowing mode to multi-window at task level, set it to
        // Rather than set windowing mode to multi-window at task level, set it to
@@ -497,11 +467,7 @@ class DesktopTasksController(
     * [startDragToDesktop].
     * [startDragToDesktop].
     */
     */
    fun cancelDragToDesktop(task: RunningTaskInfo) {
    fun cancelDragToDesktop(task: RunningTaskInfo) {
        ProtoLog.v(
        logV("cancelDragToDesktop taskId=%d", task.taskId)
            WM_SHELL_DESKTOP_MODE,
            "DesktopTasksController: cancelDragToDesktop taskId=%d",
            task.taskId
        )
        dragToDesktopTransitionHandler.cancelDragToDesktopTransition(
        dragToDesktopTransitionHandler.cancelDragToDesktopTransition(
            DragToDesktopTransitionHandler.CancelState.STANDARD_CANCEL
            DragToDesktopTransitionHandler.CancelState.STANDARD_CANCEL
        )
        )
@@ -512,11 +478,7 @@ class DesktopTasksController(
        position: Point,
        position: Point,
        transitionSource: DesktopModeTransitionSource
        transitionSource: DesktopModeTransitionSource
    ) {
    ) {
        ProtoLog.v(
        logV("moveToFullscreenWithAnimation taskId=%d", task.taskId)
            WM_SHELL_DESKTOP_MODE,
            "DesktopTasksController: moveToFullscreen with animation taskId=%d",
            task.taskId
        )
        val wct = WindowContainerTransaction()
        val wct = WindowContainerTransaction()
        addMoveToFullscreenChanges(wct, task)
        addMoveToFullscreenChanges(wct, task)


@@ -540,12 +502,7 @@ class DesktopTasksController(


    /** Move a task to the front */
    /** Move a task to the front */
    fun moveTaskToFront(taskInfo: RunningTaskInfo) {
    fun moveTaskToFront(taskInfo: RunningTaskInfo) {
        ProtoLog.v(
        logV("moveTaskToFront taskId=%s", taskInfo.taskId)
            WM_SHELL_DESKTOP_MODE,
            "DesktopTasksController: moveTaskToFront taskId=%d",
            taskInfo.taskId
        )

        val wct = WindowContainerTransaction()
        val wct = WindowContainerTransaction()
        wct.reorder(taskInfo.token, true)
        wct.reorder(taskInfo.token, true)
        val taskToMinimize = addAndGetMinimizeChangesIfNeeded(taskInfo.displayId, wct, taskInfo)
        val taskToMinimize = addAndGetMinimizeChangesIfNeeded(taskInfo.displayId, wct, taskInfo)
@@ -571,15 +528,10 @@ class DesktopTasksController(
    fun moveToNextDisplay(taskId: Int) {
    fun moveToNextDisplay(taskId: Int) {
        val task = shellTaskOrganizer.getRunningTaskInfo(taskId)
        val task = shellTaskOrganizer.getRunningTaskInfo(taskId)
        if (task == null) {
        if (task == null) {
            ProtoLog.w(WM_SHELL_DESKTOP_MODE, "moveToNextDisplay: taskId=%d not found", taskId)
            logW("moveToNextDisplay: taskId=%d not found", taskId)
            return
            return
        }
        }
        ProtoLog.v(
        logV("moveToNextDisplay: taskId=%d displayId=%d", taskId, task.displayId)
            WM_SHELL_DESKTOP_MODE,
            "moveToNextDisplay: taskId=%d taskDisplayId=%d",
            taskId,
            task.displayId
        )


        val displayIds = rootTaskDisplayAreaOrganizer.displayIds.sorted()
        val displayIds = rootTaskDisplayAreaOrganizer.displayIds.sorted()
        // Get the first display id that is higher than current task display id
        // Get the first display id that is higher than current task display id
@@ -589,7 +541,7 @@ class DesktopTasksController(
            newDisplayId = displayIds.firstOrNull { displayId -> displayId < task.displayId }
            newDisplayId = displayIds.firstOrNull { displayId -> displayId < task.displayId }
        }
        }
        if (newDisplayId == null) {
        if (newDisplayId == null) {
            ProtoLog.w(WM_SHELL_DESKTOP_MODE, "moveToNextDisplay: next display not found")
            logW("moveToNextDisplay: next display not found")
            return
            return
        }
        }
        moveToDisplay(task, newDisplayId)
        moveToDisplay(task, newDisplayId)
@@ -601,21 +553,15 @@ class DesktopTasksController(
     * No-op if task is already on that display per [RunningTaskInfo.displayId].
     * No-op if task is already on that display per [RunningTaskInfo.displayId].
     */
     */
    private fun moveToDisplay(task: RunningTaskInfo, displayId: Int) {
    private fun moveToDisplay(task: RunningTaskInfo, displayId: Int) {
        ProtoLog.v(
        logV("moveToDisplay: taskId=%d displayId=%d", task.taskId, displayId)
            WM_SHELL_DESKTOP_MODE,
            "moveToDisplay: taskId=%d displayId=%d",
            task.taskId,
            displayId
        )

        if (task.displayId == displayId) {
        if (task.displayId == displayId) {
            ProtoLog.d(WM_SHELL_DESKTOP_MODE, "moveToDisplay: task already on display")
            logD("moveToDisplay: task already on display %d", displayId)
            return
            return
        }
        }


        val displayAreaInfo = rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(displayId)
        val displayAreaInfo = rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(displayId)
        if (displayAreaInfo == null) {
        if (displayAreaInfo == null) {
            ProtoLog.w(WM_SHELL_DESKTOP_MODE, "moveToDisplay: display not found")
            logW("moveToDisplay: display not found")
            return
            return
        }
        }


@@ -652,7 +598,7 @@ class DesktopTasksController(
            // If the task's pre-maximize stable bounds were saved, toggle the task to those bounds.
            // If the task's pre-maximize stable bounds were saved, toggle the task to those bounds.
            // Otherwise, toggle to the default bounds.
            // Otherwise, toggle to the default bounds.
            val taskBoundsBeforeMaximize =
            val taskBoundsBeforeMaximize =
                desktopModeTaskRepository.removeBoundsBeforeMaximize(taskInfo.taskId)
                taskRepository.removeBoundsBeforeMaximize(taskInfo.taskId)
            if (taskBoundsBeforeMaximize != null) {
            if (taskBoundsBeforeMaximize != null) {
                destinationBounds.set(taskBoundsBeforeMaximize)
                destinationBounds.set(taskBoundsBeforeMaximize)
            } else {
            } else {
@@ -665,7 +611,7 @@ class DesktopTasksController(
        } else {
        } else {
            // Save current bounds so that task can be restored back to original bounds if necessary
            // Save current bounds so that task can be restored back to original bounds if necessary
            // and toggle to the stable bounds.
            // and toggle to the stable bounds.
            desktopModeTaskRepository.saveBoundsBeforeMaximize(taskInfo.taskId, currentTaskBounds)
            taskRepository.saveBoundsBeforeMaximize(taskInfo.taskId, currentTaskBounds)


            if (taskInfo.isResizeable) {
            if (taskInfo.isResizeable) {
                // if resizable then expand to entire stable bounds (full display minus insets)
                // if resizable then expand to entire stable bounds (full display minus insets)
@@ -770,12 +716,7 @@ class DesktopTasksController(
        wct: WindowContainerTransaction,
        wct: WindowContainerTransaction,
        newTaskIdInFront: Int? = null
        newTaskIdInFront: Int? = null
    ): RunningTaskInfo? {
    ): RunningTaskInfo? {
        ProtoLog.v(
        logV("bringDesktopAppsToFront, newTaskId=%d", newTaskIdInFront)
            WM_SHELL_DESKTOP_MODE,
            "DesktopTasksController: bringDesktopAppsToFront, newTaskIdInFront=%s",
            newTaskIdInFront ?: "null"
        )

        // Move home to front, ensures that we go back home when all desktop windows are closed
        // Move home to front, ensures that we go back home when all desktop windows are closed
        moveHomeTask(wct, toTop = true)
        moveHomeTask(wct, toTop = true)


@@ -786,7 +727,7 @@ class DesktopTasksController(
        }
        }


        val nonMinimizedTasksOrderedFrontToBack =
        val nonMinimizedTasksOrderedFrontToBack =
            desktopModeTaskRepository.getActiveNonMinimizedOrderedTasks(displayId)
            taskRepository.getActiveNonMinimizedOrderedTasks(displayId)
        // If we're adding a new Task we might need to minimize an old one
        // If we're adding a new Task we might need to minimize an old one
        val taskToMinimize: RunningTaskInfo? =
        val taskToMinimize: RunningTaskInfo? =
            if (newTaskIdInFront != null && desktopTasksLimiter.isPresent) {
            if (newTaskIdInFront != null && desktopTasksLimiter.isPresent) {
@@ -816,7 +757,7 @@ class DesktopTasksController(
    }
    }


    private fun addWallpaperActivity(wct: WindowContainerTransaction) {
    private fun addWallpaperActivity(wct: WindowContainerTransaction) {
        ProtoLog.v(WM_SHELL_DESKTOP_MODE, "DesktopTasksController: addWallpaper")
        logV("addWallpaperActivity")
        val intent = Intent(context, DesktopWallpaperActivity::class.java)
        val intent = Intent(context, DesktopWallpaperActivity::class.java)
        val options =
        val options =
            ActivityOptions.makeBasic().apply {
            ActivityOptions.makeBasic().apply {
@@ -834,8 +775,8 @@ class DesktopTasksController(
    }
    }


    private fun removeWallpaperActivity(wct: WindowContainerTransaction) {
    private fun removeWallpaperActivity(wct: WindowContainerTransaction) {
        desktopModeTaskRepository.wallpaperActivityToken?.let { token ->
        taskRepository.wallpaperActivityToken?.let { token ->
            ProtoLog.v(WM_SHELL_DESKTOP_MODE, "DesktopTasksController: removeWallpaper")
            logV("removeWallpaperActivity")
            wct.removeTask(token)
            wct.removeTask(token)
        }
        }
    }
    }
@@ -873,11 +814,7 @@ class DesktopTasksController(
        transition: IBinder,
        transition: IBinder,
        request: TransitionRequestInfo
        request: TransitionRequestInfo
    ): WindowContainerTransaction? {
    ): WindowContainerTransaction? {
        ProtoLog.v(
        logV("handleRequest request=%s", request)
            WM_SHELL_DESKTOP_MODE,
            "DesktopTasksController: handleRequest request=%s",
            request
        )
        // Check if we should skip handling this transition
        // Check if we should skip handling this transition
        var reason = ""
        var reason = ""
        val triggerTask = request.triggerTask
        val triggerTask = request.triggerTask
@@ -915,11 +852,7 @@ class DesktopTasksController(
            }
            }


        if (!shouldHandleRequest) {
        if (!shouldHandleRequest) {
            ProtoLog.v(
            logV("skipping handleRequest reason=%s", reason)
                WM_SHELL_DESKTOP_MODE,
                "DesktopTasksController: skipping handleRequest reason=%s",
                reason
            )
            return null
            return null
        }
        }


@@ -939,11 +872,7 @@ class DesktopTasksController(
                    }
                    }
                }
                }
            }
            }
        ProtoLog.v(
        logV("handleRequest result=%s", result)
            WM_SHELL_DESKTOP_MODE,
            "DesktopTasksController: handleRequest result=%s",
            result ?: "null"
        )
        return result
        return result
    }
    }


@@ -977,25 +906,20 @@ class DesktopTasksController(
        task: RunningTaskInfo,
        task: RunningTaskInfo,
        transition: IBinder
        transition: IBinder
    ): WindowContainerTransaction? {
    ): WindowContainerTransaction? {
        ProtoLog.v(WM_SHELL_DESKTOP_MODE, "DesktopTasksController: handleFreeformTaskLaunch")
        logV("handleFreeformTaskLaunch")
        if (keyguardManager.isKeyguardLocked) {
        if (keyguardManager.isKeyguardLocked) {
            // Do NOT handle freeform task launch when locked.
            // Do NOT handle freeform task launch when locked.
            // It will be launched in fullscreen windowing mode (Details: b/160925539)
            // It will be launched in fullscreen windowing mode (Details: b/160925539)
            ProtoLog.v(WM_SHELL_DESKTOP_MODE, "DesktopTasksController: skip keyguard is locked")
            logV("skip keyguard is locked")
            return null
            return null
        }
        }
        val wct = WindowContainerTransaction()
        val wct = WindowContainerTransaction()
        if (!isDesktopModeShowing(task.displayId)) {
        if (!isDesktopModeShowing(task.displayId)) {
            ProtoLog.d(
            logD("Bring desktop tasks to front on transition=taskId=%d", task.taskId)
                WM_SHELL_DESKTOP_MODE,
                "DesktopTasksController: bring desktop tasks to front on transition" +
                    " taskId=%d",
                task.taskId
            )
            // We are outside of desktop mode and already existing desktop task is being launched.
            // We are outside of desktop mode and already existing desktop task is being launched.
            // We should make this task go to fullscreen instead of freeform. Note that this means
            // We should make this task go to fullscreen instead of freeform. Note that this means
            // any re-launch of a freeform window outside of desktop will be in fullscreen.
            // any re-launch of a freeform window outside of desktop will be in fullscreen.
            if (desktopModeTaskRepository.isActiveTask(task.taskId)) {
            if (taskRepository.isActiveTask(task.taskId)) {
                addMoveToFullscreenChanges(wct, task)
                addMoveToFullscreenChanges(wct, task)
                return wct
                return wct
            }
            }
@@ -1020,14 +944,9 @@ class DesktopTasksController(
        task: RunningTaskInfo,
        task: RunningTaskInfo,
        transition: IBinder
        transition: IBinder
    ): WindowContainerTransaction? {
    ): WindowContainerTransaction? {
        ProtoLog.v(WM_SHELL_DESKTOP_MODE, "DesktopTasksController: handleFullscreenTaskLaunch")
        logV("handleFullscreenTaskLaunch")
        if (isDesktopModeShowing(task.displayId)) {
        if (isDesktopModeShowing(task.displayId)) {
            ProtoLog.d(
            logD("Switch fullscreen task to freeform on transition: taskId=%d", task.taskId)
                WM_SHELL_DESKTOP_MODE,
                "DesktopTasksController: switch fullscreen task to freeform on transition" +
                    " taskId=%d",
                task.taskId
            )
            return WindowContainerTransaction().also { wct ->
            return WindowContainerTransaction().also { wct ->
                addMoveToDesktopChanges(wct, task)
                addMoveToDesktopChanges(wct, task)
                // In some launches home task is moved behind new task being launched. Make sure
                // In some launches home task is moved behind new task being launched. Make sure
@@ -1054,17 +973,17 @@ class DesktopTasksController(


    /** Handle task closing by removing wallpaper activity if it's the last active task */
    /** Handle task closing by removing wallpaper activity if it's the last active task */
    private fun handleTaskClosing(task: RunningTaskInfo): WindowContainerTransaction? {
    private fun handleTaskClosing(task: RunningTaskInfo): WindowContainerTransaction? {
        ProtoLog.v(WM_SHELL_DESKTOP_MODE, "DesktopTasksController: handleTaskClosing")
        logV("handleTaskClosing")
        val wct = WindowContainerTransaction()
        val wct = WindowContainerTransaction()
        if (desktopModeTaskRepository.isOnlyVisibleNonClosingTask(task.taskId)
        if (taskRepository.isOnlyVisibleNonClosingTask(task.taskId)
            && desktopModeTaskRepository.wallpaperActivityToken != null) {
            && taskRepository.wallpaperActivityToken != null) {
            // Remove wallpaper activity when the last active task is removed
            // Remove wallpaper activity when the last active task is removed
            removeWallpaperActivity(wct)
            removeWallpaperActivity(wct)
        }
        }
        desktopModeTaskRepository.addClosingTask(task.displayId, task.taskId)
        taskRepository.addClosingTask(task.displayId, task.taskId)
        // If a CLOSE or TO_BACK is triggered on a desktop task, remove the task.
        // If a CLOSE or TO_BACK is triggered on a desktop task, remove the task.
        if (Flags.enableDesktopWindowingBackNavigation() &&
        if (Flags.enableDesktopWindowingBackNavigation() &&
            desktopModeTaskRepository.isVisibleTask(task.taskId)) {
            taskRepository.isVisibleTask(task.taskId)) {
            wct.removeTask(task.token)
            wct.removeTask(task.token)
        }
        }
        return if (wct.isEmpty) null else wct
        return if (wct.isEmpty) null else wct
@@ -1095,7 +1014,7 @@ class DesktopTasksController(
            val stableBounds = Rect()
            val stableBounds = Rect()
            displayLayout.getStableBoundsForDesktopMode(stableBounds)
            displayLayout.getStableBoundsForDesktopMode(stableBounds)


            val activeTasks = desktopModeTaskRepository
            val activeTasks = taskRepository
                .getActiveNonMinimizedOrderedTasks(taskInfo.displayId)
                .getActiveNonMinimizedOrderedTasks(taskInfo.displayId)
            activeTasks.firstOrNull()?.let { activeTask ->
            activeTasks.firstOrNull()?.let { activeTask ->
                shellTaskOrganizer.getRunningTaskInfo(activeTask)?.let {
                shellTaskOrganizer.getRunningTaskInfo(activeTask)?.let {
@@ -1132,7 +1051,7 @@ class DesktopTasksController(
        if (useDesktopOverrideDensity()) {
        if (useDesktopOverrideDensity()) {
            wct.setDensityDpi(taskInfo.token, getDefaultDensityDpi())
            wct.setDensityDpi(taskInfo.token, getDefaultDensityDpi())
        }
        }
        if (desktopModeTaskRepository.isOnlyVisibleNonClosingTask(taskInfo.taskId)) {
        if (taskRepository.isOnlyVisibleNonClosingTask(taskInfo.taskId)) {
            // Remove wallpaper activity when leaving desktop mode
            // Remove wallpaper activity when leaving desktop mode
            removeWallpaperActivity(wct)
            removeWallpaperActivity(wct)
        }
        }
@@ -1151,7 +1070,7 @@ class DesktopTasksController(
        // The task's density may have been overridden in freeform; revert it here as we don't
        // The task's density may have been overridden in freeform; revert it here as we don't
        // want it overridden in multi-window.
        // want it overridden in multi-window.
        wct.setDensityDpi(taskInfo.token, getDefaultDensityDpi())
        wct.setDensityDpi(taskInfo.token, getDefaultDensityDpi())
        if (desktopModeTaskRepository.isOnlyVisibleNonClosingTask(taskInfo.taskId)) {
        if (taskRepository.isOnlyVisibleNonClosingTask(taskInfo.taskId)) {
            // Remove wallpaper activity when leaving desktop mode
            // Remove wallpaper activity when leaving desktop mode
            removeWallpaperActivity(wct)
            removeWallpaperActivity(wct)
        }
        }
@@ -1387,12 +1306,12 @@ class DesktopTasksController(


    /** Update the exclusion region for a specified task */
    /** Update the exclusion region for a specified task */
    fun onExclusionRegionChanged(taskId: Int, exclusionRegion: Region) {
    fun onExclusionRegionChanged(taskId: Int, exclusionRegion: Region) {
        desktopModeTaskRepository.updateTaskExclusionRegions(taskId, exclusionRegion)
        taskRepository.updateTaskExclusionRegions(taskId, exclusionRegion)
    }
    }


    /** Remove a previously tracked exclusion region for a specified task. */
    /** Remove a previously tracked exclusion region for a specified task. */
    fun removeExclusionRegionForTask(taskId: Int) {
    fun removeExclusionRegionForTask(taskId: Int) {
        desktopModeTaskRepository.removeExclusionRegion(taskId)
        taskRepository.removeExclusionRegion(taskId)
    }
    }


    /**
    /**
@@ -1402,7 +1321,7 @@ class DesktopTasksController(
     * @param callbackExecutor the executor to call the listener on.
     * @param callbackExecutor the executor to call the listener on.
     */
     */
    fun addVisibleTasksListener(listener: VisibleTasksListener, callbackExecutor: Executor) {
    fun addVisibleTasksListener(listener: VisibleTasksListener, callbackExecutor: Executor) {
        desktopModeTaskRepository.addVisibleTasksListener(listener, callbackExecutor)
        taskRepository.addVisibleTasksListener(listener, callbackExecutor)
    }
    }


    /**
    /**
@@ -1412,7 +1331,7 @@ class DesktopTasksController(
     * @param callbackExecutor the executor to call the listener on.
     * @param callbackExecutor the executor to call the listener on.
     */
     */
    fun setTaskRegionListener(listener: Consumer<Region>, callbackExecutor: Executor) {
    fun setTaskRegionListener(listener: Consumer<Region>, callbackExecutor: Executor) {
        desktopModeTaskRepository.setExclusionRegionListener(listener, callbackExecutor)
        taskRepository.setExclusionRegionListener(listener, callbackExecutor)
    }
    }


    override fun onUnhandledDrag(
    override fun onUnhandledDrag(
@@ -1430,7 +1349,7 @@ class DesktopTasksController(
        if (!multiInstanceHelper.supportsMultiInstanceSplit(launchComponent)) {
        if (!multiInstanceHelper.supportsMultiInstanceSplit(launchComponent)) {
            // TODO(b/320797628): Should only return early if there is an existing running task, and
            // TODO(b/320797628): Should only return early if there is an existing running task, and
            //                    notify the user as well. But for now, just ignore the drop.
            //                    notify the user as well. But for now, just ignore the drop.
            ProtoLog.v(WM_SHELL_DESKTOP_MODE, "Dropped intent does not support multi-instance")
            logV("Dropped intent does not support multi-instance")
            return false
            return false
        }
        }


@@ -1462,7 +1381,7 @@ class DesktopTasksController(
    private fun dump(pw: PrintWriter, prefix: String) {
    private fun dump(pw: PrintWriter, prefix: String) {
        val innerPrefix = "$prefix  "
        val innerPrefix = "$prefix  "
        pw.println("${prefix}DesktopTasksController")
        pw.println("${prefix}DesktopTasksController")
        desktopModeTaskRepository.dump(pw, innerPrefix)
        taskRepository.dump(pw, innerPrefix)
    }
    }


    /** The interface for calls from outside the shell, within the host process. */
    /** The interface for calls from outside the shell, within the host process. */
@@ -1537,12 +1456,12 @@ class DesktopTasksController(
                SingleInstanceRemoteListener<DesktopTasksController, IDesktopTaskListener>(
                SingleInstanceRemoteListener<DesktopTasksController, IDesktopTaskListener>(
                    controller,
                    controller,
                    { c ->
                    { c ->
                        c.desktopModeTaskRepository.addVisibleTasksListener(
                        c.taskRepository.addVisibleTasksListener(
                            listener,
                            listener,
                            c.mainExecutor
                            c.mainExecutor
                        )
                        )
                    },
                    },
                    { c -> c.desktopModeTaskRepository.removeVisibleTasksListener(listener) }
                    { c -> c.taskRepository.removeVisibleTasksListener(listener) }
                )
                )
        }
        }


@@ -1569,10 +1488,7 @@ class DesktopTasksController(
        }
        }


        override fun hideStashedDesktopApps(displayId: Int) {
        override fun hideStashedDesktopApps(displayId: Int) {
            ProtoLog.w(
            ProtoLog.w(WM_SHELL_DESKTOP_MODE, "IDesktopModeImpl: hideStashedDesktopApps is deprecated")
                WM_SHELL_DESKTOP_MODE,
                "IDesktopModeImpl: hideStashedDesktopApps is deprecated"
            )
        }
        }


        override fun getVisibleTaskCount(displayId: Int): Int {
        override fun getVisibleTaskCount(displayId: Int): Int {
@@ -1596,11 +1512,7 @@ class DesktopTasksController(
        }
        }


        override fun setTaskListener(listener: IDesktopTaskListener?) {
        override fun setTaskListener(listener: IDesktopTaskListener?) {
            ProtoLog.v(
            ProtoLog.v(WM_SHELL_DESKTOP_MODE, "IDesktopModeImpl: set task listener=%s", listener)
                WM_SHELL_DESKTOP_MODE,
                "IDesktopModeImpl: set task listener=%s",
                listener ?: "null"
            )
            executeRemoteCallWithTaskPermission(controller, "setTaskListener") { _ ->
            executeRemoteCallWithTaskPermission(controller, "setTaskListener") { _ ->
                listener?.let { remoteListener.register(it) } ?: remoteListener.unregister()
                listener?.let { remoteListener.register(it) } ?: remoteListener.unregister()
            }
            }
@@ -1613,10 +1525,22 @@ class DesktopTasksController(
        }
        }
    }
    }


    private fun logV(msg: String, vararg arguments: Any?) {
        ProtoLog.v(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments)
    }
    private fun logD(msg: String, vararg arguments: Any?) {
        ProtoLog.d(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments)
    }
    private fun logW(msg: String, vararg arguments: Any?) {
        ProtoLog.w(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments)
    }

    companion object {
    companion object {
        @JvmField
        @JvmField
        val DESKTOP_MODE_INITIAL_BOUNDS_SCALE =
        val DESKTOP_MODE_INITIAL_BOUNDS_SCALE =
            SystemProperties.getInt("persist.wm.debug.desktop_mode_initial_bounds_scale", 75) / 100f
            SystemProperties.getInt("persist.wm.debug.desktop_mode_initial_bounds_scale", 75) / 100f

        private const val TAG = "DesktopTasksController"
    }
    }


    /** The positions on a screen that a task can snap to. */
    /** The positions on a screen that a task can snap to. */