-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[local_auth] Fix device credential only check for API < 30 #6522
Conversation
@@ -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(); |
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 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.
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;
}
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 actually don't authenticate at all below API 23 (M) in order to be compatible with the biometrics library:
Lines 142 to 146 in 5a0209d
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.
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.
LGTM!
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
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.