修改./system/core/liblog/logger_write.cpp文件的__android_log_buf_write函数:
int __android_log_write(int prio, const char* tag, const char* msg) {
return __android_log_buf_write(LOG_ID_MAIN, prio, tag, msg);
}
int __android_log_buf_write(int bufID, int prio, const char* tag, const char* msg) {
struct iovec vec[3];
char tmp_tag[32];
#if defined(MTK_LOGD_ENHANCE) && defined(ANDROID_LOG_MUCH_COUNT)
char new_tag[LOG_BUF_SIZE];
void* caller = NULL;
int size;
#endif
//test no log start --这里直接返回
return 0;
//test no log end
/* XXX: This needs to go! */
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wstring-plus-int"
if (bufID != LOG_ID_RADIO) {
switch (tag[0]) {
case 'H':
if (strcmp(tag + 1, "HTC_RIL" + 1)) break;
goto inform;
case 'R':
/* Any log tag with "RIL" as the prefix */
if (strncmp(tag + 1, "RIL" + 1, strlen("RIL") - 1)) break;
goto inform;
case 'Q':
/* Any log tag with "QC_RIL" as the prefix */
if (strncmp(tag + 1, "QC_RIL" + 1, strlen("QC_RIL") - 1)) break;
goto inform;
case 'I':
/* Any log tag with "IMS" as the prefix */
if (strncmp(tag + 1, "IMS" + 1, strlen("IMS") - 1)) break;
goto inform;
case 'A':
if (strcmp(tag + 1, "AT" + 1)) break;
goto inform;
case 'G':
if (strcmp(tag + 1, "GSM" + 1)) break;
goto inform;
case 'S':
if (strcmp(tag + 1, "STK" + 1) && strcmp(tag + 1, "SMS" + 1)) break;
goto inform;
case 'C':
if (strcmp(tag + 1, "CDMA" + 1)) break;
goto inform;
case 'P':
if (strcmp(tag + 1, "PHONE" + 1)) break;
/* FALLTHRU */
inform:
bufID = LOG_ID_RADIO;
snprintf(tmp_tag, sizeof(tmp_tag), "use-Rlog/RLOG-%s", tag);
tag = tmp_tag;
[[fallthrough]];
default:
break;
}
}
#pragma clang diagnostic pop
#if defined(MTK_LOGD_ENHANCE) && defined(ANDROID_LOG_MUCH_COUNT)
if ((((__android_log_transport == LOGGER_DEFAULT) || (__android_log_transport & LOGGER_LOGD))
&& (strlen(tag) < LOG_BUF_SIZE)) && strstr(tag, "-0x") == NULL) {
caller = __builtin_return_address(0);
size = sprintf(new_tag, "%p", caller);
new_tag[size - 1] = 'x';
new_tag[size - 2] = '0';
new_tag[size - 3] = '-';
snprintf(new_tag+size, sizeof(new_tag)-size, "%s", tag);
tag = new_tag;
if (tag_add_size != size)
tag_add_size = size;
}
#endif
#if __BIONIC__
if (prio == ANDROID_LOG_FATAL) {
android_set_abort_message(msg);
}
#endif
vec[0].iov_base = (unsigned char*)&prio;
vec[0].iov_len = 1;
vec[1].iov_base = (void*)tag;
vec[1].iov_len = strlen(tag) + 1;
vec[2].iov_base = (void*)msg;
vec[2].iov_len = strlen(msg) + 1;
return write_to_log(static_cast<log_id_t>(bufID), vec, 3);
}