diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2015-10-21 12:42:03 +0200 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2015-10-21 15:17:10 +0200 |
commit | c8dcec92470745f07c51074404ce4250428f2255 (patch) | |
tree | 5aa2ab3af50ae9ebb8a6aef4c422dda47e5f32ba /android | |
parent | 030891701c2f2d32b7d5848ddc955801560dd081 (diff) |
android: remove the native DirectBufferAllocator
Change-Id: I41d25d288253f1b35c268ba70b8384812fa567e5
Diffstat (limited to 'android')
-rw-r--r-- | android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java | 51 |
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; } |