Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is in android.util.Log#println_native()?

Here is the android.util.Log source code.

At the very bottom (line 340), what is in the method:

public static native int println_native(int bufID,
        int priority, String tag, String msg);

i guess println_native() is more or less like its println(), just with an int bufID different.

But even i got the codes of println_native(), i still lack com.android.internal.os.RuntimeInit (line 19, the import) to simulate android.util.Log in old Android version.

like image 305
midnite Avatar asked Dec 26 '22 03:12

midnite


1 Answers

Just did some digging in the android source code. This function maps to

static jint android_util_Log_println_native(JNIEnv* env, jobject clazz,
    jint bufID, jint priority, jstring tagObj, jstring msgObj)
{
const char* tag = NULL;
const char* msg = NULL;

if (msgObj == NULL) {
    jniThrowNullPointerException(env, "println needs a message");
    return -1;
}

if (bufID < 0 || bufID >= LOG_ID_MAX) {
    jniThrowNullPointerException(env, "bad bufID");
    return -1;
}

if (tagObj != NULL)
    tag = env->GetStringUTFChars(tagObj, NULL);
msg = env->GetStringUTFChars(msgObj, NULL);

int res = __android_log_buf_write(bufID, (android_LogPriority)priority, tag, msg);

if (tag != NULL)
    env->ReleaseStringUTFChars(tagObj, tag);
env->ReleaseStringUTFChars(msgObj, msg);

return res;
}

Basically this then passes the arguments to the driver in the system which goes and writes to the Log buffer. Log buffer is pointed by /dev/log in the Linux kernel.

like image 165
Royston Pinto Avatar answered Dec 28 '22 16:12

Royston Pinto