Android biometric - How to detect biometric is lockout?

543 views Asked by At

I am developing a app with biometric. I try 5 attempts and biometric sensor is locked and I get errorCode 7 from AuthenticationCallback.

  biometricPrompt = BiometricPrompt(this,
      executor!!, object : BiometricPrompt.AuthenticationCallback() {
        override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
          super.onAuthenticationError(errorCode, errString)
          finishActivity(errString.toString(), errorCode)
        }

        override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
          super.onAuthenticationSucceeded(result)
          finishActivity("success", 0)
        }

        override fun onAuthenticationFailed() {
          super.onAuthenticationFailed()
        }
      })

But I recheck canAuthenticate is always return 11(not enrolled status code).

biometricManager!!.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK)

Is there any way to know the device biometric is locked?

1

There are 1 answers

0
LethalMaus On

Some devices handle errorCode 7 differently that what the internal comment suggests. Some phones lockout for 30 seconds, some up to 4 hours, while other e.g. Pixel 6, lockout until some action is performed.

This is what my Pixel 6 says:

Too many attempts. Use screen lock instead.

Which means I have to prompt the user to lock and unlock their screen before they can retry, so the 30 seconds doesn't apply here.

In the BiometricPrompt.AuthenticationCallback when onAuthenticationError(errorCode: Int, errString: CharSequence) is called, you can see the message that the system delivers. Be wary though, not every device sends an ideal translated message to the user, so handling the message yourself as well as delivering the message is advised.

You will have to prompt the user accordingly first before biometricManager!!.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK) will return true