1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 05:16:51 +01:00

Webview: make the webview more robust to disconnections

This commit is contained in:
Daniele Gobbetti 2017-09-03 17:55:00 +02:00
parent b8a137226f
commit df2a313168

View File

@ -100,9 +100,6 @@ public class WebViewSingleton {
webSettings.setDomStorageEnabled(true); webSettings.setDomStorageEnabled(true);
//needed for localstorage //needed for localstorage
webSettings.setDatabaseEnabled(true); webSettings.setDatabaseEnabled(true);
Intent intent = new Intent();
intent.setComponent(new ComponentName("nodomain.freeyourgadget.internethelper", "nodomain.freeyourgadget.internethelper.MyService"));
context.getApplicationContext().bindService(intent, internetHelperConnection, Context.BIND_AUTO_CREATE);
} }
return webViewSingleton.instance; return webViewSingleton.instance;
} }
@ -165,11 +162,17 @@ public class WebViewSingleton {
new Handler(webViewSingleton.mainLooper).post(new Runnable() { new Handler(webViewSingleton.mainLooper).post(new Runnable() {
@Override @Override
public void run() { public void run() {
webViewSingleton.instance.onResume();
webViewSingleton.instance.removeJavascriptInterface("GBjs"); webViewSingleton.instance.removeJavascriptInterface("GBjs");
webViewSingleton.instance.addJavascriptInterface(jsInterface, "GBjs"); webViewSingleton.instance.addJavascriptInterface(jsInterface, "GBjs");
webViewSingleton.instance.loadUrl("file:///android_asset/app_config/configure.html?rand=" + Math.random() * 500); webViewSingleton.instance.loadUrl("file:///android_asset/app_config/configure.html?rand=" + Math.random() * 500);
} }
}); });
if (!internetHelperBound) {
Intent intent = new Intent();
intent.setComponent(new ComponentName("nodomain.freeyourgadget.internethelper", "nodomain.freeyourgadget.internethelper.MyService"));
webViewSingleton.contextWrapper.getApplicationContext().bindService(intent, internetHelperConnection, Context.BIND_AUTO_CREATE);
}
} }
} }
@ -215,13 +218,16 @@ public class WebViewSingleton {
if (internetHelperBound) { if (internetHelperBound) {
LOG.debug("WEBVIEW: will unbind the internet helper"); LOG.debug("WEBVIEW: will unbind the internet helper");
webViewSingleton.contextWrapper.getApplicationContext().unbindService(internetHelperConnection); webViewSingleton.contextWrapper.getApplicationContext().unbindService(internetHelperConnection);
internetHelperBound = false;
} }
currentRunningUUID = null;
new Handler(webViewSingleton.mainLooper).post(new Runnable() { new Handler(webViewSingleton.mainLooper).post(new Runnable() {
@Override @Override
public void run() { public void run() {
if (webViewSingleton.instance != null) { if (webViewSingleton.instance != null) {
webViewSingleton.instance.setWebChromeClient(null); webViewSingleton.instance.removeJavascriptInterface("GBjs");
webViewSingleton.instance.setWebViewClient(null); // webViewSingleton.instance.setWebChromeClient(null);
// webViewSingleton.instance.setWebViewClient(null);
webViewSingleton.instance.clearHistory(); webViewSingleton.instance.clearHistory();
webViewSingleton.instance.clearCache(true); webViewSingleton.instance.clearCache(true);
webViewSingleton.instance.loadUrl("about:blank"); webViewSingleton.instance.loadUrl("about:blank");