什么是android.util.Log#println_native()? [英] What is in android.util.Log#println_native()?
问题描述
此处是 android.util.Log
源代码。
在最底层(第340行),什么是在方法中:
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);
我猜 println_native( )
或多或少像它的 println()
,只是与 int bufID
不同。
i guess println_native()
is more or less like its println()
, just with an int bufID
different.
但即使我得到了 println_native()
的代码,我仍然缺少 com .android.internal.os.RuntimeInit
(第19行, import
)来模拟 android.util.Log 旧的Android版本code>。
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.
推荐答案
刚刚在android源代码中进行了一些挖掘。此函数映射到
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;
}
基本上,这会将参数传递给系统中的驱动程序到日志缓冲区。 Linux内核中的 / dev / log
指向日志缓冲区。
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.
这篇关于什么是android.util.Log#println_native()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!