public static class Shell.SU
extends java.lang.Object
| Constructor and Description |
|---|
SU() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
available()
Detects whether or not superuser access is available, by checking the
output of the "id" command if available, checking if a shell runs at
all otherwise
|
static void |
clearCachedResults()
Clears results cached by isSELinuxEnforcing() and version(boolean
internal) calls.
|
static boolean |
isSELinuxEnforcing()
Detect if SELinux is set to enforcing, caches result
|
static boolean |
isSU(java.lang.String shell)
Attempts to deduce if the shell command refers to a su shell
|
static java.util.List<java.lang.String> |
run(java.util.List<java.lang.String> commands)
Runs commands as root (if available) and return output
|
static java.util.List<java.lang.String> |
run(java.lang.String command)
Runs command as root (if available) and return output
|
static java.util.List<java.lang.String> |
run(java.lang.String[] commands)
Runs commands as root (if available) and return output
|
static java.lang.String |
shell(int uid,
java.lang.String context)
Constructs a shell command to start a su shell using the supplied uid
and SELinux context.
|
static java.lang.String |
shellMountMaster()
Constructs a shell command to start a su shell connected to mount
master daemon, to perform public mounts on Android 4.3+ (or 4.2+ in
SELinux enforcing mode)
|
static java.lang.String |
version(boolean internal)
Detects the version of the su binary installed (if any), if supported
by the binary.
|
public static java.util.List<java.lang.String> run(java.lang.String command)
command - The command to runpublic static java.util.List<java.lang.String> run(java.util.List<java.lang.String> commands)
commands - The commands to runpublic static java.util.List<java.lang.String> run(java.lang.String[] commands)
commands - The commands to runpublic static boolean available()
public static java.lang.String version(boolean internal)
Detects the version of the su binary installed (if any), if supported by the binary. Most binaries support two different version numbers, the public version that is displayed to users, and an internal version number that is used for version number comparisons. Returns null if su not available or retrieving the version isn't supported.
Note that su binary version and GUI (APK) version can be completely different.
This function caches its result to improve performance on multiple calls
internal - Request human-readable version or application
internal versionpublic static boolean isSU(java.lang.String shell)
shell - Shell command to runpublic static java.lang.String shell(int uid,
java.lang.String context)
uid - Uid to use (0 == root)context - (SELinux) context name to use or nullpublic static java.lang.String shellMountMaster()
public static boolean isSELinuxEnforcing()
public static void clearCachedResults()
Clears results cached by isSELinuxEnforcing() and version(boolean internal) calls.
Most apps should never need to call this, as neither enforcing status nor su version is likely to change on a running device - though it is not impossible.