dumpsys是系統中重要的函數,我們來看看它如何使用,都能dump出來一些什麼東西
首先我們來看看dumpsys的源碼,在4.1中,它在framework/native目錄下面
frameworks/native/cmds/dumpsys/dumpsys.cpp
if (argc == 1) {
services = sm->listServices();
services.sort(sort_func);
args.add(String16("-a"));
} else {
services.add(String16(argv[1]));
for (int i=2; i<argc; i++) {
args.add(String16(argv[i]));
}
}
const size_t N = services.size();
if (N > 1) {
// first print a list of the current services
aout << "Currently running services:" << endl;
for (size_t i=0; i<N; i++) {
sp<IBinder> service = sm->checkService(services[i]);
if (service != NULL) {
aout << " " << services[i] << endl;
}
}
}
for (size_t i=0; i<N; i++) {
sp<IBinder> service = sm->checkService(services[i]);
if (service != NULL) {
if (N > 1) {//dump多個Service時,Service信息之間的分隔
aout << "------------------------------------------------------------"
"-------------------" << endl;
aout << "DUMP OF SERVICE " << services[i] << ":" << endl;
}
int err = service->dump(STDOUT_FILENO, args);
if (err != 0) {
aerr << "Error dumping service info: (" << strerror(err)
<< ") " << services[i] << endl;
}
} else {
aerr << "Can't find service: " << services[i] << endl;
}
}
我只會java,上面的代碼還是留給大家自己閱讀吧,我就不詳細解釋了……
如果參數個數=1,則在ServiceManager中查找注冊的Service
否則查找指定的Service,並且將剩余參數傳給Serivce
如果執行dumpsys命令,那麼將會dump所有Service,每個Service之間會分隔開
如果dumpsys一個沒有注冊的Service,那麼則提示找不到Service,比如:
# dumpsys adb
Can't find service: adb