adb shell一些实用的命令

重要文件位置

用户数据(壁纸/系统属性settings命令存储相关的)

1
/data/system/users/0

Window相关

获取当前界面的ui信息

1
uiautomator # 可用于自动化操作

获取当前window的view元素

1
wm dump-visible-window-views # 获取更详细的控件数据可以研究android.view.View#encode源码进行手动解析实现类似于uiautomator功能

Activity相关

启动Activity前停止app

1
adb shell am start-activity -S -n com.example.app/.MainActivity

启动activity并等待打开

1
adb shell am start-activity -W -n com.example.app/.MainActivity

系统属性

列出存在的属性

1
2
3
4
adb shell settings list system
adb shell settings list global
adb shell settings list secure
adb shell getprop

网络相关

WIFI相关

开启WIFI

1
adb shell cmd -w wifi set-wifi-enabled enabled

扫描WIFI

1
adb shell cmd -w wifi start-scan

列出WIFI扫描结果

1
adb shell cmd -w wifi list-scan-results

列出当前保存的WIFI列表

1
adb shell cmd -w wifi list-networks

连接指定的WIFI

1
adb shell cmd -w wifi connect-network home-wifi wpa2 password

nc命令

1
2
adb shell nc -l -p 8888 # 监听客户端连接
adb shell nc 127.0.0.1 8888 # 连接服务端

代理

设置代理

1
2
3
4
5
adb shell settings put global http_proxy 192.168.225.100:3128
adb shell settings put global global_http_proxy_host 192.168.225.100
adb shell settings put global global_http_proxy_port 3128
adb shell settings put global global_http_proxy_username foo
adb shell settings put global global_http_proxy_password bar

移除代理

1
2
3
4
5
6
7
8
adb shell settings delete global http_proxy
adb shell settings delete global global_http_proxy_host
adb shell settings delete global global_http_proxy_port
adb shell settings delete global global_http_proxy_username
adb shell settings delete global global_http_proxy_password
adb shell settings delete global global_http_proxy_exclusion_list
adb shell settings delete global global_proxy_pac_url
adb shell reboot

时间相关

设置时区

1
adb shell service call alarm 3 s16 America/Phoenix

设置时间

1
adb shell "su -c date $(date +%m%d%H%M%Y.%S)"

[!NOTE]

需要root权限

设备安全

设置不锁屏

1
adb shell locksettings set-disabled true

恢复出厂设置

1
am broadcast -a android.intent.action.FACTORY_RESET -n android/com.android.server.MasterClearReceiver

移动安全相关

监控目录下文件事件

1
2
inotifywait -r -m /path/to/directory # 监控所有事件
inotifywait -r -m -e create /path/to/directory # 监控特定事件

另辟蹊径检测app是否安装

1
stat -c %u /data/data/com.example # 测试在Android11上可用

使用Magisk root允许所有进程调试

参考:https://danylokos.github.io/0x02/

1
2
magisk resetprop ro.debuggable 1
stop; start

系统启动状态

1
2
adb shell getprop sys.boot_completed # 等于1时启动完成
adb shell getprop init.svc.bootanim # 等于stopped时开机动画完成

重启zygote进程

1
adb shell setprop ctl.restart zygote

屏幕相关

检查是否亮屏

1
adb shell dumpsys deviceidle | grep mScreenOn
1
adb shell dumpsys power | grep "Display Power"

显示触摸点

1
adb shell settings put system show_touches 1

显示触摸位置

1
adb shell settings put system pointer_location 1

录制触屏轨迹

1
2
3
adb shell getevent | grep --line-buffered ^/ | tee /tmp/android-touch-events.log # 录制

awk '{printf "%s %d %d %d\n", substr($1, 1, length($1) -1), strtonum("0x"$2), strtonum("0x"$3), strtonum("0x"$4)}' /tmp/android-touch-events.log | xargs -l adb shell sendevent # 重放

语言相关

设置系统语言

1
2
3
4
5
6
7
adb shell content query --uri content://settings/system --where "name=\'system_locales\'"

adb shell content delete --uri content://settings/system --where "name=\'system_locales\'"

adb shell content insert --uri content://settings/system --bind name:s:system_locales --bind value:s:en-US
adb shell content insert --uri content://settings/system --bind name:s:system_locales --bind value:s:zh-Hant-TW
adb shell content insert --uri content://settings/system --bind name:s:system_locales --bind value:s:zh-Hant-TW,en-US,ja-JP

显示相关

字体缩放

1
2
3
4
5
adb shell settings put system font_scale 0.85 # (small)
adb shell settings put system font_scale 1.0 # (default)
adb shell settings put system font_scale 1.15 # (large)
adb shell settings put system font_scale 1.30 # (largest)
adb shell settings put system font_scale 2.0 # (sizes like this can only be achieved with custom adb setting, not from ui)

窗口管理

分屏模式Split screen

