aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2023-07-09 17:11:55 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2023-07-09 17:59:33 +0530
commitdfe4b14b4c64006a3515f9b7f1a59ac4f8c00e9e (patch)
treeeacd17488d59c3f2382325ed70447f8db38c6d7e
parent6f3f7e4b4c6a7eb8efe4e7a2cb3fea8d7ef1bb5d (diff)
refactor: eliminate one level of nesting from BiometricAuthenticator
-rw-r--r--app/src/main/java/app/passwordstore/util/auth/BiometricAuthenticator.kt56
1 files changed, 29 insertions, 27 deletions
diff --git a/app/src/main/java/app/passwordstore/util/auth/BiometricAuthenticator.kt b/app/src/main/java/app/passwordstore/util/auth/BiometricAuthenticator.kt
index 4b91bee6..b81e9a16 100644
--- a/app/src/main/java/app/passwordstore/util/auth/BiometricAuthenticator.kt
+++ b/app/src/main/java/app/passwordstore/util/auth/BiometricAuthenticator.kt
@@ -61,42 +61,44 @@ object BiometricAuthenticator {
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
super.onAuthenticationError(errorCode, errString)
logcat(TAG) { "onAuthenticationError(errorCode=$errorCode, msg=$errString)" }
- callback(
- when (errorCode) {
- BiometricPrompt.ERROR_CANCELED,
- BiometricPrompt.ERROR_USER_CANCELED,
- BiometricPrompt.ERROR_NEGATIVE_BUTTON -> {
- Result.Cancelled
- }
- BiometricPrompt.ERROR_HW_NOT_PRESENT,
- BiometricPrompt.ERROR_HW_UNAVAILABLE,
- BiometricPrompt.ERROR_NO_BIOMETRICS,
- BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL -> {
- Result.HardwareUnavailableOrDisabled
- }
- BiometricPrompt.ERROR_LOCKOUT,
- BiometricPrompt.ERROR_LOCKOUT_PERMANENT,
- BiometricPrompt.ERROR_NO_SPACE,
- BiometricPrompt.ERROR_TIMEOUT,
- BiometricPrompt.ERROR_VENDOR -> {
+ when (errorCode) {
+ BiometricPrompt.ERROR_CANCELED,
+ BiometricPrompt.ERROR_USER_CANCELED,
+ BiometricPrompt.ERROR_NEGATIVE_BUTTON -> {
+ callback(Result.Cancelled)
+ }
+ BiometricPrompt.ERROR_HW_NOT_PRESENT,
+ BiometricPrompt.ERROR_HW_UNAVAILABLE,
+ BiometricPrompt.ERROR_NO_BIOMETRICS,
+ BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL -> {
+ callback(Result.HardwareUnavailableOrDisabled)
+ }
+ BiometricPrompt.ERROR_LOCKOUT,
+ BiometricPrompt.ERROR_LOCKOUT_PERMANENT,
+ BiometricPrompt.ERROR_NO_SPACE,
+ BiometricPrompt.ERROR_TIMEOUT,
+ BiometricPrompt.ERROR_VENDOR -> {
+ callback(
Result.Failure(
errorCode,
activity.getString(R.string.biometric_auth_error_reason, errString)
)
- }
- BiometricPrompt.ERROR_UNABLE_TO_PROCESS -> {
- Result.Retry
- }
- // We cover all guaranteed values above, but [errorCode] is still an Int
- // at the end of the day so a catch-all else will always be required.
- else -> {
+ )
+ }
+ BiometricPrompt.ERROR_UNABLE_TO_PROCESS -> {
+ callback(Result.Retry)
+ }
+ // We cover all guaranteed values above, but [errorCode] is still an Int
+ // at the end of the day so a catch-all else will always be required.
+ else -> {
+ callback(
Result.Failure(
errorCode,
activity.getString(R.string.biometric_auth_error_reason, errString)
)
- }
+ )
}
- )
+ }
}
override fun onAuthenticationFailed() {