Skip to content

fix(adb): read window focus from the displays section on Android 16 - #2998

Closed
cyberpunk47 wants to merge 1 commit into
morluto:mainfrom
cyberpunk47:fix/adb-window-focus-android16
Closed

cyberpunk47 wants to merge 1 commit into
morluto:mainfrom
cyberpunk47:fix/adb-window-focus-android16

Conversation

@cyberpunk47

Copy link
Copy Markdown

Summary

Fixes #2996

On Android 16, dumpsys window windows no longer prints mCurrentFocus / mFocusedApp, so inspect_adb_window returned null focus with no explanation while an app was on screen. When the windows section declares neither line, the provider now reads dumpsys window displays. Each result says which section supplied the values. When neither section declares focus, a limitation says focus is unknown, not absent.

Problem and expected behavior

  • Before (SDK 36 emulator, launcher in front): focused_window: null, focused_app: null, observed_lines: [].
  • After: focused_window: "Window{… NexusLauncherActivity}", focused_app: "ActivityRecord{… t2}", plus the limitation "Focus declarations were read from dumpsys window displays".

Violated invariant (AGENTS.md): "Unresolved identity or applicability must remain unknown rather than be treated as absent, foreign, or aligned."

Change and scope

  • src/adb/AdbProvider.ts (inspect_adb_window):
    • It still reads dumpsys window windows first, so earlier builds behave as before.
    • Only when that section declares neither line does it read dumpsys window displays.
    • A refusal from either shell call is returned unchanged.
  • New limitations:
    • one naming the source section;
    • one stating focus is unknown when neither section declares it.
  • src/contracts/adb/adbToolContracts.ts: the tool description names both sections.
  • src/adb/AdbShellOutput.ts: the doc comment names both sections; parsing is unchanged.
  • Not included:
    • no result schema change;
    • no new tool;
    • no device interaction beyond one extra read-only dumpsys call on builds that need it.

Contribution scope: not applicable (routine fix within existing boundaries).

Contract and boundary impact

  • Semantic owner and earliest changed stage: ADB provider, inspect_adb_window shell observation
  • Contribution scope fit and linked maintainer decision: routine evidence-correctness fix; not applicable
  • CLI and MCP/tool-catalog contract: result schema unchanged; tool description text updated
  • Provider, bridge, target-format, or platform compatibility: Android 16 focus is now reported; earlier builds unchanged
  • Evidence, artifact, provenance, or reconstruction contract: limitations now name the source section, or say focus is unknown
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): read-only dumpsys only
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none tracked

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated (src/adb/AdbProvider.test.ts):
    • shellStub keys can now name a third shell word (dumpsys:window:displays), so tests can tell the sections apart; existing two-word keys behave as before.
    • Android 16 layout: windows has no focus lines and displays has both. Both values are reported, and the limitation names displays.
    • Earlier layout: windows has both lines. displays is not stubbed, so a second call would fail the test.
    • Neither section declares focus: nulls, plus the "unknown, not absent" limitation.
  • Base reproduction: with only the test changes applied to the base revision, the Android 16 case fails (focused_window is null). The other two fail only on the new limitation text.
  • User-visible CLI/MCP output: see before/after above.
  • Device checks: SDK 36 emulator (BE2A.250530.026.D1) and LineageOS 23 (SDK 36). On both, windows has 0 focus lines and displays has both.
  • Remaining proof gaps: not run against a pre-Android-10 device; the windows-first order keeps their path unchanged.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npx vitest run src/adb: 5 files, 116 tests passed
  • npm run typecheck: passed
  • npm run lint: no new diagnostics in changed files. The 2 existing errors (artifactComparison.test.ts, ManagedCilDecoding.test.ts) are also on main.
  • oxfmt on changed files: clean
  • npm run jscpd: 2.93%

Compatibility, safety, and release

  • Breaking changes or migration steps: none
  • Real Hopper/Ghidra, browser, or OS coverage: Android SDK 36 emulator and device
  • Package or release metadata impact: none
  • Security, privacy, process, or containment review: one additional read-only dumpsys window displays call, only when the first section declares no focus; same timeout and output cap

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T19:25:19.282403Z 6b407ae PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium impact] Adjusts window focus detection for Android 16 compatibility.

The PR appears safe to merge; a failed-fallback test would strengthen its error coverage.

Findings

  1. P2 Fallback errors lack test coverage ▶
Fix with agent prompt
### Issue 1
src/adb/AdbProvider.test.ts:1062-1065
The new tests cover successful reads, but none checks a failed `displays` read. Add a case where `windows` declares no focus and `displays` exits with an error. Assert that `inspect_adb_window` returns the error rather than a successful unknown-focus result. Otherwise, a future change could hide a failed device read without breaking these tests.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

