[Libreoffice-commits] online.git: android/lib kit/Kit.cpp kit/Kit.hpp

Tor Lillqvist (via logerrit) logerrit at kemper.freedesktop.org
Tue Apr 21 11:44:06 UTC 2020


 android/lib/src/main/cpp/androidapp.cpp |   20 ++++++++++----------
 kit/Kit.cpp                             |   26 ++++++++++++++++++++------
 kit/Kit.hpp                             |    6 ++++--
 3 files changed, 34 insertions(+), 18 deletions(-)

New commits:
commit b94fb53d4d52bf3f847025aebbebe0383c41ffc8
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Tue Apr 21 13:42:24 2020 +0300
Commit:     Tor Lillqvist <tml at collabora.com>
CommitDate: Tue Apr 21 13:43:43 2020 +0200

    tdf#128502: Make _loKitDocument in class Document non-static again
    
    It was made static in ea2b77ce07d615e72c29b7016b464a9147373805 for
    Android's sake, so returning it to be per-instance is not a big thing.
    
    Keep a separate static just for the Android app's use for now, while
    the Android app supports just one open document at a time anyway. (It
    is for the iOS app that I am moving towards supporting multiple open
    documents at a time.)
    
    Change-Id: I7fabeb21883eb7cd7155e880eb4cc0413124d1f8
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92625
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Tor Lillqvist <tml at collabora.com>

