mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-25 03:03:58 +00:00
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:
@@ -44,7 +44,6 @@ class AppLockService: AppLockServiceProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var biometryType: LABiometryType {
|
var biometryType: LABiometryType {
|
||||||
updateBiometrics()
|
|
||||||
guard context.biometricStateHash != nil else { return .none }
|
guard context.biometricStateHash != nil else { return .none }
|
||||||
return context.biometryType
|
return context.biometryType
|
||||||
}
|
}
|
||||||
@@ -55,7 +54,6 @@ class AppLockService: AppLockServiceProtocol {
|
|||||||
|
|
||||||
var biometricUnlockTrusted: Bool {
|
var biometricUnlockTrusted: Bool {
|
||||||
guard let state = keychainController.pinCodeBiometricState() else { return false }
|
guard let state = keychainController.pinCodeBiometricState() else { return false }
|
||||||
updateBiometrics()
|
|
||||||
return state == context.biometricStateHash
|
return state == context.biometricStateHash
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,8 +66,6 @@ class AppLockService: AppLockServiceProtocol {
|
|||||||
self.appSettings = appSettings
|
self.appSettings = appSettings
|
||||||
self.context = context
|
self.context = context
|
||||||
timer = AppLockTimer(gracePeriod: appSettings.appLockGracePeriod)
|
timer = AppLockTimer(gracePeriod: appSettings.appLockGracePeriod)
|
||||||
|
|
||||||
updateBiometrics()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupPINCode(_ pinCode: String) -> Result<Void, AppLockServiceError> {
|
func setupPINCode(_ pinCode: String) -> Result<Void, AppLockServiceError> {
|
||||||
@@ -133,7 +129,6 @@ class AppLockService: AppLockServiceProtocol {
|
|||||||
|
|
||||||
if biometricUnlockEnabled, !biometricUnlockTrusted {
|
if biometricUnlockEnabled, !biometricUnlockTrusted {
|
||||||
MXLog.info("Fixing trust for biometric unlock.")
|
MXLog.info("Fixing trust for biometric unlock.")
|
||||||
updateBiometrics()
|
|
||||||
_ = enableBiometricUnlock()
|
_ = enableBiometricUnlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,16 +190,6 @@ class AppLockService: AppLockServiceProtocol {
|
|||||||
|
|
||||||
// MARK: - Private
|
// 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,
|
/// 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
|
/// and the fresh context ensures that the user is promoted to unlock based on
|
||||||
/// `timer.gracePeriod` rather than any system to defined grace period.
|
/// `timer.gracePeriod` rather than any system to defined grace period.
|
||||||
@@ -232,8 +217,7 @@ class AppLockService: AppLockServiceProtocol {
|
|||||||
|
|
||||||
nonisolated extension LAContext {
|
nonisolated extension LAContext {
|
||||||
/// A hash of the enrolled biometric data that changes whenever biometrics are added or removed.
|
/// 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,
|
/// Unlike the deprecated `evaluatedPolicyDomainState`, this doesn't need `canEvaluatePolicy` to be called first.
|
||||||
/// so the `updateBiometrics()` calls made before reading it are now redundant.
|
|
||||||
@objc var biometricStateHash: Data? {
|
@objc var biometricStateHash: Data? {
|
||||||
domainState.biometry.stateHash
|
domainState.biometry.stateHash
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,27 +9,20 @@
|
|||||||
import LocalAuthentication
|
import LocalAuthentication
|
||||||
|
|
||||||
/// A customised context that allows injecting a few mock values but otherwise behaves as expected.
|
/// 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 {
|
nonisolated class LAContextMock: LAContext {
|
||||||
var biometryTypeValue: LABiometryType!
|
var biometryTypeValue: LABiometryType!
|
||||||
private var internalBiometryTypeValue: LABiometryType!
|
|
||||||
override var biometryType: LABiometryType {
|
override var biometryType: LABiometryType {
|
||||||
internalBiometryTypeValue
|
biometryTypeValue
|
||||||
}
|
}
|
||||||
|
|
||||||
var biometricStateHashValue: Data?
|
var biometricStateHashValue: Data?
|
||||||
private var internalBiometricStateHashValue: Data?
|
|
||||||
override var biometricStateHash: Data? {
|
override var biometricStateHash: Data? {
|
||||||
internalBiometricStateHashValue
|
biometricStateHashValue
|
||||||
}
|
}
|
||||||
|
|
||||||
var canEvaluatePolicyReturnValue: Bool?
|
var canEvaluatePolicyReturnValue: Bool?
|
||||||
override func canEvaluatePolicy(_ policy: LAPolicy, error: NSErrorPointer) -> Bool {
|
override func canEvaluatePolicy(_ policy: LAPolicy, error: NSErrorPointer) -> Bool {
|
||||||
let result = canEvaluatePolicyReturnValue ?? super.canEvaluatePolicy(policy, error: error)
|
canEvaluatePolicyReturnValue ?? super.canEvaluatePolicy(policy, error: error)
|
||||||
updateInternalValues()
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var evaluatePolicyReturnValue: Bool!
|
var evaluatePolicyReturnValue: Bool!
|
||||||
@@ -41,15 +34,9 @@ nonisolated class LAContextMock: LAContext {
|
|||||||
|
|
||||||
override func evaluatePolicy(_ policy: LAPolicy, localizedReason: String) async throws -> Bool {
|
override func evaluatePolicy(_ policy: LAPolicy, localizedReason: String) async throws -> Bool {
|
||||||
evaluatePolicyCallsCount += 1
|
evaluatePolicyCallsCount += 1
|
||||||
updateInternalValues()
|
|
||||||
if let evaluatePolicyThrowableError {
|
if let evaluatePolicyThrowableError {
|
||||||
throw evaluatePolicyThrowableError
|
throw evaluatePolicyThrowableError
|
||||||
}
|
}
|
||||||
return evaluatePolicyReturnValue
|
return evaluatePolicyReturnValue
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateInternalValues() {
|
|
||||||
internalBiometryTypeValue = biometryTypeValue
|
|
||||||
internalBiometricStateHashValue = biometricStateHashValue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user