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

Commit 215a1f76 authored by Matt Pietal's avatar Matt Pietal
Browse files

[DO NOT MERGE] Rewire dozing for clock events

Continuing exploration of moving all doze events to flowables,
including both isDozing and the dozeAmount animations. At the moment,
the source of these events still comes from StatusBarStateController,
which informs the KeyguardRepository. Next up is to create a parallel
way to drive these animations that is solely based on repository
information.

Bug: 242853098
Test: atest ClockEventControllerTest KeyguardClockSwitchControllerTest
Change-Id: I8c40076ad7e716093f602e5bbf5d9f03871ac679
parent ed74a53d
Loading
Loading
Loading
Loading
+58 −28
Original line number Original line Diff line number Diff line
@@ -23,12 +23,17 @@ import android.content.res.Resources
import android.text.format.DateFormat
import android.text.format.DateFormat
import android.util.TypedValue
import android.util.TypedValue
import android.view.View
import android.view.View
import androidx.annotation.VisibleForTesting
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import com.android.systemui.broadcast.BroadcastDispatcher
import com.android.systemui.broadcast.BroadcastDispatcher
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.plugins.ClockController
import com.android.systemui.flags.Flags.REGION_SAMPLING
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.plugins.Clock
import com.android.systemui.shared.regionsampling.RegionSamplingInstance
import com.android.systemui.shared.regionsampling.RegionSamplingInstance
import com.android.systemui.statusbar.policy.BatteryController
import com.android.systemui.statusbar.policy.BatteryController
import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback
import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback
@@ -38,13 +43,19 @@ import java.util.Locale
import java.util.TimeZone
import java.util.TimeZone
import java.util.concurrent.Executor
import java.util.concurrent.Executor
import javax.inject.Inject
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DisposableHandle
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.launch


/**
/**
 * Controller for a Clock provided by the registry and used on the keyguard. Instantiated by
 * Controller for a Clock provided by the registry and used on the keyguard. Instantiated by
 * [KeyguardClockSwitchController]. Functionality is forked from [AnimatableClockController].
 * [KeyguardClockSwitchController]. Functionality is forked from [AnimatableClockController].
 */
 */
