Loading libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt +15 −4 Original line number Diff line number Diff line Loading @@ -639,6 +639,15 @@ class DesktopTasksController( return runOnTransitStart } private fun getDisplayIdForTaskOrDefault(task: TaskInfo): Int { return when { task.displayId != INVALID_DISPLAY -> task.displayId focusTransitionObserver.globallyFocusedDisplayId != INVALID_DISPLAY -> focusTransitionObserver.globallyFocusedDisplayId else -> DEFAULT_DISPLAY } } /** Moves task to desktop mode if task is running, else launches it in desktop mode. */ @JvmOverloads fun moveTaskToDefaultDeskAndActivate( Loading @@ -655,7 +664,8 @@ class DesktopTasksController( logW("moveTaskToDefaultDeskAndActivate taskId=%d not found", taskId) return false } val deskId = getOrCreateDefaultDeskId(task.displayId) ?: return false val displayId = getDisplayIdForTaskOrDefault(task) val deskId = getOrCreateDefaultDeskId(displayId) ?: return false return moveTaskToDesk( taskId = taskId, deskId = deskId, Loading Loading @@ -688,9 +698,9 @@ class DesktopTasksController( } val backgroundTask = recentTasksController?.findTaskInBackground(taskId) if (backgroundTask != null) { // TODO: b/391484662 - add support for |deskId|. return moveBackgroundTaskToDesktop( taskId, deskId, wct, transitionSource, remoteTransition, Loading @@ -703,6 +713,7 @@ class DesktopTasksController( private fun moveBackgroundTaskToDesktop( taskId: Int, deskId: Int, wct: WindowContainerTransaction, transitionSource: DesktopModeTransitionSource, remoteTransition: RemoteTransition? = null, Loading @@ -713,8 +724,8 @@ class DesktopTasksController( logW("moveBackgroundTaskToDesktop taskId=%d not found", taskId) return false } logV("moveBackgroundTaskToDesktop with taskId=%d", taskId) val deskId = getOrCreateDefaultDeskId(task.displayId) ?: return false logV("moveBackgroundTaskToDesktop with taskId=%d to deskId=%d", taskId, deskId) val runOnTransitStart = addDeskActivationChanges(deskId, wct, task) val exitResult = desktopImmersiveController.exitImmersiveIfApplicable( Loading libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt +88 −0 Original line number Diff line number Diff line Loading @@ -1803,6 +1803,94 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase() assertThat(wallpaperReorderIndex).isGreaterThan(homeReorderIndex) } @Test fun moveBackgroundTaskToDesktop_invalidDisplay_invalidFocusedDisplay_reordersHomeAndWallpaperInDefaultDisplay() { val task = createRecentTaskInfo(1, INVALID_DISPLAY) val homeTask = setUpHomeTask(displayId = DEFAULT_DISPLAY) val wallpaperToken = MockToken().token() whenever(focusTransitionObserver.globallyFocusedDisplayId).thenReturn(INVALID_DISPLAY) whenever(shellTaskOrganizer.getRunningTaskInfo(anyInt())).thenReturn(null) whenever(recentTasksController.findTaskInBackground(anyInt())).thenReturn(task) whenever(desktopWallpaperActivityTokenProvider.getToken(DEFAULT_DISPLAY)) .thenReturn(wallpaperToken) controller.moveTaskToDefaultDeskAndActivate( taskId = task.taskId, transitionSource = UNKNOWN, remoteTransition = RemoteTransition(TestRemoteTransition()), ) val wct = getLatestTransition() wct.assertReorder(homeTask) wct.assertReorder(wallpaperToken) } @Test fun moveBackgroundTaskToDesktop_invalidDisplay_validFocusedDisplay_reordersHomeAndWallpaperInFocusedDisplay() { val task = createRecentTaskInfo(1, INVALID_DISPLAY) val focusedDisplayId = 5 val homeTask = setUpHomeTask(displayId = focusedDisplayId) val wallpaperToken = MockToken().token() taskRepository.addDesk(displayId = focusedDisplayId, deskId = 5) whenever(focusTransitionObserver.globallyFocusedDisplayId).thenReturn(focusedDisplayId) whenever(shellTaskOrganizer.getRunningTaskInfo(anyInt())).thenReturn(null) whenever(recentTasksController.findTaskInBackground(anyInt())).thenReturn(task) whenever(desktopWallpaperActivityTokenProvider.getToken(focusedDisplayId)) .thenReturn(wallpaperToken) controller.moveTaskToDefaultDeskAndActivate( taskId = task.taskId, transitionSource = UNKNOWN, remoteTransition = RemoteTransition(TestRemoteTransition()), ) val wct = getLatestTransition() wct.assertReorder(homeTask) wct.assertReorder(wallpaperToken) } @Test @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun moveBackgroundTaskToDesktop_invalidDisplay_invalidFocusedDisplay_activatesDeskInDefaultDisplay() { val task = createRecentTaskInfo(1, INVALID_DISPLAY) val deskId = 2 whenever(focusTransitionObserver.globallyFocusedDisplayId).thenReturn(INVALID_DISPLAY) whenever(shellTaskOrganizer.getRunningTaskInfo(anyInt())).thenReturn(null) whenever(recentTasksController.findTaskInBackground(anyInt())).thenReturn(task) taskRepository.addDesk(displayId = DEFAULT_DISPLAY, deskId = deskId) taskRepository.setActiveDesk(displayId = DEFAULT_DISPLAY, deskId = deskId) controller.moveTaskToDefaultDeskAndActivate( taskId = task.taskId, transitionSource = UNKNOWN, remoteTransition = RemoteTransition(TestRemoteTransition()), ) val wct = getLatestTransition() verify(desksOrganizer).activateDesk(wct, deskId = deskId) } @Test @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun moveBackgroundTaskToDesktop_invalidDisplay_validFocusedDisplay_activatesDeskInFocusedDisplay() { val task = createRecentTaskInfo(1, INVALID_DISPLAY) val focusedDisplayId = 5 val deskId = 2 whenever(focusTransitionObserver.globallyFocusedDisplayId).thenReturn(focusedDisplayId) whenever(shellTaskOrganizer.getRunningTaskInfo(anyInt())).thenReturn(null) whenever(recentTasksController.findTaskInBackground(anyInt())).thenReturn(task) taskRepository.addDesk(displayId = focusedDisplayId, deskId = deskId) controller.moveTaskToDefaultDeskAndActivate( taskId = task.taskId, transitionSource = UNKNOWN, remoteTransition = RemoteTransition(TestRemoteTransition()), ) val wct = getLatestTransition() verify(desksOrganizer).activateDesk(wct, deskId = deskId) } @Test fun moveRunningTaskToDesktop_remoteTransition_usesOneShotHandler() { val transitionHandlerArgCaptor = argumentCaptor<TransitionHandler>() Loading Loading
libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt +15 −4 Original line number Diff line number Diff line Loading @@ -639,6 +639,15 @@ class DesktopTasksController( return runOnTransitStart } private fun getDisplayIdForTaskOrDefault(task: TaskInfo): Int { return when { task.displayId != INVALID_DISPLAY -> task.displayId focusTransitionObserver.globallyFocusedDisplayId != INVALID_DISPLAY -> focusTransitionObserver.globallyFocusedDisplayId else -> DEFAULT_DISPLAY } } /** Moves task to desktop mode if task is running, else launches it in desktop mode. */ @JvmOverloads fun moveTaskToDefaultDeskAndActivate( Loading @@ -655,7 +664,8 @@ class DesktopTasksController( logW("moveTaskToDefaultDeskAndActivate taskId=%d not found", taskId) return false } val deskId = getOrCreateDefaultDeskId(task.displayId) ?: return false val displayId = getDisplayIdForTaskOrDefault(task) val deskId = getOrCreateDefaultDeskId(displayId) ?: return false return moveTaskToDesk( taskId = taskId, deskId = deskId, Loading Loading @@ -688,9 +698,9 @@ class DesktopTasksController( } val backgroundTask = recentTasksController?.findTaskInBackground(taskId) if (backgroundTask != null) { // TODO: b/391484662 - add support for |deskId|. return moveBackgroundTaskToDesktop( taskId, deskId, wct, transitionSource, remoteTransition, Loading @@ -703,6 +713,7 @@ class DesktopTasksController( private fun moveBackgroundTaskToDesktop( taskId: Int, deskId: Int, wct: WindowContainerTransaction, transitionSource: DesktopModeTransitionSource, remoteTransition: RemoteTransition? = null, Loading @@ -713,8 +724,8 @@ class DesktopTasksController( logW("moveBackgroundTaskToDesktop taskId=%d not found", taskId) return false } logV("moveBackgroundTaskToDesktop with taskId=%d", taskId) val deskId = getOrCreateDefaultDeskId(task.displayId) ?: return false logV("moveBackgroundTaskToDesktop with taskId=%d to deskId=%d", taskId, deskId) val runOnTransitStart = addDeskActivationChanges(deskId, wct, task) val exitResult = desktopImmersiveController.exitImmersiveIfApplicable( Loading
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt +88 −0 Original line number Diff line number Diff line Loading @@ -1803,6 +1803,94 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase() assertThat(wallpaperReorderIndex).isGreaterThan(homeReorderIndex) } @Test fun moveBackgroundTaskToDesktop_invalidDisplay_invalidFocusedDisplay_reordersHomeAndWallpaperInDefaultDisplay() { val task = createRecentTaskInfo(1, INVALID_DISPLAY) val homeTask = setUpHomeTask(displayId = DEFAULT_DISPLAY) val wallpaperToken = MockToken().token() whenever(focusTransitionObserver.globallyFocusedDisplayId).thenReturn(INVALID_DISPLAY) whenever(shellTaskOrganizer.getRunningTaskInfo(anyInt())).thenReturn(null) whenever(recentTasksController.findTaskInBackground(anyInt())).thenReturn(task) whenever(desktopWallpaperActivityTokenProvider.getToken(DEFAULT_DISPLAY)) .thenReturn(wallpaperToken) controller.moveTaskToDefaultDeskAndActivate( taskId = task.taskId, transitionSource = UNKNOWN, remoteTransition = RemoteTransition(TestRemoteTransition()), ) val wct = getLatestTransition() wct.assertReorder(homeTask) wct.assertReorder(wallpaperToken) } @Test fun moveBackgroundTaskToDesktop_invalidDisplay_validFocusedDisplay_reordersHomeAndWallpaperInFocusedDisplay() { val task = createRecentTaskInfo(1, INVALID_DISPLAY) val focusedDisplayId = 5 val homeTask = setUpHomeTask(displayId = focusedDisplayId) val wallpaperToken = MockToken().token() taskRepository.addDesk(displayId = focusedDisplayId, deskId = 5) whenever(focusTransitionObserver.globallyFocusedDisplayId).thenReturn(focusedDisplayId) whenever(shellTaskOrganizer.getRunningTaskInfo(anyInt())).thenReturn(null) whenever(recentTasksController.findTaskInBackground(anyInt())).thenReturn(task) whenever(desktopWallpaperActivityTokenProvider.getToken(focusedDisplayId)) .thenReturn(wallpaperToken) controller.moveTaskToDefaultDeskAndActivate( taskId = task.taskId, transitionSource = UNKNOWN, remoteTransition = RemoteTransition(TestRemoteTransition()), ) val wct = getLatestTransition() wct.assertReorder(homeTask) wct.assertReorder(wallpaperToken) } @Test @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun moveBackgroundTaskToDesktop_invalidDisplay_invalidFocusedDisplay_activatesDeskInDefaultDisplay() { val task = createRecentTaskInfo(1, INVALID_DISPLAY) val deskId = 2 whenever(focusTransitionObserver.globallyFocusedDisplayId).thenReturn(INVALID_DISPLAY) whenever(shellTaskOrganizer.getRunningTaskInfo(anyInt())).thenReturn(null) whenever(recentTasksController.findTaskInBackground(anyInt())).thenReturn(task) taskRepository.addDesk(displayId = DEFAULT_DISPLAY, deskId = deskId) taskRepository.setActiveDesk(displayId = DEFAULT_DISPLAY, deskId = deskId) controller.moveTaskToDefaultDeskAndActivate( taskId = task.taskId, transitionSource = UNKNOWN, remoteTransition = RemoteTransition(TestRemoteTransition()), ) val wct = getLatestTransition() verify(desksOrganizer).activateDesk(wct, deskId = deskId) } @Test @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun moveBackgroundTaskToDesktop_invalidDisplay_validFocusedDisplay_activatesDeskInFocusedDisplay() { val task = createRecentTaskInfo(1, INVALID_DISPLAY) val focusedDisplayId = 5 val deskId = 2 whenever(focusTransitionObserver.globallyFocusedDisplayId).thenReturn(focusedDisplayId) whenever(shellTaskOrganizer.getRunningTaskInfo(anyInt())).thenReturn(null) whenever(recentTasksController.findTaskInBackground(anyInt())).thenReturn(task) taskRepository.addDesk(displayId = focusedDisplayId, deskId = deskId) controller.moveTaskToDefaultDeskAndActivate( taskId = task.taskId, transitionSource = UNKNOWN, remoteTransition = RemoteTransition(TestRemoteTransition()), ) val wct = getLatestTransition() verify(desksOrganizer).activateDesk(wct, deskId = deskId) } @Test fun moveRunningTaskToDesktop_remoteTransition_usesOneShotHandler() { val transitionHandlerArgCaptor = argumentCaptor<TransitionHandler>() Loading