赞
踩
0x01 查看dumpsys支持哪些服务: adb shell dumpsys -l
列出dumpsys支持的服务名字,例如(仅列出几个,全部服务有100多个)
$ adb shell dumpsys -l
Currently running services:
accessibility
account
activity
alarm
cpuinfo
isms
location
meminfo
mount
nfc
notification
permission
phone
power
window
0x02 查看dump某个具体服务的用法:adb shell dumpsys -h
这个就是adb shell dumpsys -l打印出来的名字,是必须遵守大小写的。
例如, adb shell dumpsys package -h
Android4.4.2中的dumpsys package -h
$ adb shell dumpsys package -h
Package manager dump options:
[-h] [-f] [cmd] ...
-f: print details of intent filters
-h: print this help
cmd may be one of:
l[ibraries]: list known shared libraries
f[ibraries]: list device features
r[esolvers]: dump intent resolvers
perm[issions]: dump permissions
pref[erred]: print preferred package settings
preferred-xml [--full]: print preferred package settings as xml
prov[iders]: dump content providers
p[ackages]: dump installed packages
s[hared-users]: dump shared user IDs
m[essages]: print collected runtime messages
v[erifiers]: print package verifier info
: info about given package
k[eysets]: print known keysets
Android6.0.1中的dumpsys package -h
$ adb shell dumpsys package -h
Package manager dump options:
[-h] [-f] [--checkin] [cmd] ...
--checkin: dump for a checkin
-f: print details of intent filters
-h: print this help
cmd may be one of:
l[ibraries]: list known shared libraries
f[ibraries]: list device features
k[eysets]: print known keysets
r[esolvers]: dump intent resolvers
perm[issions]: dump permissions
permission [name ...]: dump declaration and use of given permission
pref[erred]: print preferred package settings
preferred-xml [--full]: print preferred package settings as xml
prov[iders]: dump content providers
p[ackages]: dump installed packages
s[hared-users]: dump shared user IDs
m[essages]: print collected runtime messages
v[erifiers]: print package verifier info
d[omain-preferred-apps]: print domains preferred apps
i[ntent-filter-verifiers]|ifv: print intent filter verifier info
version: print database version info
write: write current settings now
installs: details about install sessions
check-permission []: does pkg hold perm?
: info about given package
installs: details about install sessions
例如,adb shell dumpsys activity -h
$ adb shell dumpsys activity -h
Activity manager dump options:
[-a] [-c] [-h] [cmd] ...
cmd may be one of:
a[ctivities]: activity stack state
b[roadcasts] [PACKAGE_NAME] [history [-s]]: broadcast state
i[ntents] [PACKAGE_NAME]: pending intent state
p[rocesses] [PACKAGE_NAME]: process state
o[om]: out of memory management
prov[iders] [COMP_SPEC ...]: content provider state
provider [COMP_SPEC]: provider client-side state
s[ervices] [COMP_SPEC ...]: service state
service [COMP_SPEC]: service client-side state
package [PACKAGE_NAME]: all state related to given package
all: dump all activities
top: dump the top activity
cmd may also be a COMP_SPEC to dump activities.
COMP_SPEC may be a component name (com.foo/.myApp),
a partial substring in a component name, a
hex object identifier.
-a: include all available server state.
-c: include client state.
例如,查看某个权限:
由adb shell dumpsys package -h可知,查看权限可以用:adb shell dumpsys package permissions
这会列举出手机中所有的权限。
如果只查看某一个权限可以使用adb shell dumpsys package permission 。注意这里的permission是不带s的。如果没有此选项说明手机版本比较旧了。
0x03 附dumpsys的源码
dumpsys 的代码在frameworks/native/cmds/dumpsys/dumpsys.cpp。
int main(int argc, char* const argv[])
{
signal(SIGPIPE, SIG_IGN);
sp sm = defaultServiceManager();
fflush(stdout);
Vector services;
Vector args;
bool showListOnly = false;
// 只有一个参数,即执行dumpsys -l,这时只是调用listServices()获取服务列表
if ((argc == 2) && (strcmp(argv[1], "-l") == 0)) {
showListOnly = true;
}
// argc == 1表示如果没有加任何参数,即只是执行dumpsys
// showListOnly表示执行dumpsys -l
// 这两种情况会获取服务列表
if ((argc == 1) || showListOnly) {
services = sm->listServices();
services.sort(sort_func);
args.add(String16("-a"));
} else {
// 如果有2个或2个以上参数,即执行dumpsys ...
// 这时被认为是服务名,即listServices()列出的名字
// 及之后的参数作为service->dump的参数
services.add(String16(argv[1]));
for (int i=2; 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
sp service = sm->checkService(services[i]);
if (service != NULL) {
aout << " " << services[i] << endl;
}
}
}
if (showListOnly) {//如果只有-l参数,则到此就返回了。
return 0;
}
// 执行到此,要么dumpsys没有参数,这时services中包含了所有的服务名,即将调用所有服务的dump()方法
// 要么dumpsys有多个参数,例如dumpsys package -h
for (size_t i=0; i
sp service = sm->checkService(services[i]); // dumpsys的第一个参数就是checkService的参数,要注意大小写。
if (service != NULL) {
if (N > 1) {
aout << "------------------------------------------------------------"
"-------------------" << endl;
aout << "DUMP OF SERVICE " << services[i] << ":" << endl;
}
int err = service->dump(STDOUT_FILENO, args); //调用指定service的dump方法,例如ActivityManagerService的dump()或者PackageManagerService的dump()方法
if (err != 0) {
aerr << "Error dumping service info: (" << strerror(err)
<< ") " << services[i] << endl;
}
} else {
aerr << "Can't find service: " << services[i] << endl;
}
}
return 0;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。