[ubuntu编译android12源码](https://mp.weixin.qq.com/s/jR6vpjvk6TSkFmGt3m8cwg)
[使用AndroidStudio阅读源码](https://mp.weixin.qq.com/s/PbzNo64ARHJCv_RxCc20-Q)
[Aosp开发神器Cuttlefish](https://mp.weixin.qq.com/s/94q8ldtVQzxHE30cDUr_5g)
[Aosp源码学习之目录介绍](https://mp.weixin.qq.com/s/kg9Tq5hPdVbyiCdxl4TlHA)
[Aosp之mk文件简介](https://mp.weixin.qq.com/s/cyPFvQ6IeCRXig12vllipQ)
[AOSP实战之bp文件介绍](https://mp.weixin.qq.com/s/rggXZIGccv1UuzRmObSDgQ)
[Aosp15之添加自己的产品Product](https://mp.weixin.qq.com/s/A8p5CBjErcMKS7Cts636wQ)
[Aosp之编译命令介绍](https://mp.weixin.qq.com/s/JTEQgp9PJD_8ieX5GGBRZQ)
[Aosp之添加C++可执行程序](https://mp.weixin.qq.com/s/lahaVLAMLjGiHhw8S-t0Lw)
[Aosp之添加C++动态库](https://mp.weixin.qq.com/s/ZlThBG4W7Y_tNhBxjYMB5Q)
[SEAndroid理论基础](https://mp.weixin.qq.com/s/inY7KfYXnctsaEW61bkyHA)
[Aosp实战之SEAndroid实战](https://mp.weixin.qq.com/s/RcUBB3msDbv6oyUe5VGlNw)
今天我们来回忆一下Aosp开发常用的ADB命令。。。
```bash
adb devices
adb devices -l
```
正常输出:
```
List of devices attached
emu32a08 device product:aosp_x86_64 model:Android_SDK_built_for_x86_64
```
**状态含义**:
| 状态 | 含义 | 怎么办 |
| :------------- | :-------------- | :----------------------------------------- |
| `device` | 正常可用 | 直接用 |
| `offline` | 连上了但没就绪 | 拔插 USB;`adb kill-server && adb devices` 重来 |
| `unauthorized` | 手机上弹了授权框没点 | 看手机屏幕,点"允许 USB 调试" |
| `no devices` | 没检测到 | 检查开发者选项里 USB 调试开了没;换线换口 |
| `recovery` | 设备在 recovery 模式 | 只能用部分命令(logcat 可用) |
| `bootloader` | 设备在刷机模式 | adb 不可用,要用 fastboot |
```bash
adb devices -l
adb -s R58M123ABC shell
adb -s R58M123ABC install app.apk
```
**传统方式(需要先用一次 USB)**:
```bash
adb tcpip 5555
adb connect 192.168.1.100:5555
adb devices
adb usb
```
**Android 11+ 无线配对(完全不用线)**:
```bash
adb pair 192.168.1.100:配对端口
adb connect 192.168.1.100:连接端口
```
```bash
adb wait-for-device
adb wait-for-device shell getprop sys.boot_completed
```
刷完机别急着 `adb shell`——adbd 起来了不代表系统开机完成,用上面第二条判断。
```bash
adb reboot
adb reboot recovery
adb reboot bootloader
adb reboot edl
```
---
```bash
adb install app.apk
adb install -r app.apk
adb install -r -d app.apk
adb install -t app.apk
adb install -g app.apk
adb install --bypass-low-target-sdk-block app.apk
```
**安装失败先看报错尾巴**,常见 `INSTALL_FAILED_*`
```bash
adb uninstall com.example.app
adb uninstall -k com.example.app
adb shell pm uninstall --user 0 com.example.app
adb shell pm uninstall --user 0 com.miui.player
```
> `pm uninstall --user 0` 是"软卸载":对当前用户隐藏,恢复出厂能回来,比 root 删文件安全得多。删系统 App 前先 `adb shell pm list packages -s` 确认包名。
```bash
adb shell pm list packages
adb shell pm list packages -3
adb shell pm list packages -s
adb shell pm list packages | grep video
adb shell pm path com.example.app
adb shell dumpsys package com.example.app | grep -E "versionName|versionCode|firstInstallTime"
```
**提取已安装的 apk**(逆向/备份常备):
```bash
adb shell pm path com.example.app
adb pull /data/app/~~xxxx==/com.example.app-yyyy==/base.apk ./app.apk
```
---
```bash
adb shell am start -n com.example.app/.MainActivity
adb shell monkey -p com.example.app -c android.intent.category.LAUNCHER 1
adb shell am force-stop com.example.app
adb shell am kill com.example.app
```
启动用 URL/deep link:
```bash
adb shell am start -a android.intent.action.VIEW -d "https://example.com"
adb shell am start -a android.intent.action.VIEW -d "myapp://page/detail?id=123"
```
```bash
adb shell pm clear com.example.app
```
调试 App 的祖传操作:"它坏了" → `pm clear` → 重新试 → 还坏 → 抓日志。
```bash
adb shell pm list permissions -d -g
adb shell pm grant com.example.app android.permission.CAMERA
adb shell pm revoke com.example.app android.permission.CAMERA
adb shell dumpsys package com.example.app | grep -A 20 "runtime permissions"
```
测试"拒绝权限后的降级表现",不用在设置里点来点去,`revoke` 一步到位。
```bash
adb shell am broadcast -a android.intent.action.TIME_SET
adb shell am startservice -n com.example.app/.MyService
adb shell dumpsys activity services com.example.app
adb shell dumpsys activity receivers com.example.app
```
---
```bash
adb push local.png /sdcard/Pictures/
adb pull /sdcard/DCIM/Camera ./camera
adb pull /sdcard/DCIM/Camera/img.jpg
```
| 目标路径 | shell 用户能直接写吗 | 说明 |
| :------------------------------- | :------------ | :---------------- |
| `/sdcard/` | ✅ | 随便读写 |
| `/data/local/tmp/` | ✅ | shell 的自留地,临时文件放这 |
| `/data/anr/`、`/data/tombstones/` | ⚠️ root 才行 | 崩溃/ANR 记录在这 |
| `/system/`、`/vendor/` | ❌ 只读 | 需要 root + remount |
root 机(userdebug 版)改系统文件:
```bash
adb root && adb remount
adb push framework.jar /system/framework/
adb reboot
```
```bash
adb exec-out screencap -p > screen.png
adb shell screencap -p > screen.png
adb exec-out cat /proc/kmsg > kernel.log
```
---
这是定位问题**第一现场**,值得花最多篇幅。
```bash
adb logcat
adb logcat *:E
adb logcat -s MyAppTag
adb logcat -s MyAppTag:E ActivityTaskManager:I
adb logcat AndroidRuntime:E *:S
```
优先级从低到高:`V` < `D` < `I` < `W` < `E` < `F`(Fatal)。日志行格式:
```
10-25 16:20:01.123 1234 5678 E MyAppTag: something failed
│ │ └─ 写日志的线程 id
│ └─ 进程 pid
└─ 时间
```
```bash
adb shell pidof com.example.app
adb logcat --pid=12345
adb logcat --pid=$(adb shell pidof com.example.app)
```
日志存在 4 个独立缓冲区里,**进程死了日志还在**:
```bash
adb logcat -b crash
adb logcat -b main
adb logcat -b system
adb logcat -b events
adb logcat -b all
adb logcat -c
```
```bash
adb logcat -v time
adb logcat -v threadtime
adb logcat -v color
adb logcat > crash_log.txt
adb logcat -d > crash_log.txt
adb logcat -d -b crash
```
**给别人报 bug 时**:`adb logcat -d -v threadtime -b crash -b main -b system > log.txt`,一条命令拿全证据。
```bash
adb logcat | grep -i "exception|error|fatal"
adb logcat | grep -E "ANR|FATAL|tombstone"
adb logcat -s WifiHAL:V chatty:I
```
Windows 下没有 grep,用 `findstr`:`adb logcat | findstr /i "exception"`。
---
系统把几百项配置以"属性"形式暴露出来,getprop 是读它们的标准工具:
```bash
adb shell getprop
adb shell getprop ro.build.version.release
adb shell getprop ro.build.version.sdk
adb shell getprop ro.build.fingerprint
adb shell getprop ro.product.model
adb shell getprop ro.product.cpu.abilist
adb shell getprop ro.build.type
adb shell getprop ro.debuggable
adb shell getprop sys.boot_completed
adb shell setprop debug.foo 1
adb shell setprop persist.log.tag V
```
getprop是查询系统属性,而setprop是设置系统属性。
---
dumpsys命令可以说是ADB中的重中之重了,可以说你的调试能力如何完全取决于你的dumpsys命令用得怎么样。。。
`dumpsys` 让系统里的每一个服务(AMS、WMS、电池、网络……)"交出体检报告"。
本章按用途分类:查界面(7.2)、查内存(7.3)、查 CPU/渲染(7.4)、查电量与后台(7.5)、查网络(7.6)、其余服务一张表(7.7)。
以activity为例,我们先来看看常用的玩法
```bash
adb shell dumpsys -l
adb shell dumpsys activity
adb shell dumpsys activity -h
adb shell dumpsys activity > ams.txt
adb shell dumpsys activity | head -50
adb shell dumpsys activity | grep -A 10 -B 2 "com.example.app"
```
三个探索技巧:
1. **报告开头都有 Overview/摘要段**,信息密度最高,先看开头再看细节;
2. **grep 必带上下文**(`-A 5` 看后 5 行、`-B 2` 看前 2 行),单行 grep 在 dumpsys 里等于白看;
3. 输出量太大时,存成文件用编辑器打开,比在终端里翻快 10 倍。
"App 白屏了","当前页面是谁"?"进程还在不在"?——都在这两个服务里。
```bash
adb shell dumpsys activity top
adb shell dumpsys activity activities
adb shell dumpsys activity services
adb shell dumpsys activity services com.example.app
adb shell dumpsys activity broadcasts
adb shell dumpsys activity broadcasts | grep -A 3 com.example.app
adb shell dumpsys activity processes
adb shell dumpsys activity providers
adb shell dumpsys activity recents
adb shell dumpsys window | grep -E "mCurrentFocus|mFocusedApp"
adb shell dumpsys window displays
adb shell dumpsys window windows
```
**activity 输出怎么读**(`dumpsys activity activities`,重点两段):
```
Display
Task id
mResumedActivity: ActivityRecord{... u0 com.example.app/.DetailActivity t123}
↑ 当前"活着的"(onResume 的)Activity,白屏问题先看这行
* ActivityRecord{... com.example.app/.MainActivity t123}
mState=STOPPED ↑ 每个 Activity 的生命周期状态:
RESUMED / PAUSED / STOPPED / DESTROYED
(卡在 PAUSED/STOPPED 不动 = 生命周期流程出了问题)
```
**判断 App 是否被杀/是否真的在前台**:
```bash
adb shell dumpsys activity processes | grep -B 1 -A 8 com.example.app
```
**window 实战场景**:App 点了按钮没反应?第一嫌疑是"有个透明窗口/对话框抢了焦点"——`mCurrentFocus` 显示的不是你的 Activity 就是它。
这里可以列举附上排查手段:
```
adb shell dumpsys window | grep mCurrentFocus
adb shell dumpsys window windows | grep -B 2 -A 5 "Window #"
adb shell cmd package list packages --uid 10123
adb shell input keyevent 4
adb shell dumpsys window | grep mCurrentFocus
```
```bash
adb shell dumpsys meminfo com.example.app
adb shell dumpsys meminfo 12345
adb shell dumpsys meminfo
adb shell dumpsys meminfo --checkin com.example.app
```
详细输出怎么读(判断泄漏/内存优化的核心依据):
```
Pss(KB) Private Dirty Heap Size Heap Alloc
Java Heap: 45123 44800 61440 43210 ← Java 对象堆
Native Heap: 60234 59800 102400 88700 ← C/C++ 内存、图片解码
Graphics: 20000 19800 ← GPU 纹理/缓冲
...
TOTAL PSS: 145678 ← 总占用(持续涨 = 泄漏)
Objects(对象统计):
Views: 1234 View 数量异常大 = 布局泄漏/重复添加
Activities: 8 ⭐ 理论上应 ≤ 当前存活的 Activity 数,
一直涨不降 = Activity 泄漏(经典 bug)
AppContexts: 9 Context 泄漏同理
SQL(数据库):
MEMORY_USED: 2048 数据库内存;heap 一直涨 = Cursor 没 close
```
**泄漏判定黄金法则**:反复进出同一页面 10 次,每次执行 `dumpsys meminfo`,盯 `Activities` 和 `TOTAL PSS` 两行——只涨不降就是泄漏,有实锤再上 Memory Profiler 深挖。
```bash
adb shell dumpsys cpuinfo
adb shell dumpsys cpuinfo | grep -A 3 com.example.app
adb shell top -m 10 -s 9
adb shell dumpsys gfxinfo com.example.app
adb shell dumpsys gfxinfo com.example.app reset
adb shell dumpsys gfxinfo com.example.app framestats
```
**gfxinfo 输出怎么读**:
```
Total frames rendered: 320
Janky frames: 45 (14.06%) ← 超过 16.67ms 渲染的帧叫 janky,占比 >10% 肉眼可感卡顿
95th percentile: 24ms ← 95% 的帧能在 24ms 内渲染完
```
`framestats` 的逐帧数据可以自己算出 measure/layout/draw 各阶段耗时,是定位"布局太深还是绘制太重"的依据。
```bash
adb shell dumpsys battery
adb shell dumpsys battery set ac 1
adb shell dumpsys battery unplug
adb shell dumpsys battery set level 15
adb shell dumpsys battery reset
adb shell dumpsys batterystats --reset
adb shell dumpsys batterystats --charged > battery.txt
adb shell dumpsys deviceidle
adb shell dumpsys deviceidle force-idle
adb shell dumpsys deviceidle step
adb shell dumpsys deviceidle unforce
adb shell dumpsys deviceidle whitelist
adb shell dumpsys alarm | grep -A 5 com.example.app
adb shell dumpsys jobscheduler | grep -B 2 -A 10 com.example.app
adb shell dumpsys power | grep -iE "wakefulness|wake_lock"
```
**实战场景**:后台推送收不到、定时任务不跑?先 `dumpsys battery unplug && dumpsys deviceidle force-idle` 把设备推进 Doze 再观察——90% 的"后台收不到推送"是 Doze 限制,不是 bug。
```bash
adb shell dumpsys connectivity
adb shell dumpsys netstats detail
adb shell dumpsys netpolicy
```
网络连通性测试(ping/ip 等)。
| 服务 | 命令 | 什么时候用 |
| :--- | :--- | :--- |
| package | `dumpsys package com.example.app` | 查版本、签名、权限、安装来源 |
| notification | `dumpsys notification --noredact` | 通知没显示?看通知队列和拦截状态 |
| dropbox | `dumpsys dropbox --print data_app_crash` | ⭐ 历史崩溃存档(没开 logcat 也能事后翻案) |
| procstats | `dumpsys procstats com.example.app` | 长时段内存/CPU 历史统计(评估后台占用) |
| usagestats | `dumpsys usagestats` | App 使用时长统计 |
| thermalservice | `dumpsys thermalservice` | 温度状态(降频/降亮度排查) |
| diskstats | `dumpsys diskstats` | 磁盘空间 |
| mount | `dumpsys mount` | 分区挂载状态(查 remount 问题) |
| media.session | `dumpsys media_session` | 音视频会话(谁在播、锁屏控件归谁) |
| audio | `dumpsys media.audio_flinger` | 音频焦点("为什么我的 App 没声音") |
| input_method | `dumpsys input_method` | 输入法状态(软键盘弹不出来) |
| vibrator | `dumpsys vibrator_manager` | 震动效果(测试震动反馈) |
| location | `dumpsys location` | 定位状态、有哪些 App 在请求定位 |
| account | `dumpsys account` | 系统账户 |
| backup | `dumpsys backup` | 备份服务状态 |
其中 **`dumpsys dropbox`** 最容易被忽略:系统把每次 App 崩溃都存档了,哪怕你没开着 logcat 也能事后翻案:
```bash
adb shell dumpsys dropbox --print data_app_crash | head -100
adb shell dumpsys dropbox --print data_app_anr | head -100
```
1. **不知道查哪个服务?** `dumpsys -l` 找名字,服务名基本见名知义;
2. **查 App 相关问题,命令后面直接跟包名**(activity/services/alarm/jobscheduler/package/meminfo/procstats 都支持),避免在几千行里大海捞针;
3. **复现类测量先 reset**:`gfxinfo ... reset`、`batterystats --reset`,让统计数据从零开始;
4. **改完 battery / deviceidle 的模拟状态,记得 reset/unforce 恢复**,否则设备一直处于假状态;
5. **配合 logcat 交叉验证**:dumpsys 告诉你"现在是什么状态",logcat 告诉你"状态怎么变成这样的",两者对时间轴就能还原整个事件链。
查硬件/内核这类"非服务"信息,用 cat /proc 即可:
```bash
adb shell cat /proc/cpuinfo
adb shell cat /proc/meminfo
adb shell cat /proc/version
adb shell df -h
adb shell free -m
adb shell uptime
```
---
```bash
adb shell input tap 500 800
adb shell input swipe 300 1000 300 300
adb shell input swipe 300 1000 300 300 500
adb shell input swipe 300 800 300 800 2000
adb shell input keyevent 4
adb shell input keyevent 3
adb shell input keyevent 26
adb shell input text "hello"
adb shell input text "hello%sworld"
```
常用 keyevent 码速查:`3` Home、`4` 返回、`5` 拨号、`6` 挂断、`24` 音量+、`25` 音量-、`26` 电源、`82` 菜单、`127` 暂停媒体、`164` 静音。
**怎么知道该点哪个坐标?** 开发者选项 → 指针位置(打开后屏幕显示坐标),或者:
```bash
adb shell uiautomator dump /sdcard/ui.xml
adb pull /sdcard/ui.xml && open ui.xml
```
```bash
adb exec-out screencap -p > screen.png
adb shell screencap /sdcard/s.png && adb pull /sdcard/s.png
adb shell screenrecord /sdcard/demo.mp4
adb shell screenrecord --time-limit 30 --bit-rate 8000000 /sdcard/demo.mp4
adb pull /sdcard/demo.mp4
```
录屏报 bug 复现视频 + logcat 文本,是给同事/社区提 issue 的黄金组合。
```bash
adb shell dumpsys battery set level 15 && adb shell dumpsys battery unplug
adb shell wm size 1080x1920
adb shell wm density 320
adb shell wm size reset && adb shell wm density reset
```
**`wm size/density` 是做屏幕适配测试的利器**:不用真机矩阵,一条命令把旗舰机变成小屏机。
---
本章只讲**排查流程**(先做什么后做什么),命令细节和输出解读都可以参考上面的细节。
```bash
adb shell dumpsys gfxinfo com.example.app reset
adb shell dumpsys gfxinfo com.example.app
adb shell dumpsys gfxinfo com.example.app framestats
```
进阶:抓完整渲染 trace(用 ui.perfetto.dev 打开):
```bash
adb shell perfetto -o /data/misc/perfetto-traces/trace.pftrace -t 15s sched freq gfx view am wm
adb pull /data/misc/perfetto-traces/trace.pftrace
```
```bash
adb shell dumpsys meminfo com.example.app | grep TOTAL
adb shell ps -eo PID,RSS,NAME --sort=-rss | head -20
```
```bash
adb shell top -m 10 -s 9
adb shell dumpsys cpuinfo | grep -A 3 com.example.app
adb shell pidof com.example.app
```
```bash
adb shell am force-stop com.example.app
adb shell am start -W -n com.example.app/.MainActivity
```
输出:
```
Status: ok
TotalTime: 456 ← 从启动到第一帧的总耗时(ms)
WaitTime: 512 ← 包括 AMS 等待的时间
```
跑 5 次取平均才是可信数据。
```bash
adb shell dumpsys batterystats --reset
adb shell dumpsys batterystats --charged > battery.txt
```
后台耗电大户基本就是唤醒锁(Wake lock)和后台流量(Network)两项。
---
```bash
adb shell ping -c 4 baidu.com
adb shell ifconfig wlan0
adb shell ip route
adb shell netstat -tlnp
adb shell dumpsys connectivity
adb shell svc wifi enable / disable
adb shell svc data enable / disable
```
```bash
adb forward tcp:8080 tcp:8080
adb reverse tcp:3000 tcp:3000
adb forward tcp:9222 localabstract:chrome_devtools_remote
```
`adb reverse` 是真机调试的保命符——手机没公网 IP、和电脑不在同一段网,都拦不住它。
---
```bash
adb logcat -c
adb logcat -d -b crash -v threadtime
```
看输出里的 `FATAL EXCEPTION` 段:异常类型(`NullPointerException` 等)+ 发生的类名行号,直接定位代码。如果闪退但 crash 缓冲区没东西,可能是 native 崩溃:
```bash
adb logcat -d | grep -E "SIGSEGV|SIGABRT|tombstone|Fatal signal"
```
**没抓到现场?崩溃记录有存档**(详见 7.7 的 dropbox):
```bash
adb shell dumpsys dropbox --print data_app_crash | head -100
```
```bash
adb logcat -d | grep -i "ANR in"
adb logcat -d -b events | grep am_anr
adb shell ls /data/anr/
adb shell cat /data/anr/anr_* | head -100
```
非 root 机拿不到 `/data/anr/`,用 `adb bugreport anr.zip`,解压后在 `FS/data/anr/` 里有同样的文件;历史 ANR 也可查 `dumpsys dropbox --print data_app_anr`。
按 9.2 的 SOP 执行:`dumpsys meminfo` 反复采样 → 盯 TOTAL PSS 和 Activities → 只涨不降即泄漏。
```bash
adb shell dumpsys activity top | grep ACTIVITY
adb shell dumpsys window | grep mCurrentFocus
adb exec-out screencap -p > now.png
adb shell uiautomator dump /sdcard/ui.xml
adb pull /sdcard/ui.xml
```
```bash
adb install app.apk
adb shell dumpsys package com.example.app | grep version
```
```bash
adb shell dumpsys activity processes | grep -A 5 com.example.app
adb shell dumpsys alarm | grep -A 3 com.example.app
adb shell dumpsys jobscheduler | grep -B 2 -A 8 com.example.app
adb logcat -d -b events | grep "am_wake_lock"
```
```bash
adb wait-for-device logcat -d -b all > boot.log
adb logcat -d | grep -iE "fatal|crash|zygote"
adb reboot recovery
adb reboot bootloader
```
**血泪经验**:刷机/改系统后 bootloop,第一件事不是重启,而是 `wait-for-device` 抢日志——设备循环重启时 adbd 有一小段存活窗口,抓到日志就抓住了根因。
```bash
adb exec-out screencap -p > screenshot.png
adb shell screenrecord --time-limit 20 /sdcard/repro.mp4
adb bugreport evidence.zip
adb pull /sdcard/repro.mp4
```
一个 `evidence.zip` + 一段录屏 + 一份 logcat,任何人都够定位 80% 的问题。
---
| 报错 | 原因 | 解法 |
| :--- | :--- | :--- |
| `unauthorized` | 手机没点授权弹窗 | 看手机屏幕点允许;不行就撤销授权重连(开发者选项 → 撤销 USB 调试授权) |
| `offline` | 握手未完成 | 换线/换口;`adb kill-server && adb devices` |
| `adb server version doesn't match` | 装了两个版本的 adb | `which -a adb` 找出重复的,删一个 |
| `more than one device` | 多设备 | 加 `-s 序列号` 或设 `ANDROID_SERIAL` |
| `INSTALL_FAILED_ALREADY_EXISTS` | 已装同包名 | 加 `-r` 覆盖装 |
| `INSTALL_FAILED_SIGNATURE_CONFLICT` | 签名不一致 | 先 `adb uninstall` 再装 |
| `INSTALL_FAILED_UPDATE_INCOMPATIBLE` | 系统里有残留/版本冲突 | `adb uninstall` 后重装;还不行 `pm clear` |
| `INSTALL_FAILED_NO_MATCHING_ABIS` | apk 不含设备 CPU 架构 | 换含 arm64-v8a 的包 |
| `INSTALL_PARSE_FAILED_NO_CERTIFICATES` | apk 没签名 | 用 apksigner 签名后再装 |
| `Read-only file system` | push 到了系统分区 | 先 root + remount,或推到 `/data/local/tmp` |
| `device offline` during install | 安装过程中设备掉线 | 换好线,关掉省电 USB 休眠 |
| `adb: no devices/emulators found` | 没设备 | 查 USB 调试开关、驱动、`lsusb` 看设备有没有枚举到 |
| `protocol fault (no status)` | server 与 adbd 通信崩了 | `adb kill-server` 重来;频繁出现换线 |
| `cmd: Failure calling service` | 服务不存在或被裁剪 | `dumpsys -l` 确认服务名;定制 ROM 可能删了该服务 |
---
```bash
adb exec-out screencap -p > $(date +%H%M%S).png
adb shell am force-stop com.example.app && adb shell am start -n com.example.app/.MainActivity
adb wait-for-device shell 'while [ "$(getprop sys.boot_completed)" != "1" ]; do sleep 1; done; echo BOOT_OK'
```
```bash
adb shell ls -l /sdcard/
adb shell cat file.txt
adb shell grep -r "keyword" /data/local/tmp/
adb shell stat file.txt
adb shell toybox
```
adb shell 里可用的是精简版 Linux 工具集(toybox),常用命令基本都有:`ls cp mv rm mkdir ps top netstat ifconfig df du free kill` 等。
后面有了再补充。。。