hieuvp / react-native-fingerprint-scanner

Provide Fingerprint, Touch ID, and Face ID Scanner for React Native (Compatible with both Android and iOS)
https://www.npmjs.com/package/react-native-fingerprint-scanner
870 stars 298 forks source link

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

Open jong-hui opened 3 years ago

jong-hui commented 3 years ago

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.

hishamelgezeery commented 3 years ago

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()

jong-hui commented 3 years ago

@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?