diff options
| author | 2023-07-18 18:32:47 +0000 | |
|---|---|---|
| committer | 2023-07-18 18:32:47 +0000 | |
| commit | 83ec16e2a1e41eee7d596797c09bfde46ecd66a7 (patch) | |
| tree | 739e44976806fc04ab2fb12201444a6ed70ca73b | |
| parent | 13feec746b2a31fdf9ac55a1e0fd75460aa2d096 (diff) | |
| parent | a278f5290bcff3a9c14c075437869f83ef8612b0 (diff) | |
Merge "Make sure `isNonStrongBiometricAllowed` value is correct after reboot" into udc-qpr-dev
2 files changed, 57 insertions, 14 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepository.kt index 0b6c7c415599..ff3e77c46f1c 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepository.kt @@ -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,15 +339,12 @@ private class StrongAuthTracker(private val userRepository: UserRepository, cont ) val currentUserAuthFlags: Flow<AuthenticationFlags> = - userRepository.selectedUserInfo - .map { it.id } - .distinctUntilChanged() - .flatMapLatest { userId -> - _authFlags - .map { AuthenticationFlags(userId, getStrongAuthForUser(userId)) } - .onEach { Log.d(TAG, "currentUser authFlags changed, new value: $it") } - .onStart { emit(AuthenticationFlags(userId, getStrongAuthForUser(userId))) } - } + selectedUserId.flatMapLatest { userId -> + _authFlags + .map { AuthenticationFlags(userId, getStrongAuthForUser(userId)) } + .onEach { Log.d(TAG, "currentUser authFlags changed, new value: $it") } + .onStart { emit(AuthenticationFlags(userId, getStrongAuthForUser(userId))) } + } /** isStrongBiometricAllowed for the current user. */ val isStrongBiometricAllowed: Flow<Boolean> = @@ -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 } diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepositoryTest.kt index f9070b37ca48..c6a2fa50b446 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepositoryTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepositoryTest.kt @@ -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) { |