[Libreoffice-commits] core.git: Branch 'feature/droid_calcimpress3' - 6 commits - android/Bootstrap android/experimental desktop/source sal/android solenv/bin

Tomaž Vajngerl tomaz.vajngerl at collabora.com
Mon Nov 17 01:52:23 PST 2014


 android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java              |   14 -
 android/Bootstrap/src/org/libreoffice/kit/Document.java                           |    4 
 android/Bootstrap/src/org/libreoffice/kit/LibreOfficeKit.java                     |   33 +--
 android/Bootstrap/src/org/libreoffice/kit/Office.java                             |   12 -
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java   |   53 +++---
 android/experimental/LOAndroid3/src/java/org/libreoffice/TileProviderFactory.java |    2 
 desktop/source/lib/init.cxx                                                       |   87 +++++++---
 desktop/source/lib/lokandroid.cxx                                                 |   24 --
 sal/android/libreofficekit-jni.c                                                  |    8 
 solenv/bin/native-code.py                                                         |    4 
 10 files changed, 143 insertions(+), 98 deletions(-)

New commits:
commit 9bb1d121a822ca18aff83966f13e393d6fa639ba
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Mon Nov 17 10:47:02 2014 +0100

    android: use ByteBuffer to send or store pointers in JNI bindings
    
    Using direct ByteBuffer is much nicer option to store or send
    pointers between C(++) code and Java via JNI as it handles endiness
    and pointer size for us. Using "long" type can have unexpected
    results in 32-bit architectures (mostly Android). This was causing
    grief especially when Android introduced support for 64-bit
    architectures starting with SDK 19.
    
    Change-Id: Ie92d0f913b668e1724e846d70d1820445d9cb086

