[Libreoffice-commits] online.git: Branch 'distro/collabora/co-4-2-5' - android/lib

Jan Holesovsky (via logerrit) logerrit at kemper.freedesktop.org
Tue Jul 14 12:49:12 UTC 2020


 android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java |   31 +++++-----
 1 file changed, 18 insertions(+), 13 deletions(-)

New commits:
commit 1f0a184edd44c611ea93f71e4ccd5db70ba246ce
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Mon Jul 13 18:21:28 2020 +0200
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue Jul 14 14:48:52 2020 +0200

    android: Avoid calling methods of a destroyed WebView.
    
    Avoids exceptions like:
    
    2020-07-13 13:19:49.607 2919-2919/? I/LOActivity: Forwarding to the WebView: 'statusindicatorsetvalue: 86'
    2020-07-13 13:19:49.609 2919-2919/? W/cr_AwContents: Application attempted to call on a destroyed WebView
        java.lang.Throwable
            at org.chromium.android_webview.AwContents.t(chromium-SystemWebViewGoogle.apk-stable-410410651:2)
            at com.android.webview.chromium.WebViewChromium.loadUrl(chromium-SystemWebViewGoogle.apk-stable-410410651:11)
            at android.webkit.WebView.loadUrl(WebView.java:970)
            at org.libreoffice.androidlib.LOActivity$6.run(LOActivity.java:794)
            at android.os.Handler.handleCallback(Handler.java:873)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:193)
            at android.app.ActivityThread.main(ActivityThread.java:6971)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:865)
    
    Change-Id: Ic853131bac937deec7e68723b956a4ab7cf61872
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98723
    Tested-by: Michael Meeks <michael.meeks at collabora.com>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
index 855fa63b0..5fb44fa97 100644
--- a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
+++ b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
@@ -101,7 +101,7 @@ public class LOActivity extends AppCompatActivity {
     private URI documentUri;
 
     private String urlToLoad;
-    private WebView mWebView;
+    private WebView mWebView = null;
     private SharedPreferences sPrefs;
     private Handler mMainHandler = null;
     private RateAppController rateAppController;
@@ -544,6 +544,7 @@ public class LOActivity extends AppCompatActivity {
         if (viewGroup != null)
             viewGroup.removeView(mWebView);
         mWebView.destroy();
+        mWebView = null;
 
         // Most probably the native part has already got a 'BYE' from
         // finishWithProgress(), but it is actually better to send it twice
@@ -780,20 +781,24 @@ public class LOActivity extends AppCompatActivity {
      */
     void callFakeWebsocketOnMessage(final String message) {
         // call from the UI thread
-        mWebView.post(new Runnable() {
-            public void run() {
-                Log.i(TAG, "Forwarding to the WebView: " + message);
+        if (mWebView != null)
+            mWebView.post(new Runnable() {
+                public void run() {
+                    if (mWebView != null)
+                        Log.i(TAG, "Skipped forwarding to the WebView: " + message);
 
-                /* Debug only: in case the message is too long, truncated in the logcat, and you need to see it.
-                final int size = 80;
-                for (int start = 0; start < message.length(); start += size) {
-                    Log.i(TAG, "split: " + message.substring(start, Math.min(message.length(), start + size)));
-                }
-                */
+                    Log.i(TAG, "Forwarding to the WebView: " + message);
 
-                mWebView.loadUrl("javascript:window.TheFakeWebSocket.onmessage({'data':" + message + "});");
-            }
-        });
+                    /* Debug only: in case the message is too long, truncated in the logcat, and you need to see it.
+                    final int size = 80;
+                    for (int start = 0; start < message.length(); start += size) {
+                        Log.i(TAG, "split: " + message.substring(start, Math.min(message.length(), start + size)));
+                    }
+                    */
+
+                    mWebView.loadUrl("javascript:window.TheFakeWebSocket.onmessage({'data':" + message + "});");
+                }
+            });
 
         // update progress bar when loading
         if (message.startsWith("'statusindicator") || message.startsWith("'error:")) {


More information about the Libreoffice-commits mailing list