需求1、在系统启动时候输出自己的log
根据系统启动流程图得知,Android系统会在SystemServer.java中启动
(aosppy2) aosp@ubuntu:~/android/android5.1$ godir SystemServer.java (aosppy2) aosp@ubuntu:~/android/android5.1/frameworks/base/services/java/com/android/server$ ls SystemServer.java
sudo gedit SystemServer.java
#修改完成后,mm编译当前的模块
mm
修改内容:
通过adb logcat 命令抓取日志,-b 参数标识从系统缓冲区抓取,-s 标识 过滤关键字
(base) aosp@ubuntu:~$ adb logcat -b system -s 'swb' I/swb ( 3118): Android system server boot do something ! I/swb ( 3118): Android system server boot do something !
需求2、对指定的日志截取修改
1、找到Log.java所在的位置
(aosppy2) aosp@ubuntu:~/android/android5.1/packages/apps/Calculator$ godir Log.java #输出多个含有Log.java的位置,找到framework层的进行修改 [130] ./frameworks/base/core/java/android/util Select one: 130
2、修改log.java的wtf()方法
public static int wtf(String tag, String msg) { if("swb".equals(tag)){ msg = "i handle swb this log.............................."; } return wtf(LOG_ID_MAIN, tag, msg, null, false, false); }
修改完成后进行编译,push到当前的模拟器上,进入ADB ,“stop;start” 进行重新启动Android系统
(aosppy2) aosp@ubuntu:~/android/android5.1/frameworks/base/core/java/android/util$ adb push $(gettop)/out/target/product/generic_x86/system/framework/framework.jar /system/framework failed to copy '/home/aosp/android/android5.1/out/target/product/generic_x86/system/framework/framework.jar' to '/system/framework/framework.jar': Read-only file system (aosppy2) aosp@ubuntu:~/android/android5.1/frameworks/base/core/java/android/util$ adb remount remount succeeded (aosppy2) aosp@ubuntu:~/android/android5.1/frameworks/base/core/java/android/util$ adb push $(gettop)/out/target/product/generic_x86/system/framework/framework.jar /system/framework
(aosppy2) aosp@ubuntu:~/android/android5.1/frameworks/base/core/java/android/util$ adb shell
root@generic_x86:/ # stop;start
3、在任意一个APP里面增加 Log.wtf()调用,这里方便对比,wtf方法中我们做了处理而普通的Log.d()方法未处理
Log.d("swb","on calculator is start ~~~~~~~~~~~~~~~~~~~~~~~~");
Log.wtf("swb","on calculator is start ~~~~~~~~~~~~~~~~~~~~~~~~");
adb logcat 查看修改的日志
(base) aosp@ubuntu:~$ adb logcat -s 'swb'
--------- beginning of main
--------- beginning of system
I/swb ( 1224): Android system server boot ---------------------------------------------------------------------------------------------------------------------->do something !
I/swb ( 1224): Android system server boot ---------------------------------------------------------------------------------------------------------------------->do something !
D/swb ( 2001): on calculator is start ~~~~~~~~~~~~~~~~~~~~~~~~
F/swb ( 2001): i handle swb this log..............................
我这里在计算器的启动类中调用了代码,运行模拟器,抓取日志
应用层——>framework层——>JNI层——>natvice层修改生效