ShellBackend

interface ShellBackend

Abstraction over a privileged shell-command pipeline.

Two concrete implementations are planned:

  • ShizukuShellBackend (in :droid-mcp-shizuku, ships 0.8.0) — wraps Shizuku.newProcess for shell-UID execution without root.

  • RootShellBackend (in :droid-mcp-root, ships 0.9.0) — wraps libsu for root-UID execution. Same surface, broader capabilities (writes to /system, etc.).

Tools in :droid-mcp-shell-core are parameterised over ShellBackend so the LLM-facing surface is identical across backends; the host app picks which one (or both) to register at startup.

Inheritors

Properties

Link copied to clipboard
abstract val name: String

One-line description of what this backend is, surfaced in tool errors (e.g. "Shizuku", "libsu (root)"). Helps the LLM disambiguate when one tool errors with "shell_unavailable" and the host registered multiple backends.

Functions

Link copied to clipboard
abstract suspend fun exec(command: String, args: List<String> = emptyList()): ShellResult

Run command with args as a shell process. Returns stdout/stderr/exit. Implementations should NOT throw on non-zero exit codes — surface them via ShellResult.exitCode so tools can decide whether that's an error.

Link copied to clipboard
open suspend fun execBinary(command: String, args: List<String> = emptyList()): ShellResult

Run command with args and return raw stdout bytes. Defaults to exec — backends whose exec is already binary-safe (Shizuku) don't need to override. Backends with a text-only output API (libsu) MUST override with a binary-safe path (e.g. temp-file roundtrip).

Link copied to clipboard
abstract fun isAvailable(): Boolean

True when the backend is currently reachable — Shizuku binder pingable with permission granted, or su available, depending on the impl. Tools call this for fast-fail before constructing a command.