From 0dae71f4b7edc4da160cca2ee1fd4eaa52eb8d49 Mon Sep 17 00:00:00 2001 From: adbenitez Date: Thu, 19 Dec 2024 15:48:57 +0100 Subject: [PATCH 1/4] try to avoid FILL500 getting stuck in some devices --- .../org/thoughtcrime/securesms/WebxdcActivity.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java b/src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java index dc8589999..8d1676bf9 100644 --- a/src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java +++ b/src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java @@ -67,6 +67,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE private static final String EXTRA_HIDE_ACTION_BAR = "hideActionBar"; private static final String EXTRA_HREF = "href"; private static final int REQUEST_CODE_FILE_PICKER = 51426; + private static long lastOpenTime = 0; private ValueCallback filePathCallback; private DcContext dcContext; @@ -233,7 +234,16 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE e.printStackTrace(); } - webView.loadUrl(this.baseURL + "/webxdc_bootstrap324567869.html?i=" + (internetAccess? "1" : "0") + "&href=" + encodedHref); + long now = System.currentTimeMillis(); + long timeDelta = now - lastOpenTime; + lastOpenTime = now; + final String url = this.baseURL + "/webxdc_bootstrap324567869.html?i=" + (internetAccess? "1" : "0") + "&href=" + encodedHref; + Util.runOnAnyBackgroundThread(() -> { + if (timeDelta < 2000) Util.sleep(1000); + Util.runOnMain(() -> { + webView.loadUrl(url); + }); + }); Util.runOnAnyBackgroundThread(() -> { final DcChat chat = dcContext.getChat(dcAppMsg.getChatId()); From 7a4913b394da5f0e92b2b1c9c36ba6241b28042b Mon Sep 17 00:00:00 2001 From: adbenitez Date: Thu, 19 Dec 2024 15:52:16 +0100 Subject: [PATCH 2/4] tweak code --- .../java/org/thoughtcrime/securesms/WebxdcActivity.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java b/src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java index 8d1676bf9..5d98c4bab 100644 --- a/src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java +++ b/src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java @@ -239,10 +239,8 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE lastOpenTime = now; final String url = this.baseURL + "/webxdc_bootstrap324567869.html?i=" + (internetAccess? "1" : "0") + "&href=" + encodedHref; Util.runOnAnyBackgroundThread(() -> { - if (timeDelta < 2000) Util.sleep(1000); - Util.runOnMain(() -> { - webView.loadUrl(url); - }); + if (timeDelta < 2000) {Util.sleep(1000);} + Util.runOnMain(() -> webView.loadUrl(url)); }); Util.runOnAnyBackgroundThread(() -> { From 291700dfc7f351bad57ca9eea5ff5880ac30e2e6 Mon Sep 17 00:00:00 2001 From: adbenitez Date: Thu, 19 Dec 2024 16:30:58 +0100 Subject: [PATCH 3/4] update lastOpenTime in onDestroy() --- src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java b/src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java index 5d98c4bab..7211dc525 100644 --- a/src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java +++ b/src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java @@ -234,9 +234,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE e.printStackTrace(); } - long now = System.currentTimeMillis(); - long timeDelta = now - lastOpenTime; - lastOpenTime = now; + long timeDelta = System.currentTimeMillis() - lastOpenTime; final String url = this.baseURL + "/webxdc_bootstrap324567869.html?i=" + (internetAccess? "1" : "0") + "&href=" + encodedHref; Util.runOnAnyBackgroundThread(() -> { if (timeDelta < 2000) {Util.sleep(1000);} @@ -265,6 +263,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE @Override protected void onDestroy() { + lastOpenTime = System.currentTimeMillis(); DcHelper.getEventCenter(this.getApplicationContext()).removeObservers(this); leaveRealtimeChannel(); super.onDestroy(); From eb93e2bb7e56daeac6a65aa596cfdd9261a9b426 Mon Sep 17 00:00:00 2001 From: adbenitez Date: Thu, 19 Dec 2024 16:39:52 +0100 Subject: [PATCH 4/4] add comment --- .../java/org/thoughtcrime/securesms/WebxdcActivity.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java b/src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java index 7211dc525..703bdbeaf 100644 --- a/src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java +++ b/src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java @@ -237,7 +237,11 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE long timeDelta = System.currentTimeMillis() - lastOpenTime; final String url = this.baseURL + "/webxdc_bootstrap324567869.html?i=" + (internetAccess? "1" : "0") + "&href=" + encodedHref; Util.runOnAnyBackgroundThread(() -> { - if (timeDelta < 2000) {Util.sleep(1000);} + if (timeDelta < 2000) { + // this is to avoid getting stuck in the FILL500 in some devices if the + // previous webview was not destroyed yet and a new app is opened too soon + Util.sleep(1000); + } Util.runOnMain(() -> webView.loadUrl(url)); });