Loading...
Loading...
Compare original and translation side by side
adbadb devices../../architecture/understanding-adb-architecture/SKILL.md../../capture/capturing-screenshots-and-screenrecord/SKILL.mdadbadb devices../../architecture/understanding-adb-architecture/SKILL.md../../capture/capturing-screenshots-and-screenrecord/SKILL.mdwm size 411x731wm density 320window_animation_scale = 0am force-stopadb shell svc wifi disablecmd wifi set-wifi-enabled disabled--ez--ei--eswm size 411x731wm density 320window_animation_scale = 0am force-stopadb shell svc wifi disablecmd wifi set-wifi-enabled disabled--ez--ei--es../../capture/capturing-screenshots-and-screenrecord/SKILL.md../../observability/extracting-logs-with-logcat/SKILL.md../../transfer/extracting-test-artifacts/SKILL.md../../../instrumentation/scenarios/launching-activities-with-activityscenario/SKILL.md../../apps/installing-and-managing-apps/SKILL.md../../devices/connecting-to-devices/SKILL.md../../devices/connecting-over-wifi/SKILL.md../../capture/capturing-screenshots-and-screenrecord/SKILL.md../../observability/extracting-logs-with-logcat/SKILL.md../../transfer/extracting-test-artifacts/SKILL.md../../../instrumentation/scenarios/launching-activities-with-activityscenario/SKILL.md../../apps/installing-and-managing-apps/SKILL.md../../devices/connecting-to-devices/SKILL.md../../devices/connecting-over-wifi/SKILL.mdadb get-statedeviceadb shellcmdcmdadb get-statedeviceadb shellcmdcmdinputinputinputInputManager.injectInputEvent()input [<source>] <command> [<arg>...]<source>tapswipetextkeyeventinputInputManager.injectInputEvent()input [<source>] <command> [<arg>...]<source>tapswipetextkeyeventadb shell input tap <x> <y>
adb shell input swipe <x1> <y1> <x2> <y2> [<duration_ms>]
adb shell input draganddrop <x1> <y1> <x2> <y2> [<duration_ms>]
adb shell input roll <dx> <dy> # rotary/trackball axes
adb shell input motionevent <DOWN|UP|MOVE|CANCEL> <x> <y>swipe<duration_ms>input swipe <x> <y> <x> <y> 1000draganddropswipeView.OnDragListenerswipeadb shell input tap <x> <y>
adb shell input swipe <x1> <y1> <x2> <y2> [<duration_ms>]
adb shell input draganddrop <x1> <y1> <x2> <y2> [<duration_ms>]
adb shell input roll <dx> <dy> # rotary/trackball axes
adb shell input motionevent <DOWN|UP|MOVE|CANCEL> <x> <y><duration_ms>swipeinput swipe <x> <y> <x> <y> 1000draganddropswipeView.OnDragListenerswipeadb shell input text "<string>"%sinput text "hello world"hello'"&()<>|;\input textUiObject2.setText(...)adb shell input text "<string>"%sinput text "hello world"hello'"&()<>|;\input textUiObject2.setText(...)adb shell input keyevent [--longpress|--doubletap] <KEYCODE> [<KEYCODE>...]
adb shell input keyevent <NUMERIC_CODE>KEYCODE_*| Mnemonic | Numeric | Notes |
|---|---|---|
| 3 | Press Home (does not always wake screen). |
| 4 | Back button. |
| 19-23 | TV / focus traversal. |
| 24/25/164 | |
| 26 | Toggles screen off/on. |
| 61 | |
| 66 | |
| 67 | Backspace. |
| 82 | |
| 187 | Recents button. |
| 224 | Wake without unlocking. |
| 223 | Force sleep. |
adb shell input keyevent KEYCODE_WAKEUP
adb shell input keyevent 82 # menu, dismiss the AOSP swipe-upadb shell input keyevent [--longpress|--doubletap] <KEYCODE> [<KEYCODE>...]
adb shell input keyevent <NUMERIC_CODE>KEYCODE_*| 助记符 | 数值 | 说明 |
|---|---|---|
| 3 | 按下 Home(不一定会唤醒屏幕)。 |
| 4 | 返回按钮。 |
| 19-23 | 电视 / 焦点遍历。 |
| 24/25/164 | |
| 26 | 切换屏幕关闭/开启。 |
| 61 | |
| 66 | |
| 67 | 退格键。 |
| 82 | |
| 187 | 最近任务按钮。 |
| 224 | 唤醒但不解除锁屏。 |
| 223 | 强制休眠。 |
adb shell input keyevent KEYCODE_WAKEUP
adb shell input keyevent 82 # menu, dismiss the AOSP swipe-upinput <source> <command>InputDevice.SOURCE_*| Source | Typical use |
|---|---|
| Default for |
| External touchpads (Chromebook / Android tablet keyboard). |
| TV/focus traversal: |
| Default for |
| Mouse buttons + scroll. |
| Trackball roll. |
| Gamepad buttons / joystick axes. |
| Pressure-aware touch (S-Pen). |
input <source> <command>InputDevice.SOURCE_*| 输入源 | 典型用途 |
|---|---|
| |
| 外接触摸板(Chromebook / Android 平板键盘)。 |
| 电视/焦点遍历: |
| |
| 鼠标按键与滚动。 |
| Trackball 滚动。 |
| Gamepad 按键与摇杆轴。 |
| 支持压力感知的触控(S-Pen)。 |
wmwmwmIWindowManageradb shell wm size # read current logical size
adb shell wm size 1080x1920 # override
adb shell wm size reset # restore device default
adb shell wm density # read current dpi
adb shell wm density 320 # override
adb shell wm density reset
adb shell wm dismiss-keyguard # insecure keyguard only
adb shell wm user-rotation [free|lock [<rotation>]] # 0,1,2,3 = 0/90/180/270undefinedwmIWindowManageradb shell wm size # read current logical size
adb shell wm size 1080x1920 # override
adb shell wm size reset # restore device default
adb shell wm density # read current dpi
adb shell wm density 320 # override
adb shell wm density reset
adb shell wm dismiss-keyguard # insecure keyguard only
adb shell wm user-rotation [free|lock [<rotation>]] # 0,1,2,3 = 0/90/180/270undefined
Caveats:
- **MUST** call `reset` in `@AfterClass` / suite teardown — otherwise the device stays in the modified configuration after the run, breaking later runs and any human user.
- `wm size` / `wm density` trigger a configuration change that recreates the foreground Activity. Treat them as between-test knobs, not mid-test.
- `am display-size` / `am display-density` are equivalent legacy spellings; `wm` is preferred.
注意事项:
- **必须**在 `@AfterClass` / 测试套件拆卸阶段调用 `reset`——否则测试运行结束后设备仍会保持修改后的配置,从而破坏后续运行和人工使用。
- `wm size` / `wm density` 会触发配置变更并重新创建前台 Activity。应将其视为测试之间可调整的配置项,而不是测试执行中的操作。
- `am display-size` / `am display-density` 是等价的旧版写法;应优先使用 `wm`。settingssettingsadb shell settings [--user <id>] get <namespace> <key>
adb shell settings [--user <id>] put <namespace> <key> <value> [<tag>] [default]
adb shell settings [--user <id>] delete <namespace> <key>
adb shell settings [--user <id>] reset <namespace> [<package>] [untrusted_defaults|untrusted_clear|trusted_defaults]
adb shell settings [--user <id>] list <namespace><namespace>globalsystemsecureadb shell settings [--user <id>] get <namespace> <key>
adb shell settings [--user <id>] put <namespace> <key> <value> [<tag>] [default]
adb shell settings [--user <id>] delete <namespace> <key>
adb shell settings [--user <id>] reset <namespace> [<package>] [untrusted_defaults|untrusted_clear|trusted_defaults]
adb shell settings [--user <id>] list <namespace><namespace>globalsystemsecure0adb shell settings put global window_animation_scale 0
adb shell settings put global transition_animation_scale 0
adb shell settings put global animator_duration_scale 0testOptions.animationsDisabled = true0adb shell settings put global window_animation_scale 0
adb shell settings put global transition_animation_scale 0
adb shell settings put global animator_duration_scale 0testOptions.animationsDisabled = true| Namespace | Key | Purpose |
|---|---|---|
| | Float (e.g. |
| | |
| | CSV |
| | Force a known IME. |
| | |
| | Stabilise long-press tests. |
| | Pair with |
| | E.g. |
| 命名空间 | 键 | 用途 |
|---|---|---|
| | 浮点数(例如 |
| | 设为 |
| | 用于无障碍测试的 CSV 格式 |
| | 强制使用已知 IME。 |
| | 在模拟器上设为 |
| | 稳定长按测试。 |
| | 与 |
| | 例如 |
am force-stoppm clearam force-stoppm clear| Command | Kills processes? | Clears data/cache/prefs? | Resets runtime permissions? |
|---|---|---|---|
| Yes | No | No |
| Yes (implicitly) | Yes | Yes |
| Yes (modern, API 28+) | No | No |
pm clearam force-stop../../apps/installing-and-managing-apps/SKILL.mdpm| 命令 | 终止进程? | 清除数据/缓存/prefs? | 重置运行时权限? |
|---|---|---|---|
| 是 | 否 | 否 |
| 是(隐式) | 是 | 是 |
| 是(现代写法,API 28+) | 否 | 否 |
pm clearam force-stoppm../../apps/installing-and-managing-apps/SKILL.mdam startam startundefinedundefined
Intent specifier flags (abridged from developer.android.com/tools/adb#IntentSpec):
| Token | Effect |
|---|---|
| `-a action` | Intent action (e.g. `android.intent.action.VIEW`). |
| `-d data_uri` | Data URI. |
| `-t mime_type` | MIME type. |
| `-c category` | Category. |
| `-n component` | Explicit component (`pkg/.Activity`). |
| `-f flags` | Hex `setFlags()` value. |
| `--es | -e key value` | String extra. |
| `--ez key bool` | Boolean extra. |
| `--ei key int` | Int extra. |
| `--el key long` | Long extra. |
| `--ef key float` | Float extra. |
| `--eu key uri` | URI extra. |
| `--ecn key component` | ComponentName extra. |
| `--eia/--ela/--efa key v[,v...]` | Array extras. |
| `--activity-clear-top` etc. | Map to `FLAG_ACTIVITY_*`. |
| `-S` | Force-stop the target before starting. |
| `-W` | Wait for launch to complete. |
Intent 标记参数(节选自 developer.android.com/tools/adb#IntentSpec):
| 标记 | 效果 |
|---|---|
| `-a action` | Intent action(例如 `android.intent.action.VIEW`)。 |
| `-d data_uri` | Data URI。 |
| `-t mime_type` | MIME 类型。 |
| `-c category` | Category。 |
| `-n component` | 显式组件(`pkg/.Activity`)。 |
| `-f flags` | 十六进制 `setFlags()` 值。 |
| `--es | -e key value` | 字符串 extra。 |
| `--ez key bool` | 布尔值 extra。 |
| `--ei key int` | 整数 extra。 |
| `--el key long` | Long extra。 |
| `--ef key float` | 浮点数 extra。 |
| `--eu key uri` | URI extra。 |
| `--ecn key component` | ComponentName extra。 |
| `--eia/--ela/--efa key v[,v...]` | 数组 extra。 |
| `--activity-clear-top` 等 | 映射到 `FLAG_ACTIVITY_*`。 |
| `-S` | 启动前强制停止目标应用。 |
| `-W` | 等待启动完成。 |cmd <service>cmd <service>cmdonShellCommandadb shell cmd -ldumpsys -l| Invocation | Effect |
|---|---|
| Modern equivalent of |
| Same as |
| |
| Force AOT compilation. |
| `cmd appops set <pkg> <op> allow | deny |
| Force a JobService to run now. |
| `cmd uimode night yes | no |
| Per-app locales (Android 13+). |
| Expand/collapse the shade. |
| `cmd wifi set-wifi-enabled enabled | disabled` |
| `cmd connectivity airplane-mode enable | disable` |
| Reset device to a hermetic test-harness state (Android 10+). |
cmdonShellCommandadb shell cmd -ldumpsys -l| 调用方式 | 效果 |
|---|---|
| |
| 与 |
| 等价于 |
| 强制执行 AOT 编译。 |
| `cmd appops set <pkg> <op> allow | deny |
| 立即运行 JobService。 |
| `cmd uimode night yes | no |
| 应用单独设置语言区域(Android 13+)。 |
| 展开/收起通知栏。 |
| `cmd wifi set-wifi-enabled enabled | disabled` |
| `cmd connectivity airplane-mode enable | disable` |
| 将设备重置为 hermetic test-harness 状态(Android 10+)。 |
svcsvcsvc datasvc wifisvc bluetoothcmdsvc datasvc wifisvc bluetoothcmdsvc wifi disablesvc wifi disableundefinedundefined
```bash
```bashundefinedundefinedam force-stopam force-stopundefinedundefined
```bash
```bash
(Test Orchestrator with `clearPackageData: 'true'` is the equivalent inside Gradle — see `../../tests/running-instrumented-tests-via-adb/SKILL.md`.)
(Gradle 中与之等效的 Test Orchestrator 配置为 `clearPackageData: 'true'`——见 `../../tests/running-instrumented-tests-via-adb/SKILL.md`。)input text "hello world"input text "hello world"undefinedundefinedinput textinput text
```bash
```bashundefinedundefinedadb shell settings put global window_animation_scale 0
adb shell settings put global transition_animation_scale 0
adb shell settings put global animator_duration_scale 0
adb shell pm clear com.example.app
adb shell am start -S -W -n com.example.app/.MainActivity-S-Wadb shell settings put global window_animation_scale 0
adb shell settings put global transition_animation_scale 0
adb shell settings put global animator_duration_scale 0
adb shell pm clear com.example.app
adb shell am start -S -W -n com.example.app/.MainActivity-S-Wadb shell input dpad keyevent KEYCODE_DPAD_DOWN
adb shell input dpad keyevent KEYCODE_DPAD_DOWN
adb shell input dpad keyevent KEYCODE_DPAD_CENTERdpadadb shell input dpad keyevent KEYCODE_DPAD_DOWN
adb shell input dpad keyevent KEYCODE_DPAD_DOWN
adb shell input dpad keyevent KEYCODE_DPAD_CENTERdpadcmd wifi set-wifi-enabledcmd connectivity airplane-modecmd bluetooth_manager enablesvc wifisvc bluetoothsvc datapm clear <pkg>am force-stopforce-stopinput text%swm size resetwm density reset0testOptions.animationsDisabled = trueThread.sleepadb shell input../../../compose/synchronization/synchronizing-with-idle/SKILL.mdadb shell am start -Wadb shell wait-for-deviceadb shell am instrument-w../../tests/running-instrumented-tests-via-adb/SKILL.md../../automation/scripting-adb-for-ci/SKILL.mdam start -S -W -n pkg/.Activity-S-Wcmd wifi set-wifi-enabledcmd connectivity airplane-modecmd bluetooth_manager enablesvc wifisvc bluetoothsvc datapm clear <pkg>am force-stopforce-stopinput text%swm size resetwm density reset0testOptions.animationsDisabled = trueadb shell inputThread.sleep../../../compose/synchronization/synchronizing-with-idle/SKILL.mdadb shell am start -Wadb shell wait-for-device-wadb shell am instrument../../tests/running-instrumented-tests-via-adb/SKILL.md../../automation/scripting-adb-for-ci/SKILL.mdam start -S -W -n pkg/.Activity-S-Wadb shell settings get global window_animation_scale00.0transition_animation_scaleanimator_duration_scalescripts/.github/workflows/svc wifisvc bluetoothsvc dataam force-stoppm clearinput text "<string with spaces>"%swm size <override>wm size resetadb shell settings get global window_animation_scale00.0transition_animation_scaleanimator_duration_scalescripts/.github/workflows/svc wifisvc bluetoothsvc dataam force-stoppm clearpm clearinput text "<string with spaces>"%ssetupwm size <override>wm size resetampminputwmsettingsadb shellKEYCODE_*testOptions.animationsDisabledtasks/research/A2-adb-shell-commands.mdinputwmsettingsampmcmdsvc../../architecture/understanding-adb-architecture/SKILL.md../../devices/connecting-to-devices/SKILL.mdadb deviceswait-for-device../../devices/connecting-over-wifi/SKILL.mdadb pairadb connect../../apps/installing-and-managing-apps/SKILL.mdpm installpm uninstallpm grant../../tests/running-instrumented-tests-via-adb/SKILL.mdam instrument -w -r../../capture/capturing-screenshots-and-screenrecord/SKILL.md../../observability/extracting-logs-with-logcat/SKILL.md../../transfer/extracting-test-artifacts/SKILL.mdadb pulladb pushrun-as../../automation/scripting-adb-for-ci/SKILL.md../../../instrumentation/scenarios/launching-activities-with-activityscenario/SKILL.md../../../fundamentals/strategies/applying-testing-strategies/SKILL.mdadbampminputwmsettingsadb shellKEYCODE_*testOptions.animationsDisabledtasks/research/A2-adb-shell-commands.mdinputwmsettingsampmcmdsvc../../architecture/understanding-adb-architecture/SKILL.md../../devices/connecting-to-devices/SKILL.mdadb deviceswait-for-device../../devices/connecting-over-wifi/SKILL.mdadb pairadb connect../../apps/installing-and-managing-apps/SKILL.mdpm installpm uninstallpm grant../../tests/running-instrumented-tests-via-adb/SKILL.mdam instrument -w -r../../capture/capturing-screenshots-and-screenrecord/SKILL.md../../observability/extracting-logs-with-logcat/SKILL.md../../transfer/extracting-test-artifacts/SKILL.mdadb pulladb pushrun-as../../automation/scripting-adb-for-ci/SKILL.md../../../instrumentation/scenarios/launching-activities-with-activityscenario/SKILL.md../../../fundamentals/strategies/applying-testing-strategies/SKILL.mdadb