Elevation to shell identity for Android apps.
Shellom! is a novel approach to adopting privileged shell (ADB) permissions at runtime, no root required. Unlike implementations that spawn a separate app process, Shellom! utilizes an ADB session provided to it to elevate the main process of the application to user 2000's identity. This way, it's possible to use privileged system service wrappers without any hassle:
- No reflection ✅
- No manual AIDL communication, use managers directly ✅
- No parcelization problems ✅
- No manual swapping of binder references ✅
Shellom! can be used to launch regular Android Services that can directly run privileged code, without the need to imitate headless AIDL services. Shellom! uses the instrumentation testing framework to adopt debugger permissions for the desired app.
Warning
Only one instrumented test is allowed to run in the system, so just one app can be elevated using Shellom! at once. Let your users choose who gets this superpower!
- Android 12+ (API 31): Required for
--no-restartinstrumentation. - ADB Connection: Required to trigger the elevation command.
Tip
Any ADB transport works as Shellom! only needs a ShellExecutor.
See Integrations for supported elevation transports.
<dependency>
<groupId>com.indidevs.android</groupId>
<artifactId>shellom</artifactId>
<version>LATEST_VERSION</version>
<type>aar</type>
</dependency>dependencies {
implementation("com.indidevs.android:shellom:LATEST_VERSION")
}maven_install(
artifacts = [
"com.indidevs.android:shellom:LATEST_VERSION",
],
repositories = [
"https://repo1.maven.org/maven2",
],
)Register the ShellRunner in your manifest to handle the instrumentation process.
<instrumentation
android:name="com.indidevs.android.shellom.ShellRunner"
android:targetPackage="your.package.id" />The ShellExecutor routes the elevation command through your ADB channel.
See Integrations for ready ADB executors.
Define a custom executor:
val executor = ShellExecutor { cmd ->
myAdb.execute(cmd) // Must return Result<Unit>
}Reactive connection:
If your ADB session is dynamic (e.g. a StateFlow), use fromFlow. It suspends until an executor is available.
val executor = ShellExecutor.fromFlow(adbSessionFlow.map { session ->
session?.let { s -> ShellExecutor { cmd -> s.execute(cmd) } }
})Initialize the provider and call awaitContext(). It will trigger elevation if needed and return a Context with the requested permissions.
val provider = InstrumentationShellProvider(context, scope, executor, listOf(
"android.permission.WRITE_SECURE_SETTINGS"
))
// Suspend until ready
val privilegedContext = provider.awaitContext() Monitor the elevation lifecycle (IDLE, ELEVATING, READY, ERROR) via the status StateFlow or the observeStatus helper.
provider.observeStatus(lifecycleScope) { status ->
when(status) {
ShellStatus.ELEVATING -> showLoading()
ShellStatus.READY -> proceed()
ShellStatus.ERROR -> showError()
else -> Unit
}
}To clear the cached privileged context and allow a fresh elevation attempt:
provider.reset()If you use a custom AndroidJUnitRunner subclass, pass its name to the provider:
val provider = InstrumentationShellProvider(..., runnerClass = "com.myapp.MyRunner")| Integration | Artifact |
|---|---|
| ADBeesh | com.indidevs.android:adbeesh |
| [Shizuku](#shizuku compatible) | dev.rikka.shizuku:api |
val session = pairing.openSession(timeoutMs = 5000)
val executor = AdbeeshExecutor(
session = session,
elevationSatisfied = { provider.status.value == ShellStatus.READY },
tag = "AdbeeshExecutor"
)Shizuku Compatible
val executor = ShizukuExecutor(
binderTimeoutMs = 5000L,
autoRequestPermission = true,
requestCode = 1001 // Permission request code supplied to Shizuku
)