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] Fix device credential only check for API < 30 #6522

Merged
merged 8 commits into from
Oct 24, 2022

Conversation

camsim99
Copy link
Contributor

@camsim99 camsim99 commented Sep 30, 2022

Fixes flutter/flutter#111025.

Changes check for ability to authenticate with device credentials to check for device credentials and biometrics, since as per the documentation, checking for device only authentication is not supported before API 30.

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.

@camsim99 camsim99 changed the title [local_auth] Leave fallback default behavior to Android [local_auth] Fix device credential only check for API < 30 Sep 30, 2022
@@ -274,6 +274,7 @@ private boolean canAuthenticateWithDeviceCredential() {
if (Build.VERSION.SDK_INT < 30) {
// Checking/setting device credential only authentication is not allowed before API 11,
// so check for presence of PIN, pattern, or password instead.
if (keyguardManager == null) return false;
return keyguardManager.isDeviceSecure();
Copy link

Choose a reason for hiding this comment

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

@camsim99 I think u need to update the code to

iif (Build.VERSION.SDK_INT >= 16 30 && Build.VERSION.SDK_INT < 30) {

keyguardManager.isDeviceSecure() only works on M and above.

Screenshot 2022-10-07 at 5 15 39 PM

or you can just use what i wrote before

private boolean canAuthenticateWithDeviceCredential() {
    //supports from Android 23 onwards
    if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.R ) {
      if (biometricManager == null) return false;
      return biometricManager.canAuthenticate(BiometricManager.Authenticators.DEVICE_CREDENTIAL)
          == BiometricManager.BIOMETRIC_SUCCESS;
    }else if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ) {
      if (keyguardManager == null) return false;
      return keyguardManager.isDeviceSecure();
    }
    return false;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We actually don't authenticate at all below API 23 (M) in order to be compatible with the biometrics library:

if (!isDeviceSupported()) {
authInProgress.set(false);
result.error("NotAvailable", "Required security features not enabled", null);
return;
}

You are right about needing an explicit check for that, so I refactored the code a bit.

@camsim99 camsim99 marked this pull request as ready for review October 20, 2022 19:10
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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.

[local_auth] PlatformException(NotAvailable, Security credentials not available., null, null) on devices with no biometric hardware
3 participants