braintree / braintree_android

Braintree SDK for Android
https://developer.paypal.com/braintree/docs/start/hello-client/android/v4
MIT License
403 stars 232 forks source link

java.lang.IllegalArgumentException: View=DecorView@d9de0d2[ThreeDSecureActivity] not attached to window manager #982

Closed francescocervone closed 2 months ago

francescocervone commented 4 months ago

Braintree SDK Version

4.45.0

Environment

Production

Android Version & Device

No response

Braintree dependencies

Describe the bug

We are getting few crashes in production caused by com.cardinalcommerce.shared.userinterfaces.ProgressDialog. We had this crash since forever, but it seems to be increased starting from Braintree 4.43 (I'll attach screenshots below). Here you can find the stacktrace:

Fatal Exception: java.lang.IllegalArgumentException: View=DecorView@d9de0d2[getServiceWorkerController] not attached to window manager
       at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:544)
       at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:448)
       at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:206)
       at android.app.Dialog.dismissDialog(Dialog.java:413)
       at android.app.Dialog.dismiss(Dialog.java:395)
       at com.cardinalcommerce.shared.userinterfaces.ProgressDialog$2.run(SourceFile:52)
       at android.os.Handler.handleCallback(Handler.java:942)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:211)
       at android.os.Looper.loop(Looper.java:300)
       at android.app.ActivityThread.main(ActivityThread.java:8152)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1028)

For what it's worth, by reading our logs, it seems to be happening always after a 3D secure failure, usually with this stacktrace:

Caused by com.braintreepayments.api.BraintreeException: Cardinal SDK cca_continue Error.
       at com.braintreepayments.api.ThreeDSecureActivityResultContract.parseResult(ThreeDSecureActivityResultContract.java:44)
       at androidx.activity.result.ActivityResultRegistry.doDispatch(ActivityResultRegistry.java:414)
       at androidx.activity.result.ActivityResultRegistry.dispatchResult(ActivityResultRegistry.java:371)
       at androidx.activity.ComponentActivity.onActivityResult(ComponentActivity.java:845)
       at androidx.fragment.app.FragmentActivity.onActivityResult(FragmentActivity.java:151)
       at android.app.Activity.dispatchActivityResult(Activity.java:8893)
       at android.app.ActivityThread.deliverResults(ActivityThread.java:5489)
       at android.app.ActivityThread.handleSendResult(ActivityThread.java:5535)
       at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:67)
       at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2405)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:211)
       at android.os.Looper.loop(Looper.java:300)
       at android.app.ActivityThread.main(ActivityThread.java:8152)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1028)

It does not happen on a particular device (we have Xiaomi, Samsung, Motorola, Huawei,...) or an OS version (we have almost all of them, from 7 to 14)

It's just a guess, but it might be probably related to the memory leak mentioned here? https://github.com/braintree/braintree_android/issues/898

To reproduce

Unfortunately I'm not able to reproduce the issue on the sandbox. Tested with some of the cards here and "Don't keep activities" flag on/off (which sometimes may cause issues like this).

Expected behavior

The app doesn't crash.

Screenshots

Screenshot 2024-04-30 at 11 16 54

sarahkoop commented 3 months ago

Hi @francescocervone - Thanks for reporting this issue. We are actively investigating this and will post here when we have an update!

francescocervone commented 3 months ago

Hi @sarahkoop is there any update about this issue? It's our top issue with hundreds of crashes every month. Thanks.

sshropshire commented 2 months ago

Hello all. Please see version 4.48.0. We found a race condition recently where we were calling a CardinalSDK "cleanup" method too early, and applied a patch to resolve it. Feel free to re-open if the problem persists.