From 8dd75128a5a7e068ae63f3d1cc6b41410f7d7122 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Mon, 18 Jun 2012 22:02:57 +0300 Subject: ByteBufferWrapper tweaks operator() gets called in a Java GC thread. A JNIEnv* saved in the constructor (which is called from the UI thread) is not valid in other threads (although for now, Dalvik notices, warns, and works around it). So don't bother keeping the JNIEnv*. Instead fetch one when needed. Move the method implementations from inline in the header to libotouch's android.cxx. Change-Id: I7de6fc54bb8d9a59146576d6e8c325fe917393ee --- touch/Library_libotouch.mk | 4 ++++ touch/source/android/android.cxx | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) (limited to 'touch') diff --git a/touch/Library_libotouch.mk b/touch/Library_libotouch.mk index 1e06db466583..17d1f4529084 100644 --- a/touch/Library_libotouch.mk +++ b/touch/Library_libotouch.mk @@ -33,6 +33,10 @@ $(eval $(call gb_Library_add_exception_objects,libotouch,\ ifeq ($(OS),ANDROID) +$(eval $(call gb_Library_use_libraries,libotouch,\ + lo-bootstrap \ +)) + $(eval $(call gb_Library_add_exception_objects,libotouch,\ touch/source/android/android \ )) diff --git a/touch/source/android/android.cxx b/touch/source/android/android.cxx index 06768c86c646..3a116b18e643 100644 --- a/touch/source/android/android.cxx +++ b/touch/source/android/android.cxx @@ -10,9 +10,43 @@ #include #include +#include using org::libreoffice::touch::ByteBufferWrapper; +static JNIEnv *get_env() +{ + JavaVMAttachArgs args = { + JNI_VERSION_1_2, + NULL, + NULL + }; + + JavaVM *jvm = lo_get_javavm(); + JNIEnv *env = NULL; + + jvm->AttachCurrentThread(&env, &args); + return env; +} + +__attribute__ ((visibility("default"))) +ByteBufferWrapper::ByteBufferWrapper(JNIEnv *env, jobject o) +{ + object = env->NewGlobalRef(o); +} + +__attribute__ ((visibility("default"))) +sal_uInt8* ByteBufferWrapper::pointer() +{ + return (sal_uInt8 *) get_env()->GetDirectBufferAddress(object); +} + +__attribute__ ((visibility("default"))) +void ByteBufferWrapper::operator()(sal_uInt8 * /* p */) +{ + get_env()->DeleteGlobalRef(object); +} + extern "C" __attribute__ ((visibility("default"))) jlong -- cgit