Validate Android screenshot captures before use
Add android/scripts/capture_png.sh, which captures on-device (screencap -p -d <SurfaceFlinger id>) to /sdcard, pulls the file, and validates PNG magic bytes plus the reported type, deleting and failing on anything that is not a real image. Document the multi-display warning failure mode and the required helper in android/README.md so every UI-capturing run captures and validates instead of writing adb screencap straight to a file.
This commit is contained in:
@@ -58,6 +58,29 @@ gradle :app:installDebug
|
||||
adb shell am start -n net.awan.pipelines/.MainActivity
|
||||
```
|
||||
|
||||
### Capturing screenshots
|
||||
|
||||
Never write `adb … screencap` to a file through `exec-out` or a redirect: on a
|
||||
device with more than one display (e.g. the fold emulator's inner and cover
|
||||
panels) `screencap` prints a `[Warning] Multiple displays were found…` line to
|
||||
stderr, adb folds it into the stream, and the `.png` ends up 100+ KB of text
|
||||
while `adb` still exits 0. Such a file must never be cited as evidence. Capture
|
||||
on the device to a file, pull it, name the display explicitly, and validate the
|
||||
bytes before use:
|
||||
|
||||
```sh
|
||||
android/scripts/capture_png.sh -s <serial> <out.png> # capture + validate
|
||||
android/scripts/capture_png.sh --check <file.png> # validate an existing file
|
||||
```
|
||||
|
||||
The helper resolves the primary SurfaceFlinger display id (`dumpsys
|
||||
SurfaceFlinger --display-id`, the id `screencap -d` expects - not the logical
|
||||
`dumpsys display` id), captures `-d <id>` to `/sdcard`, pulls, and checks the
|
||||
PNG magic bytes (and the reported type). A file that is not a real image is
|
||||
deleted and the helper exits non-zero, so a bad capture stops the run with
|
||||
`blocked` instead of reaching an approval. Every UI-capturing run must use this
|
||||
helper and state in its evidence that each image was validated.
|
||||
|
||||
## Configuration
|
||||
|
||||
Open the **Settings** tab and enter:
|
||||
|
||||
Reference in New Issue
Block a user