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

Commit 46c9c412 authored by Hawkwood Glazier's avatar Hawkwood Glazier Committed by Android (Google) Code Review
Browse files

Merge "Always load the current clock when it is first connected" into main

parents ece12b99 a90bacd3
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -173,8 +173,10 @@ open class ClockRegistry(
                    { "Skipping initial load of known clock package package: $str1" }
                )

                var isCurrentClock = false
                var isClockListChanged = false
                for (metadata in knownClocks) {
                    isCurrentClock = isCurrentClock || currentClockId == metadata.clockId
                    val id = metadata.clockId
                    val info =
                        availableClocks.concurrentGetOrPut(id, ClockInfo(metadata, null, manager)) {
@@ -207,8 +209,9 @@ open class ClockRegistry(
                }
                verifyLoadedProviders()

                // Load executed via verifyLoadedProviders
                return false
                // Load immediately if it's the current clock, otherwise let verifyLoadedProviders
                // load and unload clocks as necessary on the background thread.
                return isCurrentClock
            }

            override fun onPluginLoaded(
+16 −7
Original line number Diff line number Diff line
@@ -381,12 +381,15 @@ class ClockRegistryTest : SysuiTestCase() {
    }

    @Test
    fun knownPluginAttached_clockAndListChanged_notLoaded() {
        val lifecycle1 = FakeLifecycle("Metro", null).apply {
            mComponentName = ComponentName("com.android.systemui.clocks.metro", "MetroClock")
    fun knownPluginAttached_clockAndListChanged_loadedCurrent() {
        val metroLifecycle = FakeLifecycle("Metro", null).apply {
            mComponentName = ComponentName("com.android.systemui.clocks.metro", "Metro")
        }
        val lifecycle2 = FakeLifecycle("BigNum", null).apply {
            mComponentName = ComponentName("com.android.systemui.clocks.bignum", "BigNumClock")
        val bignumLifecycle = FakeLifecycle("BigNum", null).apply {
            mComponentName = ComponentName("com.android.systemui.clocks.bignum", "BigNum")
        }
        val calligraphyLifecycle = FakeLifecycle("Calligraphy", null).apply {
            mComponentName = ComponentName("com.android.systemui.clocks.calligraphy", "Calligraphy")
        }

        var changeCallCount = 0
@@ -401,15 +404,21 @@ class ClockRegistryTest : SysuiTestCase() {
        assertEquals(1, changeCallCount)
        assertEquals(0, listChangeCallCount)

        assertEquals(false, pluginListener.onPluginAttached(lifecycle1))
        assertEquals(false, pluginListener.onPluginAttached(metroLifecycle))
        scheduler.runCurrent()
        assertEquals(1, changeCallCount)
        assertEquals(1, listChangeCallCount)

        assertEquals(false, pluginListener.onPluginAttached(lifecycle2))
        assertEquals(false, pluginListener.onPluginAttached(bignumLifecycle))
        scheduler.runCurrent()
        assertEquals(1, changeCallCount)
        assertEquals(2, listChangeCallCount)

        // This returns true, but doesn't trigger onCurrentClockChanged yet
        assertEquals(true, pluginListener.onPluginAttached(calligraphyLifecycle))
        scheduler.runCurrent()
        assertEquals(1, changeCallCount)
        assertEquals(3, listChangeCallCount)
    }

    @Test