diff --git a/android/Bootstrap/src/org/libreoffice/kit/Document.java b/android/Bootstrap/src/org/libreoffice/kit/Document.java
index 52b9bfd..aad4d5a 100644
--- a/android/Bootstrap/src/org/libreoffice/kit/Document.java
+++ b/android/Bootstrap/src/org/libreoffice/kit/Document.java
@@ -24,9 +24,9 @@ public class Document {
     public static final int DOCTYPE_DRAWING = 3;
     public static final int DOCTYPE_OTHER = 4;
 
-    private final long handle;
+    private final ByteBuffer handle;
 
-    public Document(long handle) {
+    public Document(ByteBuffer handle) {
         this.handle = handle;
     }
 
diff --git a/android/Bootstrap/src/org/libreoffice/kit/LibreOfficeKit.java b/android/Bootstrap/src/org/libreoffice/kit/LibreOfficeKit.java
index 4fe2061..2a60f84 100644
--- a/android/Bootstrap/src/org/libreoffice/kit/LibreOfficeKit.java
+++ b/android/Bootstrap/src/org/libreoffice/kit/LibreOfficeKit.java
@@ -14,6 +14,7 @@ import android.content.pm.ApplicationInfo;
 import android.util.Log;
 
 import java.io.InputStream;
+import java.nio.ByteBuffer;
 
 // Native methods in this class are all implemented in
 // sal/android/lo-bootstrap.c as the lo-bootstrap library is loaded with
@@ -34,7 +35,7 @@ public final class LibreOfficeKit
     // Trigger initialization on the JNI - LOKit side.
     private static native boolean initializeNative(String dataDir, String cacheDir, String apkFile);
 
-    public static native long getLibreOfficeKitHandle();
+    public static native ByteBuffer getLibreOfficeKitHandle();
 
     // Wrapper for putenv()
     public static native void putenv(String string);
diff --git a/android/Bootstrap/src/org/libreoffice/kit/Office.java b/android/Bootstrap/src/org/libreoffice/kit/Office.java
index bd6144f..e7d26c5 100644
--- a/android/Bootstrap/src/org/libreoffice/kit/Office.java
+++ b/android/Bootstrap/src/org/libreoffice/kit/Office.java
@@ -9,22 +9,24 @@
 
 package org.libreoffice.kit;
 
+import java.nio.ByteBuffer;
+
 public class Office {
 
-    private long handle;
+    private ByteBuffer handle;
 
-    public Office(long handle) {
+    public Office(ByteBuffer handle) {
         this.handle = handle;
     }
 
     public native String getError();
 
-    private native long documentLoadNative(String url);
+    private native ByteBuffer documentLoadNative(String url);
 
     public Document documentLoad(String url) {
-        long documentHandle = documentLoadNative(url);
+        ByteBuffer documentHandle = documentLoadNative(url);
         Document document = null;
-        if (documentHandle > 0) {
+        if (documentHandle != null) {
             document = new Document(documentHandle);
         }
         return document;
diff --git a/desktop/source/lib/lokandroid.cxx b/desktop/source/lib/lokandroid.cxx
index 707996e..0f408ea 100644
--- a/desktop/source/lib/lokandroid.cxx
+++ b/desktop/source/lib/lokandroid.cxx
@@ -25,21 +25,14 @@
 jfieldID getHandleField(JNIEnv* pEnv, jobject aObject)
 {
     jclass clazz = pEnv->GetObjectClass(aObject);
-    return pEnv->GetFieldID(clazz, "handle", "J");
+    return pEnv->GetFieldID(clazz, "handle", "Ljava/nio/ByteBuffer;");
 }
 
 template <typename T>
 T* getHandle(JNIEnv* pEnv, jobject aObject)
 {
-    jlong aHandle = pEnv->GetLongField(aObject, getHandleField(pEnv, aObject));
-    return reinterpret_cast<T*>(aHandle);
-}
-
-template <typename T>
-void setHandle(JNIEnv* pEnv, jobject aObject, T* aType)
-{
-    jlong aHandle = reinterpret_cast<jlong>(aType);
-    pEnv->SetLongField(aObject, getHandleField(pEnv, aObject), aHandle);
+    jobject aHandle = pEnv->GetObjectField(aObject, getHandleField(pEnv, aObject));
+    return reinterpret_cast<T*>(pEnv->GetDirectBufferAddress(aHandle));
 }
 
 const char* copyJavaString(JNIEnv* pEnv, jstring aJavaString)
@@ -60,11 +53,6 @@ extern "C" SAL_JNI_EXPORT jstring JNICALL Java_org_libreoffice_kit_Office_getErr
     return pEnv->NewStringUTF(pError);
 }
 
-extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_initialize(JNIEnv* pEnv, jobject aObject, jlong aLokHandle)
-{
-    pEnv->SetLongField(aObject, getHandleField(pEnv, aObject), aLokHandle);
-}
-
 extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_destroy(JNIEnv* pEnv, jobject aObject)
 {
     LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
@@ -80,13 +68,15 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_destroyAn
     _exit(0);
 }
 
-extern "C" SAL_JNI_EXPORT jlong JNICALL Java_org_libreoffice_kit_Office_documentLoadNative(JNIEnv* pEnv, jobject aObject, jstring documentPath)
+extern "C" SAL_JNI_EXPORT jobject JNICALL Java_org_libreoffice_kit_Office_documentLoadNative(JNIEnv* pEnv, jobject aObject, jstring documentPath)
 {
     const char* aCloneDocumentPath = copyJavaString(pEnv, documentPath);
     LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
 
     LibreOfficeKitDocument* pDocument = pLibreOfficeKit->pClass->documentLoad(pLibreOfficeKit, aCloneDocumentPath);
-    return (jlong) pDocument;
+    jobject aHandle = pEnv->NewDirectByteBuffer((void*) pDocument, sizeof(LibreOfficeKitDocument));
+
+    return aHandle;
 }
 
 /* Document */
diff --git a/sal/android/libreofficekit-jni.c b/sal/android/libreofficekit-jni.c
index 4161982..41fa97e 100644
--- a/sal/android/libreofficekit-jni.c
+++ b/sal/android/libreofficekit-jni.c
@@ -147,13 +147,17 @@ jboolean Java_org_libreoffice_kit_LibreOfficeKit_initializeNative
 }
 
 __attribute__ ((visibility("default")))
-jlong Java_org_libreoffice_kit_LibreOfficeKit_getLibreOfficeKitHandle
+jobject Java_org_libreoffice_kit_LibreOfficeKit_getLibreOfficeKitHandle
     (JNIEnv* env, jobject clazz)
 {
+    LibreOfficeKit* aOffice;
+
     (void) env;
     (void) clazz;
 
-    return (jlong) (intptr_t) libreofficekit_hook(full_program_dir);
+    aOffice = libreofficekit_hook(full_program_dir);
+
+    return (*env)->NewDirectByteBuffer(env, (void*) aOffice, sizeof(LibreOfficeKit));
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit e6e87df5a199e77e4a6d217423ec6fe07bc9e7b5
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Mon Nov 17 10:44:04 2014 +0100

    android: cleanup LibreOfficeKit initialization in Java
    
    Change-Id: I7688968e92ae4b3d6fef19c4544ae91bdcd8b1b9

diff --git a/android/Bootstrap/src/org/libreoffice/kit/LibreOfficeKit.java b/android/Bootstrap/src/org/libreoffice/kit/LibreOfficeKit.java
index afd81b3..4fe2061 100644
--- a/android/Bootstrap/src/org/libreoffice/kit/LibreOfficeKit.java
+++ b/android/Bootstrap/src/org/libreoffice/kit/LibreOfficeKit.java
@@ -15,27 +15,23 @@ import android.util.Log;
 
 import java.io.InputStream;
 
-// final because subclassing would be meaningless.
+// Native methods in this class are all implemented in
+// sal/android/lo-bootstrap.c as the lo-bootstrap library is loaded with
+// System.loadLibrary() and Android's JNI works only to such libraries, it
+// seems.
 public final class LibreOfficeKit
 {
-    private long handle;
-
-    public static void loadStatic() {
-
-    }
+    private static String LOGTAG = LibreOfficeKit.class.getSimpleName();
 
     // private constructor because instantiating would be meaningless
-    private LibreOfficeKit()
-    {
+    private LibreOfficeKit() {
     }
 
-    private static String TAG = "LibreOfficeKit";
-
-    // Native methods in this class are all implemented in
-    // sal/android/lo-bootstrap.c as the lo-bootstrap library is loaded with
-    // System.loadLibrary() and Android's JNI works only to such libraries, it
-    // seems.
+    // Trigger library initialization - as this is done automatically by executing the "static" block, this method remains empty. However we need this to manually (at the right time) can force library initialization.
+    public static void initializeLibrary() {
+    }
 
+    // Trigger initialization on the JNI - LOKit side.
     private static native boolean initializeNative(String dataDir, String cacheDir, String apkFile);
 
     public static native long getLibreOfficeKitHandle();
@@ -53,14 +49,15 @@ public final class LibreOfficeKit
     // LO-based apps.
     public static synchronized void init(Activity activity)
     {
-        if (initializeDone)
+        if (initializeDone) {
             return;
+        }
 
         String dataDir = null;
 
         ApplicationInfo applicationInfo = activity.getApplicationInfo();
         dataDir = applicationInfo.dataDir;
-        Log.i(TAG, String.format("Initializing LibreOfficeKit, dataDir=%s\n", dataDir));
+        Log.i(LOGTAG, String.format("Initializing LibreOfficeKit, dataDir=%s\n", dataDir));
 
         redirectStdio(true);
 
@@ -85,6 +82,7 @@ public final class LibreOfficeKit
         putenv("TMPDIR=" + activity.getCacheDir().getAbsolutePath());
 
         if (!initializeNative(dataDir, cacheDir, apkFile)) {
+            Log.i(LOGTAG, "Initialize native failed!");
             return;
         }
 
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProviderFactory.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProviderFactory.java
index 5cd3ed0..3bfe0b7 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProviderFactory.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProviderFactory.java
@@ -13,7 +13,7 @@ public class TileProviderFactory {
 
     public static void initialize() {
         if (currentTileProvider == TileProviderID.LOKIT) {
-            LibreOfficeKit.loadStatic();
+            LibreOfficeKit.initializeLibrary();
         }
     }
 
commit d9c040afa9f03243605b19555e2a661ae2e6fd14
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Mon Nov 17 10:38:54 2014 +0100

    android: use different function to prevent stripping JNI symbols
    
    Change-Id: Ib003da5c7fec7fc3783f01a33a63deb384c7e770

diff --git a/solenv/bin/native-code.py b/solenv/bin/native-code.py
index a8f8a30..62b04fb 100755
--- a/solenv/bin/native-code.py
+++ b/solenv/bin/native-code.py
@@ -252,8 +252,8 @@ if options.java:
     extern void Java_org_libreoffice_kit_LibreOfficeKit_initializeNative();
     p = (void *) Java_org_libreoffice_kit_LibreOfficeKit_initializeNative;
 
-    extern void Java_org_libreoffice_kit_Office_initialize();
-    p = (void *) Java_org_libreoffice_kit_Office_initialize;
+    extern void Java_org_libreoffice_kit_Office_getError();
+    p = (void *) Java_org_libreoffice_kit_Office_getError;
 
     """)
 
commit 4dcabf94246dfaa2e374544b8a873eb3f38cccdd
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Mon Nov 17 10:36:53 2014 +0100

    lok: improve error reporting in lok implementation
    
    Change-Id: Ifc7b18e173b0c91c24a53fad9c35ac3a34a4b33e

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index fd6bbb0..2df9edc 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -292,13 +292,28 @@ static LibreOfficeKitDocument* lo_documentLoad(LibreOfficeKit* pThis, const char
 {
     LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
 
+    SolarMutexGuard aGuard;
+
     OUString aURL = getAbsoluteURL(pURL);
 
-    SolarMutexGuard aGuard;
+    pLib->maLastExceptionMsg = "";
+
+    if (!xContext.is())
+    {
+        pLib->maLastExceptionMsg = "ComponentContext is not available!";
+        SAL_INFO("lok", "ComponentContext is not available!");
+        return NULL;
+    }
 
     uno::Reference<frame::XDesktop2> xComponentLoader = frame::Desktop::create(xContext);
 
-    pLib->maLastExceptionMsg = "";
+    if (!xComponentLoader.is())
+    {
+        pLib->maLastExceptionMsg = "ComponentLoader is not available!";
+        SAL_INFO("lok", "ComponentLoader is not available!");
+        return NULL;
+    }
+
 
     try
     {
@@ -307,15 +322,19 @@ static LibreOfficeKitDocument* lo_documentLoad(LibreOfficeKit* pThis, const char
                                             aURL, OUString("_blank"), 0,
                                             uno::Sequence<css::beans::PropertyValue>());
 
-        if (xComponent.is())
-            return new LibLODocument_Impl(xComponent);
-        else
+        if (!xComponent.is())
+        {
             pLib->maLastExceptionMsg = "unknown load failure";
+            SAL_INFO("lok", "Document can't be loaded - unknown load failure");
+        }
+
+        return new LibLODocument_Impl(xComponent);
 
     }
     catch (const uno::Exception& exception)
     {
         pLib->maLastExceptionMsg = exception.Message;
+        SAL_INFO("lok", "Document can't be loaded - exception: " << exception.Message);
     }
 
     return NULL;
@@ -633,20 +652,43 @@ static void aBasicErrorFunc(const OUString& rError, const OUString& rAction)
     fprintf(stderr, "Unexpected basic error dialog '%s'\n", aBuffer.getStr());
 }
 
-static void initialize_uno(const OUString &aAppProgramURL)
+static bool initialize_uno(const OUString& aAppProgramURL)
 {
     rtl::Bootstrap::setIniFilename(aAppProgramURL + "/" SAL_CONFIGFILE("soffice"));
 
     xContext = cppu::defaultBootstrap_InitialComponentContext();
-    fprintf(stderr, "Uno initialized %d\n", xContext.is());
+    if (!xContext.is())
+    {
+        gImpl->maLastExceptionMsg = "XComponentContext could not be created";
+        SAL_INFO("lok", "XComponentContext could not be created");
+        return false;
+    }
+
     xFactory = xContext->getServiceManager();
+    if (!xFactory.is())
+    {
+        gImpl->maLastExceptionMsg = "XMultiComponentFactory could not be created";
+        SAL_INFO("lok", "XMultiComponentFactory could not be created");
+        return false;
+    }
+
     xSFactory = uno::Reference<lang::XMultiServiceFactory>(xFactory, uno::UNO_QUERY_THROW);
+    if (!xSFactory.is())
+    {
+        gImpl->maLastExceptionMsg = "XMultiServiceFactory could not be created";
+        SAL_INFO("lok", "XMultiServiceFactory could not be created");
+        return false;
+    }
     comphelper::setProcessServiceFactory(xSFactory);
 
+    SAL_INFO("lok", "Uno initialized  - " <<  xContext.is());
+
     // set UserInstallation to user profile dir in test/user-template
 //    rtl::Bootstrap aDefaultVars;
 //    aDefaultVars.set(OUString("UserInstallation"), aAppProgramURL + "../registry" );
     // configmgr setup ?
+
+    return true;
 }
 
 static void* lo_startmain(void*)
@@ -701,12 +743,16 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath)
         // to LOK in an external program).
         if (!osl_areCommandArgsSet())
         {
-            SAL_INFO("lok", "commandArgs not previously set");
+            SAL_INFO("lok", "CommandArgs not previously set");
             osl_setCommandArgs(2, pArgs);
         }
-        SAL_INFO("lok", "attempting to initalize UNO");
-        initialize_uno(aAppURL);
-        SAL_INFO("lok", "uno successfully initalized");
+        SAL_INFO("lok", "Attempting to initalize UNO");
+        if (!initialize_uno(aAppURL))
+        {
+            return false;
+        }
+        SAL_INFO("lok", "UNO successfully initalized");
+
         force_c_locale();
 
         // Force headless -- this is only for bitmap rendering.
@@ -728,11 +774,11 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath)
         // the Thread from wherever (it's done again in Desktop::Main), and can
         // then use it to wait until we're definitely ready to continue.
 
-        SAL_INFO("lok", "enabling OfficeIPCThread");
+        SAL_INFO("lok", "Enabling OfficeIPCThread");
         OfficeIPCThread::EnableOfficeIPCThread();
-        SAL_INFO("lok", "starting soffice_main");
+        SAL_INFO("lok", "Starting soffice_main");
         pthread_create(&(pLib->maThread), 0, lo_startmain, NULL);
-        SAL_INFO("lok", "waiting for OfficeIPCThread");
+        SAL_INFO("lok", "Waiting for OfficeIPCThread");
         OfficeIPCThread::WaitForReady();
         SAL_INFO("lok", "OfficeIPCThread ready -- continuing");
 
@@ -749,12 +795,12 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath)
 
         ErrorHandler::RegisterDisplay(aBasicErrorFunc);
 
-        fprintf(stderr, "initialized\n");
+        SAL_INFO("lok", "LOK Initialized");
         bInitialized = true;
     }
     catch (css::uno::Exception& exception)
     {
-        fprintf(stderr, "bootstrapping exception '%s'\n",
+        fprintf(stderr, "Bootstrapping exception '%s'\n",
                  OUStringToOString(exception.Message, RTL_TEXTENCODING_UTF8).getStr());
     }
     return bInitialized;
@@ -764,7 +810,8 @@ SAL_DLLPUBLIC_EXPORT LibreOfficeKit *libreofficekit_hook(const char* install_pat
 {
     if (!gImpl)
     {
-        fprintf(stderr, "create libreoffice object\n");
+        SAL_INFO("lok", "Create libreoffice object");
+
         gImpl = new LibLibreOffice_Impl();
         if (!lo_initialize(gImpl, install_path))
         {
@@ -774,19 +821,19 @@ SAL_DLLPUBLIC_EXPORT LibreOfficeKit *libreofficekit_hook(const char* install_pat
     return static_cast<LibreOfficeKit*>(gImpl);
 }
 
-static void lo_destroy(LibreOfficeKit *pThis)
+static void lo_destroy(LibreOfficeKit* pThis)
 {
     LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
     gImpl = NULL;
 
-    SAL_INFO("lok", "lo_destroy");
+    SAL_INFO("lok", "LO Destroy");
 
     Application::Quit();
     pthread_join(pLib->maThread, NULL);
 
     delete pLib;
     bInitialized = false;
-    SAL_INFO("lok", "lo_destroy done");
+    SAL_INFO("lok", "LO Destroy Done");
 }
 
 }
commit 02ce97d866d9229cec342a8379dbf5d4c590eb63
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Mon Nov 17 10:34:20 2014 +0100

    android: extract gathering document info into postLoad method
    
    Change-Id: Id90680d3b207973b55927add1c91111268bb2a48

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
index 1bc6499..d4531d1 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
@@ -60,36 +60,39 @@ public class LOKitTileProvider implements TileProvider {
         Log.i(LOGTAG, "====> mDocument = " + mDocument);
 
         if (checkDocument()) {
-            int parts = mDocument.getParts();
-            Log.i(LOGTAG, "Document parts: " + parts);
-
-            LibreOfficeMainActivity.mAppContext.getDocumentPartView().clear();
-
-            if (parts > 1) {
-                for (int i = 0; i < parts; i++) {
-                    String partName = mDocument.getPartName(i);
-                    if (partName.isEmpty()) {
-                        partName = getGenericPartName(i);
-                    }
-                    Log.i(LOGTAG, "Document part " + i + " name:'" + partName + "'");
-
-                    mDocument.setPart(i);
-                    final DocumentPartView partView = new DocumentPartView(i, partName, thumbnail(128));
-                    LibreOfficeMainActivity.mAppContext.getDocumentPartView().add(partView);
-                }
-            }
+            postLoad();
+            mIsReady = true;
+        }
+    }
 
-            mDocument.setPart(0);
+    public void postLoad() {
+        int parts = mDocument.getParts();
+        Log.i(LOGTAG, "Document parts: " + parts);
 
-            LOKitShell.getMainHandler().post(new Runnable() {
-                @Override
-                public void run() {
-                    LibreOfficeMainActivity.mAppContext.getDocumentPartViewListAdpater().notifyDataSetChanged();
+        LibreOfficeMainActivity.mAppContext.getDocumentPartView().clear();
+
+        if (parts > 1) {
+            for (int i = 0; i < parts; i++) {
+                String partName = mDocument.getPartName(i);
+                if (partName.isEmpty()) {
+                    partName = getGenericPartName(i);
                 }
-            });
+                Log.i(LOGTAG, "Document part " + i + " name:'" + partName + "'");
 
-            mIsReady = true;
+                mDocument.setPart(i);
+                final DocumentPartView partView = new DocumentPartView(i, partName, thumbnail(128));
+                LibreOfficeMainActivity.mAppContext.getDocumentPartView().add(partView);
+            }
         }
+
+        mDocument.setPart(0);
+
+        LOKitShell.getMainHandler().post(new Runnable() {
+            @Override
+            public void run() {
+                LibreOfficeMainActivity.mAppContext.getDocumentPartViewListAdpater().notifyDataSetChanged();
+            }
+        });
     }
 
     private String getGenericPartName(int i) {
commit a80761426ae7dad740f46bf62a83c00947cd4dfb
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Mon Nov 17 10:32:26 2014 +0100

    android: improve error messages in DirectBufferAllocator
    
    Change-Id: Iefab77e543606cfad937a79743fb3b9a68a0f2a2

diff --git a/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java b/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java
index 431ccad..f509030 100644
--- a/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java
+++ b/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java
@@ -15,7 +15,7 @@ import android.util.Log;
 
 import java.nio.ByteBuffer;
 
-public class DirectBufferAllocator {
+public final class DirectBufferAllocator {
 
     private static final String LOGTAG = DirectBufferAllocator.class.getSimpleName();
 
@@ -27,7 +27,7 @@ public class DirectBufferAllocator {
     private static native void freeDirectBufferNative(ByteBuffer aBuffer);
 
     public static ByteBuffer allocate(int size) {
-        Log.i(LOGTAG, "Buffer size: " + size);
+        Log.i(LOGTAG, "Allocating size: " + size);
         return allocateVM(size);
     }
 
@@ -37,7 +37,6 @@ public class DirectBufferAllocator {
 
     private static ByteBuffer allocateJNI(int size) {
         ByteBuffer directBuffer = allocateDirectBufferNative(size);
-
         if (directBuffer == null) {
             if (size <= 0) {
                 throw new IllegalArgumentException("Invalid allocation size: " + size);
@@ -47,17 +46,17 @@ public class DirectBufferAllocator {
         } else if (!directBuffer.isDirect()) {
             throw new AssertionError("allocateDirectBuffer() did not return a direct buffer");
         }
-
         return directBuffer;
     }
 
     private static ByteBuffer freeJNI(ByteBuffer buffer) {
         if (buffer == null) {
+            Log.i(LOGTAG, "ByteBuffer is null");
             return null;
         }
 
         if (!buffer.isDirect()) {
-            throw new IllegalArgumentException("buffer must be direct");
+            throw new IllegalArgumentException("ByteBuffer must be direct");
         }
 
         freeDirectBufferNative(buffer);
@@ -81,13 +80,14 @@ public class DirectBufferAllocator {
 
     private static ByteBuffer freeVM(ByteBuffer buffer) {
         if (buffer == null) {
+            Log.i(LOGTAG, "ByteBuffer is null");
             return null;
         }
 
         if (!buffer.isDirect()) {
-            throw new IllegalArgumentException("buffer must be direct");
+            throw new IllegalArgumentException("ByteBuffer must be direct");
         }
-
+        // can't free buffer - leave this to the VM
         return null;
     }
 }


More information about the Libreoffice-commits mailing list