apache / apache/cordova-plugin-inappbrowser

[InAppBrowser]Fatal Exception occured due to "not attached to window" on AndroidP

Open
#893 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.1k
Forks
2.2k
PR merge metrics
No merged PRs in 30d

Description

Steps to reproduce:
1. Open InAppBrowser on cordova app.
2. Move to Settings.
3. Setting > Display > Display size. Then change display size.
4. Resume cordova app.
Then, App is crashed by fatal exception.

```
Process: com.myapp, PID: 18768
java.lang.IllegalArgumentException: View=DecorView@fb121f3[MainActivity] not attached to window manager
at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:497)
at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:406)
at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:138)
at android.app.Dialog.dismissDialog(Dialog.java:375)
at android.app.Dialog.dismiss(Dialog.java:358)
at org.apache.cordova.inappbrowser.InAppBrowser$5$1.onPageFinished(Unknown Source:18)
at xf.c(SourceFile:251)
at afs.handleMessage(SourceFile:72)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6813)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:522)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:889)
```
I think MainActivity have been destroyed and dialog is detacched when Display size is changed.
But InAppBrowser still have old dialog and try to dismiss() when app is resumed.
my-app\plugins\cordova-plugin-inappbrowser\src\android\InAppBrowser.java
```
public void closeDialog() {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
final WebView childView = inAppWebView;
// The JS protects against multiple calls, so this should happen only when
// closeDialog() is called by other native code.
if (childView == null) {
return;
}

childView.setWebViewClient(new WebViewClient() {
// NB: wait for about:blank before dismissing
public void onPageFinished(WebView view, String url) {
if (dialog != null) {
dialog.dismiss(); //!!!dialog is not attached to window
dialog = null;
}
}
});
```

This issue is not reproduced on Android O.
(onPageFinished is not called on Android O, So dialog.dismiss() is not called.)

Contributor guide

Open the contributing guide

Research direction

Start in src/android/InAppBrowser.java, especially closeDialog() and its onPageFinished handler. Reproduce the Android P display-size change sequence and inspect how the dialog relates to the destroyed activity. Done means resuming after the configuration change no longer produces the “not attached to window manager” fatal exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.