From d63ddec037c5ca102af344f03419561197fb698c Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 6 Mar 2022 12:56:18 +0100 Subject: [PATCH] Handle fingerprint hardware errors --- .../main/java/eu/faircode/email/Helper.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index 9ccdbfb5b4..f1dc2dbe60 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -2166,11 +2166,18 @@ public class Helper { @Override public void onAuthenticationError(final int errorCode, @NonNull final CharSequence errString) { - Log.w("Authenticate biometric error " + errorCode + ": " + errString); + if (isCancelled(errorCode)) + Log.w("Authenticate biometric error " + errorCode + ": " + errString); + else + Log.e("Authenticate biometric error " + errorCode + ": " + errString); - if (errorCode != BiometricPrompt.ERROR_NEGATIVE_BUTTON && - errorCode != BiometricPrompt.ERROR_CANCELED && - errorCode != BiometricPrompt.ERROR_USER_CANCELED) + if (isHardwareFailure(errorCode)) { + prefs.edit().remove("biometrics").apply(); + ApplicationEx.getMainHandler().post(authenticated); + return; + } + + if (!isCancelled(errorCode)) ApplicationEx.getMainHandler().post(new Runnable() { @Override public void run() { @@ -2196,6 +2203,19 @@ public class Helper { if (++fails >= 3) ApplicationEx.getMainHandler().post(cancelled); } + + private boolean isCancelled(int errorCode) { + return (errorCode == BiometricPrompt.ERROR_NEGATIVE_BUTTON || + errorCode == BiometricPrompt.ERROR_CANCELED || + errorCode == BiometricPrompt.ERROR_USER_CANCELED); + } + + private boolean isHardwareFailure(int errorCode) { + return (errorCode == BiometricPrompt.ERROR_HW_UNAVAILABLE || + errorCode == BiometricPrompt.ERROR_NO_BIOMETRICS || + errorCode == BiometricPrompt.ERROR_HW_NOT_PRESENT || + errorCode == BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL); + } }); prompt.authenticate(info.build());