- Decision
- ADR-034
- Date
- 2026-08-06
- Status
- SupersededSuperseded by ADR-240. Accepted
- Mentions
- ADR-032, ADR-240
- Mentioned by
- ADR-035, ADR-240
1Decision
Fix a Critical finding from the final whole-branch code review of the Guardian platform integration branch: GuardianActivity was declared android:exported="true" with no permission check, while its own detectBackgroundLocation() path (via GuardianUiController.start(), vendored, unmodifiable) destructively consumed the single pending-detection slot on every read — meaning any other installed app could launch it via an implicit start and silently suppress a real incident before the owner ever saw it, and (separately) the owner had no legitimate way to open Guardian at all (no launcher icon, no notification; only manual adb shell am start, itself only possible because exported="true" happened to allow it).
2Why and evidence
An independent final-review subagent (dispatched per superpowers:subagent-driven-development, most-capable model, read-only against the full 19-commit branch diff) found this and eight further Important/Minor issues; all findings were independently re-verified against real source (not merely trusted from the review) before any fix: GuardianUiController.start()'s vendored source confirmed it calls scenario.detectBackgroundLocation() unconditionally, and the real built APK's manifest (aapt2 dump xmltree) confirmed exported="true" before the fix.
Setting exported="false" alone was verified live to be airtight — even adb shell am start -n (uid 2000, shell) now fails with Permission Denial: ... not exported from uid 10084 — but this also meant Guardian's own validation flow could no longer reach the UI at all, turning the deferred "no entry point" Important finding into an immediate functional blocker, not a follow-up.
Fix: GuardianWatcherService now opens GuardianActivity itself (startActivity with FLAG_ACTIVITY_NEW_TASK) the instant it records a genuine DetectedIncident, from within Guardian's own android:persistent="true" process.
Verified against real source before implementing, not assumed: BackgroundActivityStartController.java:1296-1298 grants BAL_ALLOW_ALLOWLISTED_COMPONENT to any caller whose process state is <= PROCESS_STATE_PERSISTENT_UI, which a persistent app satisfies, so this background-activity-start is legitimately exempt from Android's BAL restrictions rather than relying on undocumented behavior.
The destructive-read half was fixed independently of the exported change: GuardianApplication.consumeDetection() (nulled the slot on every read) was split into a non-destructive peekDetection() plus an explicit clearDetection(), the latter wired to GuardianReferenceScreen's onDone callback (fires on "Not now", "Back to overview", and "Dismiss" — i.e. only once the owner has actually resolved or explicitly declined the incident, never on a mere reopen).
Six further findings were fixed in the same pass: GuardianApplication.onCreate()'s startService() call wrapped in try/catch (an uncaught throw would crash-loop a persistent system process during boot); test_revoke_background_location.sh no longer prints PASS before its final foreground-location assertion runs, and its now-broken manual am start -n .../.GuardianActivity step (would fail with the same Permission Denial) is replaced with reliance on the new auto-open; a stale Android.bp comment claiming three Compose module names were unconfirmed (Tasks 7/8's real build has since confirmed them); an unused import; ADR-032's Consequences text corrected (it had wrongly implied GRANT_RUNTIME_PERMISSIONS was privapp-permissions.xml-allowlisted, when it is actually granted via platform signing — no allowlist entry exists or should exist for it); the Serena MCP server's local state directory added to .gitignore.
Every fix was rebuilt and re-run against the real emulator before being accepted, including a full detect -> auto-open -> protect -> verify -> Undo cycle confirmed working end-to-end on the corrected build (not just "it compiles").
3Consequences
guardian/app/AndroidManifest.xml's GuardianActivity is now exported="false"; this is the durable, correct state going forward and future changes to it require the same security review this finding got.
The remaining findings from the same review are accepted as documented, non-blocking residuals rather than fixed in this pass, each with a real reason rather than deferred by default: (1) InMemoryGuardianAuditStore (vendored) is genuinely in-memory-only, so Guardian's audit trail does not survive a process restart — a real gap against capability-boundaries.md's audit-event requirement, not yet closed; (2) BackgroundLocationWatcher's AppOps callback and the in-memory stores it feeds are correct only because AppOpsManager.startWatchingNoted's no-Executor overload delivers on the main thread (confirmed against real source) — undocumented in code, a future switch to the Executor overload would silently introduce a data race; (3) detection covers OPSTR_FINE_LOCATION only, not OPSTR_COARSE_LOCATION — background coarse-only location access is undetected; (4) the single-slot detection holder (even with the peek/clear fix) still means a second real detection before the first is resolved overwrites it; (5) no filterTouchesWhenObscured on the Compose surface, so the Undo control is theoretically tapjackable; (6) GuardianLocationFixture in PRODUCT_PACKAGES was confirmed (via the real device/generic/goldfish product-inheritance chain on the build server) scoped to the sdk_phone* emulator product family only, never a physical-device tree, but is not further gated by TARGET_BUILD_VARIANT within that family.
4Review when
Before BLOCK_BACKGROUND_NETWORK, REMOVE_OVERLAY_PERMISSION, or FREEZE_APPLICATION reuse any part of this branch's Activity/entry-point pattern, confirm the same exported/BAL/destructive-read analysis rather than assuming it transfers; or when any of the six documented residuals above is proposed to be closed, whichever comes first.
Read from docs/governance/decision-log.md, entry ADR-034.