aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRicardo Cerqueira <cyanogenmod@cerqueira.org>2013-07-24 23:45:04 +0100
committerRicardo Cerqueira <cyanogenmod@cerqueira.org>2013-07-24 23:45:04 +0100
commit3abb5383d9883eb98c0371957043e5d67e448a06 (patch)
tree69c9e8a496d7e126b4fce7c3634440c9a7296c22
parent73d3c2e3ed100f1d0ccc08a9675844bf8a0848fa (diff)
parenta7de6785939e53982e93afacf03647ff1a759b5a (diff)
downloadandroid_libnativehelper-cm-10.2.tar.gz
android_libnativehelper-cm-10.2.tar.bz2
android_libnativehelper-cm-10.2.zip
Merge tag 'android-4.3_r2.1' into cm-10.2cm-10.2.1cm-10.2.0cm-10.2-M1stable/cm-10.2cm-10.2
Android 4.3 release 2.1
-rw-r--r--JNIHelp.cpp61
-rw-r--r--include/nativehelper/JNIHelp.h9
-rw-r--r--include/nativehelper/jni.h37
3 files changed, 62 insertions, 45 deletions
diff --git a/JNIHelp.cpp b/JNIHelp.cpp
index 041776c..bc0b49c 100644
--- a/JNIHelp.cpp
+++ b/JNIHelp.cpp
@@ -72,13 +72,15 @@ extern "C" int jniRegisterNativeMethods(C_JNIEnv* env, const char* className,
scoped_local_ref<jclass> c(env, findClass(env, className));
if (c.get() == NULL) {
- ALOGE("Native registration unable to find class '%s', aborting", className);
- abort();
+ char* msg;
+ asprintf(&msg, "Native registration unable to find class '%s', aborting", className);
+ e->FatalError(msg);
}
if ((*env)->RegisterNatives(e, c.get(), gMethods, numMethods) < 0) {
- ALOGE("RegisterNatives failed for '%s', aborting", className);
- abort();
+ char* msg;
+ asprintf(&msg, "RegisterNatives failed for '%s', aborting", className);
+ e->FatalError(msg);
}
return 0;
@@ -304,11 +306,15 @@ const char* jniStrError(int errnum, char* buf, size_t buflen) {
}
}
-static struct CachedFields {
- jclass fileDescriptorClass;
- jmethodID fileDescriptorCtor;
- jfieldID descriptorField;
-} gCachedFields;
+static struct {
+ jclass clazz;
+ jmethodID ctor;
+ jfieldID descriptor;
+} gFileDescriptorClassInfo;
+
+static struct {
+ jmethodID get;
+} gReferenceClassInfo;
jint JNI_OnLoad(JavaVM* vm, void*) {
JNIEnv* env;
@@ -317,21 +323,31 @@ jint JNI_OnLoad(JavaVM* vm, void*) {
abort();
}
- gCachedFields.fileDescriptorClass =
+ gFileDescriptorClassInfo.clazz =
reinterpret_cast<jclass>(env->NewGlobalRef(env->FindClass("java/io/FileDescriptor")));
- if (gCachedFields.fileDescriptorClass == NULL) {
+ if (gFileDescriptorClassInfo.clazz == NULL) {
+ abort();
+ }
+
+ gFileDescriptorClassInfo.ctor =
+ env->GetMethodID(gFileDescriptorClassInfo.clazz, "<init>", "()V");
+ if (gFileDescriptorClassInfo.ctor == NULL) {
abort();
}
- gCachedFields.fileDescriptorCtor =
- env->GetMethodID(gCachedFields.fileDescriptorClass, "<init>", "()V");
- if (gCachedFields.fileDescriptorCtor == NULL) {
+ gFileDescriptorClassInfo.descriptor =
+ env->GetFieldID(gFileDescriptorClassInfo.clazz, "descriptor", "I");
+ if (gFileDescriptorClassInfo.descriptor == NULL) {
abort();
}
- gCachedFields.descriptorField =
- env->GetFieldID(gCachedFields.fileDescriptorClass, "descriptor", "I");
- if (gCachedFields.descriptorField == NULL) {
+ jclass clazz = reinterpret_cast<jclass>(env->FindClass("java/lang/ref/Reference"));
+ if (clazz == NULL) {
+ abort();
+ }
+
+ gReferenceClassInfo.get = env->GetMethodID(clazz, "get", "()Ljava/lang/Object;");
+ if (gReferenceClassInfo.get == NULL) {
abort();
}
@@ -341,19 +357,24 @@ jint JNI_OnLoad(JavaVM* vm, void*) {
jobject jniCreateFileDescriptor(C_JNIEnv* env, int fd) {
JNIEnv* e = reinterpret_cast<JNIEnv*>(env);
jobject fileDescriptor = (*env)->NewObject(e,
- gCachedFields.fileDescriptorClass, gCachedFields.fileDescriptorCtor);
+ gFileDescriptorClassInfo.clazz, gFileDescriptorClassInfo.ctor);
jniSetFileDescriptorOfFD(env, fileDescriptor, fd);
return fileDescriptor;
}
int jniGetFDFromFileDescriptor(C_JNIEnv* env, jobject fileDescriptor) {
JNIEnv* e = reinterpret_cast<JNIEnv*>(env);
- return (*env)->GetIntField(e, fileDescriptor, gCachedFields.descriptorField);
+ return (*env)->GetIntField(e, fileDescriptor, gFileDescriptorClassInfo.descriptor);
}
void jniSetFileDescriptorOfFD(C_JNIEnv* env, jobject fileDescriptor, int value) {
JNIEnv* e = reinterpret_cast<JNIEnv*>(env);
- (*env)->SetIntField(e, fileDescriptor, gCachedFields.descriptorField, value);
+ (*env)->SetIntField(e, fileDescriptor, gFileDescriptorClassInfo.descriptor, value);
+}
+
+jobject jniGetReferent(C_JNIEnv* env, jobject ref) {
+ JNIEnv* e = reinterpret_cast<JNIEnv*>(env);
+ return (*env)->CallObjectMethod(e, ref, gReferenceClassInfo.get);
}
/*
diff --git a/include/nativehelper/JNIHelp.h b/include/nativehelper/JNIHelp.h
index 446a710..2fadcdf 100644
--- a/include/nativehelper/JNIHelp.h
+++ b/include/nativehelper/JNIHelp.h
@@ -97,6 +97,11 @@ int jniGetFDFromFileDescriptor(C_JNIEnv* env, jobject fileDescriptor);
void jniSetFileDescriptorOfFD(C_JNIEnv* env, jobject fileDescriptor, int value);
/*
+ * Returns the reference from a java.lang.ref.Reference.
+ */
+jobject jniGetReferent(C_JNIEnv* env, jobject ref);
+
+/*
* Log a message and an exception.
* If exception is NULL, logs the current exception in the JNI environment.
*/
@@ -157,6 +162,10 @@ inline void jniSetFileDescriptorOfFD(JNIEnv* env, jobject fileDescriptor, int va
jniSetFileDescriptorOfFD(&env->functions, fileDescriptor, value);
}
+inline jobject jniGetReferent(JNIEnv* env, jobject ref) {
+ return jniGetReferent(&env->functions, ref);
+}
+
inline void jniLogException(JNIEnv* env, int priority, const char* tag, jthrowable exception = NULL) {
jniLogException(&env->functions, priority, tag, exception);
}
diff --git a/include/nativehelper/jni.h b/include/nativehelper/jni.h
index e4d74cf..1c2fb0c 100644
--- a/include/nativehelper/jni.h
+++ b/include/nativehelper/jni.h
@@ -25,33 +25,20 @@
#define JNI_H_
#include <stdarg.h>
-
-/*
- * Primitive types that match up with Java equivalents.
- */
-#ifdef HAVE_INTTYPES_H
-# include <inttypes.h> /* C99 */
-typedef uint8_t jboolean; /* unsigned 8 bits */
-typedef int8_t jbyte; /* signed 8 bits */
-typedef uint16_t jchar; /* unsigned 16 bits */
-typedef int16_t jshort; /* signed 16 bits */
-typedef int32_t jint; /* signed 32 bits */
-typedef int64_t jlong; /* signed 64 bits */
-typedef float jfloat; /* 32-bit IEEE 754 */
-typedef double jdouble; /* 64-bit IEEE 754 */
-#else
-typedef unsigned char jboolean; /* unsigned 8 bits */
-typedef signed char jbyte; /* signed 8 bits */
-typedef unsigned short jchar; /* unsigned 16 bits */
-typedef short jshort; /* signed 16 bits */
-typedef int jint; /* signed 32 bits */
-typedef long long jlong; /* signed 64 bits */
-typedef float jfloat; /* 32-bit IEEE 754 */
-typedef double jdouble; /* 64-bit IEEE 754 */
-#endif
+#include <stdint.h>
+
+/* Primitive types that match up with Java equivalents. */
+typedef uint8_t jboolean; /* unsigned 8 bits */
+typedef int8_t jbyte; /* signed 8 bits */
+typedef uint16_t jchar; /* unsigned 16 bits */
+typedef int16_t jshort; /* signed 16 bits */
+typedef int32_t jint; /* signed 32 bits */
+typedef int64_t jlong; /* signed 64 bits */
+typedef float jfloat; /* 32-bit IEEE 754 */
+typedef double jdouble; /* 64-bit IEEE 754 */
/* "cardinal indices and sizes" */
-typedef jint jsize;
+typedef jint jsize;
#ifdef __cplusplus
/*