Skip to content

refactor(android): share one package/Activity parser and trim the escape-guard comments - #5030

Merged
thymikee merged 4 commits into
callstack:mainfrom
imranbarbhuiya:refactor/android-escape-followups
Nov 23, 2026
Merged

thymikee merged 4 commits into
callstack:mainfrom
imranbarbhuiya:refactor/android-escape-followups

Conversation

@imranbarbhuiya

@imranbarbhuiya imranbarbhuiya commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #5011, from its review:

  • Five Android readers (resumed activity, focused window, three foreground reads) each carried the same package/Activity regex. app-parsers.ts now owns parseAndroidComponent. Each reader passes it the segment it already selected, in its existing marker order.
  • window-state.ts re-exports the contract's AndroidBlockingDialogObservation instead of restating it, and the helper focus branch in observation.ts uses clearAndroidBlockingDialogObservation.
  • The escape guard's comments are trimmed to the invariant: the pre-dispatch exemption covers only an escape surface other than the session app.

No behaviour change.

Value

base head
Copies of the component regex in platform-android/src 5 1
Restatements of the observation union outside the contract 2 0
Escape-guard JSDoc lines 6 4

Validation

  • Head 9389048bb, check:affected --run --head, exactCommit: true: format, lint, typecheck, layering, fallow, build and vitest-related (411 tests) pass.
  • Existing parser tests pass unchanged. New parseAndroidComponent table tests fail when the regex loses the activity group, the /, $, or the dotted-package rule, or reads past }.
  • The old regex and parseAndroidComponent agree on all 634 segments from 164 dumpsys lines (test fixtures plus live dumps from a Pixel 9 AVD, Android 16).
  • Live at head on that AVD: open, snapshot -i, press and appstate read the Clock app, then the launcher after home. In Chrome, Settings > Notifications opens system Settings:
$ press @e25 --count 2 --interval-ms 800
Error (COMMAND_FAILED): press @e25 left com.android.chrome and foregrounded com.android.settings. The tap likely escaped the app. May have reached the device.

A single press passes: the guard's one read right after the tap still sees Chrome. This PR does not change that read.

…d comments

parseAndroidResumedActivity inlined the same package/Activity regex that the
focused-window read uses. Both now use ANDROID_COMPONENT_PATTERN, which captures
the activity too. clearAndroidBlockingDialogObservation returns the clear branch
of the existing AndroidBlockingDialogObservation type instead of restating it.

The escape guard's JSDoc and CONSERVATIVE comment are wrapped and cut down to
the invariant.
The permission prompt and Trusted Web Activity cases pin that only an escape
surface owning the focus skips the guard, not any package other than the app.
The title and a one-line comment now say so.
@thymikee

Copy link
Copy Markdown
Member

Thanks for trimming these call sites.

The code at 9d5fdfd looks correct, and the PR has no blocking findings. The two Body rules checks were cancelled, and the other 15 checks pass. Those two checks only read the PR body, so the cancellation is likely unrelated to the diff. Before merge, re-run the cancelled Body rules checks. Not verified here: the mutation-test claims in the PR body, the Body rules result, and the live Pixel 9 run.

Not blocking, and fine to take or leave: the same component regex remains in parseAndroidComponentFromSegment, parseForeground and parseLegacyAndroidForegroundApp; AndroidBlockingDialogObservation in window-state.ts repeats the contract union in android-observation.ts; the native helper focus branch in observation.ts builds the same clear observation that clearAndroidBlockingDialogObservation already provides; and the new JSDoc in interaction-android-escape.ts should say the pre-dispatch exemption applies only to an escape surface outside the session app.

Could app-parsers.ts own one package/activity segment parser for the resumed, focused-window and foreground readers, while each caller keeps its current marker order and segment selection?

The resumed-activity, focused-window and both foreground readers each matched
the same package/Activity regex. app-parsers.ts now owns
parseAndroidComponent, and every reader passes it the segment it already
selected, in its existing marker order.

window-state.ts re-exports the contract's AndroidBlockingDialogObservation
instead of restating the union, and the helper focus branch in observation.ts
builds its clear observation with clearAndroidBlockingDialogObservation.
@imranbarbhuiya imranbarbhuiya changed the title refactor(android): share the component regex and trim the escape-guard comments refactor(android): share one package/Activity parser and trim the escape-guard comments Nov 23, 2026
@imranbarbhuiya

Copy link
Copy Markdown
Contributor Author
  • Done in bb84b7f: parseAndroidComponent in app-parsers.ts replaces the regex in parseAndroidComponentFromSegment, parseForeground and parseLegacyAndroidForegroundApp.
  • Done in bb84b7f: window-state.ts re-exports the contract's AndroidBlockingDialogObservation instead of repeating the union.
  • Done in bb84b7f: the helper focus branch in observation.ts returns clearAndroidBlockingDialogObservation(focus.focusedPackage).
  • Done in 9389048: the JSDoc says the pre-dispatch exemption applies only to an escape surface other than the session app.
  • Yes, done in bb84b7f: app-parsers.ts owns one segment parser for the resumed, focused-window and foreground readers, and each caller keeps its marker order and segment selection.

@thymikee

Copy link
Copy Markdown
Member

Thanks for the update.

The code looks good at 9389048. The shared package/Activity parser keeps the same regex text and segments, so the evidence gap from the earlier review is closed by the diff trace. The 15 checks pass and there are no conflicts, so nothing else is needed before merge.

Not verified here: the tests and the Pixel 9 AVD were not run, and the 634-segment old/new agreement from the PR body was not reproduced. Neither is needed given the character-identical regex.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 23, 2026
@thymikee
thymikee merged commit f7620d0 into callstack:main Nov 23, 2026
15 checks passed
@imranbarbhuiya
imranbarbhuiya deleted the refactor/android-escape-followups branch November 23, 2026 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants