# Foldable Device Screenshot Display Selection ## Problem On foldable devices (e.g., Pixel Fold), the device has multiple physical displays (inner and outer). When the device is folded, the outer display is active; when unfolded, the inner display is active. However, `screencap` without a display ID may default to the wrong display, producing small placeholder screenshots (~22KB) instead of actual screen captures. ## Display State Discovery ### Step 1: List Available Displays ```bash su -c "dumpsys SurfaceFlinger --display-id" ``` Example output: ``` Display 4619827677550801152 (HWC display 0): port=0 pnpId=GGL screenPartStatus=ORIGINAL displayName="Common Panel" Display 4619827677550801153 (HWC display 1): port=1 pnpId=GGL screenPartStatus=ORIGINAL displayName="Common Panel" ``` ### Step 2: Check Which Display is Active ```bash su -c "dumpsys display | grep 'state' | grep -v 'state OFF' | grep 'ON' | head -3" ``` Example output (folded - outer active): ``` DisplayDeviceInfo{"Outer Display": ... state ON, committedState ON ... ``` Example output (unfolded - inner active): ``` DisplayDeviceInfo{"Inner Display": ... state ON, committedState ON ... ``` ### Step 3: Screenshot the Active Display ```bash # For inner display (when unfolded) su -c "screencap -d 4619827677550801152 -p /path/to/screenshot.png" # For outer display (when folded) su -c "screencap -d 4619827677550801153 -p /path/to/screenshot.png" ``` ## Screenshot Size Indicators | Display | State | Typical Size | Meaning | |---------|-------|-------------|---------| | Inner (4619827677550801152) | OFF (folded) | ~22KB | Placeholder/invalid | | Inner (4619827677550801152) | ON (unfolded) | ~200KB-2MB | Valid screenshot | | Outer (4619827677550801153) | ON (folded) | ~1.5MB+ | Valid screenshot | | Outer (4619827677550801153) | OFF (unfolded) | ~15KB | Placeholder/invalid | ## Key Insight: Do Not Trust Default screencap `screencap -p` without `-d` defaults to "the first display found," which is NOT guaranteed to be the active one. On a Pixel Fold: - When folded, the default may be the inner display (which is OFF), producing a 22KB placeholder - When unfolded, the default may be the outer display (which is OFF), producing a 15KB placeholder **Always specify the display ID of the active display.** ## Automated Detection Pattern ```bash # One-liner to find the active display and screenshot it active_display=$(su -c "dumpsys display | grep 'state ON' | grep -o 'DisplayDeviceInfo{\"[^\"]*\"' | head -1 | sed 's/DisplayDeviceInfo{\"//;s/\"//'") if echo "$active_display" | grep -q "Inner"; then display_id="4619827677550801152" else display_id="4619827677550801153" fi su -c "screencap -d $display_id -p /sdcard/VisualAgent/screenshots/screenshot_$(date +%s).png" ``` ## Pitfalls 1. **MCP `mcp_android_phone_screenshot` may also default to wrong display** — The MCP tool may have the same default-display issue. If screenshots are consistently small (~15-22KB), the tool is likely capturing the inactive display. Use `terminal` with explicit `screencap -d` instead. 2. **Screen wakefulness != display state** — `dumpsys power` shows `mWakefulness=Awake` even when the display is OFF. Do not use power state to determine display readiness. Use `dumpsys display` instead. 3. **Display IDs are stable across reboots** — The IDs `4619827677550801152` (inner) and `4619827677550801153` (outer) are hardware-assigned and stable. You can hardcode them after initial discovery. 4. **Virtual displays may appear** — Some apps create virtual displays (e.g., `install_display_yyb` at 1x1 resolution). These should be ignored for screenshot purposes. Filter for `type INTERNAL` in the display info. ## Related - `pixel-fold-screen-detector` skill — For detecting which screen is active and adapting UI coordinates - Pitfall #60 in `android-ui-automation/SKILL.md` — The foldable device screenshot pitfall summary