新聞中心

Android 框架簡介

作者: 時間:2016-09-12 來源:網(wǎng)絡(luò) 收藏

/** @hide */ public static final int LOG_ID_SYSTEM = 3;

/** @hide */ public static native int println_native(int bufID,

int priority, String tag, String msg);

}

我們看到所有代碼都是調(diào)用public static native int println_native(int bufID,

int priority, String tag, String msg);來實現(xiàn)輸出的,這個函數(shù)的實現(xiàn)就是C++,調(diào)用的方式就是JNI

我們看一下對應(yīng)的jni代碼froyo/frameworks/base/core/jni/_util_Log.cpp,最終調(diào)用的輸出函數(shù)是

/*

* In class .util.Log:

* public static native int println_native(int buffer, int priority, String tag, String msg)

*/

static jint _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) {

jclass npeClazz;

npeClazz = env->FindClass(java/lang/NullPointerException);

assert(npeClazz != NULL);

env->ThrowNew(npeClazz, println needs a message);

return -1;

}

if (bufID 0 || bufID >= LOG_ID_MAX) {

jclass npeClazz;

npeClazz = env->FindClass(java/lang/NullPointerException);

assert(npeClazz != NULL);

env->ThrowNew(npeClazz, 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;

}

當(dāng)然我們發(fā)現(xiàn)最終輸出是

? 1int res = __Android_log_buf_write(bufID, (android_LogPriority)priority, tag, msg);

用力grep了一下代碼,結(jié)果如下

./system/core/include/cutils/log.h:int __Android_log_buf_write(int bufID, int prio, const char *tag, const char *text);

./system/core/liblog/logd_write.c:int __Android_log_buf_write(int bufID, int prio, const char *tag, const char *msg)

./system/core/liblog/logd_write.c: return __Android_log_buf_write(bufID, prio, tag, buf);

這個就是和Android專用驅(qū)動進(jìn)行通信的方式,這個分析下去就有點深了,后面分析。


上一頁 1 2 3 4 下一頁

關(guān)鍵詞: Android 框架簡介

評論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