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

Commit 3a1138a8 authored by Austin Delgado's avatar Austin Delgado Committed by Android (Google) Code Review
Browse files

Merge "Move Face/FingerprintManager registration calls off main thread" into main

parents dbb916f1 bb632ecb
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -29,13 +29,16 @@ import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLoggin
import com.android.systemui.common.coroutine.ConflatedCallbackFlow
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.withContext

/** A repository for the global state of Face sensor. */
interface FacePropertyRepository {
@@ -56,7 +59,8 @@ class FacePropertyRepositoryImpl
@Inject
constructor(
    @Application private val applicationScope: CoroutineScope,
    private val faceManager: FaceManager?
    @Background private val backgroundDispatcher: CoroutineDispatcher,
    private val faceManager: FaceManager?,
) : FacePropertyRepository {

    override val sensorInfo: StateFlow<FaceSensorInfo?> =
@@ -77,7 +81,9 @@ constructor(
                            )
                        }
                    }
                withContext(backgroundDispatcher) {
                    faceManager?.addAuthenticatorsRegisteredCallback(callback)
                }
                awaitClose {}
            }
            .onEach { Log.d(TAG, "sensorProps changed: $it") }
+7 −1
Original line number Diff line number Diff line
@@ -33,7 +33,9 @@ import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLoggin
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
@@ -41,6 +43,7 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.withContext

/**
 * A repository for the global state of FingerprintProperty.
@@ -67,6 +70,7 @@ class FingerprintPropertyRepositoryImpl
@Inject
constructor(
    @Application private val applicationScope: CoroutineScope,
    @Background private val backgroundDispatcher: CoroutineDispatcher,
    private val fingerprintManager: FingerprintManager?,
) : FingerprintPropertyRepository {

@@ -93,7 +97,9 @@ constructor(
                            }
                        }
                    }
                withContext(backgroundDispatcher) {
                    fingerprintManager?.addAuthenticatorsRegisteredCallback(callback)
                }
                awaitClose {}
            }
            .stateIn(
+6 −2
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestDispatcher
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
@@ -54,18 +56,20 @@ class FacePropertyRepositoryImplTest : SysuiTestCase() {
    @JvmField @Rule val mockitoRule: MockitoRule = MockitoJUnit.rule()

    private lateinit var underTest: FacePropertyRepository
    private lateinit var dispatcher: TestDispatcher
    private lateinit var testScope: TestScope

    @Captor private lateinit var callback: ArgumentCaptor<IFaceAuthenticatorsRegisteredCallback>
    @Mock private lateinit var faceManager: FaceManager
    @Before
    fun setup() {
        testScope = TestScope()
        dispatcher = StandardTestDispatcher()
        testScope = TestScope(dispatcher)
        underTest = createRepository(faceManager)
    }

    private fun createRepository(manager: FaceManager? = faceManager) =
        FacePropertyRepositoryImpl(testScope.backgroundScope, manager)
        FacePropertyRepositoryImpl(testScope.backgroundScope, dispatcher, manager)

    @Test
    fun whenFaceManagerIsNotPresentIsNull() =
+5 −1
Original line number Diff line number Diff line
@@ -65,7 +65,11 @@ class FingerprintRepositoryImplTest : SysuiTestCase() {
        val dispatcher = StandardTestDispatcher()
        testScope = TestScope(dispatcher)
        repository =
            FingerprintPropertyRepositoryImpl(testScope.backgroundScope, fingerprintManager)
            FingerprintPropertyRepositoryImpl(
                testScope.backgroundScope,
                dispatcher,
                fingerprintManager
            )
        testScope.runCurrent()

        verify(fingerprintManager)