Merge "Make sure isNonStrongBiometricAllowed value is correct after reboot" into udc-qpr-dev am: 83ec16e2a1
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23782495 Change-Id: Ia1fd34a2202111a9ba2f668963be08994d3a37b4 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -325,6 +325,9 @@ constructor(
|
|||||||
private class StrongAuthTracker(private val userRepository: UserRepository, context: Context?) :
|
private class StrongAuthTracker(private val userRepository: UserRepository, context: Context?) :
|
||||||
LockPatternUtils.StrongAuthTracker(context) {
|
LockPatternUtils.StrongAuthTracker(context) {
|
||||||
|
|
||||||
|
private val selectedUserId =
|
||||||
|
userRepository.selectedUserInfo.map { it.id }.distinctUntilChanged()
|
||||||
|
|
||||||
// Backing field for onStrongAuthRequiredChanged
|
// Backing field for onStrongAuthRequiredChanged
|
||||||
private val _authFlags =
|
private val _authFlags =
|
||||||
MutableStateFlow(AuthenticationFlags(currentUserId, getStrongAuthForUser(currentUserId)))
|
MutableStateFlow(AuthenticationFlags(currentUserId, getStrongAuthForUser(currentUserId)))
|
||||||
@@ -336,10 +339,7 @@ private class StrongAuthTracker(private val userRepository: UserRepository, cont
|
|||||||
)
|
)
|
||||||
|
|
||||||
val currentUserAuthFlags: Flow<AuthenticationFlags> =
|
val currentUserAuthFlags: Flow<AuthenticationFlags> =
|
||||||
userRepository.selectedUserInfo
|
selectedUserId.flatMapLatest { userId ->
|
||||||
.map { it.id }
|
|
||||||
.distinctUntilChanged()
|
|
||||||
.flatMapLatest { userId ->
|
|
||||||
_authFlags
|
_authFlags
|
||||||
.map { AuthenticationFlags(userId, getStrongAuthForUser(userId)) }
|
.map { AuthenticationFlags(userId, getStrongAuthForUser(userId)) }
|
||||||
.onEach { Log.d(TAG, "currentUser authFlags changed, new value: $it") }
|
.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. */
|
/** isNonStrongBiometricAllowed for the current user. */
|
||||||
val isNonStrongBiometricAllowed: Flow<Boolean> =
|
val isNonStrongBiometricAllowed: Flow<Boolean> =
|
||||||
userRepository.selectedUserInfo
|
selectedUserId
|
||||||
.map { it.id }
|
|
||||||
.distinctUntilChanged()
|
|
||||||
.flatMapLatest { userId ->
|
.flatMapLatest { userId ->
|
||||||
_nonStrongBiometricAllowed
|
_nonStrongBiometricAllowed
|
||||||
.filter { it.first == userId }
|
.filter { it.first == userId }
|
||||||
.map { it.second }
|
.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)) }
|
.onStart { emit(isNonStrongBiometricAllowedAfterIdleTimeout(userId)) }
|
||||||
}
|
}
|
||||||
|
.and(isStrongBiometricAllowed)
|
||||||
|
|
||||||
private val currentUserId
|
private val currentUserId
|
||||||
get() = userRepository.getSelectedUserInfo().id
|
get() = userRepository.getSelectedUserInfo().id
|
||||||
@@ -387,3 +388,6 @@ private fun DevicePolicyManager.isFingerprintDisabled(userId: Int): Boolean =
|
|||||||
|
|
||||||
private fun DevicePolicyManager.isNotActive(userId: Int, policy: Int): Boolean =
|
private fun DevicePolicyManager.isNotActive(userId: Int, policy: Int): Boolean =
|
||||||
(getKeyguardDisabledFeatures(null, userId) and policy) == 0
|
(getKeyguardDisabledFeatures(null, userId) and policy) == 0
|
||||||
|
|
||||||
|
private fun Flow<Boolean>.and(anotherFlow: Flow<Boolean>): Flow<Boolean> =
|
||||||
|
this.combine(anotherFlow) { a, b -> a && b }
|
||||||
|
|||||||
@@ -162,11 +162,11 @@ class BiometricSettingsRepositoryTest : SysuiTestCase() {
|
|||||||
@Test
|
@Test
|
||||||
fun convenienceBiometricAllowedChange() =
|
fun convenienceBiometricAllowedChange() =
|
||||||
testScope.runTest {
|
testScope.runTest {
|
||||||
|
overrideResource(com.android.internal.R.bool.config_strongAuthRequiredOnBoot, false)
|
||||||
createBiometricSettingsRepository()
|
createBiometricSettingsRepository()
|
||||||
val convenienceBiometricAllowed =
|
val convenienceBiometricAllowed =
|
||||||
collectLastValue(underTest.isNonStrongBiometricAllowed)
|
collectLastValue(underTest.isNonStrongBiometricAllowed)
|
||||||
runCurrent()
|
runCurrent()
|
||||||
|
|
||||||
onNonStrongAuthChanged(true, PRIMARY_USER_ID)
|
onNonStrongAuthChanged(true, PRIMARY_USER_ID)
|
||||||
assertThat(convenienceBiometricAllowed()).isTrue()
|
assertThat(convenienceBiometricAllowed()).isTrue()
|
||||||
|
|
||||||
@@ -175,6 +175,45 @@ class BiometricSettingsRepositoryTest : SysuiTestCase() {
|
|||||||
|
|
||||||
onNonStrongAuthChanged(false, PRIMARY_USER_ID)
|
onNonStrongAuthChanged(false, PRIMARY_USER_ID)
|
||||||
assertThat(convenienceBiometricAllowed()).isFalse()
|
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) {
|
private fun onStrongAuthChanged(flags: Int, userId: Int) {
|
||||||
|
|||||||
Reference in New Issue
Block a user