From a0ba0e12d6da198cf4fe4cb2e1be2114dd79bc94 Mon Sep 17 00:00:00 2001 From: Gustav Sennton Date: Mon, 25 Nov 2024 15:52:06 +0000 Subject: Desktop: check wallpaper to know if last window is closing Before this CL, to know whether Desktop Mode is closing, we would check whether the closing task is the last active task in our desktop repository. However, in cases where we close the last task while the second to last task is still closing there will still be two active tasks in our desktop repository. In this CL we instead determine whether desktop mode is closing by checking whether the wallpaper activity is closing. Bug: 379852092 Test: ensure closing last task while 2nd last still closing works Flag: com.android.window.flags.enable_desktop_windowing_exit_transitions Change-Id: I7e999e6baf4e809409f54d7093f0b32609866f38 Change-Id: Iab045e98e0e5f88925dfc4f0dd7166494910269b --- .../desktopmode/DesktopMixedTransitionHandler.kt | 16 ++++-- .../DesktopMixedTransitionHandlerTest.kt | 64 ++++++++++++++-------- 2 files changed, 52 insertions(+), 28 deletions(-) (limited to 'libs') diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopMixedTransitionHandler.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopMixedTransitionHandler.kt index 36904fb5a05f..7764688695f7 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopMixedTransitionHandler.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopMixedTransitionHandler.kt @@ -23,6 +23,7 @@ import android.os.Handler import android.os.IBinder import android.view.SurfaceControl import android.view.WindowManager +import android.view.WindowManager.TRANSIT_CLOSE import android.view.WindowManager.TRANSIT_OPEN import android.window.DesktopModeFlags import android.window.TransitionInfo @@ -197,8 +198,9 @@ class DesktopMixedTransitionHandler( logW("Should have closing desktop task") return false } - if (isLastDesktopTask(closeChange)) { - // Dispatch close desktop task animation to the default transition handlers. + if (isWallpaperActivityClosing(info)) { + // If the wallpaper activity is closing then the desktop is closing, animate the closing + // desktop by dispatching to other transition handlers. return dispatchCloseLastDesktopTaskAnimation( transition, info, @@ -419,10 +421,12 @@ class DesktopMixedTransitionHandler( ) != null } - private fun isLastDesktopTask(change: TransitionInfo.Change): Boolean = - change.taskInfo?.let { - desktopUserRepositories.getProfile(it.userId).getExpandedTaskCount(it.displayId) == 1 - } ?: false + private fun isWallpaperActivityClosing(info: TransitionInfo) = + info.changes.any { change -> + change.mode == TRANSIT_CLOSE && + change.taskInfo != null && + DesktopWallpaperActivity.isWallpaperTask(change.taskInfo!!) + } private fun findCloseDesktopTaskChange(info: TransitionInfo): TransitionInfo.Change? { if (info.type != WindowManager.TRANSIT_CLOSE) return null diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopMixedTransitionHandlerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopMixedTransitionHandlerTest.kt index 267bbb6c51e8..49a7e2951a7e 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopMixedTransitionHandlerTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopMixedTransitionHandlerTest.kt @@ -21,6 +21,7 @@ import android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM import android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN import android.app.WindowConfiguration.WindowingMode +import android.content.Intent import android.os.Binder import android.os.Handler import android.os.IBinder @@ -36,7 +37,9 @@ import android.view.WindowManager.TRANSIT_NONE import android.view.WindowManager.TRANSIT_OPEN import android.view.WindowManager.TRANSIT_TO_BACK import android.view.WindowManager.TransitionType +import android.window.IWindowContainerToken import android.window.TransitionInfo +import android.window.WindowContainerToken import android.window.WindowContainerTransaction import androidx.test.filters.SmallTest import com.android.internal.jank.Cuj.CUJ_DESKTOP_MODE_EXIT_MODE_ON_LAST_WINDOW_CLOSE @@ -188,7 +191,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() { fun startAnimation_withoutClosingDesktopTask_returnsFalse() { val transition = mock() val transitionInfo = - createTransitionInfo( + createCloseTransitionInfo( changeMode = TRANSIT_OPEN, task = createTask(WINDOWING_MODE_FREEFORM) ) @@ -213,8 +216,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() { fun startAnimation_withClosingDesktopTask_callsCloseTaskHandler() { val wct = WindowContainerTransaction() val transition = mock() - val transitionInfo = createTransitionInfo(task = createTask(WINDOWING_MODE_FREEFORM)) - whenever(desktopRepository.getExpandedTaskCount(any())).thenReturn(2) + val transitionInfo = createCloseTransitionInfo(task = createTask(WINDOWING_MODE_FREEFORM)) whenever( closeDesktopTaskTransitionHandler.startAnimation(any(), any(), any(), any(), any()) ) @@ -243,8 +245,8 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() { fun startAnimation_withClosingLastDesktopTask_dispatchesTransition() { val wct = WindowContainerTransaction() val transition = mock() - val transitionInfo = createTransitionInfo(task = createTask(WINDOWING_MODE_FREEFORM)) - whenever(desktopRepository.getExpandedTaskCount(any())).thenReturn(1) + val transitionInfo = createCloseTransitionInfo( + task = createTask(WINDOWING_MODE_FREEFORM), withWallpaper = true) whenever(transitions.dispatchTransition(any(), any(), any(), any(), any(), any())) .thenReturn(mock()) whenever(transitions.startTransition(WindowManager.TRANSIT_CLOSE, wct, mixedHandler)) @@ -355,7 +357,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() { val otherChange = createChange(createTask(WINDOWING_MODE_FREEFORM)) mixedHandler.startAnimation( transition, - createTransitionInfo( + createCloseTransitionInfo( TRANSIT_OPEN, listOf(launchTaskChange, otherChange) ), @@ -395,7 +397,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() { val immersiveChange = createChange(immersiveTask) mixedHandler.startAnimation( transition, - createTransitionInfo( + createCloseTransitionInfo( TRANSIT_OPEN, listOf(launchTaskChange, immersiveChange) ), @@ -437,7 +439,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() { ) mixedHandler.startAnimation( transition, - createTransitionInfo( + createCloseTransitionInfo( TRANSIT_OPEN, listOf(launchTaskChange) ), @@ -471,7 +473,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() { ) mixedHandler.startAnimation( transition, - createTransitionInfo( + createCloseTransitionInfo( TRANSIT_OPEN, listOf(launchTaskChange, minimizeChange) ), @@ -505,7 +507,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() { val started = mixedHandler.startAnimation( transition, - createTransitionInfo( + createCloseTransitionInfo( TRANSIT_OPEN, listOf(nonLaunchTaskChange) ), @@ -535,7 +537,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() { val started = mixedHandler.startAnimation( transition, - createTransitionInfo( + createCloseTransitionInfo( TRANSIT_OPEN, listOf(createChange(task, mode = TRANSIT_OPEN)) ), @@ -569,7 +571,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() { val openingChange = createChange(openingTask, mode = TRANSIT_OPEN) val started = mixedHandler.startAnimation( transition, - createTransitionInfo( + createCloseTransitionInfo( TRANSIT_OPEN, listOf(immersiveChange, openingChange) ), @@ -604,7 +606,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() { ) mixedHandler.startAnimation( transition, - createTransitionInfo( + createCloseTransitionInfo( TRANSIT_OPEN, listOf(launchTaskChange) ), @@ -640,7 +642,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() { ) mixedHandler.startAnimation( transition, - createTransitionInfo( + createCloseTransitionInfo( TRANSIT_OPEN, listOf(launchTaskChange, minimizeChange) ), @@ -670,7 +672,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() { val launchTaskChange = createChange(launchingTask) mixedHandler.startAnimation( transition, - createTransitionInfo( + createCloseTransitionInfo( TRANSIT_OPEN, listOf(launchTaskChange) ), @@ -727,7 +729,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() { val started = mixedHandler.startAnimation( transition = transition, info = - createTransitionInfo( + createCloseTransitionInfo( TRANSIT_TO_BACK, listOf(minimizingTaskChange) ), @@ -766,7 +768,7 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() { mixedHandler.startAnimation( transition = transition, info = - createTransitionInfo( + createCloseTransitionInfo( TRANSIT_TO_BACK, listOf(minimizingTaskChange) ), @@ -786,12 +788,12 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() { ) } - private fun createTransitionInfo( - type: Int = WindowManager.TRANSIT_CLOSE, + private fun createCloseTransitionInfo( changeMode: Int = WindowManager.TRANSIT_CLOSE, - task: RunningTaskInfo + task: RunningTaskInfo, + withWallpaper: Boolean = false, ): TransitionInfo = - TransitionInfo(type, 0 /* flags */).apply { + TransitionInfo(WindowManager.TRANSIT_CLOSE, 0 /* flags */).apply { addChange( TransitionInfo.Change(mock(), closingTaskLeash).apply { mode = changeMode @@ -799,9 +801,18 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() { taskInfo = task } ) + if (withWallpaper) { + addChange( + TransitionInfo.Change(/* container= */ mock(), /* leash= */ mock()).apply { + mode = WindowManager.TRANSIT_CLOSE + parent = null + taskInfo = createWallpaperTask() + } + ) + } } - private fun createTransitionInfo( + private fun createCloseTransitionInfo( @TransitionType type: Int, changes: List = emptyList() ): TransitionInfo = TransitionInfo(type, /* flags= */ 0).apply { @@ -822,4 +833,13 @@ class DesktopMixedTransitionHandlerTest : ShellTestCase() { .setActivityType(ACTIVITY_TYPE_STANDARD) .setWindowingMode(windowingMode) .build() + + private fun createWallpaperTask() = + RunningTaskInfo().apply { + token = WindowContainerToken(mock()) + baseIntent = + Intent().apply { + component = DesktopWallpaperActivity.wallpaperActivityComponent + } + } } -- cgit v1.2.3-59-g8ed1b