Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[local_auth] Convert Android to Pigeon #3748

Merged
merged 3 commits into from
Apr 18, 2023

Conversation

stuartmorgan
Copy link
Contributor

Updates the platform communication to use Pigeon. This includes some changes to the API boundary:

  • Collected authentication options into an options object; this avoids having a lot of positional boolean arguments (since Pigeon doesn't currently support named arguments).
  • Collected strings into a strings object, since having them as individual parameters would have been extremely messy.
  • Changes the authenticate return from a bool+exceptions to an enum that encompasses all of the explicitly known failure modes. To avoid a breaking change for clients, the Dart code creates PlatformExceptions that match the old ones, but this will make it much easier to someday make a (cross-platform) breaking change to replace them with better errors per the best practices we have documented on the wiki. Using an enum rather than throwing errors avoids the need to do string matching when we want to eventually translate them into something other than PlatformException.

This removes all Java warnings from the baseline file; the remaining issues in code I wasn't already changing were easy enough to fix opportunistically. There are still XML-based warnings, but fixing those was well out of scope so I left them.

Part of flutter/flutter#117912

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

/*
* Stops the authentication if in progress.
*/
private void stopAuthentication(Result result) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost all of the "removed" code in this removed-code diff block is actually just moved up inline into the new Pigeon API implementation functions above.

binding.addActivityResultListener(resultListener);
setServicesFromActivity(binding.getActivity());
lifecycle = FlutterLifecycleAdapter.getActivityLifecycle(binding);
channel.setMethodCallHandler(this);
Copy link
Contributor Author

@stuartmorgan stuartmorgan Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're no longer creating and removing the channel as part of the activity lifecycle. It's inconvenient to do with Pigeon (since we need the messenger), and I don't see any need for it since we're checking the activity in the necessary functions anyway. In fact, I think with the old code people would see "missing plugin" exceptions instead of our "this plugin needs a foreground activity" errors, which seems strictly worse.

@stuartmorgan stuartmorgan added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 18, 2023
@auto-submit auto-submit bot merged commit 773c7a8 into flutter:main Apr 18, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 19, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 19, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 19, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Apr 19, 2023
flutter/packages@faf53fb...88591be

2023-04-19 engine-flutter-autoroll@skia.org Roll Flutter from 42fb0b2 to 3476b96 (20 revisions) (flutter/packages#3760)
2023-04-19 49699333+dependabot[bot]@users.noreply.github.com Bump cirrusci/flutter from `794fbbc` to `d99b1ba` in /.ci (flutter/packages#3724)
2023-04-18 10687576+bparrishMines@users.noreply.github.com [webview_flutter] Adds support to listen to url changes  (flutter/packages#3313)
2023-04-18 engine-flutter-autoroll@skia.org Roll Flutter from 15cb1f8 to 42fb0b2 (19 revisions) (flutter/packages#3756)
2023-04-18 49699333+dependabot[bot]@users.noreply.github.com [webview]: Bump com.android.tools.build:gradle from 7.2.2 to 8.0.0 in /packages/webview_flutter/webview_flutter_android/android (flutter/packages#3739)
2023-04-18 stuartmorgan@google.com [local_auth] Convert Android to Pigeon (flutter/packages#3748)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@asaarnak
Copy link
Contributor

When we updated from 1.0.21 to 1.0.23 we started getting this error:

Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(channel-error, Unable to establish connection on channel., null, null)
       at LocalAuthApi.getEnrolledBiometrics(messages.g.dart:313)
       at LocalAuthAndroid.getEnrolledBiometrics(local_auth_android.dart:99)

@stuartmorgan stuartmorgan deleted the local-auth-android-pigeon branch April 20, 2023 14:25
@stuartmorgan
Copy link
Contributor Author

Please file issues in the issue tracker.

stuartmorgan added a commit to stuartmorgan/packages that referenced this pull request Apr 20, 2023
The Pigeon conversion in flutter#3748
used a `List<enum>` return value, which Pigeon doesn't support correctly
(see flutter/flutter#125230 for catching this
earlier next time). Because the method doesn't return any values in
integration test environments it wasn't caught (since the issue is in
Pigeon message handling, and thus doesn't show up in unit tests of the
plugin).

This adds a wrapper class, since enum fields do work.

Fixes flutter/flutter#125214
stuartmorgan added a commit to stuartmorgan/packages that referenced this pull request Apr 20, 2023
The Pigeon conversion in flutter#3748
used a `List<enum>` return value, which Pigeon doesn't support correctly
(see flutter/flutter#125230 for catching this
earlier next time). Because the method doesn't return any values in
integration test environments it wasn't caught (since the issue is in
Pigeon message handling, and thus doesn't show up in unit tests of the
plugin).

This adds a wrapper class, since enum fields do work.

Fixes flutter/flutter#125214
@asaarnak
Copy link
Contributor

Sorry, next time i'll file an issue. Found that there already exists one: flutter/flutter#125236

auto-submit bot pushed a commit that referenced this pull request Apr 21, 2023
The Pigeon conversion in #3748 used a `List<enum>` return value, which Pigeon doesn't support correctly (see flutter/flutter#125230 for catching this earlier next time). Because the method doesn't return any values in integration test environments it wasn't caught (since the issue is in Pigeon message handling, and thus doesn't show up in unit tests of the plugin).

This adds a wrapper class, since enum fields do work.

Fixes flutter/flutter#125214
auto-submit bot pushed a commit that referenced this pull request May 19, 2023
Updates the platform communication to use Pigeon. This includes some changes to the API boundary:
- Collected authentication options into an options object; this avoids having a lot of positional boolean arguments (since Pigeon doesn't currently support named arguments).
- Collected strings into a strings object, since having them as individual parameters would have been extremely messy.
- Changes the `authenticate` return from a bool+exceptions to an enum that encompasses all of the explicitly known failure modes. To avoid a breaking change for clients, the Dart code creates `PlatformException`s that match the old ones, but this will make it much easier to someday make a (cross-platform) breaking change to replace them with better errors per the best practices we have documented on the wiki. Using an enum rather than throwing errors avoids the need to do string matching when we want to eventually translate them into something other than `PlatformException`.

The Pigeon file, Dart implementation, and rewritten tests are all based very heavily on the recent Android migration: #3748

I noted several bugs that I noticed in the existing implementation during the migration. I intentionally didn't fix them so this isn't changing behavior at the same time that it's changing so much of the code and tests, but I marked them with TODO comments.

Fixes flutter/flutter#117912
nploi pushed a commit to nploi/packages that referenced this pull request Jul 16, 2023
Updates the platform communication to use Pigeon. This includes some changes to the API boundary:
- Collected authentication options into an options object; this avoids having a lot of positional boolean arguments (since Pigeon doesn't currently support named arguments).
- Collected strings into a strings object, since having them as individual parameters would have been extremely messy.
- Changes the `authenticate` return from a bool+exceptions to an enum that encompasses all of the explicitly known failure modes. To avoid a breaking change for clients, the Dart code creates `PlatformException`s that match the old ones, but this will make it much easier to someday make a (cross-platform) breaking change to replace them with better errors per the best practices we have documented on the wiki. Using an enum rather than throwing errors avoids the need to do string matching when we want to eventually translate them into something other than `PlatformException`.

This removes all Java warnings from the baseline file; the remaining issues in code I wasn't already changing were easy enough to fix opportunistically. There are still XML-based warnings, but fixing those was well out of scope so I left them.

Part of flutter/flutter#117912
nploi pushed a commit to nploi/packages that referenced this pull request Jul 16, 2023
The Pigeon conversion in flutter#3748 used a `List<enum>` return value, which Pigeon doesn't support correctly (see flutter/flutter#125230 for catching this earlier next time). Because the method doesn't return any values in integration test environments it wasn't caught (since the issue is in Pigeon message handling, and thus doesn't show up in unit tests of the plugin).

This adds a wrapper class, since enum fields do work.

Fixes flutter/flutter#125214
nploi pushed a commit to nploi/packages that referenced this pull request Jul 16, 2023
Updates the platform communication to use Pigeon. This includes some changes to the API boundary:
- Collected authentication options into an options object; this avoids having a lot of positional boolean arguments (since Pigeon doesn't currently support named arguments).
- Collected strings into a strings object, since having them as individual parameters would have been extremely messy.
- Changes the `authenticate` return from a bool+exceptions to an enum that encompasses all of the explicitly known failure modes. To avoid a breaking change for clients, the Dart code creates `PlatformException`s that match the old ones, but this will make it much easier to someday make a (cross-platform) breaking change to replace them with better errors per the best practices we have documented on the wiki. Using an enum rather than throwing errors avoids the need to do string matching when we want to eventually translate them into something other than `PlatformException`.

The Pigeon file, Dart implementation, and rewritten tests are all based very heavily on the recent Android migration: flutter#3748

I noted several bugs that I noticed in the existing implementation during the migration. I intentionally didn't fix them so this isn't changing behavior at the same time that it's changing so much of the code and tests, but I marked them with TODO comments.

Fixes flutter/flutter#117912
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: local_auth platform-android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants