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

Here is the source code of android.util.Log .

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

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

I think println_native() more or less similar to its println() , just with int bufID different.

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

0
source share
2 answers

Just made a dig in the Android source code. This function is displayed on

 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; } 

This basically passes arguments to the driver in the system, which goes and writes to the log buffer. The log buffer is specified by /dev/log in the Linux kernel.

+5
source

Once you have downloaded sdk, you can use find to generate the files. Java code linked to cpp code via jni.

In your case, you can use this command to search for related files:

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

then you will see that your java function is associated with this file: framework / base / core / jni / android_util_Log.cpp

+1
source

All Articles