Loading packages/SystemUI/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepository.kt +17 −13 Original line number Diff line number Diff line Loading @@ -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))) Loading @@ -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") } Loading @@ -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 Loading @@ -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 } packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepositoryTest.kt +40 −1 Original line number Diff line number Diff line Loading @@ -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() Loading @@ -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) { Loading Loading
packages/SystemUI/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepository.kt +17 −13 Original line number Diff line number Diff line Loading @@ -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))) Loading @@ -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") } Loading @@ -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 Loading @@ -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 }
packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepositoryTest.kt +40 −1 Original line number Diff line number Diff line Loading @@ -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() Loading @@ -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) { Loading