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

Commit 2a26787e authored by Hawkwood Glazier's avatar Hawkwood Glazier Committed by Android Build Coastguard Worker
Browse files

Select the default clock if current clock id was not found

Bug: 295371293
Test: Manually tested invalid clock ids
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:6194a27664896ff9cbae646483659959dfb3aca8)
Merged-In: I98d96bf72cbe09895b644a5a53f86499bf74bfab
Change-Id: I98d96bf72cbe09895b644a5a53f86499bf74bfab
parent ccf04777
Loading
Loading
Loading
Loading
+12 −0
Original line number Original line Diff line number Diff line
@@ -401,6 +401,18 @@ open class ClockRegistry(
            scope.launch(bgDispatcher) { mutateSetting { it.copy(seedColor = value) } }
            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 {
    init {
        // Register default clock designs
        // Register default clock designs
        for (clock in defaultClockProvider.getClocks()) {
        for (clock in defaultClockProvider.getClocks()) {
+19 −0
Original line number Original line Diff line number Diff line
@@ -223,6 +223,25 @@ class ClockRegistryTest : SysuiTestCase() {
        assertEquals(mockClock, clock)
        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
    @Test
    fun createDefaultClock_pluginDisconnected() {
    fun createDefaultClock_pluginDisconnected() {
        val plugin1 = FakeClockPlugin()
        val plugin1 = FakeClockPlugin()