Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
Description
When using any of the suspending extensions
FragmentActivity.authenticateWithClassXBiometrics
, failing to authenticate on the first try causes the method to throw anAuthPromptFailureException
.While this behavior is documented, it is highly undesireable, as the prompt window is still visible and allows the user to try again. In addition, trying to authenticate again will result in a
IllegalStateException
, because the underlyingCoroutineAuthPromptCallback
tries to resume its continuation twice.BUILD INFO
STEPS TO REPRODUCE
activity.authenticateWithClass2Biometrics("Authenticate", "Cancel")
EXPECTED RESULTS
The suspend function should only complete or throw an exception when the prompt window reaches a terminal state
OBSERVED RESULTS
Unless caught, a
IllegalStateException
will crash your appNUMBER OF TIMES YOU WERE ABLE TO REPRODUCE: 10/10, can reproduce again
Additional thoughts
I think this is rooted in a general misconception about when each method of android documentation ), the of the androidx
BiometricPrompt.AuthenticationCallback
is invoked. While the system invokesonAuthenticationFailed
on valid but unrecognized attempts (see theAuthPromptCallback
wrapper, says "Called when an authentication attempt by the user has been rejected."Proposed fix
In
androidx.biometric.auth.CoroutineAuthPromptCallback
, do not resume the continuation upononAuthenticationFailed
. Instead allow passing a (optional) lambda to to be invoked instead. This allows developers to handle the error, but does not force the suspend function to complete earlier than desired.