diff --git a/android/lib/src/main/cpp/androidapp.cpp b/android/lib/src/main/cpp/androidapp.cpp
index defe7b628..a3f847135 100644
--- a/android/lib/src/main/cpp/androidapp.cpp
+++ b/android/lib/src/main/cpp/androidapp.cpp
@@ -340,7 +340,7 @@ Java_org_libreoffice_androidlib_LOActivity_saveAs(JNIEnv *env, jobject instance,
     const char *fileUri = env->GetStringUTFChars(fileUri_, 0);
     const char *format = env->GetStringUTFChars(format_, 0);
 
-    getLOKDocument()->saveAs(fileUri, format, nullptr);
+    getLOKDocumentForAndroidOnly()->saveAs(fileUri, format, nullptr);
 
     env->ReleaseStringUTFChars(fileUri_, fileUri);
     env->ReleaseStringUTFChars(format_, format);
@@ -356,7 +356,7 @@ Java_org_libreoffice_androidlib_LOActivity_postUnoCommand(JNIEnv* pEnv, jobject
     if (arguments != nullptr)
         pArguments = pEnv->GetStringUTFChars(arguments, nullptr);
 
-    getLOKDocument()->postUnoCommand(pCommand, pArguments, bNotifyWhenFinished);
+    getLOKDocumentForAndroidOnly()->postUnoCommand(pCommand, pArguments, bNotifyWhenFinished);
 
     pEnv->ReleaseStringUTFChars(command, pCommand);
     if (arguments != nullptr)
@@ -402,9 +402,9 @@ Java_org_libreoffice_androidlib_LOActivity_getClipboardContent(JNIEnv *env, jobj
     jclass class_LokClipboardData = env->GetObjectClass(lokClipboardData);
     jfieldID fieldId_LokClipboardData_clipboardEntries = env->GetFieldID(class_LokClipboardData , "clipboardEntries", "Ljava/util/ArrayList;");
 
-    if (getLOKDocument()->getClipboard(mimeTypes,
-                                       &outCount, &outMimeTypes,
-                                       &outSizes, &outStreams))
+    if (getLOKDocumentForAndroidOnly()->getClipboard(mimeTypes,
+                                                     &outCount, &outMimeTypes,
+                                                     &outSizes, &outStreams))
     {
         // return early
         if (outCount == 0)
@@ -440,9 +440,9 @@ Java_org_libreoffice_androidlib_LOActivity_getClipboardContent(JNIEnv *env, jobj
 
     const char* mimeTypesHTML[] = { "text/plain;charset=utf-8", "text/html", nullptr };
 
-    if (getLOKDocument()->getClipboard(mimeTypesHTML,
-                                       &outCount, &outMimeTypes,
-                                       &outSizes, &outStreams))
+    if (getLOKDocumentForAndroidOnly()->getClipboard(mimeTypesHTML,
+                                                     &outCount, &outMimeTypes,
+                                                     &outSizes, &outStreams))
     {
         // return early
         if (outCount == 0)
@@ -522,7 +522,7 @@ Java_org_libreoffice_androidlib_LOActivity_setClipboardContent(JNIEnv *env, jobj
         pStreams[nEntryIndex] = dataArray;
     }
 
-    getLOKDocument()->setClipboard(nEntrySize, pMimeTypes, pSizes, pStreams);
+    getLOKDocumentForAndroidOnly()->setClipboard(nEntrySize, pMimeTypes, pSizes, pStreams);
 }
 
 extern "C"
@@ -533,7 +533,7 @@ Java_org_libreoffice_androidlib_LOActivity_paste(JNIEnv *env, jobject instance,
     size_t dataArrayLength = env->GetArrayLength(inData);
     char* dataArray = new char[dataArrayLength];
     env->GetByteArrayRegion(inData, 0, dataArrayLength, reinterpret_cast<jbyte*>(dataArray));
-    getLOKDocument()->paste(mimeType, dataArray, dataArrayLength);
+    getLOKDocumentForAndroidOnly()->paste(mimeType, dataArray, dataArrayLength);
     env->ReleaseStringUTFChars(inMimeType, mimeType);
 }
 
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index 142392f6e..a34b91334 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -1427,6 +1427,9 @@ private:
                     _sessions.size() << " sessions still. Destroying the document.");
 #ifdef IOS
             lok_document = nullptr;
+#endif
+#ifdef __ANDROID__
+            _loKitDocumentForAndroidOnly.reset();
 #endif
             _loKitDocument.reset();
             LOG_INF("Document [" << anonymizeUrl(_url) << "] session [" << sessionId << "] unloaded Document.");
@@ -1661,6 +1664,9 @@ private:
             LOG_DBG("Calling lokit::documentLoad(" << FileUtil::anonymizeUrl(pURL) << ", \"" << options << "\").");
             const auto start = std::chrono::system_clock::now();
             _loKitDocument.reset(_loKit->documentLoad(pURL, options.c_str()));
+#ifdef __ANDROID__
+            _loKitDocumentForAndroidOnly = _loKitDocument;
+#endif
             const auto duration = std::chrono::system_clock::now() - start;
             const auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(duration).count();
             const double totalTime = elapsed/1000.;
@@ -2056,7 +2062,10 @@ private:
     std::string _jailedUrl;
     std::string _renderOpts;
 
-    static std::shared_ptr<lok::Document> _loKitDocument;
+    std::shared_ptr<lok::Document> _loKitDocument;
+#ifdef __ANDROID__
+    static std::shared_ptr<lok::Document> _loKitDocumentForAndroidOnly;
+#endif
     std::shared_ptr<TileQueue> _tileQueue;
     std::shared_ptr<WebSocketHandler> _websocketHandler;
 
@@ -2089,17 +2098,22 @@ private:
     /// For showing disconnected user info in the doc repair dialog.
     std::map<int, UserInfo> _sessionUserInfo;
     std::chrono::steady_clock::time_point _lastMemStatsTime;
-
-    friend std::shared_ptr<lok::Document> getLOKDocument();
+#ifdef __ANDROID__
+    friend std::shared_ptr<lok::Document> getLOKDocumentForAndroidOnly();
+#endif
 };
 
-std::shared_ptr<lok::Document> Document::_loKitDocument = std::shared_ptr<lok::Document>();
+#ifdef __ANDROID__
+
+std::shared_ptr<lok::Document> Document::_loKitDocumentForAndroidOnly = std::shared_ptr<lok::Document>();
 
-std::shared_ptr<lok::Document> getLOKDocument()
+std::shared_ptr<lok::Document> getLOKDocumentForAndroidOnly()
 {
-    return Document::_loKitDocument;
+    return Document::_loKitDocumentForAndroidOnly;
 }
 
+#endif
+
 class KitSocketPoll : public SocketPoll
 {
     std::chrono::steady_clock::time_point _pollEnd;
diff --git a/kit/Kit.hpp b/kit/Kit.hpp
index b100fd674..1e60fdd3a 100644
--- a/kit/Kit.hpp
+++ b/kit/Kit.hpp
@@ -139,7 +139,9 @@ std::string anonymizeUrl(const std::string& url);
 /// Anonymize usernames.
 std::string anonymizeUsername(const std::string& username);
 
-/// For the mobile, we need access to the document to perform eg. saveAs() for printing.
-std::shared_ptr<lok::Document> getLOKDocument();
+#ifdef __ANDROID__
+/// For the Android app, for now, we need access to the one and only document open to perform eg. saveAs() for printing.
+std::shared_ptr<lok::Document> getLOKDocumentForAndroidOnly();
+#endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list