Loading libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTaskChangeListener.kt +28 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,14 @@ class DesktopTaskChangeListener( return } if (isFreeformTask(taskInfo) && !desktopRepository.isActiveTask(taskInfo.taskId)) { // TODO: b/420917959 - Remove this once LaunchParams respects activity options set for // [DesktopWallpaperActivity] launch which should always be in fullscreen. if (DesktopWallpaperActivity.isWallpaperTask(taskInfo)) { logE( "Trying to add freeform DesktopWallpaperActivity to DesktopRepository, returning early instead" ) return } desktopRepository.addTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible) } } Loading @@ -72,6 +80,14 @@ class DesktopTaskChangeListener( if (!isFreeformTask(taskInfo) && desktopRepository.isActiveTask(taskInfo.taskId)) { desktopRepository.removeTask(taskInfo.taskId) } else if (isFreeformTask(taskInfo)) { // TODO: b/420917959 - Remove this once LaunchParams respects activity options set for // [DesktopWallpaperActivity] launch which should always be in fullscreen. if (DesktopWallpaperActivity.isWallpaperTask(taskInfo)) { logE( "Trying to add freeform DesktopWallpaperActivity to DesktopRepository, returning early instead" ) return } // If the task is already active in the repository, then moves task to the front, // else adds the task. desktopRepository.addTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible) Loading Loading @@ -108,6 +124,14 @@ class DesktopTaskChangeListener( desktopRepository.removeTask(taskInfo.taskId) } if (isFreeformTask(taskInfo)) { // TODO: b/420917959 - Remove this once LaunchParams respects activity options set for // [DesktopWallpaperActivity] launch which should always be in fullscreen. if (DesktopWallpaperActivity.isWallpaperTask(taskInfo)) { logE( "Trying to add freeform DesktopWallpaperActivity to DesktopRepository, returning early instead" ) return } // If the task is already active in the repository, then it only moves the task to the // front. desktopRepository.addTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible) Loading Loading @@ -165,6 +189,10 @@ class DesktopTaskChangeListener( ProtoLog.d(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments) } private fun logE(msg: String, vararg arguments: Any?) { ProtoLog.e(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments) } companion object { private const val TAG = "DesktopTaskChangeListener" } Loading libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTaskChangeListenerTest.kt +50 −0 Original line number Diff line number Diff line Loading @@ -16,13 +16,18 @@ package com.android.wm.shell.desktopmode import android.app.ActivityManager.RunningTaskInfo import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM import android.content.Intent import android.platform.test.annotations.DisableFlags import android.platform.test.annotations.EnableFlags import android.testing.AndroidTestingRunner import androidx.test.filters.SmallTest import com.android.window.flags.Flags.FLAG_ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION import com.android.window.flags.Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND import com.android.wm.shell.MockToken import com.android.wm.shell.ShellTestCase import com.android.wm.shell.TestRunningTaskInfoBuilder import com.android.wm.shell.desktopmode.DesktopTestHelpers.createFreeformTask import com.android.wm.shell.desktopmode.DesktopTestHelpers.createFullscreenTask import com.android.wm.shell.shared.desktopmode.FakeDesktopState Loading Loading @@ -119,6 +124,22 @@ class DesktopTaskChangeListenerTest : ShellTestCase() { verify(desktopUserRepositories.current).addTask(task.displayId, task.taskId, task.isVisible) } @Test fun onTaskOpening_freeformWallpaperActivityTask_noop() { val freeformWallpaperActivity = createWallpaperTaskInfo(WINDOWING_MODE_FREEFORM) whenever(desktopUserRepositories.current.isActiveTask(freeformWallpaperActivity.taskId)) .thenReturn(false) desktopTaskChangeListener.onTaskOpening(freeformWallpaperActivity) verify(desktopUserRepositories.current, never()) .addTask( freeformWallpaperActivity.displayId, freeformWallpaperActivity.taskId, freeformWallpaperActivity.isVisible, ) } @Test @EnableFlags(FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun onTaskOpening_desktopModeNotSupportedInDisplay_noOp() { Loading Loading @@ -160,6 +181,16 @@ class DesktopTaskChangeListenerTest : ShellTestCase() { verify(desktopUserRepositories.current).addTask(task.displayId, task.taskId, task.isVisible) } @Test fun onTaskChanging_freeformWallpaperActivityTask_noop() { val task = createWallpaperTaskInfo(WINDOWING_MODE_FREEFORM) desktopTaskChangeListener.onTaskChanging(task) verify(desktopUserRepositories.current, never()) .addTask(task.displayId, task.taskId, task.isVisible) } @Test @EnableFlags(FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun onTaskChanging_desktopModeNotSupportedInDisplay_noOp() { Loading Loading @@ -200,6 +231,16 @@ class DesktopTaskChangeListenerTest : ShellTestCase() { verify(desktopUserRepositories.current).addTask(task.displayId, task.taskId, task.isVisible) } @Test fun onTaskMovingToFront_freeformWallpaperActivityTask_noop() { val task = createWallpaperTaskInfo(WINDOWING_MODE_FREEFORM) desktopTaskChangeListener.onTaskMovingToFront(task) verify(desktopUserRepositories.current, never()) .addTask(task.displayId, task.taskId, task.isVisible) } @Test @EnableFlags(FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun onTaskMovingToFront_desktopModeNotSupportedInDisplay_noOp() { Loading Loading @@ -314,6 +355,15 @@ class DesktopTaskChangeListenerTest : ShellTestCase() { verify(desktopUserRepositories.current, never()).removeTask(task.taskId) } private fun createWallpaperTaskInfo(windowingMode: Int): RunningTaskInfo = TestRunningTaskInfoBuilder() .setBaseIntent( Intent().apply { component = DesktopWallpaperActivity.wallpaperActivityComponent } ) .setToken(MockToken().token()) .setWindowingMode(windowingMode) .build() companion object { private const val UNSUPPORTED_DISPLAY_ID = 3 } Loading Loading
libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTaskChangeListener.kt +28 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,14 @@ class DesktopTaskChangeListener( return } if (isFreeformTask(taskInfo) && !desktopRepository.isActiveTask(taskInfo.taskId)) { // TODO: b/420917959 - Remove this once LaunchParams respects activity options set for // [DesktopWallpaperActivity] launch which should always be in fullscreen. if (DesktopWallpaperActivity.isWallpaperTask(taskInfo)) { logE( "Trying to add freeform DesktopWallpaperActivity to DesktopRepository, returning early instead" ) return } desktopRepository.addTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible) } } Loading @@ -72,6 +80,14 @@ class DesktopTaskChangeListener( if (!isFreeformTask(taskInfo) && desktopRepository.isActiveTask(taskInfo.taskId)) { desktopRepository.removeTask(taskInfo.taskId) } else if (isFreeformTask(taskInfo)) { // TODO: b/420917959 - Remove this once LaunchParams respects activity options set for // [DesktopWallpaperActivity] launch which should always be in fullscreen. if (DesktopWallpaperActivity.isWallpaperTask(taskInfo)) { logE( "Trying to add freeform DesktopWallpaperActivity to DesktopRepository, returning early instead" ) return } // If the task is already active in the repository, then moves task to the front, // else adds the task. desktopRepository.addTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible) Loading Loading @@ -108,6 +124,14 @@ class DesktopTaskChangeListener( desktopRepository.removeTask(taskInfo.taskId) } if (isFreeformTask(taskInfo)) { // TODO: b/420917959 - Remove this once LaunchParams respects activity options set for // [DesktopWallpaperActivity] launch which should always be in fullscreen. if (DesktopWallpaperActivity.isWallpaperTask(taskInfo)) { logE( "Trying to add freeform DesktopWallpaperActivity to DesktopRepository, returning early instead" ) return } // If the task is already active in the repository, then it only moves the task to the // front. desktopRepository.addTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible) Loading Loading @@ -165,6 +189,10 @@ class DesktopTaskChangeListener( ProtoLog.d(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments) } private fun logE(msg: String, vararg arguments: Any?) { ProtoLog.e(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments) } companion object { private const val TAG = "DesktopTaskChangeListener" } Loading
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTaskChangeListenerTest.kt +50 −0 Original line number Diff line number Diff line Loading @@ -16,13 +16,18 @@ package com.android.wm.shell.desktopmode import android.app.ActivityManager.RunningTaskInfo import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM import android.content.Intent import android.platform.test.annotations.DisableFlags import android.platform.test.annotations.EnableFlags import android.testing.AndroidTestingRunner import androidx.test.filters.SmallTest import com.android.window.flags.Flags.FLAG_ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION import com.android.window.flags.Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND import com.android.wm.shell.MockToken import com.android.wm.shell.ShellTestCase import com.android.wm.shell.TestRunningTaskInfoBuilder import com.android.wm.shell.desktopmode.DesktopTestHelpers.createFreeformTask import com.android.wm.shell.desktopmode.DesktopTestHelpers.createFullscreenTask import com.android.wm.shell.shared.desktopmode.FakeDesktopState Loading Loading @@ -119,6 +124,22 @@ class DesktopTaskChangeListenerTest : ShellTestCase() { verify(desktopUserRepositories.current).addTask(task.displayId, task.taskId, task.isVisible) } @Test fun onTaskOpening_freeformWallpaperActivityTask_noop() { val freeformWallpaperActivity = createWallpaperTaskInfo(WINDOWING_MODE_FREEFORM) whenever(desktopUserRepositories.current.isActiveTask(freeformWallpaperActivity.taskId)) .thenReturn(false) desktopTaskChangeListener.onTaskOpening(freeformWallpaperActivity) verify(desktopUserRepositories.current, never()) .addTask( freeformWallpaperActivity.displayId, freeformWallpaperActivity.taskId, freeformWallpaperActivity.isVisible, ) } @Test @EnableFlags(FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun onTaskOpening_desktopModeNotSupportedInDisplay_noOp() { Loading Loading @@ -160,6 +181,16 @@ class DesktopTaskChangeListenerTest : ShellTestCase() { verify(desktopUserRepositories.current).addTask(task.displayId, task.taskId, task.isVisible) } @Test fun onTaskChanging_freeformWallpaperActivityTask_noop() { val task = createWallpaperTaskInfo(WINDOWING_MODE_FREEFORM) desktopTaskChangeListener.onTaskChanging(task) verify(desktopUserRepositories.current, never()) .addTask(task.displayId, task.taskId, task.isVisible) } @Test @EnableFlags(FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun onTaskChanging_desktopModeNotSupportedInDisplay_noOp() { Loading Loading @@ -200,6 +231,16 @@ class DesktopTaskChangeListenerTest : ShellTestCase() { verify(desktopUserRepositories.current).addTask(task.displayId, task.taskId, task.isVisible) } @Test fun onTaskMovingToFront_freeformWallpaperActivityTask_noop() { val task = createWallpaperTaskInfo(WINDOWING_MODE_FREEFORM) desktopTaskChangeListener.onTaskMovingToFront(task) verify(desktopUserRepositories.current, never()) .addTask(task.displayId, task.taskId, task.isVisible) } @Test @EnableFlags(FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun onTaskMovingToFront_desktopModeNotSupportedInDisplay_noOp() { Loading Loading @@ -314,6 +355,15 @@ class DesktopTaskChangeListenerTest : ShellTestCase() { verify(desktopUserRepositories.current, never()).removeTask(task.taskId) } private fun createWallpaperTaskInfo(windowingMode: Int): RunningTaskInfo = TestRunningTaskInfoBuilder() .setBaseIntent( Intent().apply { component = DesktopWallpaperActivity.wallpaperActivityComponent } ) .setToken(MockToken().token()) .setWindowingMode(windowingMode) .build() companion object { private const val UNSUPPORTED_DISPLAY_ID = 3 } Loading