Shell Loader
Overview
The shell module builds the small dex entrypoint used by Rish to bootstrap from a shell process into the installed Shizuku app/server. Its only Java entrypoint is shell/…/ShizukuShellLoader.java, whose kept public static void main(String[]) is the method launched from the packaged dex.
At startup, ShizukuShellLoader.main stores the original shell arguments, determines the calling package, prepares the main Looper if the shell process does not already have one, and starts waiting for a Shizuku binder. Package detection first asks PackageManagerApis.getPackagesForUidNoThrow(Os.getuid()); if the UID maps to exactly one package it uses that package name, otherwise it requires the RISH_APPLICATION_ID environment variable and aborts if it is unset or still the placeholder value PKG. The loader then posts all asynchronous work through a main-thread Handler and exits through stderr plus System.exit(1) for unrecoverable failures.
Binder acquisition is done by ShizukuShellLoader.requestForBinder in shell/…/ShizukuShellLoader.java. The loader creates a local Binder callback (receiverBinder) and sends it inside a Bundle extra named data on the action rikka.shizuku.intent.action.REQUEST_BINDER, targeted at package moe.shizuku.privileged.api. It talks directly to the platform activity service through hidden APIs (IActivityManager.Stub.asInterface on Android 8+ and ActivityManagerNative.asInterface before that), so this module depends on the hidden API compatibility libraries declared in shell/build.gradle. When the Shizuku app answers the callback transaction code 1, the callback reads the server binder and the Shizuku app sourceDir; a null binder means the server is not running and the shell process exits.
After a non-null binder arrives, ShizukuShellLoader.onBinderReceived uses the returned sourceDir to load code from the installed Shizuku manager APK instead of carrying the shell implementation inside this module. It derives the native library path from the APK directory plus lib/<VMRuntime instruction set>, appends the process java.library.path, creates a BaseDexClassLoader over sourceDir, and reflectively invokes moe.shizuku.manager.shell.Shell.main(String[] args, String packageName, IBinder binder, Handler handler). That manager-side entrypoint is outside this module (manager/…/Shell.java), but it is the direct API handoff: it initializes RishConfig with the Shizuku binder descriptor, calls Shizuku.onBinderReceived, verifies server version 12+, requests Shizuku permission when needed, then starts the Rish shell flow. If the manager APK is too old to contain moe.shizuku.manager.shell.Shell, the loader prints a Shizuku v12+ requirement and exits.
The Android manifest is intentionally empty (shell/…/AndroidManifest.xml) because this artifact is not used as a normal installed application component. shell/build.gradle configures the module as an Android application only to produce dex: release builds are minified with shell/proguard-rules.pro, dependency metadata is omitted from the APK, lint release checks are disabled, and BuildConfig generation remains enabled. After every variant assemble, the Gradle task extracts the single classes*.dex from the built APK and copies it to manager/src/main/assets/rish_shizuku.dex; for minified variants it also copies the mapping file under out/mapping with a cmd-v<version>.txt name. The ProGuard rules keep only ShizukuShellLoader.main(String[]) as a public entrypoint, allow access modification, and repackage classes, so reflective access to this exact main method is part of the packaging contract.
Coupling
- If shell/…/ShizukuShellLoader.java changes the broadcast action, package name,
Bundleextra name, callback transaction code, or callback payload order, verify the Shizuku app side that handlesrikka.shizuku.intent.action.REQUEST_BINDER; the shell loader parses a raw binder transaction and will otherwise time out after five seconds or exit with “Server is not running”. - If manager/…/Shell.java changes its class name, method name, static signature, or minimum-server behavior, update
ShizukuShellLoader.onBinderReceivedin shell/…/ShizukuShellLoader.java at the same time; the shell module reaches the manager implementation only through that reflectiveShell.main(String[], String, IBinder, Handler)call. - If the Gradle output path or asset name in shell/build.gradle changes, verify the manager packaging path that expects
manager/src/main/assets/rish_shizuku.dex; this module’s assemble hook is what refreshes the dex consumed by the manager app. - If minification rules in
shell/proguard-rules.proare tightened, verify the external launcher can still callrikka.shizuku.shell.ShizukuShellLoader.main(String[]); the release build is minified and the keep rule is the only explicit preservation of the shell entrypoint. - If package detection in
ShizukuShellLoader.mainchanges, verify shell launchers still setRISH_APPLICATION_IDfor shared UIDs or ambiguous package mappings; without a unique package name the loader cannot attribute permission requests to the current app.
Risks
- shell/…/ShizukuShellLoader.java uses hidden
IActivityManager.broadcastIntent/startActivityAsUserAPIs directly. If Android changes these hidden signatures or permission checks, the binder request can fail before reaching Shizuku; the file already carries an Android 8.0/8.1 fallback for the “Calling application did not provide package name” failure, and history shows multiple fixes around this path (78f918b,b1bad17). - shell/…/ShizukuShellLoader.java holds a static
receiverBinderso the callback binder survives until Shizuku responds. If this reference is weakened or made local again, binder acquisition may become GC-sensitive; history includes87224caspecifically to hold this reference. - shell/build.gradle assumes the assembled APK contains exactly one
classes*.dexviazipTree(file(outputFile)).matching { include 'classes*.dex' }.singleFile. If multidex or additional dex outputs are introduced, assemble will fail or copy the wrong dex tomanager/src/main/assets/rish_shizuku.dex; the debug build explicitly setsmultiDexEnabled false, so enabling multidex requires revisiting this extraction logic.