Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.Main in the app’s own dex, started with CLASSPATH=<apk> app_process / org.tether.shell.Main. The helper package org.tether.shell uses no resources, AndroidX or JNI and is kept by R8 rules. It sets up a fake context for package com.android.shell before 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”): ShellEnvelope frames 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 answers ShellResult{ok = false} and never takes the helper down.
  • Main-display mirroring through the hidden DisplayManager.createVirtualDisplay(name, w, h, displayIdToMirror, surface); display changes through IWindowManager.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-off as 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 ClipboardManager on the fake context.
  • Grants by executing a fixed list of pm/appops/cmd/dumpsys commands and reading the state back; the desktop cannot send arbitrary commands. RECEIVE_SENSITIVE_NOTIFICATIONS is set with appops, since pm grant cannot grant a signature|role permission.
  • 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_SECURE windows 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.