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

Commit b9abeb8c authored by Shawn Lin's avatar Shawn Lin Committed by Android (Google) Code Review
Browse files

Merge "Fixed biometric enable for keyguard status not correctly updated" into main

parents 746235af 354029a8
Loading
Loading
Loading
Loading
+46 −0
Original line number Original line Diff line number Diff line
@@ -79,6 +79,7 @@ import org.mockito.Mockito.clearInvocations
import org.mockito.Mockito.times
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.doAnswer
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.stub
import org.mockito.kotlin.stub


@@ -472,6 +473,51 @@ class BiometricSettingsRepositoryTest : SysuiTestCase() {
            assertThat(faceAuthAllowed).isTrue()
            assertThat(faceAuthAllowed).isTrue()
        }
        }


    @Test
    @EnableFlags(com.android.settings.flags.Flags.FLAG_BIOMETRICS_ONBOARDING_EDUCATION)
    fun registerEnabledOnKeyguardCallback_multipleUsers_shouldSendAllUpdates() =
        testScope.runTest {

            // Simulate call to register callback when in multiple users setup
            biometricManager.stub {
                on { registerEnabledOnKeyguardCallback(any()) } doAnswer
                        { invocation ->
                            val callback =
                                invocation.arguments[0] as IBiometricEnabledOnKeyguardCallback
                            callback.onChanged(true, PRIMARY_USER_ID, TYPE_FACE)
                            callback.onChanged(true, PRIMARY_USER_ID, TYPE_FINGERPRINT)
                            callback.onChanged(true, ANOTHER_USER_ID, TYPE_FACE)
                            callback.onChanged(true, ANOTHER_USER_ID, TYPE_FINGERPRINT)
                        }
            }
            authController.stub {
                on { isFingerprintEnrolled(anyInt()) } doReturn true
                on { isFaceAuthEnrolled(anyInt()) } doReturn true
            }

            // Check primary user status
            createBiometricSettingsRepository()
            var fingerprintAllowed = collectLastValue(underTest.isFingerprintEnrolledAndEnabled)
            var faceAllowed = collectLastValue(underTest.isFaceAuthEnrolledAndEnabled)
            runCurrent()

            enrollmentChange(UNDER_DISPLAY_FINGERPRINT, PRIMARY_USER_ID, true)
            enrollmentChange(FACE, PRIMARY_USER_ID, true)
            assertThat(fingerprintAllowed()).isTrue()
            assertThat(faceAllowed()).isTrue()

            // Check secondary user status
            userRepository.setSelectedUserInfo(ANOTHER_USER)
            fingerprintAllowed = collectLastValue(underTest.isFingerprintEnrolledAndEnabled)
            faceAllowed = collectLastValue(underTest.isFaceAuthEnrolledAndEnabled)
            runCurrent()

            enrollmentChange(UNDER_DISPLAY_FINGERPRINT, ANOTHER_USER_ID, true)
            enrollmentChange(FACE, ANOTHER_USER_ID, true)
            assertThat(fingerprintAllowed()).isTrue()
            assertThat(faceAllowed()).isTrue()
        }

    @Test
    @Test
    fun devicePolicyControlsFaceAuthenticationEnabledState() =
    fun devicePolicyControlsFaceAuthenticationEnabledState() =
        testScope.runTest {
        testScope.runTest {
+2 −1
Original line number Original line Diff line number Diff line
@@ -55,6 +55,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filter
@@ -289,7 +290,7 @@ constructor(
        }
        }


    private val areBiometricsEnabledForDeviceEntryFromUserSetting: Flow<Triple<Int, Boolean, Int>> =
    private val areBiometricsEnabledForDeviceEntryFromUserSetting: Flow<Triple<Int, Boolean, Int>> =
        conflatedCallbackFlow {
        callbackFlow {
                val callback =
                val callback =
                    object : IBiometricEnabledOnKeyguardCallback.Stub() {
                    object : IBiometricEnabledOnKeyguardCallback.Stub() {
                        override fun onChanged(enabled: Boolean, userId: Int, modality: Int) {
                        override fun onChanged(enabled: Boolean, userId: Int, modality: Int) {