Skip to content

Commit e3d1a81

Browse files
authored
Disable biometric unlock when we disable pin code unlock (#6781)
* Disable biometric unlock when we disable pin code unlock
1 parent 4e3853a commit e3d1a81

5 files changed

Lines changed: 19 additions & 5 deletions

File tree

features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/DefaultLockScreenService.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class DefaultLockScreenService(
4343
private val coroutineScope: CoroutineScope,
4444
private val sessionObserver: SessionObserver,
4545
private val appForegroundStateService: AppForegroundStateService,
46-
biometricAuthenticatorManager: BiometricAuthenticatorManager,
46+
private val biometricAuthenticatorManager: BiometricAuthenticatorManager,
4747
) : LockScreenService {
4848
private val _lockState = MutableStateFlow<LockScreenLockState>(LockScreenLockState.Unlocked)
4949
override val lockState: StateFlow<LockScreenLockState> = _lockState
@@ -81,6 +81,7 @@ class DefaultLockScreenService(
8181
override suspend fun onSessionDeleted(userId: String, wasLastSession: Boolean) {
8282
if (wasLastSession) {
8383
pinCodeManager.deletePinCode()
84+
biometricAuthenticatorManager.disable()
8485
}
8586
}
8687
})

features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/biometric/BiometricAuthenticatorManager.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ interface BiometricAuthenticatorManager {
2424
fun addCallback(callback: BiometricAuthenticator.Callback)
2525
fun removeCallback(callback: BiometricAuthenticator.Callback)
2626

27+
/**
28+
* Disable using the biometric unlock feature and remove any data associated with it.
29+
*/
30+
suspend fun disable()
31+
2732
/**
2833
* Remember a biometric authenticator ready for unlocking the app.
2934
*/

features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/biometric/DefaultBiometricAuthenticatorManager.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ class DefaultBiometricAuthenticatorManager(
8080

8181
private val internalCallback = object : DefaultBiometricUnlockCallback() {
8282
override fun onBiometricSetupError() {
83-
coroutineScope.launch {
84-
lockScreenStore.setIsBiometricUnlockAllowed(false)
85-
secretKeyRepository.deleteKey(SECRET_KEY_ALIAS)
86-
}
83+
coroutineScope.launch { disable() }
8784
}
8885
}
8986

@@ -120,6 +117,11 @@ class DefaultBiometricAuthenticatorManager(
120117
)
121118
}
122119

120+
override suspend fun disable() {
121+
lockScreenStore.setIsBiometricUnlockAllowed(false)
122+
secretKeyRepository.deleteKey(SECRET_KEY_ALIAS)
123+
}
124+
123125
@Composable
124126
private fun rememberBiometricAuthenticator(
125127
isAvailable: Boolean,

features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/settings/LockScreenSettingsPresenter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class LockScreenSettingsPresenter(
5959
if (showRemovePinConfirmation) {
6060
showRemovePinConfirmation = false
6161
pinCodeManager.deletePinCode()
62+
biometricAuthenticatorManager.disable()
6263
}
6364
}
6465
}

features/lockscreen/impl/src/test/kotlin/io/element/android/features/lockscreen/impl/biometric/FakeBiometricAuthenticatorManager.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class FakeBiometricAuthenticatorManager(
1515
override var isDeviceSecured: Boolean = true,
1616
override var hasAvailableAuthenticator: Boolean = false,
1717
private val createBiometricAuthenticator: () -> BiometricAuthenticator = { FakeBiometricAuthenticator() },
18+
private val disableLambda: suspend () -> Unit = { },
1819
) : BiometricAuthenticatorManager {
1920
override fun addCallback(callback: BiometricAuthenticator.Callback) {
2021
// no-op
@@ -37,4 +38,8 @@ class FakeBiometricAuthenticatorManager(
3738
createBiometricAuthenticator()
3839
}
3940
}
41+
42+
override suspend fun disable() {
43+
disableLambda()
44+
}
4045
}

0 commit comments

Comments
 (0)