Loading libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt +33 −0 Original line number Diff line number Diff line Loading @@ -1441,6 +1441,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()) { Loading Loading @@ -1523,6 +1548,7 @@ class DesktopTasksController( displayId: Int, wct: WindowContainerTransaction, forceToFullscreen: Boolean, shouldEndUpAtHome: Boolean = true, ) { taskRepository.setPipShouldKeepDesktopActive(displayId, !forceToFullscreen) if (Flags.enablePerDisplayDesktopWallpaperActivity()) { Loading @@ -1544,6 +1570,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() { Loading Loading @@ -2171,6 +2202,7 @@ class DesktopTasksController( taskInfo.displayId, wct, forceToFullscreen = true, shouldEndUpAtHome = false, ) } Loading Loading @@ -2210,6 +2242,7 @@ class DesktopTasksController( taskInfo.displayId, wct, forceToFullscreen = false, shouldEndUpAtHome = false, ) } Loading libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt +43 −9 Original line number Diff line number Diff line Loading @@ -1599,6 +1599,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) } Loading Loading @@ -1633,6 +1634,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) } Loading Loading @@ -2127,15 +2129,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 Loading Loading @@ -2984,14 +2986,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 Loading @@ -3008,14 +3012,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 Loading Loading @@ -3134,14 +3140,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 Loading Loading @@ -3906,6 +3928,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) } Loading Loading @@ -5113,6 +5136,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, Loading Loading @@ -5426,6 +5459,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( Loading Loading
libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt +33 −0 Original line number Diff line number Diff line Loading @@ -1441,6 +1441,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()) { Loading Loading @@ -1523,6 +1548,7 @@ class DesktopTasksController( displayId: Int, wct: WindowContainerTransaction, forceToFullscreen: Boolean, shouldEndUpAtHome: Boolean = true, ) { taskRepository.setPipShouldKeepDesktopActive(displayId, !forceToFullscreen) if (Flags.enablePerDisplayDesktopWallpaperActivity()) { Loading @@ -1544,6 +1570,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() { Loading Loading @@ -2171,6 +2202,7 @@ class DesktopTasksController( taskInfo.displayId, wct, forceToFullscreen = true, shouldEndUpAtHome = false, ) } Loading Loading @@ -2210,6 +2242,7 @@ class DesktopTasksController( taskInfo.displayId, wct, forceToFullscreen = false, shouldEndUpAtHome = false, ) } Loading
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt +43 −9 Original line number Diff line number Diff line Loading @@ -1599,6 +1599,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) } Loading Loading @@ -1633,6 +1634,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) } Loading Loading @@ -2127,15 +2129,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 Loading Loading @@ -2984,14 +2986,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 Loading @@ -3008,14 +3012,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 Loading Loading @@ -3134,14 +3140,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 Loading Loading @@ -3906,6 +3928,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) } Loading Loading @@ -5113,6 +5136,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, Loading Loading @@ -5426,6 +5459,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( Loading