-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[local_auth] Fixes show dialog when biometrics is not enrolled on Android devices. #6041
[local_auth] Fixes show dialog when biometrics is not enrolled on Android devices. #6041
Conversation
β¦ AuthenticationErrorHandler class so it can be reused.
β¦al_auth/local_auth_android/errors_handling_publish
β¦al_auth/local_auth_android/errors_handling_publish
β¦al_auth/local_auth_android/errors_handling_publish
β¦al_auth/local_auth_android/errors_handling_publish # Conflicts: # packages/local_auth/local_auth_android/CHANGELOG.md
@camsim99 Since you are looking at |
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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 |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@camsim99 @stuartmorgan Any thoughts?
There was a problem hiding this comment.
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?
...al_auth_android/android/src/main/java/io/flutter/plugins/localauth/AuthResultErrorCodes.java
Show resolved
Hide resolved
...h_android/android/src/main/java/io/flutter/plugins/localauth/AuthenticationErrorHandler.java
Outdated
Show resolved
Hide resolved
...h_android/android/src/main/java/io/flutter/plugins/localauth/AuthenticationErrorHandler.java
Show resolved
Hide resolved
@@ -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(); |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. Thanks!
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. |
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. |
Description
It can help to avoid applying different error processing logic for same kind of errors in different places.
Related issues
flutter/flutter#96646
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.