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

Commit 7d3385ab authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Select the default clock if current clock id was not found" into...

Merge "Select the default clock if current clock id was not found" into udc-qpr-dev am: 45a8dc0e am: aa2875c7

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24465907



Change-Id: Ia60930b8315f5a717a33b821f7458bb8f5b96f13
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 9c0df5a8 aa2875c7
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -409,6 +409,18 @@ open class ClockRegistry(
            scope.launch(bgDispatcher) { mutateSetting { it.copy(seedColor = value) } }
        }

    // Returns currentClockId if clock is connected, otherwise DEFAULT_CLOCK_ID. Since this
    // is dependent on which clocks are connected, it may change when a clock is installed or
    // removed from the device (unlike currentClockId).
    // TODO: Merge w/ CurrentClockId when we convert to a flow. We shouldn't need both behaviors.
    val activeClockId: String
        get() {
            if (!availableClocks.containsKey(currentClockId)) {
                return DEFAULT_CLOCK_ID
            }
            return currentClockId
        }

    init {
        // Register default clock designs
        for (clock in defaultClockProvider.getClocks()) {
+19 −0
Original line number Diff line number Diff line
@@ -226,6 +226,25 @@ class ClockRegistryTest : SysuiTestCase() {
        assertEquals(mockClock, clock)
    }

    @Test
    fun activeClockId_changeAfterPluginConnected() {
        val plugin1 = FakeClockPlugin()
            .addClock("clock_1", "clock 1")
            .addClock("clock_2", "clock 2")

        val plugin2 = FakeClockPlugin()
            .addClock("clock_3", "clock 3", { mockClock })
            .addClock("clock_4", "clock 4")

        registry.applySettings(ClockSettings("clock_3", null))

        pluginListener.onPluginLoaded(plugin1, mockContext, mockPluginLifecycle)
        assertEquals(DEFAULT_CLOCK_ID, registry.activeClockId)

        pluginListener.onPluginLoaded(plugin2, mockContext, mockPluginLifecycle)
        assertEquals("clock_3", registry.activeClockId)
    }

    @Test
    fun createDefaultClock_pluginDisconnected() {
        val plugin1 = FakeClockPlugin()