24

I'm writing a application feature to authenticate user using Biometric fingerprint authentication API. And it worked as expected with combination of BiometricPrompt API.

In general it display own UI dialog so it can be unified across Android device.(Improvement from Fingerprint Manager API)

In one of device testing scenario I come across in-display(on screen, e.g. Oneplus 6T device) fingerprint support instead rear biometric hardware option.

When I run application on it, on call of biometricPrompt.authenticate(..) instead of dialog it display in-display fingerprint authentication option. Which is ok, and manage by internal API of BiometricPrompt.

But it create some inconsistency to manage for developer.

  1. When it provide in-build authentication dialog, all fallback error displayed in dialog itself.
  2. But in case of in-display authentication I didn't found a way where it manage to display error message it-self. And I have to handle this fallback and display in a custom way.

Now question is

  1. Is there a way to manage/display message by in-display authentication view component.
  2. How can identify if device is support in-device biometric authentication.

Edit: Code reference I'm using:

import android.content.Context
import androidx.biometric.BiometricPrompt
import androidx.fragment.app.FragmentActivity
import java.lang.Exception
import java.util.concurrent.Executors
import javax.crypto.Cipher

class BiometricAuthenticationManager(private val context: Context) :
        BiometricPrompt.AuthenticationCallback() {

    private var biometricPrompt: BiometricPrompt? = null

    override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
        super.onAuthenticationError(errorCode, errString)
        biometricPrompt?.cancelAuthentication()
    }

    override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
        super.onAuthenticationSucceeded(result)

    }

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

    fun init(cipher: Cipher, promptInfo: BiometricPrompt.PromptInfo) {
        if (context is FragmentActivity) {
            val executor = Executors.newSingleThreadExecutor()

            biometricPrompt = BiometricPrompt(context, executor, this)
            biometricPrompt?.authenticate(promptInfo, BiometricPrompt.CryptoObject(cipher))
        } else {
            throw Exception(
                    "Check for FragmentActivity context.")
        }
    }
}

For further reference about how it look like, please find following attachment.

enter image description here

I try to check same scenario for lock screen, where I guess it uses custom implementation using FingerPrintManager class and display message.

enter image description here

CoDe
  • 10,214
  • 14
  • 74
  • 180
  • 1
    "How can identify if device is support in-device biometric authentication" -- that seems like the wrong question. Based on your problem, the issue is not whether this is an in-screen fingerprint detector -- it is whether the error messages are handled for you. While in-screen fingerprint detectors might be more prone to this sort of problem, technically they are not connected. For example, iris scan devices might have the same problem. You might want to include a [mcve] showing your code and have screenshots depicting the difference in behaviors. – CommonsWare Aug 14 '19 at 11:35
  • BTW, you might want to try the `androidx` edition of `BiometricPrompt` and see if it changes the behavior. – CommonsWare Aug 14 '19 at 11:36
  • The position of the fingerprint sensor is determined by the manufacturer of the particular device. the purpose of APIs is to authenticate the right user. so checking the in-display biometric seems not possible to me with default api. – Sahil Manchanda Aug 14 '19 at 11:41
  • @CommonsWare, I checked with androidX component (should actually used to support running versions below Android P) but it's not making any difference. About "if device is support in-device biometric authentication" this is the last option I'm looking for so I can put if-else when need to display errors in custom UI when it will be handle by SDK dialog component itself. – CoDe Aug 16 '19 at 06:07
  • 1
    @SahilManchanda, true. But you see the issue, when using latest Biometric API with rear sensor, it display dialog prompt which can handle error. But when using same API with in-display sensor, it does not display error message. Do you have any finding around ? – CoDe Aug 21 '19 at 10:30
  • 1
    @CoDe Do you have any finding around ? A. no. will look into it today – Sahil Manchanda Aug 21 '19 at 10:34
  • You can use the method [BiometricManager.canAuthenticate()](https://developer.android.com/reference/androidx/biometric/BiometricManager.html#canAuthenticate()) – Gabriele Mariotti Aug 31 '19 at 10:51
  • I have a OnePlus with Android 10 and it animates the dialog. You can expect the OEM to implement error handling with e.g. haptic feedback instead of with text. – Gabor Sep 12 '19 at 05:18
  • true, but for me issue is related to displaying error when it's in-display fingerprint(or when in case if it is not displaying fingerprint dialog), because in case of dialog-display sdk it self display on dialog. – CoDe Sep 12 '19 at 08:23
  • @CoDe any solution to this issue? – Cosmic Dev Jun 09 '20 at 10:58
  • @CosmicDev so far nothing. But you can share your usecase and I can help you to do some possible solution. – CoDe Jun 16 '20 at 12:31
  • It is not displaying up in one plus 6t – Cosmic Dev Jun 16 '20 at 12:51
  • Strong reason if you are using Strong Bio-metric Authentication (Using Crypto) object and you have not registered any Finger print in device Setting. I'm not sure which version of lib you are using but latest one is [androidx.biometric:biometric:1.0.1](https://developer.android.com/jetpack/androidx/releases/biometric) . – CoDe Jun 18 '20 at 09:37
  • am facing similar but bit different issue with my in-screen fingerprintsensor(on my OP7T). In-case of wrong fingerprint, default implementation shows Negative Message which I had set and just waits and continue accepting fingerprints. But in case of OP7T, wrong fingerprint just produces haptic feedback(vibrate) and closes the dialog without even calling 'onAuthenticationError' and when I click back then it actually calls 'onAuthenticationError'. @CoDe are you facing similar issue.. will try to look into mine and your issue, will post if I find anything. – Malay Shah Jun 20 '20 at 07:13
  • second scenario looks odd, but in general there is a limit of maximum wrong attempt a user can perform after that it does not allow(even any other app) to use Biometric until user lock and unlock device again. Please also note underlying layer can be modified by OEM provider (like Samsung did), so might be device specific issue. – CoDe Jun 23 '20 at 09:19
  • 1
    @CoDe Its Oneplus's Oxygen OS buggy implementation. check pommytom's answer on OnePlus forum he has explained it quite nicely and have also mentioned some workaround: https://forums.oneplus.com/threads/oneplus-7-pro-fingerprint-biometricprompt-does-not-show.1035821/ as far as i suggest you can show Toast onAuthenticationFailed() it won't be same as LockScreen failure response but it can consider and workaround. – Malay Shah Jun 28 '20 at 09:51

0 Answers0