adb及debug常用命令

157 阅读3分钟

1.编译

编译framework:

make framework-minus-apex

把生成的framework.jar push到system/framework/下面:

adb push framework.jar /system/framework/

同时还要删除/system/framework/目录下面的arm64目录(如有arm目录,也一样操作)中的文件:

cd /system/framework/arm64

删除arm64里面所有文件:rm *

然后再执行:

adb reboot

编译别的模块,类似:

make framework-res

make services

make framework-graphics

修改overlay后,只需要替换framework_res.apk

2.Android支持adb命令启动和停用DarkMode,具体命令是:

adb shell cmd uimode night <auto | yes | no>

如暗色模式打开命令: adb shell cmd uimode night yes

3.adb -s device_xxx shell 多设备时进入到指定设备

4.查看进程2469中的所有线程:

ps -AT |grep 2469 //2496为system_server进程号

5.查看应用的安装目录:

adb shell pm path com.xxx.xxx

6.输入法

adb shell ime list -a //查看已安装的输入法

adb shell settings get secure default_input_method //查看默认输入法

adb shell settings get secure enabled_input_methods //查看可使用的输入法

adb shell dumpsys input_method // dump 输入法相关信息

7.settings值

adb shell settings get secure xxx

adb shell settings put secure xxx

8.获取Android设备屏幕分辨率:

adb shell wm size

获取android设备屏幕密度:

adb shell wm density

修改屏幕像素密度:

adb shell wm size 540×960

重置屏幕尺寸大小:

adb shell wm size reset

设置屏幕dpi (常用的dpi有160mdpi, 240hdpi, 320xhdpi, 480xxhdpi):

adb shell wm density 320

重置可用dpi如下命令

adb shell wm density reset

9.二进制格式的xml需要用/system/bin/abx2xml工具转换下:

usage: abx2xml [-i] input [output]

adb shell abx2xml /data/system/users/0/settings_secure.xml /sdcard/settings_secure_parsed.xml

adb pull /sdcard/settings_secure_parsed.xml

adb shell abx2xml /data/system/users/0/appwidgets.xml /sdcard/appwidgets_parsed.xml

10.截图和录制视频

adb shell screencap -p /sdcard/screen.png

adb shell screenrecord /sdcard/1.mp4

11.adb shell input keyevent “value”

'value'对应事件的值,如发送home(对应数值为3)按键事件:

adb shell input keyevent 3

返回键: adb shell input keyevent 4

12.常用dump

adb shell dumpsys input

adb shell dumpsys input_method

adb shell dumpsys appwidget

adb shell dumpsys SurfaceFlinger

adb shell dumpsys window

adb shell dumpsys activity

adb shell dumpsys -l

adb shell dumpsys window w //dumpsys window windows

adb shell dumpsys window -a

adb shell dumpsys activity -a

adb shell dumpsys activity activities // 查看Activity信息

adb shell dumpsys activity services // Service组件信息

adb shell dumpsys activity providers // ContentProvider组件信息

adb shell dumpsys activity broadcasts // BraodcastReceiver信息

adb shell dumpsys activity intents //Intent信息

adb shell dumpsys activity processes //进程信息

13.日志

adb logcat -c // 清除adb logcat 日志

adb logcat -b events -c //清除event日志

adb logcat -b events // 查看event日志

logcat |grep -iE "xxx|xxx" // 忽略大小写以及查找多个关键字

adb logcat | findstr xxx

14.抓trace

adb shell perfetto -o /data/misc/perfetto-traces/trace_file.perfetto-trace sched freq idle am wm gfx view binder_driver hal dalvik camera input res memory -t 3s

adb pull /data/misc/perfetto-traces/trace_file.perfetto-trace

ui.perfetto.dev/中打开

15.ps -eZ |grep settings

ll -lZ 查看文件的Security Context

ps -efZ 进程的Security Context

17.adb shell am start -W xxx/xxActivity //计算Activity(包名/类名)启动时间

18.adb shell stop //软重新启动

adb shell start

adb shell uptime //查看开机时长

adb shell lpdump //查看分区

19.pm相关命令

pm list packages // 列举安装的所有app包信息

pm list package -f |grep "包名或是关键字" //列出指定"包名或是关键字"的packages列表

pm clear xxx.xxx.xxx //清除包名为xxx.xxx.xxx应用的缓存数据

adb shell dumpsys package xxx.xxx.xxx.xxx |grep version //打印指定apk的版本信息

pm install 安装应用

pm uninstall com.xxx.xxx 卸载应用

pm enable <包名或组件名> enable应用 (桌面图标出现)

pm disable <包名或组件名> disable应用 (桌面图标会消失)

pm path 查看App路径

pm get-max-users 最大用户数

pm revoke [packageName] [permissionName] //移除指定权限

pm revoke com.tencent.mm android.permission.CAMERA /移除微信相机权限

pm grant [packageName] [permissionName] //授予指定权限

pm grant com.tencent.mm android.permission.CAMERA //给微信授予相机权限

pm list permissions -d -g //按组查看权限,查看权限的分组情况

20.am常用命令

am start [options] 启动Activity

am startservice 启动Service

am stopservice 停止Service

am broadcast 发送广播

am kill 杀指定后台进程

am kill-all 杀所有后台进程

am force-stop 强杀进程

32.查看数据库

adb root

adb remount

adb shell

cd /data/data/com.xxx.proof/databases

sqlite3 xxx.db

.tables //确认有events

select * from usage_record;