Skip to content

About

A Flutter plugin for getting root access in Android apps.

Resources

Stars

11 stars

Watchers

3 watching

Forks

Repository files navigation

pub package Tests

root_access

A Flutter plugin for rooted Android devices. It can:

  • ask for root and tell you whether it was granted, denied, or not available,
  • check for root without a prompt, looking for su, Magisk, KernelSU, APatch, Frida, Xposed and more,
  • run shell commands as root, one at a time, in a long-lived session, or streamed line by line.

The plugin has no native dependencies. It is Android only; on other platforms every call answers safely (see Other platforms).

Requirements

  • Flutter 3.10+ (Dart 3)
  • Android minSdk 21 or higher

Install

flutter pub add root_access
import 'package:root_access/root_access.dart';

Ask for root

final RootAccessStatus status = await RootAccess.requestRoot();

switch (status) {
  case RootAccessStatus.granted:
    // Root is available.
    break;
  case RootAccessStatus.denied:
    // su exists, but the user or the root manager said no.
    break;
  case RootAccessStatus.notRooted:
    // No su on this device.
    break;
  case RootAccessStatus.timedOut:
    // Nobody answered the superuser prompt (30 seconds by default).
    break;
  case RootAccessStatus.unsupported:
    // Not Android.
    break;
}

requestRoot shows the root manager's prompt unless the app was already allowed or denied. RootAccess.requestRootAccess (a bool) still works but is deprecated.

Check for root without a prompt

RootAccess.isRooted() looks for signs of root without running su, so the user never sees a superuser prompt. It reads files, system properties and the app's own /proc entries, and returns a RootReport.

final RootReport report = await RootAccess.isRooted();

if (report.isRooted) {
  print('su binaries: ${report.suBinaries}');
  print('root apps: ${report.rootManagerApps}');
  print('root mounts: ${report.rootMounts}');
}
if (report.isHooked) {
  print('hooking frameworks: ${report.hookFrameworks}');
}
Group Fields Counted by
Strong signals suBinaries, rootManagerApps (Magisk, KernelSU, APatch, SuperSU and others), rootMounts (Magisk/KernelSU/APatch mounts), systemWritable isRooted
Injected code hookFrameworks (Frida, Xposed, LSPosed, Zygisk, Riru, Substrate) isHooked
Weak signals testKeys, debuggable, insecure, bootloaderUnlocked, selinuxPermissive hasAnySignal
Context emulator none

Weak signals are also common on unrooted custom ROMs, development builds and emulators, so they don't make isRooted true. Frida can be injected into a repackaged app without root, so hooking is reported separately.

Root can be hidden from all of these checks (for example with Magisk's DenyList, Shamiko or a randomized Magisk package name), so a clean report means "no root found", not proof that the device is unrooted. If you need a strong guarantee, use the Play Integrity API and verify its verdict on your server.

The plugin declares the root manager apps it looks for in a <queries> block, so Android 11+ package visibility doesn't hide them. Your app needs no extra permission.

Run commands as root

Every command is passed to the root shell as-is, so pipes, && and redirects work. Never build a command from untrusted input.

One command

final RootCommandResult result = await RootAccess.runAsRoot(
  'ls /data/data',
  timeout: const Duration(seconds: 10), // optional
);
if (result.success) {
  print(result.stdout);
} else {
  print('Failed (${result.exitCode}): ${result.stderr}');
}
  • If root access is denied, su exits with a non-zero exit code and the command does not run.
  • If su is missing (the device is not rooted), a PlatformException with code ROOT_UNAVAILABLE is thrown.
  • If the command takes longer than timeout, the root shell is killed and a PlatformException with code TIMEOUT is thrown.
  • At most maxOutputBytes (1 MiB by default) of stdout and of stderr are kept. result.truncated tells you when output was cut; pass maxOutputBytes: 0 to keep everything.

Many commands: a session

Each runAsRoot call starts a new su. A RootSession keeps one root shell open, so the prompt appears once, commands start faster, and state such as the working directory carries over.

final RootSession session = await RootAccess.openSession();
try {
  await session.run('cd /data/local/tmp');
  final RootCommandResult files = await session.run('ls -la');
  print(files.stdout);
} finally {
  await session.close();
}

openSession throws a PlatformException with code ROOT_DENIED, ROOT_UNAVAILABLE or TIMEOUT when it can't get a root shell. Commands run one at a time with stdin set to /dev/null. A timeout, or a command that ends the shell (such as exit), closes the session; check session.isClosed.

Long-running commands: streamed output

final RootProcess process = await RootAccess.startAsRoot('logcat -d');
process.stdout.listen((String line) => print(line));
process.stderr.listen((String line) => print('ERR $line'));
final int exitCode = await process.exitCode;

Lines arrive as the command prints them. Call process.kill() to stop it.

Errors

PlatformException.code Meaning
ROOT_UNAVAILABLE su could not be started (device not rooted), or this isn't Android.
ROOT_DENIED openSession only: the shell did not get root.
TIMEOUT The command or prompt took longer than the timeout.
SESSION_CLOSED The RootSession was closed.

Other platforms

The plugin only has Android code. Elsewhere, no native code is called: requestRoot returns RootAccessStatus.unsupported, isRooted returns a report with platformSupported == false (no checks ran, which does not mean the device is clean), and the command APIs throw ROOT_UNAVAILABLE.

Testing

  • flutter test runs the Dart tests.
  • The Android code has JVM unit tests: build the example once (cd example && flutter build apk --debug), then run cd example/android && ./gradlew :root_access:testDebugUnitTest.
  • cd example && flutter test integration_test runs the plugin on a connected device or emulator.

Example

See the example app for a complete sample.

History

Earlier versions were based on RootTools by Stericson. Since 2.0.0 the plugin ships its own small su runner.

Issues and feedback

Please file issues to send feedback or report a bug. Thank you!

About

A Flutter plugin for getting root access in Android apps.

Resources

Stars

11 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages