ADR-0017: Shell helper: app_process entry point in the APK, probed abilities, own protocol
- Status: accepted
- Date: 2026-11-15
- Deciders: maintainer, after the M4 research round (
docs/notes/m4-research-shell-helper.md) - Tags:
android,protocol,security
Context
ADR-0007 decided that privileged features run in a helper started through adb as the shell uid. The research round compared what works from uid 2000 on Android 14, 15 and 16 (scrcpy 5.x and AOSP as references) and found that the hidden APIs involved break in monthly and quarterly updates, not only in major releases, and that Samsung adds its own failures.
Decision
- Entry point
org.tether.shell.Mainin the app’s own dex, started withCLASSPATH=<apk> app_process / org.tether.shell.Main. The helper packageorg.tether.shelluses no resources, AndroidX or JNI and is kept by R8 rules. It sets up a fake context for packagecom.android.shellbefore any system service is touched (including the Samsung configuration-controller fix), and exits when its control connection or stdin closes. - Own protocol (
proto/tether/v1/shell.proto,docs/reference/protocol.md“Enhanced tier”):ShellEnvelopeframes on a control connection, and one connection per mirror carrying video packets one way and input events the other. The desktop end of a mirror connection is passed to the GTK app as a file descriptor. - Probed abilities: at start the helper tests each feature against the
running build and lists what works in
ShellHello.abilities. The desktop hides what is missing. A feature that later throws answersShellResult{ok = false}and never takes the helper down. - Main-display mirroring through the hidden
DisplayManager.createVirtualDisplay(name, w, h, displayIdToMirror, surface); display changes throughIWindowManager.registerDisplayWindowListener; MediaCodec surface encoder, H.264 by default; input injected to display 0 in device coordinates. - Screen off through
SurfaceControl.setDisplayPowerMode(DisplayControl class-loader path on 14+),cmd display power-offas fallback on 15+, restored by a detached cleanup process if the helper dies; a user-activity ticker keeps the device awake while a mirror asks for it. - Clipboard through the real
ClipboardManageron the fake context. - Grants by executing a fixed list of
pm/appops/cmd/dumpsyscommands and reading the state back; the desktop cannot send arbitrary commands.RECEIVE_SENSITIVE_NOTIFICATIONSis set withappops, sincepm grantcannot grant asignature|rolepermission. - App list (M4.2) comes from the normal app over the Tether session; the helper only launches apps.
- Phasing: M4.1 mirror of the main display with input, screen off, clipboard, grants. M4.2 per-app virtual displays and phone audio. M4.3 camera.
Consequences
Positive
- No second APK or download; the helper always matches the app version.
- A broken hidden API costs one feature, not the tier.
- Video and input bypass the daemon.
Negative / risks
- Reflection against hidden APIs needs upkeep with every Android release.
FLAG_SECUREwindows stay black; there is no workaround from shell.- Typing into a new display is reported as unreliable on Android 16 / One UI 8.5 (scrcpy issue 6909); M4.2 needs paste and UHID paths.
- The helper dies with the adb connection; the daemon restarts it.
Alternatives considered
- Shizuku or a root helper: extra app or root; adb is the common denominator.
- MediaProjection in the normal app: consent per session, no input, no screen-off, no virtual displays (ADR-0007).
- Reusing the main
Envelope: the helper is not the paired app and has no identity; a separate, token-gated protocol keeps the trust model simple.