[Libreoffice-commits] core.git: Branch 'feature/droid_calcimpress3' - 3 commits - android/Bootstrap desktop/source

Tomaž Vajngerl tomaz.vajngerl at collabora.com
Mon Nov 10 04:09:22 PST 2014


 android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java |   53 ++++++++--
 android/Bootstrap/src/org/libreoffice/kit/Office.java                |    1 
 desktop/source/lib/lokandroid.cxx                                    |   22 +++-
 3 files changed, 64 insertions(+), 12 deletions(-)

New commits:
commit 0da99921b9ee33f9f6e8c41cba42cbdd9197bc77
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Mon Nov 10 13:10:03 2014 +0100

    android: add destroy and exit as a separate JNI call
    
    Change-Id: Ia8516da556b3736f34b366e2eb89ad8bbd7bafc1

diff --git a/android/Bootstrap/src/org/libreoffice/kit/Office.java b/android/Bootstrap/src/org/libreoffice/kit/Office.java
index d603066..bd6144f 100644
--- a/android/Bootstrap/src/org/libreoffice/kit/Office.java
+++ b/android/Bootstrap/src/org/libreoffice/kit/Office.java
@@ -31,4 +31,5 @@ public class Office {
     }
 
     public native void destroy();
+    public native void destroyAndExit();
 }
diff --git a/desktop/source/lib/lokandroid.cxx b/desktop/source/lib/lokandroid.cxx
index a6f02d6..707996e 100644
--- a/desktop/source/lib/lokandroid.cxx
+++ b/desktop/source/lib/lokandroid.cxx
@@ -69,6 +69,12 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_destroy(J
 {
     LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
     pLibreOfficeKit->pClass->destroy(pLibreOfficeKit);
+}
+
+extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_destroyAndExit(JNIEnv* pEnv, jobject aObject)
+{
+    LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
+    pLibreOfficeKit->pClass->destroy(pLibreOfficeKit);
     // Stopgap fix: _exit() to force the OS to restart the LO activity.
     // Better than to hang.
     _exit(0);
commit 7a454f86459c86dd6d2608f3b53bb85272d45747
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Mon Nov 10 13:04:27 2014 +0100

    android: VM based implementation of DirectBufferAllocator
    
    DirectBufferAllocator is responsible to allocate buffer. We used
    Fennec JNI based allocation (and freeing) because of overallocation
    bug in some Android versions. With this the VM based allocator
    implementation is added and used by default because of bugs that
    happen in newer Android versions (specifically when ART is used
    as the Android VM).
    
    Change-Id: I07eb364fd1647b3a09d1568d4fef82398a02dfeb

diff --git a/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java b/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java
index 7c8f808..431ccad 100644
--- a/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java
+++ b/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java
@@ -11,10 +11,14 @@ package org.libreoffice.kit;
 // https://code.google.com/p/android/issues/detail?id=16941
 //
 
+import android.util.Log;
+
 import java.nio.ByteBuffer;
 
 public class DirectBufferAllocator {
 
+    private static final String LOGTAG = DirectBufferAllocator.class.getSimpleName();
+
     private DirectBufferAllocator() {
     }
 
@@ -23,13 +27,23 @@ public class DirectBufferAllocator {
     private static native void freeDirectBufferNative(ByteBuffer aBuffer);
 
     public static ByteBuffer allocate(int size) {
-        if (size <= 0) {
-            throw new IllegalArgumentException("Invalid size " + size);
-        }
+        Log.i(LOGTAG, "Buffer size: " + size);
+        return allocateVM(size);
+    }
+
+    public static ByteBuffer free(ByteBuffer buffer) {
+        return freeVM(buffer);
+    }
 
+    private static ByteBuffer allocateJNI(int size) {
         ByteBuffer directBuffer = allocateDirectBufferNative(size);
+
         if (directBuffer == null) {
-            throw new OutOfMemoryError("allocateDirectBuffer() returned null");
+            if (size <= 0) {
+                throw new IllegalArgumentException("Invalid allocation size: " + size);
+            } else {
+                throw new OutOfMemoryError("allocateDirectBuffer() returned null");
+            }
         } else if (!directBuffer.isDirect()) {
             throw new AssertionError("allocateDirectBuffer() did not return a direct buffer");
         }
@@ -37,7 +51,7 @@ public class DirectBufferAllocator {
         return directBuffer;
     }
 
-    public static ByteBuffer free(ByteBuffer buffer) {
+    private static ByteBuffer freeJNI(ByteBuffer buffer) {
         if (buffer == null) {
             return null;
         }
@@ -49,4 +63,31 @@ public class DirectBufferAllocator {
         freeDirectBufferNative(buffer);
         return null;
     }
-}
\ No newline at end of file
+
+    private static ByteBuffer allocateVM(int size) {
+        ByteBuffer directBuffer = ByteBuffer.allocateDirect(size);
+        if (directBuffer == null) {
+            if (size <= 0) {
+                throw new IllegalArgumentException("Invalid allocation size: " + size);
+            } else {
+                throw new OutOfMemoryError("allocateDirectBuffer() returned null");
+            }
+        } else if (!directBuffer.isDirect()) {
+            throw new AssertionError("allocateDirectBuffer() did not return a direct buffer");
+        }
+
+        return directBuffer;
+    }
+
+    private static ByteBuffer freeVM(ByteBuffer buffer) {
+        if (buffer == null) {
+            return null;
+        }
+
+        if (!buffer.isDirect()) {
+            throw new IllegalArgumentException("buffer must be direct");
+        }
+
+        return null;
+    }
+}
commit c22093c4ead0b89e13e38108c7da8d3b4a55c28c
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Sat Nov 8 15:19:46 2014 +0100

    android: use int type for size in DirectBufferAllocator allocate
    
    Change-Id: Ied2687d334f7d1ff9ff2f3cb6664848d50814b7c

diff --git a/desktop/source/lib/lokandroid.cxx b/desktop/source/lib/lokandroid.cxx
index 15c41c4..a6f02d6 100644
--- a/desktop/source/lib/lokandroid.cxx
+++ b/desktop/source/lib/lokandroid.cxx
@@ -190,16 +190,20 @@ extern "C" SAL_JNI_EXPORT jint JNICALL Java_org_libreoffice_kit_Office_saveAs
 /* DirectBufferAllocator */
 
 extern "C" SAL_JNI_EXPORT jobject JNICALL Java_org_libreoffice_kit_DirectBufferAllocator_allocateDirectBufferNative
-    (JNIEnv* pEnv, jclass /*aClass*/, jlong nSize)
+    (JNIEnv* pEnv, jclass /*aClass*/, jint nSize)
 {
     jobject aBuffer = NULL;
-    void* pMemory = malloc(nSize);
-    if (pMemory != NULL)
+
+    if (nSize > 0)
     {
-        aBuffer = pEnv->NewDirectByteBuffer(pMemory, nSize);
-        if (!aBuffer)
+        void* pMemory = malloc(nSize);
+        if (pMemory != NULL)
         {
-            free(pMemory);
+            aBuffer = pEnv->NewDirectByteBuffer(pMemory, nSize);
+            if (aBuffer == NULL)
+            {
+                free(pMemory);
+            }
         }
     }
     return aBuffer;


More information about the Libreoffice-commits mailing list