Appboy / appboy-android-sdk

Public repo for the Braze Android SDK
https://www.braze.com
Other
152 stars 102 forks source link

[Bug]: Threading issue in DefaultInAppMessageViewWrapper #228

Closed olliwear closed 2 years ago

olliwear commented 2 years ago

Braze Android SDK Version

20.0.0

Steps To Reproduce

We've recently updated from v15.0.0 to v20.0.0. We couldn't reproduce this ourselves, but have some crash reports from users.

We handle In-App messages by registering a global activity lifecycle callback -

BrazeActivityLifecycleCallbackListener( sessionHandlingEnabled = true, registerInAppMessageManager = true, inAppMessagingRegistrationBlocklist = inAppMessageBlacklist, sessionHandlingBlocklist = null )

Expected Behavior

Threading handled by Braze

Actual Incorrect Behavior

Crashing due to wrong Thread

Verbose Logs

Fatal Exception: java.lang.IllegalStateException: Calling View methods on another thread than the UI thread.
       at com.android.webview.chromium.WebViewChromium.b(WebViewChromium.java:439)
       at com.android.webview.chromium.WebViewChromium.onAttachedToWindow(WebViewChromium.java:2146)
       at android.webkit.WebView.onAttachedToWindow(WebView.java:2612)
       at android.view.View.dispatchAttachedToWindow(View.java:22010)
       at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4291)
       at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4298)
       at android.view.ViewGroup.addViewInner(ViewGroup.java:6108)
       at android.view.ViewGroup.addView(ViewGroup.java:5884)
       at android.view.ViewGroup.addView(ViewGroup.java:5856)
       at com.braze.ui.inappmessage.DefaultInAppMessageViewWrapper.addInAppMessageViewToViewGroup(DefaultInAppMessageViewWrapper.java:265)
       at com.braze.ui.inappmessage.DefaultInAppMessageViewWrapper.open(DefaultInAppMessageViewWrapper.java:187)
       at com.braze.ui.inappmessage.BrazeInAppMessageManager.lambda$displayInAppMessage$1(BrazeInAppMessageManager.java:524)
       at com.braze.ui.inappmessage.BrazeInAppMessageManager.$r8$lambda$JBM1jMqq1GSlWV_bvsaShD6KOxY(BrazeInAppMessageManager.java)
       at com.braze.ui.inappmessage.BrazeInAppMessageManager$$InternalSyntheticLambda$0$4f9105367d06ca4d99a4f2fab2574eb47a459d6106c79edd3581c480fb1123ba$0.onPageFinished(BrazeInAppMessageManager.java:2)
       at com.braze.ui.inappmessage.utils.InAppMessageWebViewClient.markPageFinished(InAppMessageWebViewClient.kt:63)
       at com.braze.ui.inappmessage.utils.InAppMessageWebViewClient.access$markPageFinished(InAppMessageWebViewClient.kt:28)
       at com.braze.ui.inappmessage.utils.InAppMessageWebViewClient$setWebViewClientStateListener$1.invokeSuspend(InAppMessageWebViewClient.kt:104)
       at com.braze.ui.inappmessage.utils.InAppMessageWebViewClient$setWebViewClientStateListener$1.invoke(InAppMessageWebViewClient.kt:8)
       at com.braze.ui.inappmessage.utils.InAppMessageWebViewClient$setWebViewClientStateListener$1.invoke(InAppMessageWebViewClient.kt:2)
       at com.braze.coroutine.BrazeCoroutineScope$c.invokeSuspend(SourceFile:7)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
       at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
       at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)

Additional Information

No response

radixdev commented 2 years ago

Hi @olliwear ,

Thank you for filing. We're investigating this issue and should get back to you shortly.

radixdev commented 2 years ago

Hi @olliwear ,

We've identified a fix and will have it released in our next release.

olliwear commented 2 years ago

Hi @radixdev, thank you very much.

Could you provide a fix also for v20.0.0? We can't upgrade to v21.0.0 just now as we're not supporting target sdk 33 yet.

radixdev commented 2 years ago

Unfortunately we're not able to backport fixes to previous versions of the SDK at this time. The easiest mitigation you can do now is to change your value of maxOnPageFinishedWaitMs to something larger than 15 seconds (or whatever you have configured currently).

olliwear commented 2 years ago

Alright, I'll check it out. Thanks for your support @radixdev

edit: We've tried the solution @radixdev mentioned above, but unfortunately it didn't help. We'll downgrade to our previous version for now.

bryanlogan commented 2 years ago

Hi @olliwear,

We fixed this issue in 22.0.0. Please let us know if this fixes your issue.