android/source/src/java/org/libreoffice/LOKitThread.java |   13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

New commits:
commit 4476fd51a324930e832535c10979564afc6968f2
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Apr 13 12:59:08 2022 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Apr 13 18:22:49 2022 +0200

    tdf#148556 android: Don't delay refresh when loading doc
    
    The previous way of using a separate Runnable
    to do the refresh and posting that to the
    main handler instead of doing the refresh
    right away resulted in a timing issue, due
    to which it could happen that a Calc document
    would not be rendered when initally loaded
    (but only after another tile reevaluation was
    triggered, e.g. by tapping on the screen).
    
    While this appears to happen mostly on fast hardware,
    I could reproduce on my AVD as well when increasing
    the minimum time that has to pass between
    tile reevaluations to 100 ms:
    
        --- 
a/android/source/src/java/org/mozilla/gecko/gfx/ComposedTileLayer.java
        +++ 
b/android/source/src/java/org/mozilla/gecko/gfx/ComposedTileLayer.java
        @@ -157,7 +157,7 @@ public abstract class ComposedTileLayer extends 
Layer implements ComponentCallba
                 }
    
                 long currentReevaluationNanoTime = System.nanoTime();
        -        if ((currentReevaluationNanoTime - reevaluationNanoTime) < 25 
* 1000000) {
        +        if ((currentReevaluationNanoTime - reevaluationNanoTime) < 100 
* 1000000) {
                     return;
                 }
    
    For the bad case, the Runnable that triggers the
    refresh would be taken from the message queue and
    run on the main thread at a point in time that
    resulted in `LOKitShell.sendTileReevaluationRequest`
    not getting called in `ComposedTileLayer#reevaluateTiles`
    due to the above-mentioned minimum time in between
    tile reevaluations.
    
    Avoid the problem and simplify the whole handling by
    no longer posting a Runnable to the main handler, but
    calling `refresh()` right away.
    
    Posting to the main handler had been introduced in
    
        commit 27326e0f587c20d8dcf1595829233de1bd3fbe9e
        Date:   Fri Aug 3 07:13:00 2018 -0700
    
            tdf#119082 Exception wrong thread on Android Viewer
    
    to avoid crashes due to things being done on the wrong thread
    when switching to another app and then back to Android Viewer
    (s. tdf#119082), but that is no longer a problem, because the
    document is no longer loaded anew in that case since
    
        commit 1bc42472200c32c9a0a10dd1c3cd6c6a8a5d47d2
        Date:   Fri Apr 9 13:59:43 2021 +0200
    
            tdf#95517 android: Rework app/doc lifecycle handling
    
    , so the code path is not used there any more, but only when
    the document is initially loaded, triggered in
    `LibreOfficeMainActivity#onCreate`.
    
    After all, the problem seems to be a similar one as fixed in
    
        commit 128f67e0efa02294205a1abe1be874557ecdcecd
        Date:   Tue May 18 14:27:51 2021 +0200
    
            tdf#142348 android: Avoid extra refresh after loading doc
    
    , where another timing issue in the handling of a refresh event could
    result in a blank page instead of the Calc doc being rendered.
    
    With the refresh being done right away, the synchronization added
    in
    
        commit 55661298bb3e9087a89a08637e4285f090c4e0e8
        Date:   Wed Apr 1 09:00:13 2020 +0200
    
            tdf#131195 android: Don't destroy doc while loading it
    
    is also no more needed, because the situation described in its
    commit message no longer applies:
    
    > Since the 'refresh()' in 'LOKitThread::loadDocument' is
    > not executed synchronously but posted to the main handler,
    > this needs to be synchronized to prevent the document from
    > being deleted while it's being used.
    
    Change-Id: I15ecc2eba6c5ee441f6e14f8229594cab05dbba7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132965
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/android/source/src/java/org/libreoffice/LOKitThread.java 
b/android/source/src/java/org/libreoffice/LOKitThread.java
index a4d5ba99f1a2..b4aee40c1cd3 100644
--- a/android/source/src/java/org/libreoffice/LOKitThread.java
+++ b/android/source/src/java/org/libreoffice/LOKitThread.java
@@ -214,15 +214,7 @@ class LOKitThread extends Thread {
         if (mTileProvider.isReady()) {
             LOKitShell.showProgressSpinner(mContext);
             updateZoomConstraints();
-            LOKitShell.getMainHandler().post(new Runnable() {
-                @Override
-                public void run() {
-                    // synchronize to avoid deletion while loading
-                    synchronized (LOKitThread.this) {
-                        refresh(true);
-                    }
-                }
-            });
+            refresh(true);
             LOKitShell.hideProgressSpinner(mContext);
         } else {
             closeDocument();
@@ -266,8 +258,7 @@ class LOKitThread extends Thread {
     /**
      * Close the currently loaded document.
      */
-    // needs to be synchronized to not destroy doc while it's loaded
-    private synchronized void closeDocument() {
+    private void closeDocument() {
         if (mTileProvider != null) {
             mTileProvider.close();
             mTileProvider = null;

Reply via email to