---
name: android_screenshot
kind: function
lang: bash
domain: infra
version: "1.0.0"
purity: impure
signature: "android_screenshot([--serial <S>], output_path: string) -> void"
description: "Capture screen as PNG via adb exec-out screencap -p."
tags: [android, adb, screenshot, screen, capture, pendiente-usar]
uses_functions: [adb_wsl_bash_infra]
uses_types: []
returns: []
returns_optional: false
error_type: "error_go_core"
imports: []
params:
  - name: "--serial <S>"
    desc: "Optional ADB serial to target a specific device/emulator. If omitted, autodetects the first connected device."
  - name: "output_path"
    desc: "WSL path where the PNG screenshot will be written (e.g. /tmp/screen.png). Parent directory is created if absent."
output: "Stdout 'screenshot: <path> (<bytes> bytes) from <serial>'. PNG file written to disk."
tested: false
tests: []
test_file_path: ""
file_path: "bash/functions/infra/android_screenshot.sh"
---

## Ejemplo

```bash
source bash/functions/infra/android_screenshot.sh
android_screenshot /tmp/screen.png
# screenshot: /tmp/screen.png (123456 bytes) from emulator-5554

# Targeting a specific device:
android_screenshot --serial emulator-5554 /tmp/screen.png
```

## Notas

Sources `adb_wsl.sh` from its own directory, so `ADB` and `ANDROID_SDK_WIN` env vars
are respected as with all other android_* functions.

Exit codes:
- `0` — screenshot captured successfully.
- `1` — missing output path, screencap produced empty file, or adb error.
- `3` — no device/emulator connected (propagated from `adb_pick_serial`).

The emptiness check (`! -s`) handles the case where `adb exec-out` exits 0 but writes
zero bytes (e.g. device locked, screencap permission denied). In that case the file is
removed and exit 1 is returned.
