Thanks to visit codestin.com
Credit goes to github.com

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

[local_auth] Fixes show dialog when biometrics is not enrolled on Android devices. #6041

Conversation

vcrash
Copy link

@vcrash vcrash commented Jun 26, 2022

Description

  • Added AuthenticationErrorHandler class to encapsulate error handling logic which can be reused in several places.
    It can help to avoid applying different error processing logic for same kind of errors in different places.
  • Added AuthResultErrorCodes class containing result error codes constants. These error codes are matching to those in error_codes.dart.

Related issues

flutter/flutter#96646

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/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin 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.

vcrash added 2 commits June 26, 2022 17:44
…al_auth/local_auth_android/errors_handling_publish

# Conflicts:
#	packages/local_auth/local_auth_android/CHANGELOG.md
@stuartmorgan-g stuartmorgan-g requested review from camsim99 and removed request for blasten June 30, 2022 20:27
@stuartmorgan-g
Copy link
Contributor

@camsim99 Since you are looking at local_auth at the moment, maybe you could do the initial review here?

Copy link
Contributor

@camsim99 camsim99 left a comment

Choose a reason for hiding this comment

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

Thanks for doing this -- this is a lot cleaner! For the most part, I just had some comments on the structure of the error codes and some nits.

package io.flutter.plugins.localauth;

/** Exception codes for `PlatformException` in Flutter returned by `authenticate`. */
class AuthResultErrorCodes {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be converted to an enum since it's just values?

Copy link
Author

Choose a reason for hiding this comment

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

We can make this enum. But probably we need to move all possible error codes to this class first. Android plugin still can throw errors with codes which are not contained in error_codes.dart so they can be unexpected in Flutter part. If we make it enum we probably want to be sure that no other error codes are used and the set of enum values is full.

static final String LOCKED_OUT = "LockedOut";

/**
* Indicates the API is locked out more persistently than [lockedOut]. Strong authentication like
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Indicates the API is locked out more persistently than [lockedOut]. Strong authentication like
* Indicates the API is locked out more persistently than {@code lockedOut}. Strong authentication like

Copy link
Author

Choose a reason for hiding this comment

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

changed to @link

static final String PERMANENTLY_LOCKED_OUT = "PermanentlyLockedOut";

/** Indicates that the biometricOnly parameter can"t be true on Windows */
static final String BIOMETRIC_ONLY_NOT_SUPPORTED = "biometricOnlyNotSupported";
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need this since it's Windows only and it's already defined for Windows in error_codes.dart.

Copy link
Contributor

@camsim99 camsim99 Jul 7, 2022

Choose a reason for hiding this comment

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

Ok, I now recognize these are the same error codes defined there. I would remove the codes not used here and add a reference to the Dart error codes, unless there is a way to avoid the redundancy. @stuartmorgan what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, we should only define strings we are actually using, and referencing the Dart file that these need to be synchronized with in a comment is definitely helpful.

We don't currently have a way to avoid the redundancy. (There's a proposal for constants in Pigeon that would let us address that problem.)

Copy link
Author

Choose a reason for hiding this comment

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

We still have some error codes in Android plugin which are not contained in error_codes.dart such as "NotSupported", "NoHardware" and others. Should we add all of them to AuthResultErrorCodes.java or just keep here values matching those in error_codes.dart?

Copy link
Author

Choose a reason for hiding this comment

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

@camsim99 @stuartmorgan Any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think including them is fine. Maybe just note that those are Android only or Android-specific?

@@ -174,7 +175,9 @@ public void onError(String code, String error) {
if (!hasBiometricHardware()) {
completionHandler.onError("NoHardware", "No biometric hardware found");
}
completionHandler.onError("NotEnrolled", "No biometrics enrolled on this device.");
final AuthenticationErrorHandler errorHandler = new AuthenticationErrorHandler();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be made a class field? The newer local auth APIs have more errors that will need to be handled, see #6059

@@ -129,39 +129,51 @@ private void stop() {
@SuppressLint("SwitchIntDef")
@Override
public void onAuthenticationError(int errorCode, CharSequence errString) {
final AuthenticationErrorHandler errorHandler = new AuthenticationErrorHandler();
final Runnable onStopCallback = new Runnable() {
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this callback contribute to the error handling? Is it needed?

Copy link
Author

Choose a reason for hiding this comment

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

Since we moved part of error handling logic to AuthenticationErrorHandler class we need this callback to call stop() method of the AuthenticationHelper.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. Thanks!

@stuartmorgan-g
Copy link
Contributor

What's the status of this PR? It's not clear to me if all of the last round of review comments have been addressed yet, and it looks like some of the tests don't compile.

@vcrash
Copy link
Author

vcrash commented Sep 10, 2022

Closing this PR since the issue is not reproducing in local_auth 2.1.2. Further refactoring is not seems to be directly related to this issue.

@vcrash vcrash closed this Sep 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants