adb 命令分类总结,做报告

1,494 阅读4分钟

通用命令

  1. adb shell ps | grep -i 查找进程信息

  2. adb shell getenforce
    adb shell setenforce 0 //设置成permissive 模式
    adb shell setenforce 1 //设置成enforce 模式

  3. adb reboot edl adb reboot recovery adb reboot bootloader

  4. adb forward 转发,可以实现 pc和android app的通信 adb forward tcp:8888 tcp:9999 把PC端8888端口的数据,转发到Android端9999端口上

adb 与 AM PM WM 的交互

adb 与am 启动activity/service/发送广播

-a (action), -n(component)

  1. 发送广播 adb shell am broadcast -a *** adb shell am broadcast -a android.intent.action.BATTERY_CHANGED 电池广播

  2. 启动activity adb shell am start -a adb shell am start -a android.intent.action.CALL -d tel:10086 adb shell start -n adb shell am start -n org.codeaurora.gallery/com.android.gallery3d.app.GalleryActivity

  3. 启动服务 adb shell am startservice -n adb shell am stopservice

  4. 关闭app adb shell am force-stop 包名 adb shell am force-stop org.codeaurora.gallery

  5. adb shell am help 启动耗时; 冷启动,热启动
    adb shell am start -W org.codeaurora.gallery/com.android.gallery3d.app.GalleryActivity

adb shell stack list activity 的Stack, Task等概念

开始收集目标进程运行过程中的函数调用关系
adb shell am profile start 17495 /mnt/sdcard/profile.txt
将指定进程号的堆信息输出到指定的文件中 -n: 直接存储原始堆信息
adb shell am dumpheap -n 17495 /mnt/sdcard/dumpheap.txt

重写模拟器/设备显示大小 重写模拟器/设备显示密度 adb shell am display-size 1280x800 adb shell am display-density 480

adb 与pm

adb shell pm list packages
adb shell pm list features
adb shell pm list librarys
adb shell pm help

pm查询类

list packages:列出设备中已经安装的所有应用包(包括系统应用和用户应用);
list features:列出所有硬件相关信息;
list libraries :列出当前设备支持的libs;
list users:列出系统上所有的users;
list permissions:列出所有已知的权限;
list ‘pkgname’:列出指定包名的associated文件(APK存档文件)所在;
path ‘pkgname’:查询package的安装位置。

pm操作类

install [-lrtsfd] [PATH]:安装命令;
-l :锁定应用程序;
-r:重新安装应用,且保留应用数据;
-i:指定安装包的包名;
-s:安装到sd卡;
-f:安装到系统内置存储中(默认安装位置);
-g:授予应用程序清单中列出的所有权限(只有6.0系统可用);
uninstall [options] ‘pkgname’:卸载命令;
-k:卸载应用且保留数据与缓存(如果不加-k则全部删除); clear ‘pkgname’ :对指定的package删除所有数据;
enable ‘pkgname’ :使package或component可用。(如:pm enable “package/class”);
disable ‘pkgname’ :使package或component不可用。(如:pm disable “package/class”);
grant ‘pkgname’:授权给应用;
revoke ‘pkgname’:撤销权限;
set-install-location ‘location’:设置默认的安装位置。
其中0:让系统自动选择最佳的安装位置。1:安装到内部的设备存储空间。2:安装到外部的设备存储空间;
get-install-location :返回当前的安装位置。返回结果同上参数选项;
create-user ‘USER_NAME’ :增加一个新的USER;
remove-user ‘USER_ID’ :删除一个USER;

adb 与wm

Window manager (window) commands: help Print this help text. size [reset|WxH|WdpxHdp] Return or override display size. width and height in pixels unless suffixed with 'dp'. density [reset|DENSITY] Return or override display density. overscan [reset|LEFT,TOP,RIGHT,BOTTOM] Set overscan area for display. scaling [off|auto] Set display scaling mode. dismiss-keyguard Dismiss the keyguard, prompting user for auth if necessary. tracing (start | stop) Start or stop window tracing.

adb shell wm dismiss-keyguard
adb shell wm size
adb shell wm density

adb 的dumpsys 都能dump下来什么

PS E:\Users\Administrator\Desktop> adb shell dumpsys activity help

Activity manager dump options: [-a] [-c] [-p PACKAGE] [-h] [WHAT] ... WHAT may be one of: a[ctivities]: activity stack state r[recents]: recent activities state b[roadcasts] [PACKAGE_NAME] [history [-s]]: broadcast state broadcast-stats [PACKAGE_NAME]: aggregated broadcast statistics i[ntents] [PACKAGE_NAME]: pending intent state p[rocesses] [PACKAGE_NAME]: process state o[om]: out of memory management perm[issions]: URI permission grant state prov[iders] [COMP_SPEC ...]: content provider state provider [COMP_SPEC]: provider client-side state s[ervices] [COMP_SPEC ...]: service state as[sociations]: tracked app associations settings: currently applied config settings 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 WHAT 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. -p: limit output to given package. --checkin: output checkin format, resetting data. --C: output checkin format, not resetting data. --proto: output dump in protocol buffer format. --autofill: dump just the autofill-related state of an activity Bad activity command, or no activities match: help Use -h for help.

adb shell dumpsys meminfo --- 内存信息
adb shell dumpsys window
adb shell dumpsys window displays
adb shell dumpsys window windows
adb shell dumpsys power
adb shell dumpsys battery
adb shell dumpsys activity activities
adb shell dumpsys activity services
adb shell dumpsys activity top

adb shell settings

global /system/ security

adb shell settings put

adb shell settings get