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

Commit d84dc428 authored by Xiaoqian (Daisy) Dai's avatar Xiaoqian (Daisy) Dai Committed by Android (Google) Code Review
Browse files

Merge "desktop-exploded-view: WMShell change for activating a window from...

Merge "desktop-exploded-view: WMShell change for activating a window from desktop task view" into main
parents 320a9764 e4497433
Loading
Loading
Loading
Loading
+84 −12
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.app.ActivityManager
import android.app.ActivityManager.RecentTaskInfo
import android.app.ActivityManager.RunningTaskInfo
import android.app.ActivityOptions
import android.app.ActivityTaskManager.INVALID_TASK_ID
import android.app.AppOpsManager
import android.app.KeyguardManager
import android.app.PendingIntent
@@ -378,11 +379,19 @@ class DesktopTasksController(
        return TRANSIT_TO_FRONT
    }

    /** Show all tasks, that are part of the desktop, on top of launcher */
    /**
     * Shows all tasks, that are part of the desktop, on top of launcher. Brings the task with id
     * [taskIdToReorderToFront] to front if provided and is already on the default desk on the given
     * display.
     */
    @Deprecated("Use activateDesk() instead.", ReplaceWith("activateDesk()"))
    fun showDesktopApps(displayId: Int, remoteTransition: RemoteTransition? = null) {
    fun showDesktopApps(
        displayId: Int,
        remoteTransition: RemoteTransition? = null,
        taskIdToReorderToFront: Int? = null,
    ) {
        logV("showDesktopApps")
        activateDefaultDeskInDisplay(displayId, remoteTransition)
        activateDefaultDeskInDisplay(displayId, remoteTransition, taskIdToReorderToFront)
    }

    /** Returns whether the given display has an active desk. */
@@ -3554,9 +3563,10 @@ class DesktopTasksController(
    private fun activateDefaultDeskInDisplay(
        displayId: Int,
        remoteTransition: RemoteTransition? = null,
        taskIdToReorderToFront: Int? = null,
    ) {
        val deskId = getOrCreateDefaultDeskId(displayId) ?: return
        activateDesk(deskId, remoteTransition)
        activateDesk(deskId, remoteTransition, taskIdToReorderToFront)
    }

    /**
@@ -3756,11 +3766,57 @@ class DesktopTasksController(
        activateDesk(destinationDeskId)
    }

    /** Activates the given desk. */
    fun activateDesk(deskId: Int, remoteTransition: RemoteTransition? = null) {
        logV("activateDesk deskId=%d", deskId)
    /**
     * Activates the given desk and brings [taskIdToReorderToFront] to front if provided and is
     * already on the given desk.
     */
    fun activateDesk(
        deskId: Int,
        remoteTransition: RemoteTransition? = null,
        taskIdToReorderToFront: Int? = null,
    ) {
        if (
            taskIdToReorderToFront != null &&
                taskRepository.getDeskIdForTask(taskIdToReorderToFront) != deskId
        ) {
            logW(
                "activeDesk taskIdToReorderToFront=%d not on the desk %d",
                taskIdToReorderToFront,
                deskId,
            )
            return
        }

        val newTaskInFront =
            taskIdToReorderToFront?.let { taskId ->
                shellTaskOrganizer.getRunningTaskInfo(taskId)
                    ?: recentTasksController?.findTaskInBackground(taskId)
            }

        val wct = WindowContainerTransaction()
        val runOnTransitStart = addDeskActivationChanges(deskId, wct)
        val runOnTransitStart = addDeskActivationChanges(deskId, wct, newTaskInFront)

        // Put task with [taskIdToReorderToFront] to front.
        when (newTaskInFront) {
            is RunningTaskInfo -> {
                // Task is running, reorder it.
                if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
                    desksOrganizer.reorderTaskToFront(wct, deskId, newTaskInFront)
                } else {
                    wct.reorder(newTaskInFront.token, /* onTop= */ true)
                }
            }
            is RecentTaskInfo -> {
                // Task is not running, start it.
                wct.startTask(
                    taskIdToReorderToFront,
                    createActivityOptionsForStartTask().toBundle(),
                )
            }
            else -> {
                logW("activateDesk taskIdToReorderToFront=%d not found", taskIdToReorderToFront)
            }
        }

        val transitionType = transitionType(remoteTransition)
        val handler =
@@ -4740,15 +4796,31 @@ class DesktopTasksController(
            }
        }

        override fun activateDesk(deskId: Int, remoteTransition: RemoteTransition?) {
        override fun activateDesk(
            deskId: Int,
            remoteTransition: RemoteTransition?,
            taskIdInFront: Int,
        ) {
            executeRemoteCallWithTaskPermission(controller, "activateDesk") { c ->
                c.activateDesk(deskId, remoteTransition)
                c.activateDesk(
                    deskId,
                    remoteTransition,
                    if (taskIdInFront != INVALID_TASK_ID) taskIdInFront else null,
                )
            }
        }

        override fun showDesktopApps(displayId: Int, remoteTransition: RemoteTransition?) {
        override fun showDesktopApps(
            displayId: Int,
            remoteTransition: RemoteTransition?,
            taskIdInFront: Int,
        ) {
            executeRemoteCallWithTaskPermission(controller, "showDesktopApps") { c ->
                c.showDesktopApps(displayId, remoteTransition)
                c.showDesktopApps(
                    displayId,
                    remoteTransition,
                    if (taskIdInFront != INVALID_TASK_ID) taskIdInFront else null,
                )
            }
        }

+12 −4
Original line number Diff line number Diff line
@@ -32,8 +32,12 @@ interface IDesktopMode {
    /** If possible, creates a new desk on the display whose ID is `displayId`. */
    oneway void createDesk(int displayId);

    /** Activates the desk whose ID is `deskId` on whatever display it currently exists on. */
    oneway void activateDesk(int deskId, in RemoteTransition remoteTransition);
    /**
     * Activates the desk whose ID is [deskId] on whatever display it currently exists on.
     * If [taskIdToReorderToFront] is a valid id (not [INVALID_TASK_ID]) and is already on the given
     * desk, bring it to the front.
     */
    oneway void activateDesk(int deskId, in RemoteTransition remoteTransition, int taskIdToReorderToFront);

    /** Removes the desk with the given `deskId`. */
    oneway void removeDesk(int deskId);
@@ -41,8 +45,12 @@ interface IDesktopMode {
    /** Removes all the available desks on all displays. */
    oneway void removeAllDesks();

    /** Show apps on the desktop on the given display */
    void showDesktopApps(int displayId, in RemoteTransition remoteTransition);
    /**
     * Show apps on the desktop on the given display and bring [taskIdToReorderToFront] to front if
     * it's provided and already on the default desk on the given display. If the provided
     * [taskIdToReorderToFront]'s value is [INVALID_TASK_ID], do not change the windows' activation.
     */
    void showDesktopApps(int displayId, in RemoteTransition remoteTransition, int taskIdToReorderToFront);

    /** @deprecated use {@link #showDesktopApps} instead. */
    void stashDesktopApps(int displayId);
+64 −1
Original line number Diff line number Diff line
@@ -639,6 +639,70 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        wct.assertReorderAt(index = 2, task2)
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
    @DisableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    /** TODO: b/353948437 - add a same test for when the multi-desk flag is enabled. */
    fun showDesktopApps_allAppsInvisible_bringNewTaskInFront_tasksAreInCorrectOrder() {
        whenever(desktopWallpaperActivityTokenProvider.getToken()).thenReturn(null)
        val task1 = setUpFreeformTask()
        val task2 = setUpFreeformTask()
        markTaskHidden(task1)
        markTaskHidden(task2)

        controller.showDesktopApps(
            DEFAULT_DISPLAY,
            RemoteTransition(TestRemoteTransition()),
            task1.taskId,
        )

        val wct =
            getLatestWct(type = TRANSIT_TO_FRONT, handlerClass = OneShotRemoteHandler::class.java)
        assertThat(wct.hierarchyOps).hasSize(4)
        // Expect order to be from bottom: wallpaper intent, task2, task1.
        // Note task1 is reordered twice, once to bring all apps to the front, and once to reoder it
        // to top.
        wct.assertPendingIntentAt(index = 0, desktopWallpaperIntent)
        wct.assertReorderAt(index = 1, task1)
        wct.assertReorderAt(index = 2, task2)
        wct.assertReorderAt(index = 3, task1)
    }

    @Test
    @EnableFlags(
        Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY,
        Flags.FLAG_ENABLE_DESKTOP_TASK_LIMIT_SEPARATE_TRANSITION,
    )
    @DisableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    /** TODO: b/353948437 - add a same test for when the multi-desk flag is enabled. */
    fun showDesktopApps_allAppsInvisible_bringNewTaskInFront_ExceedLimit_tasksAreInCorrectOrder() {
        whenever(desktopWallpaperActivityTokenProvider.getToken()).thenReturn(null)
        val task1 = setUpFreeformTask()
        markTaskHidden(task1)
        val freeformTasks = (1..MAX_TASK_LIMIT).map { _ -> setUpFreeformTask() }
        freeformTasks.forEach { markTaskHidden(it) }

        controller.showDesktopApps(
            DEFAULT_DISPLAY,
            RemoteTransition(TestRemoteTransition()),
            task1.taskId,
        )

        val wct =
            getLatestWct(type = TRANSIT_TO_FRONT, handlerClass = OneShotRemoteHandler::class.java)
        assertThat(wct.hierarchyOps).hasSize(MAX_TASK_LIMIT + 3)
        // Expect order to be from bottom: wallpaper intent, freeformTasks[1], ...,
        // freeformTasks[MAX_TASK_LIMIT -1], task1.
        // Note task1 is reordered twice, once to bring all apps to the front, and once to reoder it
        // to top.
        wct.assertPendingIntentAt(index = 0, desktopWallpaperIntent)
        wct.assertReorderAt(index = 1, task1)
        wct.assertReorderAt(index = MAX_TASK_LIMIT + 2, task1)

        val taskToMinimize = freeformTasks[0]
        wct.assertReorder(taskToMinimize.token, toTop = true)
    }

    @Test
    @EnableFlags(
        Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY,
@@ -4699,7 +4763,6 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        // Make sure we reorder the home task to the top, desktop tasks to top of them and minimized
        // task is under the home task.
        wct.assertReorderAt(1, homeTask, toTop = true)
        // Oldest task that needs to minimized is never reordered to top over Home.
        val taskToMinimize = freeformTasks[0]
        wct.assertReorder(taskToMinimize.token, toTop = true)
    }