android / security-samples

Multiple samples showing the best practices in security APIs on Android.
Apache License 2.0
938 stars 395 forks source link

Dialog destroyed on rotation #12

Closed codingjeremy closed 4 years ago

codingjeremy commented 5 years ago

Issue by alex-townsend Tuesday May 24, 2016 at 19:11 GMT Originally opened as https://github.com/googlesamples/android-FingerprintDialog/issues/30


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.

codingjeremy commented 5 years ago

Comment by alex-townsend Tuesday May 24, 2016 at 19:42 GMT


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

codingjeremy commented 5 years ago

Comment by Kdoherty11 Wednesday Jul 20, 2016 at 20:23 GMT


+1

codingjeremy commented 5 years ago

Comment by nikhil-thakkar Tuesday Dec 12, 2017 at 17:49 GMT


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
}