diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-11-17 10:47:02 +0100 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-12-04 23:04:27 +0100 |
commit | 515a8cf4005cb146052256ff4b9ac2de895849ae (patch) | |
tree | 86c186054e3c1343000656a287bc58635d7adfed /android | |
parent | 333a894ba84553762542c47636791f92360c69b5 (diff) |
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
Diffstat (limited to 'android')
3 files changed, 11 insertions, 8 deletions
diff --git a/android/Bootstrap/src/org/libreoffice/kit/Document.java b/android/Bootstrap/src/org/libreoffice/kit/Document.java index 52b9bfdc2674..aad4d5a6dcc4 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 4fe2061c335b..2a60f848e0de 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 bd6144f64b8c..e7d26c5a9b8c 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; |