Repository navigation
feat(android): add boot wait and resource-id to code tracing - #3840
FabioLima77 wants to merge 32 commits into
Conversation
Add three ADB tools for dynamic Android analysis over caller-connected devices: - wait_adb_boot polls sys.boot_completed/dev.bootcomplete/init.svc.bootanim until boot completes or the deadline passes, tolerating an offline device. - capture_adb_ui_state dumps the uiautomator hierarchy through a uniquely named device temp file removed by the same shell, then captures one screenshot; both are written under one timestamped state_id and the parsed nodes (resource-id, text, content-desc, bounds, center, flags) are returned inline. - send_adb_input injects tap, tap_element (exact selector over a fresh dump), long_press, swipe, ASCII text and key events in order, stopping at the first failure and echoing a replayable executed list. Move the shared adb invocation and output-file primitives into AdbRun.ts so the provider and the new interaction module use one runner. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Add trace_android_resource_references, which takes resource-id values as uiautomator and capture_adb_ui_state report them (package:type/name) and resolves each through the APK resource table, or JADX's bundled framework map for the android package, to its integer IDs. The JADX bridge then scans every method's raw DEX instructions once and reports const literal loads, packed/sparse switch keys, and non-final R-field reads, with class, top class, method, raw method id, dex entry and code-unit offset. Totals stay exact when max_sites_per_resource bounds the returned sites. R$type declarations are listed with their origin, so an R class JADX synthesized from the resource table is not presented as APK content. Unresolved names stay explicit rather than reported as unused. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] The PR appears safe to merge; all three numbered findings are addressed. SummaryAdds Android boot waiting and static resource-ID tracing through CLI and MCP.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
Client[CLI or MCP] --> Wait[wait_adb_boot]
Wait --> Properties[Read device boot properties]
Properties --> Outcome[Boot completed or timed out]
Client --> Trace[trace_android_resource_references]
Trace --> Resolve[Resolve resource names to IDs]
Resolve --> Scan[Scan raw DEX instructions]
Scan --> Result[Bounded sites and exact totals]
Reviews (24) · Last reviewed commit: "fix(adb): keep abort reason, bound CLI m..." · Reviewed by Greptile |
- send_adb_input returns the completed actions as a replay-ready list and keeps argv/resolved-node facts in executed, so a result replays through MCP and CLI alike; the CLI reads --actions as inline JSON or a JSON file through the shared bounded reader instead of its own unbounded reader. - wait_adb_boot sleeps for the smaller of the interval and the remaining time and probes once more at the deadline instead of stopping early. - tap_element refuses a truncated hierarchy, which cannot prove a selector is unambiguous, and empty bounds no longer produce a tappable center. - The bridge resource scan shares the 8 MiB transport budget across sites and R-field declarations, keeps exact totals, and reports total_r_fields so budget-bounded results surface as partial coverage. - Add a real-JAR regression over a smali fixture covering const loads, packed and sparse switch keys, and library R-field reads. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
send-adb-input parsed --actions before entering the shared CLI execution boundary, so an unreadable file or malformed inline JSON returned an error payload without logCliCommand classifying it, and the command exited 0 although no action ran. Resolve the actions inside the same logging, exit-code and cancellation boundary as execution. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
PR #3004 vs #3840Both PRs add Android UI inspection and interaction, with substantial overlap.
OverlapBoth introduce UI hierarchy parsing, element targeting and input actions through CLI/MCP. They modify nine common files, including the ADB provider, domain schemas, tool contracts, CLI commands and MCP registration. Complementary capabilities
RecommendationCoordinate the overlapping UI contracts before merging. Boot waiting and resource-reference tracing can complement #3004; its discovered resource IDs could feed #3840’s tracing tool. Backend choice and single-action versus batch semantics need an explicit design decision. |
send-adb-input resolved --actions inside the cancellation boundary but without its signal, so a large actions file kept being read after SIGINT or SIGTERM. Pass the command signal through the input resolver to parseCliJsonInput and readJsonInputFile, and rethrow a cancelled read to the command boundary instead of reporting it as an unreadable file. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
PR morluto#3004 adds UI discovery and actions through AndroidX UI Automator with snapshot-bound element IDs, Unicode text and UI-condition waits. Remove this branch's overlapping capture_adb_ui_state and send_adb_input tools, their uiautomator XML parser, CLI commands and tests, and the adb runner extraction they needed, so the change keeps only the complementary parts: wait_adb_boot and trace_android_resource_references. None of the removed tools was released. wait_adb_boot now lives in AdbProvider beside the other adb operations and keeps its deadline behavior: it probes once more at the deadline instead of stopping a full interval early. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Thanks for the comparison. I've narrowed #3840 to the complementary parts — @morluto, does this split work for you? |
capture_adb_ui_state was removed from this PR; the guide and the trace_android_resource_references description still named it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3a4a0306f8
ℹ️ 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".
- Leave resource ids qualified with another app's package unresolved instead of borrowing this APK's code sites. - Return non-transient boot-probe failures instead of waiting them out. - Cover trace_android_resource_references in the all-contracts MCP fixture. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 752915eadd
ℹ️ 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".
… class names - Budget resource sites against 2 MiB so the Evidence frame (raw reply, normalized result, structured plus text) stays under the MCP limit. - Report class_name as JavaClass.getFullName() for inspect_android_method and keep the DEX name in raw_class_name. Not run here: verify:android against the real ApiDemos APK. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
…icit RootNode.getClasses() already returns every class, inner and anonymous included; getClassesWithoutInner() is the filtered variant. Call getClasses(true) so the intent is visible at the call site. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Keep the boot-probe constants and drop UNPARSED_LINES_REPORTED, which upstream removed and nothing here uses. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Take upstream's NodeHttpRequestOwner.ts unchanged; an earlier merge commit had picked up a lint autofix there that is not part of this PR. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Keep the resource-scan protocol schema next to upstream's new toolResponse envelope, and give the resource-scan test ports the listClasses member that JadxToolPort now requires. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 763d8f7426
ℹ️ 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".
| } | ||
| Map<String, Object> site = new LinkedHashMap<>(); | ||
| site.put("kind", kind); | ||
| site.put("class_name", className); |
There was a problem hiding this comment.
Return an exact selector for duplicate class aliases
When an APK produces two ClassNodes with the same JADX full_name, the bridge keeps both under that key and selected() rejects the key as "Ambiguous metadata class identity", but every resource site here still emits only that same key as class_name. Since inspect_android_method does not accept raw_class_name, neither site's documented drill-down can be selected; return an accepted exact identity (including DEX identity if needed) instead of the ambiguous alias.
AGENTS.md reference: AGENTS.md:L33-L33
Useful? React with 👍 / 👎.
Keep both the resource-reference and the root-manifest additions in the bridge, its verifier and the Java regression; ensureIndex now sits after upstream's manifest helpers. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e49831c6ad
ℹ️ 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".
| timeoutMs: Math.max( | ||
| 1_000, | ||
| Math.min(BOOT_PROBE_TIMEOUT_MS, probeBudget), | ||
| ), |
There was a problem hiding this comment.
Keep the final boot probe inside timeout_ms
When less than one second remains—especially for the deliberately scheduled final probe while an offline or reconnecting device makes adb shell stall—this floor gives runAdb a fresh 1,000 ms deadline instead of the remaining timeout_ms. The operation can therefore run up to roughly a second past the caller's advertised longest wait (nearly doubling the minimum 1 s timeout) and may be cancelled by an outer MCP deadline rather than return timed_out; cap the probe by the positive remaining budget or account for its runtime before the deadline.
AGENTS.md reference: AGENTS.md:L79-L79
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Kept the 1 s floor on purpose: the final probe at the deadline has ~0 ms of budget left, so capping it to the remainder would make that probe always time out and defeat its purpose (it exists so a device that finishes booting during the last interval is still seen). The overshoot is now stated in the result limitations: waited_ms can pass timeout_ms by up to about a second (5837486). Happy to change the contract if you prefer a hard cap.
🤖 Addressed by Claude Code
- The scan admits sites against a 2 MiB budget, not the bridge's 8 MiB frame, because the MCP result repeats every site. - wait_adb_boot keeps a 1 s floor on its final probe, so waited_ms can pass timeout_ms by about a second; say so in the result limitations. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Keep both appended test groups in AdbProvider.test.ts: the boot-wait tests and upstream's package-pull failure test. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 29341e46b5
ℹ️ 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".
| if (opcode == Opcode.CONST || opcode == Opcode.CONST_WIDE) { | ||
| List<Integer> hit = literals.get(insn.getLiteral()); | ||
| if (hit != null) matched.addAll(hit); | ||
| kind = "const_literal"; | ||
| } else if (opcode == Opcode.PACKED_SWITCH_PAYLOAD || opcode == Opcode.SPARSE_SWITCH_PAYLOAD) { |
There was a problem hiding this comment.
Scan IDs encoded in array-data payloads
When an app initializes an int[] from final R.id constants, D8 can put the ID values only in a fill-array-data payload; this dispatch examines immediate CONST values (then switch payloads and SGETs) but never array payload data. The tool consequently reports total_sites: 0 and coverage: "complete" for that method despite advertising every DEX instruction that loads the resource, so inspect array-data payloads or represent this form as unexamined.
AGENTS.md reference: AGENTS.md:L81-L81
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not implemented in this PR: scanning fill-array-data payloads would add a new payload decoder to the bridge that I cannot exercise against a real APK here, and the repo guidance asks for owner buy-in before adding complexity for edge forms. The guide's limitations now list fill-array-data payloads (an int[] initialized from R.id constants) as unscanned, next to layouts and reflection (c5c4f04). Leaving the thread open in case you want the decoder added.
🤖 Addressed by Claude Code
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Take upstream's version of the files an earlier merge commit had picked up lint autofixes in; they are not part of this PR. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d296dd72cb
ℹ️ 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".
A host clock correction moved Date.now() mid-wait, stretching or cutting timeout_ms and able to yield a negative waited_ms. Use performance.now(). Not run here: the sh-stub boot tests (skipped on Windows); they run in CI. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
# Conflicts: # src/adb/AdbProvider.ts
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8224d97c49
ℹ️ 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".
…ng under the JADX timeout Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…adata CI Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
@FabioLima77 thanks for the PR — there are 4 open review threads here:
Could you address or reply to these? Once they're resolved and CI is green we can take another look. |
|
@FabioLima77 also, this branch has merge conflicts with |
Requested by Fabio Lima
Summary
Adds two Android analysis tools that complement the UI Automator lane in
#3004:
wait_adb_boot: waits until a device reportssys.boot_completed=1.trace_android_resource_references: maps UIresource-idvalues (forexample those feat(adb): add UI Automator discovery, waits and actions #3004 discovers) to their integer IDs,
Rdeclarations andevery DEX instruction that loads them.
Scope was narrowed after the #3004/#3840 comparison: UI capture and input
actions are left to #3004's UI Automator backend. The removed tools remain on
FabioLima77:backup/android-ui-input-3840for reference.Problem and expected behavior
signal before installing or launching apps.
wait_adb_bootpollssys.boot_completed,dev.bootcompleteandinit.svc.bootanim, tolerates adevice that is still offline or not yet listed, fails fast on
unauthorized,and probes once more at the deadline instead of stopping a full interval
early. It returns
boot_completedortimed_outwith the last observedproperties.
com.example:id/login,android:id/title) hadno static link to code.
trace_android_resource_referencesresolves itthrough the APK resource table (or JADX's bundled framework map for
android:) and scans every method's raw DEX instructions once forconst_literalloads (findViewById),switch_casekeys (click dispatch ongetId()) andr_field_readreads of non-final libraryRfields.Change and scope
wait_adb_bootis anAdbProvideroperation beside the existing adb tools.rea_resource_referencesinReaJadxBridge.java, normalized inJadxAnalysis.ts. Sites andRdeclarations share the bridge's 8 MiBtransport budget;
total_sitesandtotal_r_fieldsstay exact and boundedresults report
coverage: "partial".Rdeclarations carryorigin(
dex|jadx_generated) because JADX synthesizes an appRclass when theAPK has none. Unresolved names stay explicit, not reported as unused.
reflection (
getIdentifier) mapping, emulator lifecycle (REA still neverstarts or manages emulators).
Contract and boundary impact
(
wait-adb-boot,trace-android-resource-references); existing contracts unchanged.one tool; verified with jadx-headless-mcp 0.7.1.
with explicit partial coverage and unresolved states.
docs:check, not committed.Expected effects:
Evidence and regression coverage
tests/conformance/android/ReaJadxMetadataRegression.javaover the smalifixture
tests/fixtures/android/resource-references/(const, packed and sparseswitch, library R-field read);
tests/boundary/android/JadxAnalysis.test.ts;src/adb/AdbProvider.test.ts(boot completion, deadline probe, unreachabledevice; POSIX adb stub);
tests/boundary/mcp/adbMcp.test.ts.google_apis x86_64, adb 37.0.1, jadx-headless-mcp 0.7.1):
wait-adb-boot→boot_completedafter 36–81 s; with a 1000 ms timeout and2000 ms interval it probes again at the deadline.
com.android.settings:id/search_action_bar→0x7f0c0523→SettingsHomepageActivity.initSearchBarView, confirmed byinspect-android-method(findViewById(R.id.search_action_bar));android:id/title→0x01020016, 37 sites; unknown id →unresolved.com.termux:id/terminal_view→0x7f080191→TermuxActivity.setTermuxTerminalViewAndClients;R$idorigindex.AdbProvider.test.tsstub tests run only onLinux/macOS CI.
Validation performed
verifyResourceReferencesvia a local driver againstjadx-headless-mcp 0.7.1) —
RESOURCE_REFERENCE_REGRESSION_PASS title_sites=3 switch=packed,sparse r_field=dex.npm run check:fast— pass.npm run docs:check— pass.npx vitest run tests/boundary/mcp/adbMcp.test.ts tests/boundary/android/JadxAnalysis.test.ts tests/acceptance/tools/localToolContracts.test.ts tests/boundary/cli/adbCli.test.ts— 29 passed, 6 skipped.npm run test:local -- src/contracts/toolEffects.test.ts src/adb/AdbProvider.test.ts— passed (provider stub suite skipped on Windows).Compatibility, safety, and release
adb arguments stay positional and shell-quoted at the adb boundary.
Author readiness
Human owner: @FabioLima77
Before merge
type(scope): outcome.🤖 Generated with Claude Code