TruckMovers / cordova-plugin-remote-injection

DEPRECATED: Cordova plugin to allow a remote site to interact with cordova's javascript APIs when loaded within a cordova app.
Apache License 2.0
91 stars 95 forks source link

android.view.WindowManager$BadTokenException crashes #31

Open mikeiomo opened 7 years ago

mikeiomo commented 7 years ago

Hi,

while using the plugin for my app I noticed many crashes from the play console, the error was always this:

android.view.WindowManager$BadTokenException com.truckmovers.cordova.RemoteInjectionPlugin$UserPromptTask$1.run

details:

android.view.WindowManager$BadTokenException: at android.view.ViewRootImpl.setView(ViewRootImpl.java:685) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:328) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85) at android.app.Dialog.show(Dialog.java:325) at com.truckmovers.cordova.RemoteInjectionPlugin$UserPromptTask$1.run(RemoteInjectionPlugin.java:312) at android.os.Handler.handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5777) at java.lang.reflect.Method.invoke(Native Method:0) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

I am using CrossWalk as webview, could this be in any way related?

bradleyjames commented 7 years ago

I'm not sure but the plugin has issues on CrossWalk. According to this SO post this plugin is instantiating the dialog correctly.

netmikey commented 7 years ago

Same problem here.

@bradleyjames you seem to be correlating these type of crashes with the use of crosswalk, but isn't it weird then that crosswalk doesn't show up in the call stack?

ekleop commented 6 years ago

We don't use crosswalk(native webview) but have the same issue. So maybe it's not related to CrossWalk?

fmp777 commented 6 years ago

We have the same issue too, no crosswalk. Quite a simple app really.

android.view.WindowManager$BadTokenException: at android.view.ViewRootImpl.setView (ViewRootImpl.java:702) at android.view.WindowManagerGlobal.addView (WindowManagerGlobal.java:342) at android.view.WindowManagerImpl.addView (WindowManagerImpl.java:94) at android.app.Dialog.show (Dialog.java:337) at com.truckmovers.cordova.RemoteInjectionPlugin$UserPromptTask$1.run (RemoteInjectionPlugin.java:312) at android.os.Handler.handleCallback (Handler.java:751) at android.os.Handler.dispatchMessage (Handler.java:95) at android.os.Looper.loop (Looper.java:154) at android.app.ActivityThread.main (ActivityThread.java:6247) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:872) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:762)

Crash by android version: image

fkoester commented 6 years ago

Have the same error, also not using CrossWalk.

chasefinch commented 6 years ago

Same issue, no CrossWalk. Anyone find a solution?

fmp777 commented 6 years ago

image

Still a serious issue, has anyone figured out how to reproduce?

I'm thinking it has something to do with "cannot contact site" error which likes to trigger the dialog which is the thing that seems to be crashing the app because android.app.Dialog.show is not working.

Which means maybe use of

and error.html might work around the problem?

I think the only fix is to update this repository to use new Dialog code

fmp777 commented 6 years ago

Its only happening when the timeout occurs during the http request to the remote site. difficult to simulate as disabling network drops directly to error.html in my case.

I dont know if its just that the Android Dialog is not getting created properly, but here is a plugin that does dialogs to get reference: https://github.com/apache/cordova-plugin-dialogs/blob/master/src/android/Notification.java

@bradleyjames any chance on this one?

zsoltboldizsar commented 4 years ago

@fmp777 this issue has been fixed with #40 but it didn't end up in master on this repository. I've added it to my fork https://github.com/zsoltboldizsar/cordova-plugin-remote-injection so anyone could directly benefit from it.

As for the fix itself, it was applied to an app I have worked on last year with +30k active users to day and there's no sign of this crash since. Hope it will help anyone coming here.