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

Commit 50cfcf9c authored by Lucas Silva's avatar Lucas Silva
Browse files

Update keyguard flow to always be on main thread.

KeyguardUpdateMonitor.registerCallback will throw an execption if not on
the main thread. Therefore this change enforces that the flow is always
collected on the main thread, even if the consumer tries to collect it
in a background thread.

Bug: 319331389
Test: atest KeyguardRepositoryImplTest
Flag: NA
Change-Id: I33482ed5797e87888dec55201ec650ccc89b7b38
parent a578f07c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -574,7 +574,7 @@ class KeyguardRepositoryImplTest : SysuiTestCase() {

    @Test
    fun isEncryptedOrLockdown() =
        testScope.runTest {
        TestScope(mainDispatcher).runTest {
            whenever(userTracker.userId).thenReturn(0)
            whenever(keyguardUpdateMonitor.isEncryptedOrLockdown(0)).thenReturn(true)

+3 −3
Original line number Diff line number Diff line
@@ -567,17 +567,17 @@ constructor(
                val callback =
                    object : KeyguardUpdateMonitorCallback() {
                        override fun onStrongAuthStateChanged(userId: Int) {
                            trySend(userId)
                            trySendWithFailureLogging(userId, TAG, "strong auth state change")
                        }
                    }

                keyguardUpdateMonitor.registerCallback(callback)

                awaitClose { keyguardUpdateMonitor.removeCallback(callback) }
            }
            .filter { userId -> userId == userTracker.userId }
            .onStart { emit(userTracker.userId) }
            .mapLatest { userId -> keyguardUpdateMonitor.isEncryptedOrLockdown(userId) }
            // KeyguardUpdateMonitor#registerCallback needs to be called on the main thread.
            .flowOn(mainDispatcher)

    override fun isKeyguardShowing(): Boolean {
        return keyguardStateController.isShowing