[Libreoffice-commits] core.git: android/source

Christian Lohmaier (via logerrit) logerrit at kemper.freedesktop.org
Tue Nov 19 10:56:12 UTC 2019


 android/source/src/java/org/libreoffice/LOKitTileProvider.java       |    4 +++-
 android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java |    4 ++--
 2 files changed, 5 insertions(+), 3 deletions(-)

New commits:
commit 7de3b4bc881671692d15cfc93a4c887ed77b6c64
Author:     Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>
AuthorDate: Fri Nov 8 16:41:42 2019 +0100
Commit:     Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>
CommitDate: Tue Nov 19 11:55:24 2019 +0100

    android: avoid NPE when trying to create cache file
    
    when the user wildly switches documents in fast succession, mDocument
    can be null - not creating a cache file definitely is better than a hard
    crash....
    
    Also onSaveInstanceState is meant for lightweight operations (e.g.
    storing what file was openend and what position it was scrolled to), not
    for backend-storing of data, so move creation of cache file to onStop
    instead.
    
    Change-Id: I2452ef24e309ea4a9594eb723e893798b9b47d98
    Reviewed-on: https://gerrit.libreoffice.org/82774
    Tested-by: Jenkins
    Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>

diff --git a/android/source/src/java/org/libreoffice/LOKitTileProvider.java b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
index 65de28fe884e..0e2649337322 100644
--- a/android/source/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
@@ -406,8 +406,10 @@ class LOKitTileProvider implements TileProvider {
         Log.i(LOGTAG, "cacheDocument: " + cacheFile);
         if(isDocumentCached()){
             LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Save"));
-        }else{
+        }else if(mDocument != null){
             mDocument.saveAs("file://"+cacheFile, FileUtilities.getExtension(input.getPath()).substring(1),"");
+        }else{
+            Log.w(LOGTAG, "mDocument was null when trying to save cacheDocument: " + cacheFile);
         }
     }
 
diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 032a8461a01b..628305d01f13 100644
--- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -423,6 +423,8 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
     @Override
     protected void onStop() {
         Log.i(LOGTAG, "onStop..");
+        //save document to cache
+        mTileProvider.cacheDocument();
         hideSoftKeyboardDirect();
         LOKitShell.sendCloseEvent();
         super.onStop();
@@ -970,8 +972,6 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
     @Override
     protected void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
-        //save document to cache
-        mTileProvider.cacheDocument();
     }
 
 }


More information about the Libreoffice-commits mailing list