mjwheatley / cordova-plugin-android-fingerprint-auth

A cordova plugin for fingerprint authentication using the hardware fingerprint scanner on devices running Android 6+
Apache License 2.0
168 stars 131 forks source link

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState #54

Closed jskrepnek closed 7 years ago

jskrepnek commented 7 years ago

Hi,

Any thoughts about the following crash:

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
    at android.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1411)
    at android.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1429)
    at android.app.BackStackRecord.commitInternal(BackStackRecord.java:687)
    at android.app.BackStackRecord.commit(BackStackRecord.java:663)
    at android.app.DialogFragment.show(DialogFragment.java:231)
    at com.cordova.plugin.android.fingerprintauth.FingerprintAuth$1.run(FingerprintAuth.java:300)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5551)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)

Here's a snippet around the line from FingerprintAuth:

// This happens if the lock screen has been disabled or or a fingerprint got
// enrolled. Thus show the dialog to authenticate with their password
mFragment.setCryptoObject(new FingerprintManager.CryptoObject(mCipher));
mFragment.setStage(FingerprintAuthenticationDialogFragment.Stage.NEW_FINGERPRINT_ENROLLED);
mFragment.show(cordova.getActivity().getFragmentManager(), DIALOG_FRAGMENT_TAG);

My quick attempt at research seems to suggest that showing the fragment is happening asynchronously after such actions should be taken?

Seems to be affecting a variety of 6+ devices.

Thanks for any help.

SeeWhat commented 7 years ago

I've been able to reproduce this crash by placing the app in the background before the FingerPrint dialog is displayed. You could handle the pause and resume events to prevent it being displayed manually or setting KeepRunning to false to prevent the app from getting to the point of display also appears to stop the crash.

SeeWhat commented 7 years ago

Looking through the forks I noticed https://github.com/kiliankoller/cordova-plugin-android-fingerprint-auth/commit/4c0cf1cf24cdfc6a1d5eca19eddeffc8f406fdcb which I tried locally (Applied changes to the latest version) and it seems to stop the crashing from occurring for me.

Reading up on the issue, it's one of the last resort methods, but better than the crashing I'm experiencing.

mjwheatley commented 7 years ago

I've already merged that change into the repo. I just haven't published a new version. I guess I need to do that.

mjwheatley commented 7 years ago

On second glance, no I don't have those changes merged. I'll work on merging them and publish a new release.

mjwheatley commented 7 years ago

change published in version 1.2.8