open class ClockEventController @Inject constructor(
open class ClockEventController @Inject constructor(
    private val statusBarStateController: StatusBarStateController,
    private val keyguardInteractor: KeyguardInteractor,
    private val broadcastDispatcher: BroadcastDispatcher,
    private val broadcastDispatcher: BroadcastDispatcher,
    private val batteryController: BatteryController,
    private val batteryController: BatteryController,
    private val keyguardUpdateMonitor: KeyguardUpdateMonitor,
    private val keyguardUpdateMonitor: KeyguardUpdateMonitor,
@@ -53,7 +64,7 @@ open class ClockEventController @Inject constructor(
    private val context: Context,
    private val context: Context,
    @Main private val mainExecutor: Executor,
    @Main private val mainExecutor: Executor,
    @Background private val bgExecutor: Executor,
    @Background private val bgExecutor: Executor,
    private val featureFlags: FeatureFlags,
    private val featureFlags: FeatureFlags
) {
) {
    var clock: ClockController? = null
    var clock: ClockController? = null
        set(value) {
        set(value) {
@@ -70,9 +81,9 @@ open class ClockEventController @Inject constructor(
    private var isCharging = false
    private var isCharging = false
    private var dozeAmount = 0f
    private var dozeAmount = 0f
    private var isKeyguardVisible = false
    private var isKeyguardVisible = false

    private var isRegistered = false
    private val regionSamplingEnabled =
    private var disposableHandle: DisposableHandle? = null
            featureFlags.isEnabled(com.android.systemui.flags.Flags.REGION_SAMPLING)
    private val regionSamplingEnabled = featureFlags.isEnabled(REGION_SAMPLING)


    private fun updateColors() {
    private fun updateColors() {
        if (regionSamplingEnabled && smallRegionSampler != null && largeRegionSampler != null) {
        if (regionSamplingEnabled && smallRegionSampler != null && largeRegionSampler != null) {
@@ -165,15 +176,6 @@ open class ClockEventController @Inject constructor(
        }
        }
    }
    }


    private val statusBarStateListener = object : StatusBarStateController.StateListener {
        override fun onDozeAmountChanged(linear: Float, eased: Float) {
            clock?.animations?.doze(linear)

            isDozing = linear > dozeAmount
            dozeAmount = linear
        }
    }

    private val keyguardUpdateMonitorCallback = object : KeyguardUpdateMonitorCallback() {
    private val keyguardUpdateMonitorCallback = object : KeyguardUpdateMonitorCallback() {
        override fun onKeyguardVisibilityChanged(visible: Boolean) {
        override fun onKeyguardVisibilityChanged(visible: Boolean) {
            isKeyguardVisible = visible
            isKeyguardVisible = visible
@@ -195,13 +197,11 @@ open class ClockEventController @Inject constructor(
        }
        }
    }
    }


    init {
    fun registerListeners(parent: View) {
        isDozing = statusBarStateController.isDozing
        if (isRegistered) {
            return
        }
        }

        isRegistered = true
    fun registerListeners() {
        dozeAmount = statusBarStateController.dozeAmount
        isDozing = statusBarStateController.isDozing || dozeAmount != 0f


        broadcastDispatcher.registerReceiver(
        broadcastDispatcher.registerReceiver(
            localeBroadcastReceiver,
            localeBroadcastReceiver,
@@ -210,17 +210,27 @@ open class ClockEventController @Inject constructor(
        configurationController.addCallback(configListener)
        configurationController.addCallback(configListener)
        batteryController.addCallback(batteryCallback)
        batteryController.addCallback(batteryCallback)
        keyguardUpdateMonitor.registerCallback(keyguardUpdateMonitorCallback)
        keyguardUpdateMonitor.registerCallback(keyguardUpdateMonitorCallback)
        statusBarStateController.addCallback(statusBarStateListener)
        smallRegionSampler?.startRegionSampler()
        smallRegionSampler?.startRegionSampler()
        largeRegionSampler?.startRegionSampler()
        largeRegionSampler?.startRegionSampler()
        disposableHandle = parent.repeatWhenAttached {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
                listenForDozing(this)
                listenForDozeAmount(this)
            }
        }
    }
    }


    fun unregisterListeners() {
    fun unregisterListeners() {
        if (!isRegistered) {
            return
        }
        isRegistered = false

        disposableHandle?.dispose()
        broadcastDispatcher.unregisterReceiver(localeBroadcastReceiver)
        broadcastDispatcher.unregisterReceiver(localeBroadcastReceiver)
        configurationController.removeCallback(configListener)
        configurationController.removeCallback(configListener)
        batteryController.removeCallback(batteryCallback)
        batteryController.removeCallback(batteryCallback)
        keyguardUpdateMonitor.removeCallback(keyguardUpdateMonitorCallback)
        keyguardUpdateMonitor.removeCallback(keyguardUpdateMonitorCallback)
        statusBarStateController.removeCallback(statusBarStateListener)
        smallRegionSampler?.stopRegionSampler()
        smallRegionSampler?.stopRegionSampler()
        largeRegionSampler?.stopRegionSampler()
        largeRegionSampler?.stopRegionSampler()
    }
    }
@@ -235,8 +245,28 @@ open class ClockEventController @Inject constructor(
        largeRegionSampler?.dump(pw)
        largeRegionSampler?.dump(pw)
    }
    }


    companion object {
    @VisibleForTesting
        private val TAG = ClockEventController::class.simpleName
    internal suspend fun listenForDozeAmount(scope: CoroutineScope): Job {
        private const val FORMAT_NUMBER = 1234567890
        return scope.launch {
            keyguardInteractor.dozeAmount.collect {
                dozeAmount = it
                clock?.animations?.doze(dozeAmount)
            }
        }
    }

    @VisibleForTesting
    internal suspend fun listenForDozing(scope: CoroutineScope): Job {
        return scope.launch {
            combine (
                keyguardInteractor.dozeAmount,
                keyguardInteractor.isDozing,
            ) { localDozeAmount, localIsDozing ->
                localDozeAmount > dozeAmount || localIsDozing
            }
            .collect { localIsDozing ->
                isDozing = localIsDozing
            }
        }
    }
    }
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -164,7 +164,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
    protected void onViewAttached() {
    protected void onViewAttached() {
        mClockRegistry.registerClockChangeListener(mClockChangedListener);
        mClockRegistry.registerClockChangeListener(mClockChangedListener);
        setClock(mClockRegistry.createCurrentClock());
        setClock(mClockRegistry.createCurrentClock());
        mClockEventController.registerListeners();
        mClockEventController.registerListeners(mView);
        mKeyguardClockTopMargin =
        mKeyguardClockTopMargin =
                mView.getResources().getDimensionPixelSize(R.dimen.keyguard_clock_top_margin);
                mView.getResources().getDimensionPixelSize(R.dimen.keyguard_clock_top_margin);


+68 −80
Original line number Original line Diff line number Diff line
@@ -17,11 +17,14 @@ package com.android.keyguard


import android.content.BroadcastReceiver
import android.content.BroadcastReceiver
import android.testing.AndroidTestingRunner
import android.testing.AndroidTestingRunner
import android.view.View
import android.widget.TextView
import android.widget.TextView
import androidx.test.filters.SmallTest
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.SysuiTestCase
import com.android.systemui.broadcast.BroadcastDispatcher
import com.android.systemui.broadcast.BroadcastDispatcher
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.plugins.ClockAnimations
import com.android.systemui.plugins.ClockAnimations
import com.android.systemui.plugins.ClockController
import com.android.systemui.plugins.ClockController
import com.android.systemui.plugins.ClockEvents
import com.android.systemui.plugins.ClockEvents
@@ -37,6 +40,9 @@ import com.android.systemui.util.mockito.eq
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.mock
import java.util.TimeZone
import java.util.TimeZone
import java.util.concurrent.Executor
import java.util.concurrent.Executor
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.yield
import org.junit.Assert.assertEquals
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Before
import org.junit.Rule
import org.junit.Rule
@@ -57,7 +63,7 @@ import org.mockito.junit.MockitoJUnit
class ClockEventControllerTest : SysuiTestCase() {
class ClockEventControllerTest : SysuiTestCase() {


    @JvmField @Rule val mockito = MockitoJUnit.rule()
    @JvmField @Rule val mockito = MockitoJUnit.rule()
    @Mock private lateinit var statusBarStateController: StatusBarStateController
    @Mock private lateinit var keyguardInteractor: KeyguardInteractor
    @Mock private lateinit var broadcastDispatcher: BroadcastDispatcher
    @Mock private lateinit var broadcastDispatcher: BroadcastDispatcher
    @Mock private lateinit var batteryController: BatteryController
    @Mock private lateinit var batteryController: BatteryController
    @Mock private lateinit var keyguardUpdateMonitor: KeyguardUpdateMonitor
    @Mock private lateinit var keyguardUpdateMonitor: KeyguardUpdateMonitor
@@ -72,8 +78,10 @@ class ClockEventControllerTest : SysuiTestCase() {
    @Mock private lateinit var largeClockController: ClockFaceController
    @Mock private lateinit var largeClockController: ClockFaceController
    @Mock private lateinit var smallClockEvents: ClockFaceEvents
    @Mock private lateinit var smallClockEvents: ClockFaceEvents
    @Mock private lateinit var largeClockEvents: ClockFaceEvents
    @Mock private lateinit var largeClockEvents: ClockFaceEvents
    @Mock private lateinit var parentView: View
    private lateinit var repository: FakeKeyguardRepository


    private lateinit var clockEventController: ClockEventController
    private lateinit var underTest: ClockEventController


    @Before
    @Before
    fun setUp() {
    fun setUp() {
@@ -86,8 +94,10 @@ class ClockEventControllerTest : SysuiTestCase() {
        whenever(clock.events).thenReturn(events)
        whenever(clock.events).thenReturn(events)
        whenever(clock.animations).thenReturn(animations)
        whenever(clock.animations).thenReturn(animations)


        clockEventController = ClockEventController(
        repository = FakeKeyguardRepository()
            statusBarStateController,

        underTest = ClockEventController(
            KeyguardInteractor(repository = repository),
            broadcastDispatcher,
            broadcastDispatcher,
            batteryController,
            batteryController,
            keyguardUpdateMonitor,
            keyguardUpdateMonitor,
@@ -98,31 +108,34 @@ class ClockEventControllerTest : SysuiTestCase() {
            bgExecutor,
            bgExecutor,
            featureFlags
            featureFlags
        )
        )
        underTest.clock = clock

        runBlocking(IMMEDIATE) {
            underTest.registerListeners(parentView)

            repository.setDozing(true)
            repository.setDozeAmount(1f)
        }
    }
    }


    @Test
    @Test
    fun clockSet_validateInitialization() {
    fun clockSet_validateInitialization() {
        clockEventController.clock = clock

        verify(clock).initialize(any(), anyFloat(), anyFloat())
        verify(clock).initialize(any(), anyFloat(), anyFloat())
    }
    }


    @Test
    @Test
    fun clockUnset_validateState() {
    fun clockUnset_validateState() {
        clockEventController.clock = clock
        underTest.clock = null
        clockEventController.clock = null


        assertEquals(clockEventController.clock, null)
        assertEquals(underTest.clock, null)
    }
    }


    @Test
    @Test
    fun themeChanged_verifyClockPaletteUpdated() {
    fun themeChanged_verifyClockPaletteUpdated() = runBlocking(IMMEDIATE) {
        clockEventController.clock = clock
        clockEventController.clock = clock
        verify(smallClockEvents).onRegionDarknessChanged(anyBoolean())
        verify(smallClockEvents).onRegionDarknessChanged(anyBoolean())
        verify(largeClockEvents).onRegionDarknessChanged(anyBoolean())
        verify(largeClockEvents).onRegionDarknessChanged(anyBoolean())


        clockEventController.registerListeners()

        val captor = argumentCaptor<ConfigurationController.ConfigurationListener>()
        val captor = argumentCaptor<ConfigurationController.ConfigurationListener>()
        verify(configurationController).addCallback(capture(captor))
        verify(configurationController).addCallback(capture(captor))
        captor.value.onThemeChanged()
        captor.value.onThemeChanged()
@@ -131,13 +144,11 @@ class ClockEventControllerTest : SysuiTestCase() {
    }
    }


    @Test
    @Test
    fun fontChanged_verifyFontSizeUpdated() {
    fun fontChanged_verifyFontSizeUpdated() = runBlocking(IMMEDIATE) {
        clockEventController.clock = clock
        clockEventController.clock = clock
        verify(smallClockEvents).onRegionDarknessChanged(anyBoolean())
        verify(smallClockEvents).onRegionDarknessChanged(anyBoolean())
        verify(largeClockEvents).onRegionDarknessChanged(anyBoolean())
        verify(largeClockEvents).onRegionDarknessChanged(anyBoolean())


        clockEventController.registerListeners()

        val captor = argumentCaptor<ConfigurationController.ConfigurationListener>()
        val captor = argumentCaptor<ConfigurationController.ConfigurationListener>()
        verify(configurationController).addCallback(capture(captor))
        verify(configurationController).addCallback(capture(captor))
        captor.value.onDensityOrFontScaleChanged()
        captor.value.onDensityOrFontScaleChanged()
@@ -146,10 +157,7 @@ class ClockEventControllerTest : SysuiTestCase() {
    }
    }


    @Test
    @Test
    fun batteryCallback_keyguardShowingCharging_verifyChargeAnimation() {
    fun batteryCallback_keyguardShowingCharging_verifyChargeAnimation() = runBlocking(IMMEDIATE) {
        clockEventController.clock = clock
        clockEventController.registerListeners()

        val batteryCaptor = argumentCaptor<BatteryController.BatteryStateChangeCallback>()
        val batteryCaptor = argumentCaptor<BatteryController.BatteryStateChangeCallback>()
        verify(batteryController).addCallback(capture(batteryCaptor))
        verify(batteryController).addCallback(capture(batteryCaptor))
        val keyguardCaptor = argumentCaptor<KeyguardUpdateMonitorCallback>()
        val keyguardCaptor = argumentCaptor<KeyguardUpdateMonitorCallback>()
@@ -161,10 +169,8 @@ class ClockEventControllerTest : SysuiTestCase() {
    }
    }


    @Test
    @Test
    fun batteryCallback_keyguardShowingCharging_Duplicate_verifyChargeAnimation() {
    fun batteryCallback_keyguardShowingCharging_Duplicate_verifyChargeAnimation() =
        clockEventController.clock = clock
        runBlocking(IMMEDIATE) {
        clockEventController.registerListeners()

            val batteryCaptor = argumentCaptor<BatteryController.BatteryStateChangeCallback>()
            val batteryCaptor = argumentCaptor<BatteryController.BatteryStateChangeCallback>()
            verify(batteryController).addCallback(capture(batteryCaptor))
            verify(batteryController).addCallback(capture(batteryCaptor))
            val keyguardCaptor = argumentCaptor<KeyguardUpdateMonitorCallback>()
            val keyguardCaptor = argumentCaptor<KeyguardUpdateMonitorCallback>()
@@ -177,10 +183,7 @@ class ClockEventControllerTest : SysuiTestCase() {
        }
        }


    @Test
    @Test
    fun batteryCallback_keyguardHiddenCharging_verifyChargeAnimation() {
    fun batteryCallback_keyguardHiddenCharging_verifyChargeAnimation() = runBlocking(IMMEDIATE) {
        clockEventController.clock = clock
        clockEventController.registerListeners()

        val batteryCaptor = argumentCaptor<BatteryController.BatteryStateChangeCallback>()
        val batteryCaptor = argumentCaptor<BatteryController.BatteryStateChangeCallback>()
        verify(batteryController).addCallback(capture(batteryCaptor))
        verify(batteryController).addCallback(capture(batteryCaptor))
        val keyguardCaptor = argumentCaptor<KeyguardUpdateMonitorCallback>()
        val keyguardCaptor = argumentCaptor<KeyguardUpdateMonitorCallback>()
@@ -192,10 +195,8 @@ class ClockEventControllerTest : SysuiTestCase() {
    }
    }


    @Test
    @Test
    fun batteryCallback_keyguardShowingNotCharging_verifyChargeAnimation() {
    fun batteryCallback_keyguardShowingNotCharging_verifyChargeAnimation() =
        clockEventController.clock = clock
        runBlocking(IMMEDIATE) {
        clockEventController.registerListeners()

            val batteryCaptor = argumentCaptor<BatteryController.BatteryStateChangeCallback>()
            val batteryCaptor = argumentCaptor<BatteryController.BatteryStateChangeCallback>()
            verify(batteryController).addCallback(capture(batteryCaptor))
            verify(batteryController).addCallback(capture(batteryCaptor))
            val keyguardCaptor = argumentCaptor<KeyguardUpdateMonitorCallback>()
            val keyguardCaptor = argumentCaptor<KeyguardUpdateMonitorCallback>()
@@ -207,10 +208,7 @@ class ClockEventControllerTest : SysuiTestCase() {
        }
        }


    @Test
    @Test
    fun localeCallback_verifyClockNotified() {
    fun localeCallback_verifyClockNotified() = runBlocking(IMMEDIATE) {
        clockEventController.clock = clock
        clockEventController.registerListeners()

        val captor = argumentCaptor<BroadcastReceiver>()
        val captor = argumentCaptor<BroadcastReceiver>()
        verify(broadcastDispatcher).registerReceiver(
        verify(broadcastDispatcher).registerReceiver(
            capture(captor), any(), eq(null), eq(null), anyInt(), eq(null)
            capture(captor), any(), eq(null), eq(null), anyInt(), eq(null)
@@ -221,10 +219,7 @@ class ClockEventControllerTest : SysuiTestCase() {
    }
    }


    @Test
    @Test
    fun keyguardCallback_visibilityChanged_clockDozeCalled() {
    fun keyguardCallback_visibilityChanged_clockDozeCalled() = runBlocking(IMMEDIATE) {
        clockEventController.clock = clock
        clockEventController.registerListeners()

        val captor = argumentCaptor<KeyguardUpdateMonitorCallback>()
        val captor = argumentCaptor<KeyguardUpdateMonitorCallback>()
        verify(keyguardUpdateMonitor).registerCallback(capture(captor))
        verify(keyguardUpdateMonitor).registerCallback(capture(captor))


@@ -236,10 +231,7 @@ class ClockEventControllerTest : SysuiTestCase() {
    }
    }


    @Test
    @Test
    fun keyguardCallback_timeFormat_clockNotified() {
    fun keyguardCallback_timeFormat_clockNotified() = runBlocking(IMMEDIATE) {
        clockEventController.clock = clock
        clockEventController.registerListeners()

        val captor = argumentCaptor<KeyguardUpdateMonitorCallback>()
        val captor = argumentCaptor<KeyguardUpdateMonitorCallback>()
        verify(keyguardUpdateMonitor).registerCallback(capture(captor))
        verify(keyguardUpdateMonitor).registerCallback(capture(captor))
        captor.value.onTimeFormatChanged("12h")
        captor.value.onTimeFormatChanged("12h")
@@ -248,11 +240,8 @@ class ClockEventControllerTest : SysuiTestCase() {
    }
    }


    @Test
    @Test
    fun keyguardCallback_timezoneChanged_clockNotified() {
    fun keyguardCallback_timezoneChanged_clockNotified() = runBlocking(IMMEDIATE) {
        val mockTimeZone = mock<TimeZone>()
        val mockTimeZone = mock<TimeZone>()
        clockEventController.clock = clock
        clockEventController.registerListeners()

        val captor = argumentCaptor<KeyguardUpdateMonitorCallback>()
        val captor = argumentCaptor<KeyguardUpdateMonitorCallback>()
        verify(keyguardUpdateMonitor).registerCallback(capture(captor))
        verify(keyguardUpdateMonitor).registerCallback(capture(captor))
        captor.value.onTimeZoneChanged(mockTimeZone)
        captor.value.onTimeZoneChanged(mockTimeZone)
@@ -261,10 +250,7 @@ class ClockEventControllerTest : SysuiTestCase() {
    }
    }


    @Test
    @Test
    fun keyguardCallback_userSwitched_clockNotified() {
    fun keyguardCallback_userSwitched_clockNotified() = runBlocking(IMMEDIATE) {
        clockEventController.clock = clock
        clockEventController.registerListeners()

        val captor = argumentCaptor<KeyguardUpdateMonitorCallback>()
        val captor = argumentCaptor<KeyguardUpdateMonitorCallback>()
        verify(keyguardUpdateMonitor).registerCallback(capture(captor))
        verify(keyguardUpdateMonitor).registerCallback(capture(captor))
        captor.value.onUserSwitchComplete(10)
        captor.value.onUserSwitchComplete(10)
@@ -273,25 +259,27 @@ class ClockEventControllerTest : SysuiTestCase() {
    }
    }


    @Test
    @Test
    fun keyguardCallback_verifyKeyguardChanged() {
    fun keyguardCallback_verifyKeyguardChanged() = runBlocking(IMMEDIATE) {
        clockEventController.clock = clock
        val job = underTest.listenForDozeAmount(this)
        clockEventController.registerListeners()
        repository.setDozeAmount(0.4f)


        val captor = argumentCaptor<StatusBarStateController.StateListener>()
        yield()
        verify(statusBarStateController).addCallback(capture(captor))
        captor.value.onDozeAmountChanged(0.4f, 0.6f)


        verify(animations).doze(0.4f)
        verify(animations).doze(0.4f)

        job.cancel()
    }
    }


    @Test
    @Test
    fun unregisterListeners_validate() {
    fun unregisterListeners_validate() = runBlocking(IMMEDIATE) {
        clockEventController.clock = clock
        underTest.unregisterListeners()
        clockEventController.unregisterListeners()
        verify(broadcastDispatcher).unregisterReceiver(any())
        verify(broadcastDispatcher).unregisterReceiver(any())
        verify(configurationController).removeCallback(any())
        verify(configurationController).removeCallback(any())
        verify(batteryController).removeCallback(any())
        verify(batteryController).removeCallback(any())
        verify(keyguardUpdateMonitor).removeCallback(any())
        verify(keyguardUpdateMonitor).removeCallback(any())
        verify(statusBarStateController).removeCallback(any())
    }

    companion object {
        private val IMMEDIATE = Dispatchers.Main.immediate
    }
    }
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -265,6 +265,6 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
    private void verifyAttachment(VerificationMode times) {
    private void verifyAttachment(VerificationMode times) {
        verify(mClockRegistry, times).registerClockChangeListener(
        verify(mClockRegistry, times).registerClockChangeListener(
                any(ClockRegistry.ClockChangeListener.class));
                any(ClockRegistry.ClockChangeListener.class));
        verify(mClockEventController, times).registerListeners();
        verify(mClockEventController, times).registerListeners(mView);
    }
    }
}
}