mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Add a state machine to AppLockFlowCoordinator. (#2166)
Fixes a bug when cancelling Face ID would loop back round to presenting Face ID.
This commit is contained in:
@@ -38,6 +38,9 @@ class AppLockService: AppLockServiceProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
private var isEnabledSubject: PassthroughSubject<Bool, Never> = .init()
|
||||
var isEnabledPublisher: AnyPublisher<Bool, Never> { isEnabledSubject.eraseToAnyPublisher() }
|
||||
|
||||
var biometryType: LABiometryType {
|
||||
updateBiometrics()
|
||||
guard context.evaluatedPolicyDomainState != nil else { return .none }
|
||||
@@ -71,6 +74,7 @@ class AppLockService: AppLockServiceProtocol {
|
||||
|
||||
do {
|
||||
try keychainController.setPINCode(pinCode)
|
||||
isEnabledSubject.send(true)
|
||||
return .success(())
|
||||
} catch {
|
||||
MXLog.error("Keychain access error: \(error)")
|
||||
@@ -105,6 +109,7 @@ class AppLockService: AppLockServiceProtocol {
|
||||
keychainController.removePINCode()
|
||||
keychainController.removePINCodeBiometricState()
|
||||
appSettings.appLockNumberOfPINAttempts = 0
|
||||
isEnabledSubject.send(false)
|
||||
}
|
||||
|
||||
func applicationDidEnterBackground() {
|
||||
@@ -128,30 +133,35 @@ class AppLockService: AppLockServiceProtocol {
|
||||
_ = enableBiometricUnlock()
|
||||
}
|
||||
|
||||
return completeUnlock()
|
||||
completeUnlock()
|
||||
return true
|
||||
}
|
||||
|
||||
func unlockWithBiometrics() async -> Bool {
|
||||
func unlockWithBiometrics() async -> AppLockServiceBiometricResult {
|
||||
guard biometryType != .none, biometricUnlockEnabled else {
|
||||
MXLog.error("Biometric unlock not setup.")
|
||||
return false
|
||||
return .failed
|
||||
}
|
||||
|
||||
guard biometricUnlockTrusted else {
|
||||
MXLog.error("Biometrics have changed. PIN should be shown.")
|
||||
return false
|
||||
return .failed
|
||||
}
|
||||
|
||||
do {
|
||||
let context = unlockContext()
|
||||
guard try await context.evaluatePolicy(unlockPolicy, localizedReason: L10n.screenAppLockBiometricUnlockReasonIos) else {
|
||||
MXLog.warning("\(context.biometryType) failed without error.")
|
||||
return false
|
||||
return .failed
|
||||
}
|
||||
return completeUnlock()
|
||||
completeUnlock()
|
||||
return .unlocked
|
||||
} catch LAError.systemCancel {
|
||||
MXLog.error("\(context.biometryType) failed: The system cancelled.")
|
||||
return .interrupted
|
||||
} catch {
|
||||
MXLog.error("\(context.biometryType) failed: \(error)")
|
||||
return false
|
||||
return .failed
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,9 +190,8 @@ class AppLockService: AppLockServiceProtocol {
|
||||
}
|
||||
|
||||
/// Shared logic for completing an unlock via a PIN or biometrics.
|
||||
private func completeUnlock() -> Bool {
|
||||
private func completeUnlock() {
|
||||
timer.registerUnlock()
|
||||
appSettings.appLockNumberOfPINAttempts = 0
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user