summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Orhan Uysal <uysalorhan@google.com> 2025-01-15 14:27:45 +0000
committer Orhan Uysal <uysalorhan@google.com> 2025-01-16 16:46:51 +0000
commitbc6abceef952f06a28406cb4a521f6f977d76b05 (patch)
treefba7489121fb9780222a348385d220e68f98494a
parentb6a6e2869660325c4b4ad72ee7fe82443169cfbe (diff)
Launch home using the home intent on exit desktop
In some cases we enter desktop from launcher that's not set to NORMAL state e.g. ALL APPS state. In those scenarios, upon exiting desktop we would like land on home page in a NORMAL state. This cl makes sure that when we are exiting desktop, we launch the home with intent so that launcher sets its states to NORMAL. Test: atest DesktopTasksControllerTest Fix: 341328243 Flag: EXEMPT bug fix Change-Id: Ie13b14882261563f3876c568f6f3c9dbd145166c
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt33
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt52
2 files changed, 76 insertions, 9 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
index f38957e48dbf..7e9a4c1ed4ef 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
@@ -1378,6 +1378,31 @@ class DesktopTasksController(
?.let { homeTask -> wct.reorder(homeTask.getToken(), /* onTop= */ toTop) }
}
+ private fun addLaunchHomePendingIntent(wct: WindowContainerTransaction, displayId: Int) {
+ val launchHomeIntent =
+ Intent(Intent.ACTION_MAIN).apply {
+ if (displayId != DEFAULT_DISPLAY) {
+ addCategory(Intent.CATEGORY_SECONDARY_HOME)
+ } else {
+ addCategory(Intent.CATEGORY_HOME)
+ }
+ }
+ val options =
+ ActivityOptions.makeBasic().apply {
+ launchWindowingMode = WINDOWING_MODE_FULLSCREEN
+ pendingIntentBackgroundActivityStartMode =
+ ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOW_ALWAYS
+ }
+ val pendingIntent =
+ PendingIntent.getActivity(
+ context,
+ /* requestCode = */ 0,
+ launchHomeIntent,
+ PendingIntent.FLAG_IMMUTABLE,
+ )
+ wct.sendPendingIntent(pendingIntent, launchHomeIntent, options.toBundle())
+ }
+
private fun addWallpaperActivity(displayId: Int, wct: WindowContainerTransaction) {
logV("addWallpaperActivity")
if (Flags.enableDesktopWallpaperActivityForSystemUser()) {
@@ -1460,6 +1485,7 @@ class DesktopTasksController(
displayId: Int,
wct: WindowContainerTransaction,
forceToFullscreen: Boolean,
+ shouldEndUpAtHome: Boolean = true,
) {
taskRepository.setPipShouldKeepDesktopActive(displayId, !forceToFullscreen)
if (Flags.enablePerDisplayDesktopWallpaperActivity()) {
@@ -1481,6 +1507,11 @@ class DesktopTasksController(
FULLSCREEN_ANIMATION_DURATION
)
removeWallpaperActivity(wct, displayId)
+ if (shouldEndUpAtHome) {
+ // If the transition should end up with user going to home, launch home with a pending
+ // intent.
+ addLaunchHomePendingIntent(wct, displayId)
+ }
}
fun releaseVisualIndicator() {
@@ -2093,6 +2124,7 @@ class DesktopTasksController(
taskInfo.displayId,
wct,
forceToFullscreen = true,
+ shouldEndUpAtHome = false,
)
}
@@ -2132,6 +2164,7 @@ class DesktopTasksController(
taskInfo.displayId,
wct,
forceToFullscreen = false,
+ shouldEndUpAtHome = false,
)
}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt
index f549b0563827..e4a3c56d2b59 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt
@@ -1569,6 +1569,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
verify(desktopModeEnterExitTransitionListener)
.onExitDesktopModeTransitionStarted(FULLSCREEN_ANIMATION_DURATION)
assertThat(taskChange.windowingMode).isEqualTo(WINDOWING_MODE_UNDEFINED)
+ assertThat(wct.hierarchyOps).hasSize(1)
// Removes wallpaper activity when leaving desktop
wct.assertReorderAt(index = 0, wallpaperToken, toTop = false)
}
@@ -1603,6 +1604,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
assertThat(taskChange.windowingMode).isEqualTo(WINDOWING_MODE_FULLSCREEN)
verify(desktopModeEnterExitTransitionListener)
.onExitDesktopModeTransitionStarted(FULLSCREEN_ANIMATION_DURATION)
+ assertThat(wct.hierarchyOps).hasSize(1)
// Removes wallpaper activity when leaving desktop
wct.assertReorderAt(index = 0, wallpaperToken, toTop = false)
}
@@ -2010,15 +2012,15 @@ class DesktopTasksControllerTest : ShellTestCase() {
}
@Test
- fun onDesktopWindowClose_singleActiveTask_noWallpaperActivityToken() {
+ fun onDesktopWindowClose_singleActiveTask_noWallpaperActivityToken_launchesHome() {
val task = setUpFreeformTask()
val wct = WindowContainerTransaction()
whenever(desktopWallpaperActivityTokenProvider.getToken()).thenReturn(null)
controller.onDesktopWindowClose(wct, displayId = DEFAULT_DISPLAY, task)
- // Doesn't modify transaction
- assertThat(wct.hierarchyOps).isEmpty()
+ // Should launch home
+ wct.assertPendingIntentAt(0, launchHomeIntent(DEFAULT_DISPLAY))
}
@Test
@@ -2867,14 +2869,16 @@ class DesktopTasksControllerTest : ShellTestCase() {
@Test
@EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
- fun handleRequest_backTransition_singleTaskNoToken_withWallpaper_removesTask() {
+ fun handleRequest_backTransition_singleTaskNoToken_withWallpaper_launchesHome() {
val task = setUpFreeformTask()
whenever(desktopWallpaperActivityTokenProvider.getToken()).thenReturn(null)
val result =
controller.handleRequest(Binder(), createTransition(task, type = TRANSIT_TO_BACK))
- assertNull(result, "Should not handle request")
+ // Should launch home
+ assertNotNull(result, "Should handle request")
+ .assertPendingIntentAt(0, launchHomeIntent(DEFAULT_DISPLAY))
}
@Test
@@ -2891,14 +2895,16 @@ class DesktopTasksControllerTest : ShellTestCase() {
@Test
@EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
- fun handleRequest_backTransition_singleTaskNoToken_doesNotHandle() {
+ fun handleRequest_backTransition_singleTaskNoToken_launchesHomes() {
val task = setUpFreeformTask()
whenever(desktopWallpaperActivityTokenProvider.getToken()).thenReturn(null)
val result =
controller.handleRequest(Binder(), createTransition(task, type = TRANSIT_TO_BACK))
- assertNull(result, "Should not handle request")
+ // Should launch home
+ assertNotNull(result, "Should handle request")
+ .assertPendingIntentAt(0, launchHomeIntent(DEFAULT_DISPLAY))
}
@Test
@@ -3017,14 +3023,30 @@ class DesktopTasksControllerTest : ShellTestCase() {
@Test
@EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
- fun handleRequest_closeTransition_singleTaskNoToken_doesNotHandle() {
+ fun handleRequest_closeTransition_singleTaskNoToken_launchesHome() {
val task = setUpFreeformTask()
whenever(desktopWallpaperActivityTokenProvider.getToken()).thenReturn(null)
val result =
controller.handleRequest(Binder(), createTransition(task, type = TRANSIT_CLOSE))
- assertNull(result, "Should not handle request")
+ // Should launch home
+ assertNotNull(result, "Should handle request")
+ .assertPendingIntentAt(0, launchHomeIntent(DEFAULT_DISPLAY))
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
+ fun handleRequest_closeTransition_singleTaskNoToken_secondaryDisplay_launchesHome() {
+ val task = setUpFreeformTask(displayId = SECOND_DISPLAY)
+ whenever(desktopWallpaperActivityTokenProvider.getToken()).thenReturn(null)
+
+ val result =
+ controller.handleRequest(Binder(), createTransition(task, type = TRANSIT_CLOSE))
+
+ // Should launch home
+ assertNotNull(result, "Should handle request")
+ .assertPendingIntentAt(0, launchHomeIntent(SECOND_DISPLAY))
}
@Test
@@ -3750,6 +3772,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
eq(SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT),
eq(task2.configuration.windowConfiguration.bounds),
)
+ assertThat(wctArgument.value.hierarchyOps).hasSize(1)
// Removes wallpaper activity when leaving desktop
wctArgument.value.assertReorderAt(index = 0, wallpaperToken, toTop = false)
}
@@ -4947,6 +4970,16 @@ class DesktopTasksControllerTest : ShellTestCase() {
private val desktopWallpaperIntent: Intent
get() = Intent(context, DesktopWallpaperActivity::class.java)
+ private fun launchHomeIntent(displayId: Int): Intent {
+ return Intent(Intent.ACTION_MAIN).apply {
+ if (displayId != DEFAULT_DISPLAY) {
+ addCategory(Intent.CATEGORY_SECONDARY_HOME)
+ } else {
+ addCategory(Intent.CATEGORY_HOME)
+ }
+ }
+ }
+
private fun addFreeformTaskAtPosition(
pos: DesktopTaskPosition,
stableBounds: Rect,
@@ -5260,6 +5293,7 @@ private fun WindowContainerTransaction.assertPendingIntentAt(index: Int, intent:
val op = hierarchyOps[index]
assertThat(op.type).isEqualTo(HIERARCHY_OP_TYPE_PENDING_INTENT)
assertThat(op.pendingIntent?.intent?.component).isEqualTo(intent.component)
+ assertThat(op.pendingIntent?.intent?.categories).isEqualTo(intent.categories)
}
private fun WindowContainerTransaction.assertLaunchTaskAt(