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

Commit 2c41fd90 authored by Cicely's avatar Cicely Committed by Cicely Lambright
Browse files

Add method to check if the current display is in DesktopMode

Test: DesktopTasksControllerTest
Fixes: b/421228545
Flag: NONE - new method, no usages yet. New usages will be flag guarded
Change-Id: I866b656393ef3c938c9f317d4611fbf78fd7b713
parent 0883e019
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -71,4 +71,7 @@ public interface DesktopMode {
     * Unregister a registered desktop-first listener
     */
    void unregisterDesktopFirstListener(@NonNull DesktopFirstListener listener);

    /** Check is a specific displayId is in DesktopMode. */
    boolean isDisplayInDesktopMode(int displayId);
}
+11 −0
Original line number Diff line number Diff line
@@ -6000,6 +6000,17 @@ class DesktopTasksController(
            }
            mainExecutor.execute { desktopFirstListenerManager.get().unregisterListener(listener) }
        }

        override fun isDisplayInDesktopMode(displayId: Int) =
            with(this@DesktopTasksController) {
                desktopState.isDesktopModeSupportedOnDisplay(displayId) &&
                    // TODO: b/440645027 - Simplify this call.
                    userRepositories.current
                        .getDeskDisplayStateForRemote()
                        .filter { it.displayId == displayId }
                        .filterNot { it.activeDeskId == INVALID_DISPLAY }
                        .isNotEmpty()
            }
    }

    /** The interface for calls from outside the host process. */
+22 −1
Original line number Diff line number Diff line
@@ -11935,6 +11935,27 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            .activateDesk(wct = eq(wct), deskId = eq(110006), skipReorder = any())
    }

    @Test
    fun isDesktopModeEnabledOnDisplay_cannotEnterDesktopMode_isFalse() {
        desktopState.canEnterDesktopMode = false
        clearInvocations(shellInit)
        controller = createController()

        assertThat(controller.asDesktopMode().isDisplayInDesktopMode(SECONDARY_DISPLAY_ID))
            .isFalse()
    }

    @Test
    fun isDesktopModeEnabledOnDisplay_displayNotDesktop_isFalse() {
        assertThat(controller.asDesktopMode().isDisplayInDesktopMode(SECONDARY_DISPLAY_ID))
            .isFalse()
    }

    @Test
    fun isDesktopModeEnabledOnDisplay_displayIsDesktop_isTrue() {
        assertThat(controller.asDesktopMode().isDisplayInDesktopMode(DEFAULT_DISPLAY)).isTrue()
    }

    private class RunOnStartTransitionCallback : ((IBinder) -> Unit) {
        var invocations = 0
            private set