1
2
adb shell am start-activity -n com.whatsapp/.Main --windowingMode 3
adb shell am start-activity -n org.telegram.messenger/.DefaultIcon --windowingMode 4

悬浮窗模式Flating window

1
2
adb shell am start-activity -n com.whatsapp/.Main --windowingMode 5
adb shell am start-activity -n org.telegram.messenger/.DefaultIcon --windowingMode 5

账户相关

请求同步

1
requestsync

输入相关

keyevent

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
0 -->  "KEYCODE_UNKNOWN" 
1 --> "KEYCODE_MENU"
2 --> "KEYCODE_SOFT_RIGHT"
3 --> "KEYCODE_HOME"
4 --> "KEYCODE_BACK"
5 --> "KEYCODE_CALL"
6 --> "KEYCODE_ENDCALL"
7 --> "KEYCODE_0"
8 --> "KEYCODE_1"
9 --> "KEYCODE_2"
10 --> "KEYCODE_3"
11 --> "KEYCODE_4"
12 --> "KEYCODE_5"
13 --> "KEYCODE_6"
14 --> "KEYCODE_7"
15 --> "KEYCODE_8"
16 --> "KEYCODE_9"
17 --> "KEYCODE_STAR"
18 --> "KEYCODE_POUND"
19 --> "KEYCODE_DPAD_UP"
20 --> "KEYCODE_DPAD_DOWN"
21 --> "KEYCODE_DPAD_LEFT"
22 --> "KEYCODE_DPAD_RIGHT"
23 --> "KEYCODE_DPAD_CENTER"
24 --> "KEYCODE_VOLUME_UP"
25 --> "KEYCODE_VOLUME_DOWN"
26 --> "KEYCODE_POWER"
27 --> "KEYCODE_CAMERA"
28 --> "KEYCODE_CLEAR"
29 --> "KEYCODE_A"
30 --> "KEYCODE_B"
31 --> "KEYCODE_C"
32 --> "KEYCODE_D"
33 --> "KEYCODE_E"
34 --> "KEYCODE_F"
35 --> "KEYCODE_G"
36 --> "KEYCODE_H"
37 --> "KEYCODE_I"
38 --> "KEYCODE_J"
39 --> "KEYCODE_K"
40 --> "KEYCODE_L"
41 --> "KEYCODE_M"
42 --> "KEYCODE_N"
43 --> "KEYCODE_O"
44 --> "KEYCODE_P"
45 --> "KEYCODE_Q"
46 --> "KEYCODE_R"
47 --> "KEYCODE_S"
48 --> "KEYCODE_T"
49 --> "KEYCODE_U"
50 --> "KEYCODE_V"
51 --> "KEYCODE_W"
52 --> "KEYCODE_X"
53 --> "KEYCODE_Y"
54 --> "KEYCODE_Z"
55 --> "KEYCODE_COMMA"
56 --> "KEYCODE_PERIOD"
57 --> "KEYCODE_ALT_LEFT"
58 --> "KEYCODE_ALT_RIGHT"
59 --> "KEYCODE_SHIFT_LEFT"
60 --> "KEYCODE_SHIFT_RIGHT"
61 --> "KEYCODE_TAB"
62 --> "KEYCODE_SPACE"
63 --> "KEYCODE_SYM"
64 --> "KEYCODE_EXPLORER"
65 --> "KEYCODE_ENVELOPE"
66 --> "KEYCODE_ENTER"
67 --> "KEYCODE_DEL"
68 --> "KEYCODE_GRAVE"
69 --> "KEYCODE_MINUS"
70 --> "KEYCODE_EQUALS"
71 --> "KEYCODE_LEFT_BRACKET"
72 --> "KEYCODE_RIGHT_BRACKET"
73 --> "KEYCODE_BACKSLASH"
74 --> "KEYCODE_SEMICOLON"
75 --> "KEYCODE_APOSTROPHE"
76 --> "KEYCODE_SLASH"
77 --> "KEYCODE_AT"
78 --> "KEYCODE_NUM"
79 --> "KEYCODE_HEADSETHOOK"
80 --> "KEYCODE_FOCUS"
81 --> "KEYCODE_PLUS"
82 --> "KEYCODE_MENU"
83 --> "KEYCODE_NOTIFICATION"
84 --> "KEYCODE_SEARCH"
85 --> "TAG_LAST_KEYCODE"

进程相关

打印进程中的所有线程

1
ps -Twwww -p {pid}

命令行转义

解决多层嵌套转义

1
2
3
adb shell su <<-EOF
sed -i 's/hello" world/hello world/g' /sdcard/abc
EOF

使用here-doc的机制来避免复杂的命令增加多层转义,EOF前加-号可以确保文本内容使用tab来对齐代码

将aar文件转换成dex文件

1
~/Android/Sdk/build-tools/35.0.0/d8 --release demo.aar
Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2015-2025 Kaisar
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信