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

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

Merge "Remove obsolete desktop stashing for Desktop Windowing." into main

parents 9308e1b7 39603ddf
Loading
Loading
Loading
Loading
+0 −17
Original line number Diff line number Diff line
@@ -41,15 +41,6 @@ public class DesktopModeStatus {
    public static final boolean IS_DISPLAY_CHANGE_ENABLED = SystemProperties.getBoolean(
            "persist.wm.debug.desktop_change_display", false);


    /**
     * Flag to indicate that desktop stashing is enabled.
     * When enabled, swiping home from desktop stashes the open apps. Next app that launches,
     * will be added to the desktop.
     */
    private static final boolean IS_STASHING_ENABLED = SystemProperties.getBoolean(
            "persist.wm.debug.desktop_stashing", false);

    /**
     * Flag to indicate whether to apply shadows to windows in desktop mode.
     */
@@ -108,14 +99,6 @@ public class DesktopModeStatus {
        return IS_VEILED_RESIZE_ENABLED;
    }

    /**
     * Return {@code true} if desktop task stashing is enabled when going home.
     * Allows users to use home screen to add tasks to desktop.
     */
    public static boolean isStashingEnabled() {
        return IS_STASHING_ENABLED;
    }

    /**
     * Return whether to use window shadows.
     *
+0 −31
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ class DesktopModeTaskRepository {
        val activeTasks: ArraySet<Int> = ArraySet(),
        val visibleTasks: ArraySet<Int> = ArraySet(),
        val minimizedTasks: ArraySet<Int> = ArraySet(),
        var stashed: Boolean = false
    )

    // Token of the current wallpaper activity, used to remove it when the last task is removed
@@ -95,10 +94,8 @@ class DesktopModeTaskRepository {
        visibleTasksListeners[visibleTasksListener] = executor
        displayData.keyIterator().forEach { displayId ->
            val visibleTasksCount = getVisibleTaskCount(displayId)
            val stashed = isStashed(displayId)
            executor.execute {
                visibleTasksListener.onTasksVisibilityChanged(displayId, visibleTasksCount)
                visibleTasksListener.onStashedChanged(displayId, stashed)
            }
        }
    }
@@ -399,26 +396,6 @@ class DesktopModeTaskRepository {
        }
    }

    /**
     * Update stashed status on display with id [displayId]
     */
    fun setStashed(displayId: Int, stashed: Boolean) {
        val data = displayData.getOrCreate(displayId)
        val oldValue = data.stashed
        data.stashed = stashed
        if (oldValue != stashed) {
            KtProtoLog.d(
                    WM_SHELL_DESKTOP_MODE,
                    "DesktopTaskRepo: mark stashed=%b displayId=%d",
                    stashed,
                    displayId
            )
            visibleTasksListeners.forEach { (listener, executor) ->
                executor.execute { listener.onStashedChanged(displayId, stashed) }
            }
        }
    }

    /**
     * Removes and returns the bounds saved before maximizing the given task.
     */
@@ -433,13 +410,6 @@ class DesktopModeTaskRepository {
        boundsBeforeMaximizeByTaskId.set(taskId, Rect(bounds))
    }

    /**
     * Check if display with id [displayId] has desktop tasks stashed
     */
    fun isStashed(displayId: Int): Boolean {
        return displayData[displayId]?.stashed ?: false
    }

    internal fun dump(pw: PrintWriter, prefix: String) {
        val innerPrefix = "$prefix  "
        pw.println("${prefix}DesktopModeTaskRepository")
@@ -455,7 +425,6 @@ class DesktopModeTaskRepository {
            pw.println("${prefix}Display $displayId:")
            pw.println("${innerPrefix}activeTasks=${data.activeTasks.toDumpString()}")
            pw.println("${innerPrefix}visibleTasks=${data.visibleTasks.toDumpString()}")
            pw.println("${innerPrefix}stashed=${data.stashed}")
        }
    }

+15 −67
Original line number Diff line number Diff line
@@ -240,34 +240,6 @@ class DesktopTasksController(
        }
    }

    /**
     * Stash desktop tasks on display with id [displayId].
     *
     * When desktop tasks are stashed, launcher home screen icons are fully visible. New apps
     * launched in this state will be added to the desktop. Existing desktop tasks will be brought
     * back to front during the launch.
     */
    fun stashDesktopApps(displayId: Int) {
        if (DesktopModeStatus.isStashingEnabled()) {
            KtProtoLog.v(WM_SHELL_DESKTOP_MODE, "DesktopTasksController: stashDesktopApps")
            desktopModeTaskRepository.setStashed(displayId, true)
        }
    }

    /**
     * Clear the stashed state for the given display
     */
    fun hideStashedDesktopApps(displayId: Int) {
        if (DesktopModeStatus.isStashingEnabled()) {
            KtProtoLog.v(
                    WM_SHELL_DESKTOP_MODE,
                    "DesktopTasksController: hideStashedApps displayId=%d",
                    displayId
            )
            desktopModeTaskRepository.setStashed(displayId, false)
        }
    }

    /** Get number of tasks that are marked as visible */
    fun getVisibleTaskCount(displayId: Int): Int {
        return desktopModeTaskRepository.getVisibleTaskCount(displayId)
@@ -871,8 +843,6 @@ class DesktopTasksController(
        val result = triggerTask?.let { task ->
            when {
                request.type == TRANSIT_TO_BACK -> handleBackNavigation(task)
                // If display has tasks stashed, handle as stashed launch
                task.isStashed -> handleStashedTaskLaunch(task, transition)
                // Check if the task has a top transparent activity
                shouldLaunchAsModal(task) -> handleTransparentTaskLaunch(task)
                // Check if fullscreen task should be updated
@@ -911,12 +881,8 @@ class DesktopTasksController(
                .forEach { finishTransaction.setCornerRadius(it.leash, cornerRadius) }
    }

    private val TaskInfo.isStashed: Boolean
        get() = desktopModeTaskRepository.isStashed(displayId)

    private fun shouldLaunchAsModal(task: TaskInfo): Boolean {
        return Flags.enableDesktopWindowingModalsPolicy() && isSingleTopActivityTranslucent(task)
    }
    private fun shouldLaunchAsModal(task: TaskInfo) =
        Flags.enableDesktopWindowingModalsPolicy() && isSingleTopActivityTranslucent(task)

    private fun shouldRemoveWallpaper(request: TransitionRequestInfo): Boolean {
        return Flags.enableDesktopWindowingWallpaperActivity() &&
@@ -976,24 +942,6 @@ class DesktopTasksController(
        return null
    }

    private fun handleStashedTaskLaunch(
            task: RunningTaskInfo,
            transition: IBinder
    ): WindowContainerTransaction {
        KtProtoLog.d(
                WM_SHELL_DESKTOP_MODE,
                "DesktopTasksController: launch apps with stashed on transition taskId=%d",
                task.taskId
        )
        val wct = WindowContainerTransaction()
        val taskToMinimize =
                bringDesktopAppsToFrontBeforeShowingNewTask(task.displayId, wct, task.taskId)
        addMoveToDesktopChanges(wct, task)
        desktopModeTaskRepository.setStashed(task.displayId, false)
        addPendingMinimizeTransition(transition, taskToMinimize)
        return wct
    }

    // Always launch transparent tasks in fullscreen.
    private fun handleTransparentTaskLaunch(task: RunningTaskInfo): WindowContainerTransaction? {
        // Already fullscreen, no-op.
@@ -1467,25 +1415,25 @@ class DesktopTasksController(
            ) { c -> c.showDesktopApps(displayId, remoteTransition) }
        }

        override fun stashDesktopApps(displayId: Int) {
        override fun showDesktopApp(taskId: Int) {
            ExecutorUtils.executeRemoteCallWithTaskPermission(
                    controller,
                    "stashDesktopApps"
            ) { c -> c.stashDesktopApps(displayId) }
                    "showDesktopApp"
            ) { c -> c.moveTaskToFront(taskId) }
        }

        override fun hideStashedDesktopApps(displayId: Int) {
            ExecutorUtils.executeRemoteCallWithTaskPermission(
                    controller,
                    "hideStashedDesktopApps"
            ) { c -> c.hideStashedDesktopApps(displayId) }
        override fun stashDesktopApps(displayId: Int) {
            KtProtoLog.w(
                WM_SHELL_DESKTOP_MODE,
                "IDesktopModeImpl: stashDesktopApps is deprecated"
            )
        }

        override fun showDesktopApp(taskId: Int) {
            ExecutorUtils.executeRemoteCallWithTaskPermission(
                    controller,
                    "showDesktopApp"
            ) { c -> c.moveTaskToFront(taskId) }
        override fun hideStashedDesktopApps(displayId: Int) {
            KtProtoLog.w(
                WM_SHELL_DESKTOP_MODE,
                "IDesktopModeImpl: hideStashedDesktopApps is deprecated"
            )
        }

        override fun getVisibleTaskCount(displayId: Int): Int {
+2 −2
Original line number Diff line number Diff line
@@ -28,10 +28,10 @@ interface IDesktopMode {
    /** Show apps on the desktop on the given display */
    void showDesktopApps(int displayId, in RemoteTransition remoteTransition);

    /** Stash apps on the desktop to allow launching another app from home screen */
    /** @deprecated use {@link #showDesktopApps} instead. */
    void stashDesktopApps(int displayId);

    /** Hide apps that may be stashed */
    /** @deprecated this is no longer supported. */
    void hideStashedDesktopApps(int displayId);

    /** Bring task with the given id to front */
+0 −91
Original line number Diff line number Diff line
@@ -181,18 +181,6 @@ class DesktopModeTaskRepositoryTest : ShellTestCase() {
        assertThat(listener.visibleChangesOnDefaultDisplay).isEqualTo(1)
    }

    @Test
    fun addListener_notifiesStashed() {
        repo.setStashed(DEFAULT_DISPLAY, true)
        val listener = TestVisibilityListener()
        val executor = TestShellExecutor()
        repo.addVisibleTasksListener(listener, executor)
        executor.flushAll()

        assertThat(listener.stashedOnDefaultDisplay).isTrue()
        assertThat(listener.stashedChangesOnDefaultDisplay).isEqualTo(1)
    }

    @Test
    fun addListener_tasksOnDifferentDisplay_doesNotNotify() {
        repo.updateVisibleFreeformTasks(SECOND_DISPLAY, taskId = 1, visible = true)
@@ -399,65 +387,6 @@ class DesktopModeTaskRepositoryTest : ShellTestCase() {
        assertThat(tasks.first()).isEqualTo(6)
    }

    @Test
    fun setStashed_stateIsUpdatedForTheDisplay() {
        repo.setStashed(DEFAULT_DISPLAY, true)
        assertThat(repo.isStashed(DEFAULT_DISPLAY)).isTrue()
        assertThat(repo.isStashed(SECOND_DISPLAY)).isFalse()

        repo.setStashed(DEFAULT_DISPLAY, false)
        assertThat(repo.isStashed(DEFAULT_DISPLAY)).isFalse()
    }

    @Test
    fun setStashed_notifyListener() {
        val listener = TestVisibilityListener()
        val executor = TestShellExecutor()
        repo.addVisibleTasksListener(listener, executor)
        repo.setStashed(DEFAULT_DISPLAY, true)
        executor.flushAll()
        assertThat(listener.stashedOnDefaultDisplay).isTrue()
        assertThat(listener.stashedChangesOnDefaultDisplay).isEqualTo(1)

        repo.setStashed(DEFAULT_DISPLAY, false)
        executor.flushAll()
        assertThat(listener.stashedOnDefaultDisplay).isFalse()
        assertThat(listener.stashedChangesOnDefaultDisplay).isEqualTo(2)
    }

    @Test
    fun setStashed_secondCallDoesNotNotify() {
        val listener = TestVisibilityListener()
        val executor = TestShellExecutor()
        repo.addVisibleTasksListener(listener, executor)
        repo.setStashed(DEFAULT_DISPLAY, true)
        repo.setStashed(DEFAULT_DISPLAY, true)
        executor.flushAll()
        assertThat(listener.stashedChangesOnDefaultDisplay).isEqualTo(1)
    }

    @Test
    fun setStashed_tracksPerDisplay() {
        val listener = TestVisibilityListener()
        val executor = TestShellExecutor()
        repo.addVisibleTasksListener(listener, executor)

        repo.setStashed(DEFAULT_DISPLAY, true)
        executor.flushAll()
        assertThat(listener.stashedOnDefaultDisplay).isTrue()
        assertThat(listener.stashedOnSecondaryDisplay).isFalse()

        repo.setStashed(SECOND_DISPLAY, true)
        executor.flushAll()
        assertThat(listener.stashedOnDefaultDisplay).isTrue()
        assertThat(listener.stashedOnSecondaryDisplay).isTrue()

        repo.setStashed(DEFAULT_DISPLAY, false)
        executor.flushAll()
        assertThat(listener.stashedOnDefaultDisplay).isFalse()
        assertThat(listener.stashedOnSecondaryDisplay).isTrue()
    }

    @Test
    fun removeFreeformTask_removesTaskBoundsBeforeMaximize() {
        val taskId = 1
@@ -598,12 +527,6 @@ class DesktopModeTaskRepositoryTest : ShellTestCase() {
        var visibleChangesOnDefaultDisplay = 0
        var visibleChangesOnSecondaryDisplay = 0

        var stashedOnDefaultDisplay = false
        var stashedOnSecondaryDisplay = false

        var stashedChangesOnDefaultDisplay = 0
        var stashedChangesOnSecondaryDisplay = 0

        override fun onTasksVisibilityChanged(displayId: Int, visibleTasksCount: Int) {
            when (displayId) {
                DEFAULT_DISPLAY -> {
@@ -617,20 +540,6 @@ class DesktopModeTaskRepositoryTest : ShellTestCase() {
                else -> fail("Visible task listener received unexpected display id: $displayId")
            }
        }

        override fun onStashedChanged(displayId: Int, stashed: Boolean) {
            when (displayId) {
                DEFAULT_DISPLAY -> {
                    stashedOnDefaultDisplay = stashed
                    stashedChangesOnDefaultDisplay++
                }
                SECOND_DISPLAY -> {
                    stashedOnSecondaryDisplay = stashed
                    stashedChangesOnDefaultDisplay++
                }
                else -> fail("Visible task listener received unexpected display id: $displayId")
            }
        }
    }

    companion object {
Loading