inspect_adb_window now reads dumpsys window displays when windows declares neither focus field.

  • Window inspection finds Android 16 focus in the displays section.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Read windows] --> B{Read succeeded?}
  B -->|No| E[Return error]
  B -->|Yes| C{Either focus line exists?}
  C -->|Yes| W[Return windows declarations]
  C -->|No| D[Read displays]
  D --> F{Read succeeded?}
  F -->|No| E
  F -->|Yes| G{Either focus line exists?}
  G -->|Yes| H[Return displays declarations]
  G -->|No| I[Return nulls with unknown-focus limitation]
Loading

Reviews (1) · Last reviewed commit: "fix(adb): read window focus from the dis..." · Reviewed by Greptile

Comment on lines +1062 to +1065
it("reports focus as unknown when neither section declares it", async () => {
const { window, limitations } = await inspectWindow({
"dumpsys:window:windows": "WINDOW MANAGER WINDOWS\n",
"dumpsys:window:displays": "WINDOW MANAGER DISPLAY CONTENTS\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Fallback errors lack test coverage

The new tests cover successful reads, but none checks a failed displays read. Add a case where windows declares no focus and displays exits with an error. Assert that inspect_adb_window returns the error rather than a successful unknown-focus result. Otherwise, a future change could hide a failed device read without breaking these tests.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/adb/AdbProvider.test.ts
Line: 1062-1065

Comment:
**Fallback errors lack test coverage**

The new tests cover successful reads, but none checks a failed `displays` read. Add a case where `windows` declares no focus and `displays` exits with an error. Assert that `inspect_adb_window` returns the error rather than a successful unknown-focus result. Otherwise, a future change could hide a failed device read without breaking these tests.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6b407ae2e6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/adb/AdbProvider.ts
maxOutputBytes: DUMPSYS_WINDOW_MAX_OUTPUT_BYTES,
});
if (!fallback.ok) return fallback;
({ focusedWindow, focusedApp } = parseWindowFocusOutput(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Select the focused display before parsing focus

On an Android 16 device with more than one display, AOSP's RootWindowContainer.dumpDisplayContents iterates getChildCount() and dumps each DisplayContent, so this fallback can contain several mCurrentFocus/mFocusedApp pairs (often null for an inactive display). Passing the whole stream to parseWindowFocusOutput, which retains only the first pair, drops display identity and can report a secondary display or literal null even when another display is focused. Select the top-focused/display-specific block before producing the singular result.

AGENTS.md reference: AGENTS.md:L23-L23

Useful? React with 👍 / 👎.

@morluto morluto added area: runtime Process capture and runtime observation bug Something isn't working labels Oct 13, 2026
morluto added a commit that referenced this pull request Oct 14, 2026
Share tagged readiness observations, retain partial provider facts, authenticate bridge identity, bound diagnostics, and preserve cancellation and lost-session reasons. Fail closed for unparsed MIPS ABI attributes and macOS saved Hopper databases without a script-capable bridge route.

Reviewed fixes: #2010, #2108, #2513, #2695, #2731, #2771, #2828, #2867, #2868, #2870, #2880, #2919, #2945, #2961, #2981, #2998, #3000, #3002.

Validation: 285 focused source/boundary tests passed. Real Ghidra, IDA, Linux Hopper, and Windows provider runs were not repeated.

BREAKING CHANGE: MIPS targets with unresolved GNU ABI attributes and saved Hopper databases on macOS are refused rather than advertised as supported.
morluto added a commit that referenced this pull request Oct 14, 2026
Use one named input-schema projection for clients and catalog identity, preserve dialect declarations, and bound compact schema depth. Keep canonical SDK output validation when output advertisements are disabled. Release request-owned state on cancellation and carry upstream limitations through composed workflows. Preserve doctor full-output envelopes and validate navigation facts at their owner.

Reviewed fixes: #2088, #2108, #2513, #2684, #2693, #2695, #2836, #2864, #2868, #2877, #2933, #2998, #3002, #3015.

Validation: focused schema, SDK output-validation, context, and workflow tests passed; no schema dialect or canonical output validation was relaxed.
@cyberpunk47

Copy link
Copy Markdown
Author

@morluto shall i close this pr as relevent fixes have been done.

@CassieFox23

Copy link
Copy Markdown
Contributor

Heads up: main covers this in its own way in d4bd65c. The code is in src/adb/AdbProvider.ts, and reads Android 16 focus declarations from displays when windows omits them shows it. It is listed on tracker #3582. If this PR still adds something main doesn't have, please say so here and I'll take it off the list. Thanks for the fix!

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Superseded by the delivered change on main: d4bd65c53. ADB foreground-window observation supports the Android 16 displays section, with the documented fallback and parser regressions already on main. Closing this earlier proposal. Current main qualification passed: https://github.com/morluto/rea/actions/runs/38690953281.

@morluto morluto closed this Oct 15, 2026
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks @cyberpunk47 for the Android 16 display-section fallback case. Main includes the fallback handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] inspect_adb_window reports no focus on Android 16 because focus lines moved out of dumpsys window windows

3 participants