ActivityManager:dumpPackageState(FileDescriptor fd, String packageName)
1.作用
用于获取相应包名对应的apk的各种状态信息。
2.源码
public void dumpPackageState(FileDescriptor fd, String packageName) {
dumpPackageStateStatic(fd, packageName);
}
public static void dumpPackageStateStatic(FileDescriptor fd, String packageName) {
FileOutputStream fout = new FileOutputStream(fd);
PrintWriter pw = new FastPrintWriter(fout);
dumpService(pw, fd, "package", new String[] { packageName });
pw.println();
dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] {
"-a", "package", packageName });
pw.println();
dumpService(pw, fd, "meminfo", new String[] { "--local", "--package", packageName });
pw.println();
dumpService(pw, fd, ProcessStats.SERVICE_NAME, new String[] { packageName });
pw.println();
dumpService(pw, fd, "usagestats", new String[] { "--packages", packageName });
pw.println();
dumpService(pw, fd, BatteryStats.SERVICE_NAME, new String[] { packageName });
pw.flush();
}
3.分析及说明
参数说明:1.FileDescriptor文件描述
2.packageName要获取信息的包名
值得一提的是该方法不要在UI线程中调用。