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

Commit 83ec16e2 authored by Chandru S's avatar Chandru S Committed by Android (Google) Code Review
Browse files

Merge "Make sure `isNonStrongBiometricAllowed` value is correct after reboot" into udc-qpr-dev

parents 13feec74 a278f529
Loading
Loading
Loading
Loading
+17 −13
Original line number Diff line number Diff line
@@ -325,6 +325,9 @@ constructor(
private class StrongAuthTracker(private val userRepository: UserRepository, context: Context?) :
    LockPatternUtils.StrongAuthTracker(context) {

    private val selectedUserId =
        userRepository.selectedUserInfo.map { it.id }.distinctUntilChanged()

    // Backing field for onStrongAuthRequiredChanged
    private val _authFlags =
        MutableStateFlow(AuthenticationFlags(currentUserId, getStrongAuthForUser(currentUserId)))
@@ -336,10 +339,7 @@ private class StrongAuthTracker(private val userRepository: UserRepository, cont
        )

    val currentUserAuthFlags: Flow<AuthenticationFlags> =
        userRepository.selectedUserInfo
            .map { it.id }
            .distinctUntilChanged()
            .flatMapLatest { userId ->
        selectedUserId.flatMapLatest { userId ->
            _authFlags
                .map { AuthenticationFlags(userId, getStrongAuthForUser(userId)) }
                .onEach { Log.d(TAG, "currentUser authFlags changed, new value: $it") }
@@ -352,16 +352,17 @@ private class StrongAuthTracker(private val userRepository: UserRepository, cont

    /** isNonStrongBiometricAllowed for the current user. */
    val isNonStrongBiometricAllowed: Flow<Boolean> =
        userRepository.selectedUserInfo
            .map { it.id }
            .distinctUntilChanged()
        selectedUserId
            .flatMapLatest { userId ->
                _nonStrongBiometricAllowed
                    .filter { it.first == userId }
                    .map { it.second }
                    .onEach { Log.d(TAG, "isNonStrongBiometricAllowed changed for current user") }
                    .onEach {
                        Log.d(TAG, "isNonStrongBiometricAllowed changed for current user: $it")
                    }
                    .onStart { emit(isNonStrongBiometricAllowedAfterIdleTimeout(userId)) }
            }
            .and(isStrongBiometricAllowed)

    private val currentUserId
        get() = userRepository.getSelectedUserInfo().id
@@ -387,3 +388,6 @@ private fun DevicePolicyManager.isFingerprintDisabled(userId: Int): Boolean =

private fun DevicePolicyManager.isNotActive(userId: Int, policy: Int): Boolean =
    (getKeyguardDisabledFeatures(null, userId) and policy) == 0

private fun Flow<Boolean>.and(anotherFlow: Flow<Boolean>): Flow<Boolean> =
    this.combine(anotherFlow) { a, b -> a && b }
+40 −1
Original line number Diff line number Diff line
@@ -162,11 +162,11 @@ class BiometricSettingsRepositoryTest : SysuiTestCase() {
    @Test
    fun convenienceBiometricAllowedChange() =
        testScope.runTest {
            overrideResource(com.android.internal.R.bool.config_strongAuthRequiredOnBoot, false)
            createBiometricSettingsRepository()
            val convenienceBiometricAllowed =
                collectLastValue(underTest.isNonStrongBiometricAllowed)
            runCurrent()

            onNonStrongAuthChanged(true, PRIMARY_USER_ID)
            assertThat(convenienceBiometricAllowed()).isTrue()

@@ -175,6 +175,45 @@ class BiometricSettingsRepositoryTest : SysuiTestCase() {

            onNonStrongAuthChanged(false, PRIMARY_USER_ID)
            assertThat(convenienceBiometricAllowed()).isFalse()
            mContext.orCreateTestableResources.removeOverride(
                com.android.internal.R.bool.config_strongAuthRequiredOnBoot
            )
        }

    @Test
    fun whenStrongAuthRequiredAfterBoot_nonStrongBiometricNotAllowed() =
        testScope.runTest {
            overrideResource(com.android.internal.R.bool.config_strongAuthRequiredOnBoot, true)
            createBiometricSettingsRepository()

            val convenienceBiometricAllowed =
                collectLastValue(underTest.isNonStrongBiometricAllowed)
            runCurrent()
            onNonStrongAuthChanged(true, PRIMARY_USER_ID)

            assertThat(convenienceBiometricAllowed()).isFalse()
            mContext.orCreateTestableResources.removeOverride(
                com.android.internal.R.bool.config_strongAuthRequiredOnBoot
            )
        }

    @Test
    fun whenStrongBiometricAuthIsNotAllowed_nonStrongBiometrics_alsoNotAllowed() =
        testScope.runTest {
            overrideResource(com.android.internal.R.bool.config_strongAuthRequiredOnBoot, false)
            createBiometricSettingsRepository()

            val convenienceBiometricAllowed =
                collectLastValue(underTest.isNonStrongBiometricAllowed)
            runCurrent()
            onNonStrongAuthChanged(true, PRIMARY_USER_ID)
            assertThat(convenienceBiometricAllowed()).isTrue()

            onStrongAuthChanged(STRONG_AUTH_REQUIRED_AFTER_TIMEOUT, PRIMARY_USER_ID)
            assertThat(convenienceBiometricAllowed()).isFalse()
            mContext.orCreateTestableResources.removeOverride(
                com.android.internal.R.bool.config_strongAuthRequiredOnBoot
            )
        }

    private fun onStrongAuthChanged(flags: Int, userId: Int) {