Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[local_auth] Fix default deviceSupportsBiometrics #5321

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.0.3

* Fixes regression in the default method channel implementation of
`deviceSupportsBiometrics` from federation that would cause it to return true
only if something is enrolled.

## 1.0.2

* Adopts `Object.hash`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class DefaultLocalAuthPlatform extends LocalAuthPlatform {
biometrics.add(BiometricType.iris);
break;
case 'undefined':
// Sentinel value for the case when nothing is enrolled, but hardware
// support for biometrics is available.
break;
}
}
Expand All @@ -65,7 +67,14 @@ class DefaultLocalAuthPlatform extends LocalAuthPlatform {

@override
Future<bool> deviceSupportsBiometrics() async {
return (await getEnrolledBiometrics()).isNotEmpty;
final List<String> availableBiometrics =
(await _channel.invokeListMethod<String>(
'getAvailableBiometrics',
)) ??
<String>[];
// If anything, including the 'undefined' sentinel, is returned, then there
// is device support for biometrics.
return availableBiometrics.isNotEmpty;
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/master/packages/local_auth/l
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+local_auth%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 1.0.2
version: 1.0.3

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:local_auth_platform_interface/default_method_channel_platform.da
import 'package:local_auth_platform_interface/local_auth_platform_interface.dart';
import 'package:local_auth_platform_interface/types/auth_messages.dart';
import 'package:local_auth_platform_interface/types/auth_options.dart';
import 'package:local_auth_platform_interface/types/biometric_type.dart';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();
Expand All @@ -19,9 +18,13 @@ void main() {
'plugins.flutter.io/local_auth',
);

final List<MethodCall> log = <MethodCall>[];
late List<MethodCall> log;
late LocalAuthPlatform localAuthentication;

setUp(() async {
log = <MethodCall>[];
});

test(
'DefaultLocalAuthPlatform is registered as the default platform implementation',
() async {
Expand All @@ -32,10 +35,9 @@ void main() {
test('getAvailableBiometrics', () async {
channel.setMockMethodCallHandler((MethodCall methodCall) {
log.add(methodCall);
return Future<dynamic>.value(<BiometricType>[]);
return Future<dynamic>.value(<String>[]);
});
localAuthentication = DefaultLocalAuthPlatform();
log.clear();
await localAuthentication.getEnrolledBiometrics();
expect(
log,
Expand All @@ -45,14 +47,36 @@ void main() {
);
});

test('deviceSupportsBiometrics handles special sentinal value', () async {
// The pre-federation implementation of the platform channels, which the
// default implementation retains compatibility with for the benefit of any
// existing unendorsed implementations, used 'undefined' as a special
// return value from `getAvailableBiometrics` to indicate that nothing was
// enrolled, but that the hardware does support biometrics.
channel.setMockMethodCallHandler((MethodCall methodCall) {
log.add(methodCall);
return Future<dynamic>.value(<String>['undefined']);
});

localAuthentication = DefaultLocalAuthPlatform();
final bool supportsBiometrics =
await localAuthentication.deviceSupportsBiometrics();
expect(supportsBiometrics, true);
expect(
log,
<Matcher>[
isMethodCall('getAvailableBiometrics', arguments: null),
],
);
});

group('Boolean returning methods', () {
setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) {
log.add(methodCall);
return Future<dynamic>.value(true);
});
localAuthentication = DefaultLocalAuthPlatform();
log.clear();
});

test('isDeviceSupported', () async {
Expand Down