diff options
| author | 2024-09-27 10:28:51 +0000 | |
|---|---|---|
| committer | 2024-10-03 09:15:18 +0000 | |
| commit | cec97c3c0cd06f8366d6a31879b2c2f7d05c65ad (patch) | |
| tree | b23f6be92506a7f45db86df15868d1daf5cbc666 /libs | |
| parent | 82a6c7a96a58fb7468ffc8bfd2bf8ba9c690a8f2 (diff) | |
Remove vanished tasks from repo
When a task vanishes we might mark them as minimized. If that task is
being launched in a different windowing mode, we should remove it from
the repository.
Bug: 369975365
Test: atest DesktopTasksTransitionObserverTest
Flag: com.android.window.flags.enable_desktop_windowing_back_navigation
Change-Id: I252c090e7b690f87223c000840fc41d64f4fb239
Diffstat (limited to 'libs')
2 files changed, 59 insertions, 3 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt index 4796c4d0655a..b20c9fc6e443 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt @@ -29,6 +29,7 @@ import android.window.flags.DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_WALLPAPER_ import com.android.internal.protolog.ProtoLog import com.android.wm.shell.ShellTaskOrganizer import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE +import com.android.wm.shell.shared.TransitionUtil import com.android.wm.shell.shared.desktopmode.DesktopModeStatus import com.android.wm.shell.sysui.ShellInit import com.android.wm.shell.transition.Transitions @@ -67,9 +68,29 @@ class DesktopTasksTransitionObserver( ) { // TODO: b/332682201 Update repository state updateWallpaperToken(info) - if (DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION.isTrue()) { handleBackNavigation(info) + removeTaskIfNeeded(info) + } + } + + private fun removeTaskIfNeeded(info: TransitionInfo) { + // Since we are no longer removing all the tasks [onTaskVanished], we need to remove them by + // checking the transitions. + if (!TransitionUtil.isOpeningType(info.type)) return + // Remove a task from the repository if the app is launched outside of desktop. + for (change in info.changes) { + val taskInfo = change.taskInfo + if (taskInfo == null || taskInfo.taskId == -1) continue + + if (desktopModeTaskRepository.isActiveTask(taskInfo.taskId) + && taskInfo.windowingMode != WINDOWING_MODE_FREEFORM + ) { + desktopModeTaskRepository.removeFreeformTask( + taskInfo.displayId, + taskInfo.taskId + ) + } } } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserverTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserverTest.kt index c989d1640f80..42fcc836bac3 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserverTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserverTest.kt @@ -18,11 +18,13 @@ package com.android.wm.shell.desktopmode import android.app.ActivityManager.RunningTaskInfo import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM +import android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN import android.content.ComponentName import android.content.Context import android.content.Intent import android.platform.test.annotations.EnableFlags import android.view.Display.DEFAULT_DISPLAY +import android.view.WindowManager.TRANSIT_OPEN import android.view.WindowManager.TRANSIT_TO_BACK import android.window.IWindowContainerToken import android.window.TransitionInfo @@ -110,6 +112,24 @@ class DesktopTasksTransitionObserverTest { verify(taskRepository, never()).minimizeTask(task.displayId, task.taskId) } + @Test + @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION) + fun removeTasks_onTaskFullscreenLaunch_taskRemovedFromRepo() { + val task = createTaskInfo(1, WINDOWING_MODE_FULLSCREEN) + whenever(taskRepository.getVisibleTaskCount(any())).thenReturn(1) + whenever(taskRepository.isActiveTask(task.taskId)).thenReturn(true) + + transitionObserver.onTransitionReady( + transition = mock(), + info = createOpenTransition(task), + startTransaction = mock(), + finishTransaction = mock(), + ) + + verify(taskRepository, never()).minimizeTask(task.displayId, task.taskId) + verify(taskRepository).removeFreeformTask(task.displayId, task.taskId) + } + private fun createBackNavigationTransition( task: RunningTaskInfo? ): TransitionInfo { @@ -125,11 +145,26 @@ class DesktopTasksTransitionObserverTest { } } - private fun createTaskInfo(id: Int) = + private fun createOpenTransition( + task: RunningTaskInfo? + ): TransitionInfo { + return TransitionInfo(TRANSIT_OPEN, 0 /* flags */).apply { + addChange( + Change(mock(), mock()).apply { + mode = TRANSIT_OPEN + parent = null + taskInfo = task + flags = flags + } + ) + } + } + + private fun createTaskInfo(id: Int, windowingMode: Int = WINDOWING_MODE_FREEFORM) = RunningTaskInfo().apply { taskId = id displayId = DEFAULT_DISPLAY - configuration.windowConfiguration.windowingMode = WINDOWING_MODE_FREEFORM + configuration.windowConfiguration.windowingMode = windowingMode token = WindowContainerToken(Mockito.mock(IWindowContainerToken::class.java)) baseIntent = Intent().apply { component = ComponentName("package", "component.name") |