perf(android): run settings permission all in one adb shell per batch

Merged
IM
2d ago
+1223-152

Summary

settings permission grant|deny|reset all on Android spawned one adb shell pm per declared permission, plus two pm clear-permission-flags per applied one on reset. On an app declaring 55 permissions that took 1.4-2.1 s. The e2e runner sends all before every fresh launch.

Consecutive pm ids now run in one adb shell script, split into chunks under 3 KiB. Each command's exit code, stdout and stderr go through the same classification as before, and the script stops at the first refusal that is not skippable, so results, warnings, errors and the stop point are unchanged. Notifications and photos keep their paths and positions.

The script calls cmd package directly when /system/bin/pm is that wrapper, and uses the builtin print; this saved 329 ms on grant and 566 ms on reset.

Host adb still passes no timeout, as before. On a remote provider a batch gets 30 s plus 500 ms per pm call, capped at 90 s.

Before / after

Pixel 9 emulator, API 36, an app declaring 55 permissions, 5 runs each:

Timing, adb spawns and diffs
action     base median (range)    head median (range)   adb spawns for permissions
grant all  1528 ms (1403-1561)    630 ms (596-685)      59 -> 10
deny all   1456 ms (1393-1484)    602 ms (576-700)      59 -> 10
reset all  2144 ms (2082-2318)    800 ms (781-812)      89 -> 14

base vs head, each action:
  --json result diff: empty
  dumpsys package permissions + flags, appops get: empty
missing package: exit 1 vs 1, error JSON diff (requestId aside): empty

Validation

  • check:affected --run --head f351a5a9b and pnpm gate: format, lint, typecheck, layering, di-seams, fallow, native-dupes, native-dupes-model, mcp-metadata, build, package, vitest-related, provider-integration, integration-node, macos-coverage.
  • At 5273126d4: format, lint, typecheck, layering, fallow, build, provider-integration, related tests.
  • Tests cover each action, skips, a mid-list failure, truncation, quoting, chunking and order; twelve mutants each fail a test.
  • Not run: physical Android devices, a remote provider, and a mid-list hard failure on a device.