Remove the redundant biometric refresh calls from AppLockService

The biometric state hash now comes from LAContext.domainState, which
unlike the deprecated evaluatedPolicyDomainState doesn't need
canEvaluatePolicy to be called before it can be read. Drop
updateBiometrics() and make LAContextMock return its values directly
instead of waiting for a policy evaluation.
This commit is contained in:
Mauro Romito
2026-10-19 12:49:52 +02:00
committed by Mauro
parent 031e99e208
commit 06e71f796d
2 changed files with 4 additions and 33 deletions
@@ -44,7 +44,6 @@ class AppLockService: AppLockServiceProtocol {
}
var biometryType: LABiometryType {
updateBiometrics()
guard context.biometricStateHash != nil else { return .none }
return context.biometryType
}
@@ -55,7 +54,6 @@ class AppLockService: AppLockServiceProtocol {
var biometricUnlockTrusted: Bool {
guard let state = keychainController.pinCodeBiometricState() else { return false }
updateBiometrics()
return state == context.biometricStateHash
}
@@ -68,8 +66,6 @@ class AppLockService: AppLockServiceProtocol {
self.appSettings = appSettings
self.context = context
timer = AppLockTimer(gracePeriod: appSettings.appLockGracePeriod)
updateBiometrics()
}
func setupPINCode(_ pinCode: String) -> Result<Void, AppLockServiceError> {
@@ -133,7 +129,6 @@ class AppLockService: AppLockServiceProtocol {
if biometricUnlockEnabled, !biometricUnlockTrusted {
MXLog.info("Fixing trust for biometric unlock.")
updateBiometrics()
_ = enableBiometricUnlock()
}
@@ -195,16 +190,6 @@ class AppLockService: AppLockServiceProtocol {
// MARK: - Private
/// Queries the context for supported biometrics and enrolment state.
private func updateBiometrics() {
var error: NSError?
context.canEvaluatePolicy(unlockPolicy, error: &error)
if let error {
MXLog.error("Biometrics error: \(error)")
}
}
/// Creates a context specifically for unlocking the app. The titles are customised,
/// and the fresh context ensures that the user is promoted to unlock based on
/// `timer.gracePeriod` rather than any system to defined grace period.
@@ -232,8 +217,7 @@ class AppLockService: AppLockServiceProtocol {
nonisolated extension LAContext {
/// A hash of the enrolled biometric data that changes whenever biometrics are added or removed.
/// Unlike `evaluatedPolicyDomainState`, this doesn't need `canEvaluatePolicy` to be called first,
/// so the `updateBiometrics()` calls made before reading it are now redundant.
/// Unlike the deprecated `evaluatedPolicyDomainState`, this doesn't need `canEvaluatePolicy` to be called first.
@objc var biometricStateHash: Data? {
domainState.biometry.stateHash
}
@@ -9,27 +9,20 @@
import LocalAuthentication
/// A customised context that allows injecting a few mock values but otherwise behaves as expected.
/// It works as the actual context does and won't update the return values of `biometryType` and
/// `biometricStateHash` until either `canEvaluatePolicy` or
/// `evaluatePolicy` have been called.
nonisolated class LAContextMock: LAContext {
var biometryTypeValue: LABiometryType!
private var internalBiometryTypeValue: LABiometryType!
override var biometryType: LABiometryType {
internalBiometryTypeValue
biometryTypeValue
}
var biometricStateHashValue: Data?
private var internalBiometricStateHashValue: Data?
override var biometricStateHash: Data? {
internalBiometricStateHashValue
biometricStateHashValue
}
var canEvaluatePolicyReturnValue: Bool?
override func canEvaluatePolicy(_ policy: LAPolicy, error: NSErrorPointer) -> Bool {
let result = canEvaluatePolicyReturnValue ?? super.canEvaluatePolicy(policy, error: error)
updateInternalValues()
return result
canEvaluatePolicyReturnValue ?? super.canEvaluatePolicy(policy, error: error)
}
var evaluatePolicyReturnValue: Bool!
@@ -41,15 +34,9 @@ nonisolated class LAContextMock: LAContext {
override func evaluatePolicy(_ policy: LAPolicy, localizedReason: String) async throws -> Bool {
evaluatePolicyCallsCount += 1
updateInternalValues()
if let evaluatePolicyThrowableError {
throw evaluatePolicyThrowableError
}
return evaluatePolicyReturnValue
}
private func updateInternalValues() {
internalBiometryTypeValue = biometryTypeValue
internalBiometricStateHashValue = biometricStateHashValue
}
}