Skip to content

Commit

Permalink
[local_auth_darwin] Handle when FaceID hardware is available but perm…
Browse files Browse the repository at this point in the history
…issions have been denied for the app (#8348)

LocalAuth  [`-canEvaluatePolicy::`](https://developer.apple.com/documentation/localauthentication/lacontext/canevaluatepolicy(_:error:)?language=objc) returns error `LAErrorBiometryNotAvailable` when either Face ID isn't available at the hardware level, OR the Face ID is available/setup but the permissions for the app were denied.

If it returns `LAErrorBiometryNotAvailable`, also check `biometryType` since this _should_ be none if there really is no biometry, but gets populated with [`LABiometryTypeTouchID`](https://developer.apple.com/documentation/localauthentication/labiometrytype/touchid?language=objc) when the FaceID hardware is available, but permission is denied.  I tried this on a iPhone 16 Pro which has Face ID but not Touch ID support.

Fixes flutter/flutter#160083
  • Loading branch information
jmagman authored Jan 17, 2025
1 parent 973e8b5 commit cfc56a2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/local_auth/local_auth_darwin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 1.4.3

* Handles when biometry hardware is available but permissions have been denied for the app.
* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.

## 1.4.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ class FLALocalAuthPluginTests: XCTestCase {
XCTAssertNil(error)
}

func testDeviceSupportsBiometrics_withNoBiometricHardware() {
func testDeviceSupportsBiometrics_withBiometryNotAvailable() {
let stubAuthContext = StubAuthContext()
let alertFactory = StubAlertFactory()
let viewProvider = StubViewProvider()
Expand All @@ -456,14 +456,34 @@ class FLALocalAuthPluginTests: XCTestCase {
alertFactory: alertFactory, viewProvider: viewProvider)

stubAuthContext.expectBiometrics = true
stubAuthContext.canEvaluateError = NSError(domain: "error", code: 0)
stubAuthContext.canEvaluateError = NSError(
domain: "error", code: LAError.biometryNotAvailable.rawValue)

var error: FlutterError?
let result = plugin.deviceCanSupportBiometricsWithError(&error)
XCTAssertFalse(result!.boolValue)
XCTAssertNil(error)
}

func testDeviceSupportsBiometrics_withBiometryNotAvailableLoadedBiometryType() {
let stubAuthContext = StubAuthContext()
let alertFactory = StubAlertFactory()
let viewProvider = StubViewProvider()
let plugin = FLALocalAuthPlugin(
contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]),
alertFactory: alertFactory, viewProvider: viewProvider)

stubAuthContext.expectBiometrics = true
stubAuthContext.biometryType = LABiometryType.touchID
stubAuthContext.canEvaluateError = NSError(
domain: "error", code: LAError.biometryNotAvailable.rawValue)

var error: FlutterError?
let result = plugin.deviceCanSupportBiometricsWithError(&error)
XCTAssertTrue(result!.boolValue)
XCTAssertNil(error)
}

func testGetEnrolledBiometricsWithFaceID() {
let stubAuthContext = StubAuthContext()
let alertFactory = StubAlertFactory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ - (nullable NSNumber *)deviceCanSupportBiometricsWithError:
if (authError.code == LAErrorBiometryNotEnrolled) {
return @YES;
}
// Biometry hardware is available, but possibly permissions were denied.
if (authError.code == LAErrorBiometryNotAvailable &&
context.biometryType != LABiometryTypeNone) {
return @YES;
}
}

return @NO;
Expand Down
2 changes: 1 addition & 1 deletion packages/local_auth/local_auth_darwin/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: local_auth_darwin
description: iOS implementation of the local_auth plugin.
repository: https://github.com/flutter/packages/tree/main/packages/local_auth/local_auth_darwin
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+local_auth%22
version: 1.4.2
version: 1.4.3

environment:
sdk: ^3.4.0
Expand Down

0 comments on commit cfc56a2

Please sign in to comment.