Skip to content

Commit

Permalink
Added new option to isAvailable - requireStrongBiometrics
Browse files Browse the repository at this point in the history
  • Loading branch information
austinwark authored and NiklasMerz committed Mar 23, 2024
1 parent 72a2cf4 commit 80f2684
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Fingerprint.isAvailable(isAvailableSuccess, isAvailableError, optionalParams);
### Optional parameters

* __allowBackup (iOS)__: If `true` checks if backup authentication option is available, e.g. passcode. Default: `false`, which means check for biometrics only.
* __requireStrongBiometrics (Android)__: If `true` will only return success if Class 3 (BIOMETRIC_STRONG) Biometrics are enrolled on the device. It is reccomended you use this if planning on using the `registerBiometricSecret` and `loadBiometricSecret` methods.

### Show authentication dialogue
```javascript
Expand Down
18 changes: 12 additions & 6 deletions src/android/Fingerprint.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,16 @@ public boolean execute(final String action, JSONArray args, CallbackContext call
return true;

} else if ("isAvailable".equals(action)) {
executeIsAvailable();
executeIsAvailable(args);
return true;

}
return false;
}

private void executeIsAvailable() {
PluginError error = canAuthenticate();
private void executeIsAvailable(JSONArray args) {
boolean requireStrongBiometrics = new Args(args).getBoolean("requireStrongBiometrics", false);
PluginError error = canAuthenticate(requireStrongBiometrics);
if (error != null) {
sendError(error);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P){
Expand All @@ -88,8 +89,13 @@ private void executeAuthenticate(JSONArray args) {
this.runBiometricActivity(args, BiometricActivityType.JUST_AUTHENTICATE);
}

private boolean determineStrongBiometricsRequired(BiometricActivityType type) {
return type == BiometricActivityType.REGISTER_SECRET || type == BiometricActivityType.LOAD_SECRET;
}

private void runBiometricActivity(JSONArray args, BiometricActivityType type) {
PluginError error = canAuthenticate();
boolean requireStrongBiometrics = determineStrongBiometricsRequired(type);
PluginError error = canAuthenticate(requireStrongBiometrics);
if (error != null) {
sendError(error);
return;
Expand Down Expand Up @@ -135,8 +141,8 @@ private void sendError(Intent intent) {
}
}

private PluginError canAuthenticate() {
int error = BiometricManager.from(cordova.getContext()).canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK);
private PluginError canAuthenticate(boolean requireStrongBiometrics) {
int error = BiometricManager.from(cordova.getContext()).canAuthenticate(requireStrongBiometrics ? BiometricManager.Authenticators.BIOMETRIC_STRONG : BiometricManager.Authenticators.BIOMETRIC_WEAK);
switch (error) {
case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
Expand Down

0 comments on commit 80f2684

Please sign in to comment.