Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit dfe4b14

Browse files
committed
refactor: eliminate one level of nesting from BiometricAuthenticator
1 parent 6f3f7e4 commit dfe4b14

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

app/src/main/java/app/passwordstore/util/auth/BiometricAuthenticator.kt

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -61,42 +61,44 @@ object BiometricAuthenticator {
6161
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
6262
super.onAuthenticationError(errorCode, errString)
6363
logcat(TAG) { "onAuthenticationError(errorCode=$errorCode, msg=$errString)" }
64-
callback(
65-
when (errorCode) {
66-
BiometricPrompt.ERROR_CANCELED,
67-
BiometricPrompt.ERROR_USER_CANCELED,
68-
BiometricPrompt.ERROR_NEGATIVE_BUTTON -> {
69-
Result.Cancelled
70-
}
71-
BiometricPrompt.ERROR_HW_NOT_PRESENT,
72-
BiometricPrompt.ERROR_HW_UNAVAILABLE,
73-
BiometricPrompt.ERROR_NO_BIOMETRICS,
74-
BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL -> {
75-
Result.HardwareUnavailableOrDisabled
76-
}
77-
BiometricPrompt.ERROR_LOCKOUT,
78-
BiometricPrompt.ERROR_LOCKOUT_PERMANENT,
79-
BiometricPrompt.ERROR_NO_SPACE,
80-
BiometricPrompt.ERROR_TIMEOUT,
81-
BiometricPrompt.ERROR_VENDOR -> {
64+
when (errorCode) {
65+
BiometricPrompt.ERROR_CANCELED,
66+
BiometricPrompt.ERROR_USER_CANCELED,
67+
BiometricPrompt.ERROR_NEGATIVE_BUTTON -> {
68+
callback(Result.Cancelled)
69+
}
70+
BiometricPrompt.ERROR_HW_NOT_PRESENT,
71+
BiometricPrompt.ERROR_HW_UNAVAILABLE,
72+
BiometricPrompt.ERROR_NO_BIOMETRICS,
73+
BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL -> {
74+
callback(Result.HardwareUnavailableOrDisabled)
75+
}
76+
BiometricPrompt.ERROR_LOCKOUT,
77+
BiometricPrompt.ERROR_LOCKOUT_PERMANENT,
78+
BiometricPrompt.ERROR_NO_SPACE,
79+
BiometricPrompt.ERROR_TIMEOUT,
80+
BiometricPrompt.ERROR_VENDOR -> {
81+
callback(
8282
Result.Failure(
8383
errorCode,
8484
activity.getString(R.string.biometric_auth_error_reason, errString)
8585
)
86-
}
87-
BiometricPrompt.ERROR_UNABLE_TO_PROCESS -> {
88-
Result.Retry
89-
}
90-
// We cover all guaranteed values above, but [errorCode] is still an Int
91-
// at the end of the day so a catch-all else will always be required.
92-
else -> {
86+
)
87+
}
88+
BiometricPrompt.ERROR_UNABLE_TO_PROCESS -> {
89+
callback(Result.Retry)
90+
}
91+
// We cover all guaranteed values above, but [errorCode] is still an Int
92+
// at the end of the day so a catch-all else will always be required.
93+
else -> {
94+
callback(
9395
Result.Failure(
9496
errorCode,
9597
activity.getString(R.string.biometric_auth_error_reason, errString)
9698
)
97-
}
99+
)
98100
}
99-
)
101+
}
100102
}
101103

102104
override fun onAuthenticationFailed() {

0 commit comments

Comments
 (0)