fix(android): let open --relaunch accept a package Android restarts at once

Merged
TH
3d ago
+97-4

Summary

open --relaunch com.android.settings failed with android-app-close-timeout (phase process) on Android 17. A system client of the Settings slice provider restarts Settings right after am force-stop, so the close fence saw a new pid. A relaunch needs only the foreground and exit fences: the process fence runs after them, so once they pass, every process that ran before the stop is gone, and the launch reuses the new one. Both relaunch routes — the session-owner close and the in-open stop — accept a refusal from the process fence alone, through one predicate (passedAndroidRelaunchStopFences). Plain close still refuses a restarted process. help close and commands.md say so.

6 files touched. Fixes #4482.

Validation

  • Tested SHA 753e5a2bd7, base 9676eedac5.
    • Round 1: no CLI syntax in the close description, which MCP shares.
    • Round 2: one shared catch replaces the purpose parameter.
  • New tests fail on base with process remained running after close and pass at head: lifecycle.test.ts (owner-close relaunch) and app-lifecycle-close.test.ts (in-open relaunch). The existing exit/foreground refusals still pass.
  • pnpm exec vitest run --project unit-core packages/platform-android/src packages/command-surface/src/__tests__/command-surface-metadata.test.ts: 137 files, 1413 tests passed. pnpm check:quick: pass.
  • Live: Pixel 9a API 37 emulator (Android 17, Google APIs arm64), T3 device command against a source daemon. Six looping shell clients call content://android.settings.slices, standing in for the system client. Each run reads the Settings am_kill/am_proc_start events from logcat.
Buildopen com.android.settings --relaunch --foreground (session-owner close)
base 9676eedac52/4 failed, android-app-close-timeout, phase process
head10/10 succeeded. In 8 runs Settings restarted for its content provider 83–233 ms after am_kill; those took 3.1–3.4 s (the 2 s process fence expired and its refusal was accepted). The other 2 had no restart and took 1.7–1.9 s.

Without the stand-in clients, base succeeds on this emulator: the restart depends on timing. open settings --relaunch resolves to an intent and relaunches through am start, so it never reaches the in-open stop. For package targets, open resolution supplies an app id, so relaunches take the owner route. The in-open stop has only its unit test.

🤖 Generated with Claude Code