This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[local_auth] Convert Windows to Pigeon (#7012)
Updates `local_auth_windows` to use Pigeon, and moves to a more platform-tailored and Dart-centric implementation (rather than keeping the previous cross-platform method channel interface that the current implementation was duplicated from): - Eliminates `deviceSupportsBiometrics` from the platform interface, since it's always the same as `isDeviceSupported`, in favor of doing that mapping in Dart. - Eliminates `getEnrolledBiometrics` from the platform interface, since it was the same implementation as `isDeviceSupported` just with a different return value, in favor of doing that logic in Dart. - Moves throwing for the `biometricOnly` option to the Dart side, simplifying the native logic. Related changes: - Adds a significant amount of previously-missing Dart unit test coverage. - Removes the `biometricOnly` UI from the example app, since it will always fail. Part of flutter/flutter#117912
- Loading branch information
1 parent
729c14a
commit d649e18
Showing
15 changed files
with
512 additions
and
403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
packages/local_auth/local_auth_windows/lib/src/messages.g.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
// Autogenerated from Pigeon (v5.0.1), do not edit directly. | ||
// See also: https://pub.dev/packages/pigeon | ||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import | ||
import 'dart:async'; | ||
import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; | ||
|
||
import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; | ||
import 'package:flutter/services.dart'; | ||
|
||
class LocalAuthApi { | ||
/// Constructor for [LocalAuthApi]. The [binaryMessenger] named argument is | ||
/// available for dependency injection. If it is left null, the default | ||
/// BinaryMessenger will be used which routes to the host platform. | ||
LocalAuthApi({BinaryMessenger? binaryMessenger}) | ||
: _binaryMessenger = binaryMessenger; | ||
final BinaryMessenger? _binaryMessenger; | ||
|
||
static const MessageCodec<Object?> codec = StandardMessageCodec(); | ||
|
||
/// Returns true if this device supports authentication. | ||
Future<bool> isDeviceSupported() async { | ||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>( | ||
'dev.flutter.pigeon.LocalAuthApi.isDeviceSupported', codec, | ||
binaryMessenger: _binaryMessenger); | ||
final List<Object?>? replyList = await channel.send(null) as List<Object?>?; | ||
if (replyList == null) { | ||
throw PlatformException( | ||
code: 'channel-error', | ||
message: 'Unable to establish connection on channel.', | ||
); | ||
} else if (replyList.length > 1) { | ||
throw PlatformException( | ||
code: replyList[0]! as String, | ||
message: replyList[1] as String?, | ||
details: replyList[2], | ||
); | ||
} else if (replyList[0] == null) { | ||
throw PlatformException( | ||
code: 'null-error', | ||
message: 'Host platform returned null value for non-null return value.', | ||
); | ||
} else { | ||
return (replyList[0] as bool?)!; | ||
} | ||
} | ||
|
||
/// Attempts to authenticate the user with the provided [localizedReason] as | ||
/// the user-facing explanation for the authorization request. | ||
/// | ||
/// Returns true if authorization succeeds, false if it is attempted but is | ||
/// not successful, and an error if authorization could not be attempted. | ||
Future<bool> authenticate(String arg_localizedReason) async { | ||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>( | ||
'dev.flutter.pigeon.LocalAuthApi.authenticate', codec, | ||
binaryMessenger: _binaryMessenger); | ||
final List<Object?>? replyList = | ||
await channel.send(<Object?>[arg_localizedReason]) as List<Object?>?; | ||
if (replyList == null) { | ||
throw PlatformException( | ||
code: 'channel-error', | ||
message: 'Unable to establish connection on channel.', | ||
); | ||
} else if (replyList.length > 1) { | ||
throw PlatformException( | ||
code: replyList[0]! as String, | ||
message: replyList[1] as String?, | ||
details: replyList[2], | ||
); | ||
} else if (replyList[0] == null) { | ||
throw PlatformException( | ||
code: 'null-error', | ||
message: 'Host platform returned null value for non-null return value.', | ||
); | ||
} else { | ||
return (replyList[0] as bool?)!; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Copyright 2013 The Flutter Authors. All rights reserved. | ||
Use of this source code is governed by a BSD-style license that can be | ||
found in the LICENSE file. |
27 changes: 27 additions & 0 deletions
27
packages/local_auth/local_auth_windows/pigeons/messages.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:pigeon/pigeon.dart'; | ||
|
||
@ConfigurePigeon(PigeonOptions( | ||
dartOut: 'lib/src/messages.g.dart', | ||
cppOptions: CppOptions(namespace: 'local_auth_windows'), | ||
cppHeaderOut: 'windows/messages.g.h', | ||
cppSourceOut: 'windows/messages.g.cpp', | ||
copyrightHeader: 'pigeons/copyright.txt', | ||
)) | ||
@HostApi() | ||
abstract class LocalAuthApi { | ||
/// Returns true if this device supports authentication. | ||
@async | ||
bool isDeviceSupported(); | ||
|
||
/// Attempts to authenticate the user with the provided [localizedReason] as | ||
/// the user-facing explanation for the authorization request. | ||
/// | ||
/// Returns true if authorization succeeds, false if it is attempted but is | ||
/// not successful, and an error if authorization could not be attempted. | ||
@async | ||
bool authenticate(String localizedReason); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.