hieuvp/react-native-fingerprint-scanner

[Question, bug?] why Android getBiometricPrompt use memoize?

Opened this issue · 2 comments

Hello. Thank you for making a good library.

While using the library, I found unwanted behavior and was looking at the library code.
I have a question. This can be a bug.

in ReactNativeFingerprintScannerModule.java:97

public BiometricPrompt getBiometricPrompt(final FragmentActivity fragmentActivity, final Promise promise) {
  // memoize so can be accessed to cancel 
  if (biometricPrompt != null) { // << I'm curious this line
      return biometricPrompt;
  }

  // listen for onHost* methods
  mReactContext.addLifecycleEventListener(this);

  AuthCallback authCallback = new AuthCallback(promise);
  Executor executor = Executors.newSingleThreadExecutor();
  biometricPrompt = new BiometricPrompt(
      fragmentActivity,
      executor,
      authCallback
  );

  return biometricPrompt;
}

You can only do one bio-certification on Android.
Because 'biometricPrompt' is memoized in 'getBiometricPrompt function'.

Bio-certification can be done several times in iOS.
And if I didn't do memoize, I could do it on Android several times.

I think the action is caused by the autoCallback not initialized.

I have to memoize, I think should update the AuthenticationCallback of biometricPrompt.

Thank you for reading it.

PS. As a temporary solution, I am going to delete the code(memoize). For bio-certification several times.

Hello,

I also thought this was an issue, but I guess we were missing calling the FingerprintScanner.release(), which if you look in the native code actually sets the biometricPrompt you're mentioning above to null. So in the finally callback of your call to authenticate, just call FingerprintScanner.release()

@hishamelgezeery Thank you for explanation.

As hishamelgezeery said, calling FingerprintScanner.release() might solve this issue.
However, this behavior(memoize) can cause confusion because it works differently than ios.
How much benefit does Memoize give it?