Loading libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java +3 −2 Original line number Diff line number Diff line Loading @@ -1646,9 +1646,10 @@ public abstract class WMShellModule { Context context, DesktopPersistentRepository desktopPersistentRepository, @ShellMainThread CoroutineScope mainScope, DesktopConfig desktopConfig) { DesktopConfig desktopConfig, DesktopState desktopState) { return new DesktopRepositoryInitializerImpl(context, desktopPersistentRepository, mainScope, desktopConfig); mainScope, desktopConfig, desktopState); } @WMSingleton Loading libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt +5 −0 Original line number Diff line number Diff line Loading @@ -557,6 +557,11 @@ class DesktopTasksController( userId, enforceDeskLimit, ) if (!desktopState.isDesktopModeSupportedOnDisplay(displayId)) { // Display does not support desktops, no-op. logW("createDesk displayId $displayId does not support desktops, ignoring request") return } val repository = userRepositories.getProfile(userId) if (enforceDeskLimit && !canCreateDesks(repository)) { // At the limit, no-op. Loading libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/persistence/DesktopRepositoryInitializerImpl.kt +7 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import com.android.wm.shell.desktopmode.persistence.DesktopRepositoryInitializer import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE import com.android.wm.shell.shared.annotations.ShellMainThread import com.android.wm.shell.shared.desktopmode.DesktopConfig import com.android.wm.shell.shared.desktopmode.DesktopState import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow Loading @@ -43,6 +44,7 @@ class DesktopRepositoryInitializerImpl( private val persistentRepository: DesktopPersistentRepository, @ShellMainThread private val mainCoroutineScope: CoroutineScope, private val desktopConfig: DesktopConfig, private val desktopState: DesktopState, ) : DesktopRepositoryInitializer { override var deskRecreationFactory: DeskRecreationFactory = DefaultDeskRecreationFactory() Loading @@ -51,7 +53,11 @@ class DesktopRepositoryInitializerImpl( override val isInitialized: StateFlow<Boolean> = _isInitialized override fun initialize(userRepositories: DesktopUserRepositories) { if (!DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_PERSISTENCE.isTrue) { // TODO: b/401107440 - Remove second check once restoring to external displays is supported if ( !DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_PERSISTENCE.isTrue || !desktopState.isDesktopModeSupportedOnDisplay(Display.DEFAULT_DISPLAY) ) { _isInitialized.value = true return } Loading libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt +14 −0 Original line number Diff line number Diff line Loading @@ -9634,6 +9634,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase() @Test @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun testCreateDesk() { desktopState.overrideDesktopModeSupportPerDisplay[DEFAULT_DISPLAY] = true val currentDeskCount = taskRepository.getNumberOfDesks(DEFAULT_DISPLAY) whenever(desksOrganizer.createDesk(eq(DEFAULT_DISPLAY), any(), any())).thenAnswer { invocation -> Loading @@ -9648,6 +9649,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase() @Test @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun testCreateDesk_invalidDisplay_dropsRequest() { desktopState.overrideDesktopModeSupportPerDisplay[DEFAULT_DISPLAY] = true controller.createDesk(INVALID_DISPLAY) verify(desksOrganizer, never()).createDesk(any(), any(), any()) Loading @@ -9656,6 +9658,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase() @Test @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun testCreateDesk_systemUser_dropsRequest() { desktopState.overrideDesktopModeSupportPerDisplay[DEFAULT_DISPLAY] = true assumeTrue(UserManager.isHeadlessSystemUserMode()) controller.createDesk(DEFAULT_DISPLAY, UserHandle.USER_SYSTEM) Loading @@ -9666,6 +9669,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase() @Test @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun testCreateDesk_enforceLimitAndOverLimit_dropsRequest() { desktopState.overrideDesktopModeSupportPerDisplay[DEFAULT_DISPLAY] = true desktopConfig.maxDeskLimit = 2 // Add a second desk to bring the number up to the limit. taskRepository.addDesk(displayId = DEFAULT_DISPLAY, deskId = 2) Loading @@ -9675,6 +9679,16 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase() verify(desksOrganizer, never()).createDesk(any(), any(), any()) } @Test @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun testCreateDesk_displayDoesNotSupportDesks_dropsRequest() { desktopState.overrideDesktopModeSupportPerDisplay[DEFAULT_DISPLAY] = false controller.createDesk(DEFAULT_DISPLAY) verify(desksOrganizer, never()).createDesk(any(), any(), any()) } @Test @EnableFlags( Flags.FLAG_ENABLE_DISPLAY_DISCONNECT_INTERACTION, Loading libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/persistence/DesktopRepositoryInitializerTest.kt +25 −0 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ class DesktopRepositoryInitializerTest : ShellTestCase() { persistentRepository, datastoreScope, desktopConfig, desktopState, ) desktopUserRepositories = DesktopUserRepositories( Loading Loading @@ -116,6 +117,7 @@ class DesktopRepositoryInitializerTest : ShellTestCase() { ) fun initWithPersistence_multipleUsers_addedCorrectly() = runTest(StandardTestDispatcher()) { desktopState.overrideDesktopModeSupportPerDisplay[DEFAULT_DISPLAY] = true whenever(persistentRepository.getUserDesktopRepositoryMap()) .thenReturn( mapOf( Loading Loading @@ -202,6 +204,7 @@ class DesktopRepositoryInitializerTest : ShellTestCase() { @EnableFlags(FLAG_ENABLE_DESKTOP_WINDOWING_PERSISTENCE, FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun initWithPersistence_singleUser_addedCorrectly() = runTest(StandardTestDispatcher()) { desktopState.overrideDesktopModeSupportPerDisplay[DEFAULT_DISPLAY] = true whenever(persistentRepository.getUserDesktopRepositoryMap()) .thenReturn(mapOf(USER_ID_1 to desktopRepositoryState1)) whenever(persistentRepository.getDesktopRepositoryState(USER_ID_1)) Loading Loading @@ -269,6 +272,7 @@ class DesktopRepositoryInitializerTest : ShellTestCase() { ) fun initWithPersistence_deskRecreationFailed_deskNotAdded() = runTest(StandardTestDispatcher()) { desktopState.overrideDesktopModeSupportPerDisplay[DEFAULT_DISPLAY] = true whenever(persistentRepository.getUserDesktopRepositoryMap()) .thenReturn(mapOf(USER_ID_1 to desktopRepositoryState1)) whenever(persistentRepository.getDesktopRepositoryState(USER_ID_1)) Loading @@ -291,6 +295,27 @@ class DesktopRepositoryInitializerTest : ShellTestCase() { .containsExactly(DESKTOP_ID_1) } @Test @EnableFlags( FLAG_ENABLE_DESKTOP_WINDOWING_PERSISTENCE, FLAG_ENABLE_DESKTOP_WINDOWING_HSUM, FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND, ) fun initWithPersistence_defaultDisplayDoesNotSupportDesks_deskNotAdded() = runTest(StandardTestDispatcher()) { desktopState.overrideDesktopModeSupportPerDisplay[DEFAULT_DISPLAY] = false whenever(persistentRepository.getUserDesktopRepositoryMap()) .thenReturn(mapOf(USER_ID_1 to desktopRepositoryState1)) whenever(persistentRepository.getDesktopRepositoryState(USER_ID_1)) .thenReturn(desktopRepositoryState1) whenever(persistentRepository.readDesktop(USER_ID_1, DESKTOP_ID_1)).thenReturn(desktop1) repositoryInitializer.initialize(desktopUserRepositories) assertThat(desktopUserRepositories.getProfile(USER_ID_1).getDeskIds(DEFAULT_DISPLAY)) .isEmpty() } @After fun tearDown() { datastoreScope.cancel() Loading Loading
libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java +3 −2 Original line number Diff line number Diff line Loading @@ -1646,9 +1646,10 @@ public abstract class WMShellModule { Context context, DesktopPersistentRepository desktopPersistentRepository, @ShellMainThread CoroutineScope mainScope, DesktopConfig desktopConfig) { DesktopConfig desktopConfig, DesktopState desktopState) { return new DesktopRepositoryInitializerImpl(context, desktopPersistentRepository, mainScope, desktopConfig); mainScope, desktopConfig, desktopState); } @WMSingleton Loading
libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt +5 −0 Original line number Diff line number Diff line Loading @@ -557,6 +557,11 @@ class DesktopTasksController( userId, enforceDeskLimit, ) if (!desktopState.isDesktopModeSupportedOnDisplay(displayId)) { // Display does not support desktops, no-op. logW("createDesk displayId $displayId does not support desktops, ignoring request") return } val repository = userRepositories.getProfile(userId) if (enforceDeskLimit && !canCreateDesks(repository)) { // At the limit, no-op. Loading
libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/persistence/DesktopRepositoryInitializerImpl.kt +7 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import com.android.wm.shell.desktopmode.persistence.DesktopRepositoryInitializer import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE import com.android.wm.shell.shared.annotations.ShellMainThread import com.android.wm.shell.shared.desktopmode.DesktopConfig import com.android.wm.shell.shared.desktopmode.DesktopState import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow Loading @@ -43,6 +44,7 @@ class DesktopRepositoryInitializerImpl( private val persistentRepository: DesktopPersistentRepository, @ShellMainThread private val mainCoroutineScope: CoroutineScope, private val desktopConfig: DesktopConfig, private val desktopState: DesktopState, ) : DesktopRepositoryInitializer { override var deskRecreationFactory: DeskRecreationFactory = DefaultDeskRecreationFactory() Loading @@ -51,7 +53,11 @@ class DesktopRepositoryInitializerImpl( override val isInitialized: StateFlow<Boolean> = _isInitialized override fun initialize(userRepositories: DesktopUserRepositories) { if (!DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_PERSISTENCE.isTrue) { // TODO: b/401107440 - Remove second check once restoring to external displays is supported if ( !DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_PERSISTENCE.isTrue || !desktopState.isDesktopModeSupportedOnDisplay(Display.DEFAULT_DISPLAY) ) { _isInitialized.value = true return } Loading
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt +14 −0 Original line number Diff line number Diff line Loading @@ -9634,6 +9634,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase() @Test @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun testCreateDesk() { desktopState.overrideDesktopModeSupportPerDisplay[DEFAULT_DISPLAY] = true val currentDeskCount = taskRepository.getNumberOfDesks(DEFAULT_DISPLAY) whenever(desksOrganizer.createDesk(eq(DEFAULT_DISPLAY), any(), any())).thenAnswer { invocation -> Loading @@ -9648,6 +9649,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase() @Test @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun testCreateDesk_invalidDisplay_dropsRequest() { desktopState.overrideDesktopModeSupportPerDisplay[DEFAULT_DISPLAY] = true controller.createDesk(INVALID_DISPLAY) verify(desksOrganizer, never()).createDesk(any(), any(), any()) Loading @@ -9656,6 +9658,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase() @Test @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun testCreateDesk_systemUser_dropsRequest() { desktopState.overrideDesktopModeSupportPerDisplay[DEFAULT_DISPLAY] = true assumeTrue(UserManager.isHeadlessSystemUserMode()) controller.createDesk(DEFAULT_DISPLAY, UserHandle.USER_SYSTEM) Loading @@ -9666,6 +9669,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase() @Test @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun testCreateDesk_enforceLimitAndOverLimit_dropsRequest() { desktopState.overrideDesktopModeSupportPerDisplay[DEFAULT_DISPLAY] = true desktopConfig.maxDeskLimit = 2 // Add a second desk to bring the number up to the limit. taskRepository.addDesk(displayId = DEFAULT_DISPLAY, deskId = 2) Loading @@ -9675,6 +9679,16 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase() verify(desksOrganizer, never()).createDesk(any(), any(), any()) } @Test @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun testCreateDesk_displayDoesNotSupportDesks_dropsRequest() { desktopState.overrideDesktopModeSupportPerDisplay[DEFAULT_DISPLAY] = false controller.createDesk(DEFAULT_DISPLAY) verify(desksOrganizer, never()).createDesk(any(), any(), any()) } @Test @EnableFlags( Flags.FLAG_ENABLE_DISPLAY_DISCONNECT_INTERACTION, Loading
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/persistence/DesktopRepositoryInitializerTest.kt +25 −0 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ class DesktopRepositoryInitializerTest : ShellTestCase() { persistentRepository, datastoreScope, desktopConfig, desktopState, ) desktopUserRepositories = DesktopUserRepositories( Loading Loading @@ -116,6 +117,7 @@ class DesktopRepositoryInitializerTest : ShellTestCase() { ) fun initWithPersistence_multipleUsers_addedCorrectly() = runTest(StandardTestDispatcher()) { desktopState.overrideDesktopModeSupportPerDisplay[DEFAULT_DISPLAY] = true whenever(persistentRepository.getUserDesktopRepositoryMap()) .thenReturn( mapOf( Loading Loading @@ -202,6 +204,7 @@ class DesktopRepositoryInitializerTest : ShellTestCase() { @EnableFlags(FLAG_ENABLE_DESKTOP_WINDOWING_PERSISTENCE, FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun initWithPersistence_singleUser_addedCorrectly() = runTest(StandardTestDispatcher()) { desktopState.overrideDesktopModeSupportPerDisplay[DEFAULT_DISPLAY] = true whenever(persistentRepository.getUserDesktopRepositoryMap()) .thenReturn(mapOf(USER_ID_1 to desktopRepositoryState1)) whenever(persistentRepository.getDesktopRepositoryState(USER_ID_1)) Loading Loading @@ -269,6 +272,7 @@ class DesktopRepositoryInitializerTest : ShellTestCase() { ) fun initWithPersistence_deskRecreationFailed_deskNotAdded() = runTest(StandardTestDispatcher()) { desktopState.overrideDesktopModeSupportPerDisplay[DEFAULT_DISPLAY] = true whenever(persistentRepository.getUserDesktopRepositoryMap()) .thenReturn(mapOf(USER_ID_1 to desktopRepositoryState1)) whenever(persistentRepository.getDesktopRepositoryState(USER_ID_1)) Loading @@ -291,6 +295,27 @@ class DesktopRepositoryInitializerTest : ShellTestCase() { .containsExactly(DESKTOP_ID_1) } @Test @EnableFlags( FLAG_ENABLE_DESKTOP_WINDOWING_PERSISTENCE, FLAG_ENABLE_DESKTOP_WINDOWING_HSUM, FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND, ) fun initWithPersistence_defaultDisplayDoesNotSupportDesks_deskNotAdded() = runTest(StandardTestDispatcher()) { desktopState.overrideDesktopModeSupportPerDisplay[DEFAULT_DISPLAY] = false whenever(persistentRepository.getUserDesktopRepositoryMap()) .thenReturn(mapOf(USER_ID_1 to desktopRepositoryState1)) whenever(persistentRepository.getDesktopRepositoryState(USER_ID_1)) .thenReturn(desktopRepositoryState1) whenever(persistentRepository.readDesktop(USER_ID_1, DESKTOP_ID_1)).thenReturn(desktop1) repositoryInitializer.initialize(desktopUserRepositories) assertThat(desktopUserRepositories.getProfile(USER_ID_1).getDeskIds(DEFAULT_DISPLAY)) .isEmpty() } @After fun tearDown() { datastoreScope.cancel() Loading