From 0411a287b8ec54c42d17fa09f27d2c67b2432685 Mon Sep 17 00:00:00 2001 From: Alex Yaz Date: Tue, 26 Mar 2019 10:46:49 -0400 Subject: [PATCH 1/2] (android) defensive code to prevent NULL reference exceptions for async Signed-off-by: Niklas Merz --- src/android/InAppBrowser.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index 87df9d230..c35f3e873 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -313,7 +313,9 @@ else if (action.equals("show")) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { - dialog.show(); + if(dialog != null){ + dialog.show(); + } } }); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); @@ -324,7 +326,9 @@ else if (action.equals("hide")) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { - dialog.hide(); + if(dialog != null){ + dialog.hide(); + } } }); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); @@ -1066,12 +1070,16 @@ public void postMessage(String data) { lp.height = WindowManager.LayoutParams.MATCH_PARENT; dialog.setContentView(main); - dialog.show(); + if(dialog != null){ + dialog.show(); + } dialog.getWindow().setAttributes(lp); // the goal of openhidden is to load the url and not display it // Show() needs to be called to cause the URL to be loaded if(openWindowHidden) { - dialog.hide(); + if(dialog != null){ + dialog.hide(); + } } } }; From d4338bd64ac599dfec4aeec6d02c3ccccd3ecaec Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Thu, 2 Jan 2020 19:53:36 +0100 Subject: [PATCH 2/2] (android) improve defensive code for NULL check --- src/android/InAppBrowser.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index c35f3e873..84144389f 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -313,7 +313,7 @@ else if (action.equals("show")) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { - if(dialog != null){ + if (dialog != null) { dialog.show(); } } @@ -326,7 +326,7 @@ else if (action.equals("hide")) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { - if(dialog != null){ + if (dialog != null) { dialog.hide(); } } @@ -1069,17 +1069,15 @@ public void postMessage(String data) { lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; - dialog.setContentView(main); - if(dialog != null){ + if (dialog != null) { + dialog.setContentView(main); dialog.show(); + dialog.getWindow().setAttributes(lp); } - dialog.getWindow().setAttributes(lp); // the goal of openhidden is to load the url and not display it // Show() needs to be called to cause the URL to be loaded - if(openWindowHidden) { - if(dialog != null){ - dialog.hide(); - } + if (openWindowHidden && dialog != null) { + dialog.hide(); } } };