Skip to content

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

Merged
thymikee merged 2 commits into
callstack:mainfrom
imranbarbhuiya:perf/android-permission-all-batch
Nov 26, 2026
Merged

thymikee merged 2 commits into
callstack:mainfrom
imranbarbhuiya:perf/android-permission-all-batch

Conversation

@imranbarbhuiya

@imranbarbhuiya imranbarbhuiya commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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 5273126: 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.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

@thymikee

Copy link
Copy Markdown
Member

Thanks for the speedup, no code problems that need a change before merge were found at f351a5a, and the required evidence is in place.

The two checks that did not pass are cancelled Body rules runs, not failures. That job reads the PR body and the diff only touches packages/platform-android sources and tests, so they look unrelated.

Five lower-priority inline threads still apply.

Not verified here: the live timing and the base-versus-head result, dumpsys and appops diffs are author-reported and were not reproduced. The cmd package and mksh print branches of pmSetup run only on a device, while CI runs the script in the host /bin/sh. The remote provider route (timeout pass-through and a multi-KB shellFragment) was not exercised live or by an integration test. It is inferred to be safe because inventory.ts already sends shellFragment through runAndroidShell. The nine-mutants claim was not reproduced. Behavior on API 23 or without shell_v2 is inferred from adb semantics and was not tested.

Nothing blocks merge.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 26, 2026
Share one fake for batched and single pm calls in the permission tests,
and name two tests after what they check.
@thymikee
thymikee merged commit a810488 into callstack:main Nov 26, 2026
15 checks passed
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