Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b53743a
Bind to local platform interface package
stuartmorgan-g Aug 26, 2025
dff4dec
Add structured exception class
stuartmorgan-g Aug 26, 2025
0f54e0f
Update Windows
stuartmorgan-g Aug 26, 2025
9f9c148
Clarify platform interface docs
stuartmorgan-g Sep 3, 2025
a623537
Android implementation
stuartmorgan-g Aug 27, 2025
8ce45dc
Convert iOS
stuartmorgan-g Sep 3, 2025
6b44729
Documentation updates
stuartmorgan-g Sep 4, 2025
3894214
Remove useErrorDialogs and all related handling, update README
stuartmorgan-g Sep 8, 2025
b7cbe24
More changelog and version updates
stuartmorgan-g Sep 9, 2025
4897463
Rename Android biometricHint
stuartmorgan-g Sep 9, 2025
7362182
Throw structured exception from getEnrolledBiometrics
stuartmorgan-g Sep 9, 2025
a9d6b2f
Merge branch 'main' into local-auth-structured-errors
stuartmorgan-g Sep 9, 2025
359be0c
Apply Gemini error formatting suggestions in app-facing package
stuartmorgan-g Sep 11, 2025
5d23e5c
autoformat Gemini changes
stuartmorgan-g Sep 11, 2025
4f8fb80
Merge branch 'main' into local-auth-structured-errors
stuartmorgan-g Sep 11, 2025
3125501
Merge branch 'main' into local-auth-structured-errors
stuartmorgan-g Sep 16, 2025
d6dc783
Typo fixes
stuartmorgan-g Sep 16, 2025
11d257d
Merge branch 'main' into local-auth-structured-errors
stuartmorgan-g Sep 17, 2025
f11d2be
Update for adjustment to auth_options
stuartmorgan-g Sep 24, 2025
4e99fdd
Sync with landed version of platform interface
stuartmorgan-g Sep 30, 2025
fbd24bf
Merge branch 'main' into local-auth-structured-errors
stuartmorgan-g Sep 30, 2025
859b046
iOS README update
stuartmorgan-g Sep 30, 2025
3955e48
Revert app-facing package
stuartmorgan-g Sep 30, 2025
bb45330
Update interface dependency
stuartmorgan-g Sep 30, 2025
2796b1c
Merge branch 'main' into local-auth-structured-errors-impls
stuartmorgan-g Oct 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Throw structured exception from getEnrolledBiometrics
  • Loading branch information
stuartmorgan-g committed Sep 9, 2025
commit 73621826274e35f37f0cdcfe6a3dfc7bde09ba5e
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public LocalAuthPlugin() {}

@Override
public @NonNull List<AuthClassification> getEnrolledBiometrics() {
if (biometricManager == null) {
return null;
}
ArrayList<AuthClassification> biometrics = new ArrayList<>();
if (biometricManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK)
== BiometricManager.BIOMETRIC_SUCCESS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,11 @@ public interface LocalAuthApi {
Boolean stopAuthentication();
/**
* Returns the biometric types that are enrolled, and can thus be used without additional setup.
*
* <p>Returns null if there is no activity, in which case the enrolled biometrics can't be
* determined.
*/
@NonNull
@Nullable
List<AuthClassification> getEnrolledBiometrics();
/**
* Attempts to authenticate the user with the provided [options], and using [strings] for any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@ public void onDetachedFromActivity_ShouldReleaseActivity() {
assertNull(plugin.getActivity());
}

@Test
public void getEnrolledBiometrics_shouldReturnNullForNoActivity() {
final LocalAuthPlugin plugin = new LocalAuthPlugin();

final List<AuthClassification> enrolled = plugin.getEnrolledBiometrics();
assertNull(enrolled);
}

@Test
public void getEnrolledBiometrics_shouldReturnEmptyList_withoutHardwarePresent() {
final LocalAuthPlugin plugin = new LocalAuthPlugin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ class LocalAuthAndroid extends LocalAuthPlatform {

@override
Future<List<BiometricType>> getEnrolledBiometrics() async {
final List<AuthClassification> result = await _api.getEnrolledBiometrics();
final List<AuthClassification>? result = await _api.getEnrolledBiometrics();
if (result == null) {
throw const LocalAuthException(
code: LocalAuthExceptionCode.uiUnavailable,
description: 'No Activity available.',
);
}
return result.map((AuthClassification value) {
switch (value) {
case AuthClassification.weak:
Expand Down
14 changes: 6 additions & 8 deletions packages/local_auth/local_auth_android/lib/src/messages.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,10 @@ class LocalAuthApi {

/// Returns the biometric types that are enrolled, and can thus be used
/// without additional setup.
Future<List<AuthClassification>> getEnrolledBiometrics() async {
///
/// Returns null if there is no activity, in which case the enrolled
/// biometrics can't be determined.
Future<List<AuthClassification>?> getEnrolledBiometrics() async {
final String pigeonVar_channelName =
'dev.flutter.pigeon.local_auth_android.LocalAuthApi.getEnrolledBiometrics$pigeonVar_messageChannelSuffix';
final BasicMessageChannel<Object?> pigeonVar_channel =
Expand All @@ -342,14 +345,9 @@ class LocalAuthApi {
message: pigeonVar_replyList[1] as String?,
details: pigeonVar_replyList[2],
);
} else if (pigeonVar_replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
return (pigeonVar_replyList[0] as List<Object?>?)!
.cast<AuthClassification>();
return (pigeonVar_replyList[0] as List<Object?>?)
?.cast<AuthClassification>();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ abstract class LocalAuthApi {

/// Returns the biometric types that are enrolled, and can thus be used
/// without additional setup.
List<AuthClassification> getEnrolledBiometrics();
///
/// Returns null if there is no activity, in which case the enrolled
/// biometrics can't be determined.
List<AuthClassification>? getEnrolledBiometrics();

/// Attempts to authenticate the user with the provided [options], and using
/// [strings] for any UI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ void main() {

expect(result, <BiometricType>[]);
});

test('throws no UI for null', () async {
when(api.getEnrolledBiometrics()).thenAnswer((_) async => null);

expect(
() async => plugin.getEnrolledBiometrics(),
throwsA(
isA<LocalAuthException>().having(
(LocalAuthException e) => e.code,
'code',
LocalAuthExceptionCode.uiUnavailable,
),
),
);
});
});

group('authenticate', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,12 @@ class MockLocalAuthApi extends _i1.Mock implements _i2.LocalAuthApi {
as _i4.Future<bool>);

@override
_i4.Future<List<_i2.AuthClassification>> getEnrolledBiometrics() =>
_i4.Future<List<_i2.AuthClassification>?> getEnrolledBiometrics() =>
(super.noSuchMethod(
Invocation.method(#getEnrolledBiometrics, []),
returnValue: _i4.Future<List<_i2.AuthClassification>>.value(
<_i2.AuthClassification>[],
),
returnValue: _i4.Future<List<_i2.AuthClassification>?>.value(),
)
as _i4.Future<List<_i2.AuthClassification>>);
as _i4.Future<List<_i2.AuthClassification>?>);

@override
_i4.Future<_i2.AuthResult> authenticate(
Expand Down