summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.com>2015-10-21 12:42:03 +0200
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2015-10-21 20:13:28 +0200
commite1ab55f23b68c2907e35d0d1764f71d614cd72b2 (patch)
tree9bd59de16939ceeadf97282abb4e368941089c28 /android
parent74dd8be2918bc7931a7494936f951b26cb39a13a (diff)
android: remove the native DirectBufferAllocator
Change-Id: I41d25d288253f1b35c268ba70b8384812fa567e5 (cherry picked from commit c8dcec92470745f07c51074404ce4250428f2255)
Diffstat (limited to 'android')
-rw-r--r--android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java51
1 files changed, 5 insertions, 46 deletions
diff --git a/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java b/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java
index de90303d9eba..99cb3a48620f 100644
--- a/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java
+++ b/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java
@@ -5,14 +5,12 @@
package org.libreoffice.kit;
-//
-// We must manually allocate direct buffers in JNI to work around a bug where Honeycomb's
-// ByteBuffer.allocateDirect() grossly overallocates the direct buffer size.
-// https://code.google.com/p/android/issues/detail?id=16941
-//
-
import java.nio.ByteBuffer;
+/**
+ * This is the common code for allocation and freeing of memory. For this direct ByteBuffer is used but
+ * in the past it was possible to use a JNI version of allocation because of a bug in old Android version.
+ */
public final class DirectBufferAllocator {
private static final String LOGTAG = DirectBufferAllocator.class.getSimpleName();
@@ -20,46 +18,7 @@ public final class DirectBufferAllocator {
private DirectBufferAllocator() {
}
- private static native ByteBuffer allocateDirectBufferNative(int size);
-
- private static native void freeDirectBufferNative(ByteBuffer aBuffer);
-
public static ByteBuffer allocate(int 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) {
- 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 freeJNI(ByteBuffer buffer) {
- if (buffer == null) {
- return null;
- }
-
- if (!buffer.isDirect()) {
- throw new IllegalArgumentException("ByteBuffer must be direct");
- }
-
- freeDirectBufferNative(buffer);
- return null;
- }
-
- private static ByteBuffer allocateVM(int size) {
ByteBuffer directBuffer = ByteBuffer.allocateDirect(size);
if (directBuffer == null) {
if (size <= 0) {
@@ -74,7 +33,7 @@ public final class DirectBufferAllocator {
return directBuffer;
}
- private static ByteBuffer freeVM(ByteBuffer buffer) {
+ public static ByteBuffer free(ByteBuffer buffer) {
if (buffer == null) {
return null;
}