新聞中心

Android 框架簡(jiǎn)介

作者: 時(shí)間:2016-09-12 來(lái)源:網(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);來(lái)實(shí)現(xiàn)輸出的,這個(gè)函數(shù)的實(shí)現(xiàn)就是C++,調(diào)用的方式就是JNI

我們看一下對(duì)應(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);

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


上一頁(yè) 1 2 3 4 下一頁(yè)

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

評(píng)論


相關(guān)推薦

技術(shù)專(zhuān)區(qū)

關(guān)閉