android 5.0 源码
1、/system/core/rootdir/Init.rc
service dumpstate /system/bin/dumpstate -s =》linux服务进程
class main
socket dumpstate stream 0660 shell log
disabled
oneshot
2、对应/framework/native/cmds/dumpstate/Dumpstate.c
int main(int argc, char *argv[]) {
......
if (getuid() != 0) {
// Old versions of the adb client would call the dumpstate command directly. Newer clients call /system/bin/bugreport instead.
// If we detect we're being called incorrectly, then exec the correct program.
return execl("/system/bin/bugreport", "/system/bin/bugreport", NULL);
}
......
dumpstate();
/* tell activity manager we're done */ =》广播通知AM,已经结束?
if (do_broadcast && use_outfile && do_fb) {
run_command(NULL, 5, "/system/bin/am", "broadcast", "--user", "0",
"-a", "android.intent.action.BUGREPORT_FINISHED",
"--es", "android.intent.extra.BUGREPORT", path,
"--es", "android.intent.extra.SCREENSHOT", screenshot_path,
"--receiver-permission", "android.permission.DUMP", NULL);
}
......
}
/* dumps the current system state to stdout */
static void dumpstate() { ...... }
3、对应/framework/native/cmds/bugreport/Bugreport.c
说明,bugreport命令,是在dumpstate服务外面包装了一层,通过socket连接dumpstate服务。
int main(int argc, char *argv[]) {
......
/* start the dumpstate service */
property_set("ctl.start", "dumpstate");
/* socket will not be available until service starts */
for (i = 0; i < 20; i++) {
s = socket_local_client("dumpstate",
ANDROID_SOCKET_NAMESPACE_RESERVED,
SOCK_STREAM);
if (s >= 0)
break;
/* try again in 1 second */
sleep(1);
}
......
}
参考:
http://blog.youkuaiyun.com/kevinx_xu/article/details/26253969
http://blog.youkuaiyun.com/chenzhiqin20/article/details/12506227