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

Commit 0c9b45ef authored by Ivan Tkachenko's avatar Ivan Tkachenko
Browse files

Move home to front when bringing apps to front

- When `desktopWallpaperActivity` flag is enabled, we were not moving
  home to front before bringing desktop activities to front. It resulted
  in navigating to the previous fullscreen app, when all the windows
  were closed.
- Added `moveHomeToFront` event, when the flag is on, to ensure that
  home is in the beginning of the navigation stack so we always show
  home when we leave desktop.

Bug: 352326674
Test: atest WMShellUnitTests:DesktopTasksControllerTest
Flag: com.android.window.flags.enable_desktop_windowing_wallpaper_activity
Change-Id: I9f1b07ddfa605701d72a25185c626b2b8828d412
parent 732fe397
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -764,15 +764,13 @@ class DesktopTasksController(
            newTaskIdInFront ?: "null"
        )

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

        // Currently, we only handle the desktop on the default display really.
        if (displayId == DEFAULT_DISPLAY) {
            if (Flags.enableDesktopWindowingWallpaperActivity()) {
        if (displayId == DEFAULT_DISPLAY && Flags.enableDesktopWindowingWallpaperActivity()) {
            // Add translucent wallpaper activity to show the wallpaper underneath
            addWallpaperActivity(wct)
            } else {
                // Move home to front
                moveHomeTask(wct, toTop = true)
            }
        }

        val nonMinimizedTasksOrderedFrontToBack =
+33 −19
Original line number Diff line number Diff line
@@ -313,6 +313,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
  @Test
  @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
  fun showDesktopApps_onSecondaryDisplay_desktopWallpaperEnabled_shouldNotShowWallpaper() {
    val homeTask = setUpHomeTask(SECOND_DISPLAY)
    val task1 = setUpFreeformTask(SECOND_DISPLAY)
    val task2 = setUpFreeformTask(SECOND_DISPLAY)
    markTaskHidden(task1)
@@ -321,10 +322,11 @@ class DesktopTasksControllerTest : ShellTestCase() {
    controller.showDesktopApps(SECOND_DISPLAY, RemoteTransition(TestRemoteTransition()))

    val wct = getLatestWct(type = TRANSIT_TO_FRONT, handlerClass = OneShotRemoteHandler::class.java)
    assertThat(wct.hierarchyOps).hasSize(2)
    // Expect order to be from bottom: task1, task2 (no wallpaper intent)
    wct.assertReorderAt(index = 0, task1)
    wct.assertReorderAt(index = 1, task2)
    assertThat(wct.hierarchyOps).hasSize(3)
    // Expect order to be from bottom: home, task1, task2 (no wallpaper intent)
    wct.assertReorderAt(index = 0, homeTask)
    wct.assertReorderAt(index = 1, task1)
    wct.assertReorderAt(index = 2, task2)
  }

  @Test
@@ -349,6 +351,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
  @Test
  @DisableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
  fun showDesktopApps_onSecondaryDisplay_desktopWallpaperDisabled_shouldNotMoveLauncher() {
    val homeTask = setUpHomeTask(SECOND_DISPLAY)
    val task1 = setUpFreeformTask(SECOND_DISPLAY)
    val task2 = setUpFreeformTask(SECOND_DISPLAY)
    markTaskHidden(task1)
@@ -357,9 +360,11 @@ class DesktopTasksControllerTest : ShellTestCase() {
    controller.showDesktopApps(SECOND_DISPLAY, RemoteTransition(TestRemoteTransition()))

    val wct = getLatestWct(type = TRANSIT_TO_FRONT, handlerClass = OneShotRemoteHandler::class.java)
    assertThat(wct.hierarchyOps).hasSize(2)
    wct.assertReorderAt(index = 0, task1)
    wct.assertReorderAt(index = 1, task2)
    assertThat(wct.hierarchyOps).hasSize(3)
    // Expect order to be from bottom: home, task1, task2
    wct.assertReorderAt(index = 0, homeTask)
    wct.assertReorderAt(index = 1, task1)
    wct.assertReorderAt(index = 2, task2)
  }

  @Test
@@ -460,6 +465,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
  @Test
  @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
  fun showDesktopApps_twoDisplays_bringsToFrontOnlyOneDisplay_desktopWallpaperEnabled() {
    val homeTaskDefaultDisplay = setUpHomeTask(DEFAULT_DISPLAY)
    val taskDefaultDisplay = setUpFreeformTask(DEFAULT_DISPLAY)
    setUpHomeTask(SECOND_DISPLAY)
    val taskSecondDisplay = setUpFreeformTask(SECOND_DISPLAY)
@@ -469,10 +475,13 @@ class DesktopTasksControllerTest : ShellTestCase() {
    controller.showDesktopApps(DEFAULT_DISPLAY, RemoteTransition(TestRemoteTransition()))

    val wct = getLatestWct(type = TRANSIT_TO_FRONT, handlerClass = OneShotRemoteHandler::class.java)
    assertThat(wct.hierarchyOps).hasSize(2)
    // Expect order to be from bottom: wallpaper intent, task
    wct.assertPendingIntentAt(index = 0, desktopWallpaperIntent)
    wct.assertReorderAt(index = 1, taskDefaultDisplay)
    assertThat(wct.hierarchyOps).hasSize(3)
    // Move home to front
    wct.assertReorderAt(index = 0, homeTaskDefaultDisplay)
    // Add desktop wallpaper activity
    wct.assertPendingIntentAt(index = 1, desktopWallpaperIntent)
    // Move freeform task to front
    wct.assertReorderAt(index = 2, taskDefaultDisplay)
  }

  @Test
@@ -497,7 +506,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
  @Test
  @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
  fun showDesktopApps_desktopWallpaperEnabled_dontReorderMinimizedTask() {
    setUpHomeTask()
    val homeTask = setUpHomeTask()
    val freeformTask = setUpFreeformTask()
    val minimizedTask = setUpFreeformTask()

@@ -507,11 +516,13 @@ class DesktopTasksControllerTest : ShellTestCase() {
    controller.showDesktopApps(DEFAULT_DISPLAY, RemoteTransition(TestRemoteTransition()))

    val wct = getLatestWct(type = TRANSIT_TO_FRONT, handlerClass = OneShotRemoteHandler::class.java)
    assertThat(wct.hierarchyOps).hasSize(2)
    assertThat(wct.hierarchyOps).hasSize(3)
    // Move home to front
    wct.assertReorderAt(index = 0, homeTask, toTop = true)
    // Add desktop wallpaper activity
    wct.assertPendingIntentAt(index = 0, desktopWallpaperIntent)
    wct.assertPendingIntentAt(index = 1, desktopWallpaperIntent)
    // Reorder freeform task to top, don't reorder the minimized task
    wct.assertReorderAt(index = 1, freeformTask, toTop = true)
    wct.assertReorderAt(index = 2, freeformTask, toTop = true)
  }

  @Test
@@ -894,16 +905,19 @@ class DesktopTasksControllerTest : ShellTestCase() {
    val taskLimit = desktopTasksLimiter.getMaxTaskLimit()
    val freeformTasks = (1..taskLimit).map { _ -> setUpFreeformTask() }
    val newTask = setUpFullscreenTask()
    setUpHomeTask()
    val homeTask = setUpHomeTask()

    controller.moveToDesktop(newTask, transitionSource = UNKNOWN)

    val wct = getLatestEnterDesktopWct()
    assertThat(wct.hierarchyOps.size).isEqualTo(taskLimit + 1) // visible tasks + wallpaper
    assertThat(wct.hierarchyOps.size).isEqualTo(taskLimit + 2) // tasks + home + wallpaper
    // Move home to front
    wct.assertReorderAt(0, homeTask)
    // Add desktop wallpaper activity
    wct.assertPendingIntentAt(0, desktopWallpaperIntent)
    wct.assertPendingIntentAt(1, desktopWallpaperIntent)
    // Bring freeform tasks to front
    wct.assertReorderSequenceInRange(
      range = 1..<(taskLimit + 1),
      range = 2..<(taskLimit + 2),
      *freeformTasks.drop(1).toTypedArray(), // Skipping freeformTasks[0]
      newTask
    )