googlearchive / android-FingerprintDialog

Migrated:
https://github.com/android/security
Apache License 2.0
1.38k stars 477 forks source link

Dialog destroyed on rotation #30

Closed alex-townsend closed 5 years ago

alex-townsend commented 8 years ago

The dialog fragment for the fingerprint authentication does not survive rotation, despite having setRetainInstanceState(true) set. This appears to be because the CancellationSignal does not emit the cancellation before the dialog fragment is recreated and resumed again -- mSelfCancelled = false then, causing mCallback.onError() to be called and to close the newly created dialog fragment to be dismissed.

Flow looks something like this (user selects Purchase to start):

1) FingerprintAuthenticationDialogFragment created:

2) User rotates device

3) New FingerprintAuthenticationDialogFragment created:

So it looks like the cancellation is not sent quickly enough on a rotation, causing the fragment created after the rotation to receive that cancellation message, which then closes the dialog fragment.

alex-townsend commented 8 years ago

Here's a log of the flow as well:

05-24 15:39:30.241 8110-8110/ D/DEBUG_TAG: startListening // Purchase pressed 05-24 15:39:39.811 8110-8110/ D/DEBUG_TAG: stopListening // Rotation happens 05-24 15:39:39.878 8110-8110/ D/DEBUG_TAG: startListening 05-24 15:39:39.882 8110-8110/ D/DEBUG_TAG: onAuthenticationError: errString: Fingerprint operation canceled. mSelfCancelled: false 05-24 15:39:40.110 8110-8110/ D/DEBUG_TAG: stopListening 05-24 15:39:40.203 8110-8110/ D/DEBUG_TAG: onAuthenticationError: errString: Fingerprint operation canceled. mSelfCancelled: true

Kdoherty11 commented 8 years ago

+1

nikhil-thakkar commented 6 years ago

Late answer but I also found it the hard way. The way it is handled is:

override fun onFingerprintAuthenticationError(errMsgId: Int, message: String) {
  if (errMsgId != android.hardware.fingerprint.FingerprintManager.FINGERPRINT_ERROR_CANCELED) {
      //do your thing
}
codingjeremy commented 5 years ago

I am closing this issue/PR, as it has been migrated to the new repo linked above in the comments. Thank you!