fix(android): verify the helper APK digest before running settings locale as shell

Merged
TH
1d ago
+581-105

Summary

settings locale on Android (#5050) runs SystemLocaleCommand from the installed helper APK as the shell user. The install step can trust a memo or a higher versionCode without reading the APK, so a foreign APK under the helper package name could run as shell.

Each locale command now hashes the base APK and runs app_process from that path only when the SHA-256 matches the trusted manifest.

  • Android before 8.0 can reuse install paths, so it refuses with locale-api-level-unsupported before helper preparation.
  • A missing base APK or a mismatch refuses with locale-helper-apk-unverified. The next locale command inspects the install; the shared snapshot memo stays, and an older overlapping call cannot clear a newer refusal.
  • pm path and pull failures keep their adb classification.
  • Failures before the locale write state dispatched: no and name a completed helper install.

Follow-ups: cmd locale set-device-locale on Android 16 QPR2+; reset semantics.

Before / after

settings locale de-DE with a newer foreign APK as the helper package:

  • Before: app_process runs it as shell.
  • After: locale-helper-apk-unverified, dispatched: no, no shell execution.

Validation

Source build of cda1497, Android 17 emulator, one daemon: settings locale de-DE twice (previousLocale en-US, then de-DE), then reset (en-US).

At 566e9c7, settings-locale.test.ts passes 17/17. Removing the digest check, the API gate, the locale recheck, or the refusal token fails the matching tests. The changes since cda1497 touch only refusal bookkeeping. CI pending. Android 8–16 and remote providers not run.

šŸ¤– Generated with Claude Code