Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4e290dcc authored by Matt Sziklay's avatar Matt Sziklay Committed by Android (Google) Code Review
Browse files

Merge "No-op desk creation if display doesn't support desks." into main

parents 09a4ab90 03c0e9e1
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -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
+5 −0
Original line number Diff line number Diff line
@@ -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.
+7 −1
Original line number Diff line number Diff line
@@ -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
@@ -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()
@@ -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
        }
+14 −0
Original line number Diff line number Diff line
@@ -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 ->
@@ -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())
@@ -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)
@@ -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)
@@ -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,
+25 −0
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ class DesktopRepositoryInitializerTest : ShellTestCase() {
                persistentRepository,
                datastoreScope,
                desktopConfig,
                desktopState,
            )
        desktopUserRepositories =
            DesktopUserRepositories(
@@ -116,6 +117,7 @@ class DesktopRepositoryInitializerTest : ShellTestCase() {
    )
    fun initWithPersistence_multipleUsers_addedCorrectly() =
        runTest(StandardTestDispatcher()) {
            desktopState.overrideDesktopModeSupportPerDisplay[DEFAULT_DISPLAY] = true
            whenever(persistentRepository.getUserDesktopRepositoryMap())
                .thenReturn(
                    mapOf(
@@ -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))
@@ -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))
@@ -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()