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

2

4

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.

Bakunin answered 14/5, 2013 at 16:21 Comment(0)
F
9

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.

Fortunate answered 14/5, 2013 at 17:13 Comment(5)
Do you mean you downloaded the source and the above codes show up?Bakunin
Thanks. Could you quote where exact you traced to those codes? And let me know where to download it?Bakunin
Try this one code.google.com/p/pdroid/source/browse/trunk/frameworks/base/…Fortunate
one up. Could you explain how to trace it? I traced it down to line 340 of the Log.java class and don't know where to look next.Crosswise
I am hoping that line 340 is a call to 'public static native int println_native(int bufID, int priority, String tag, String msg);'. This will correspond to the function posted from Log.cpp. The above function then makes a call to the Log buffer in Linux to post the message. DDMS reads this buffer to show the logs.Fortunate
D
2

Once you have downloaded the sdk, you can use find to dig files. Java code is linked to cpp code through jni.

In your case, you can use this command to find the related files:

find framework -type f -name "*.cpp" -exec grep "println_native" {} \; -ls

then you'll see that your java function is linked to this file : framework/base/core/jni/android_util_Log.cpp

Distended answered 14/10, 2015 at 13:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.