Android JNI conflicts with Java JNI Specification

157 Views Asked by At

According to Java JNI Specification Native Method Arguments:

The JNI interface pointer is the first argument to native methods. The JNI interface pointer is of type JNIEnv. The second argument differs depending on whether the native method is static or nonstatic. The second argument to a nonstatic native method is a reference to the object. The second argument to a static native method is a reference to its Java class.

So a native function implementation should contains at least two local argument:first is JNIEnv, second is jobject or jclass, but in android framework there are many codes conflits with these rule, for example:

android.googlesource.com/platform/frameworks/base/+/cd92588/media/java/android/media/MediaScanner.java#1822

private static native final void native_init();

android.googlesource.com/platform/frameworks/base/+/master/media/jni/android_media_MediaScanner.cpp#375

static void android_media_MediaScanner_native_init(JNIEnv *env)
{
    ALOGV("native_init");
    jclass clazz = env->FindClass(kClassMediaScanner);
    if (clazz == NULL) {
        return;
    }

  fields.context = env->GetFieldID(clazz, "mNativeContext", "J");
    if (fields.context == NULL) {
        return;
    }
}

function registe:

{
    "native_init",
    "()V",
    (void *)android_media_MediaScanner_native_init
},

android_media_MediaScanner_native_init only receive one argument, so is there any dalvik or art runtime tricks or other reason?

0

There are 0 best solutions below