|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.stericson.RootTools.RootTools
public class RootTools
Nested Class Summary | |
---|---|
static class |
RootTools.Result
|
Field Summary | |
---|---|
static java.lang.String |
customShell
You can use this to force sendshell to use a shell other than the deafult. |
static boolean |
debugMode
This class is the gateway to every functionality within the RootTools library.The developer should only have access to this class and this class only.This means that this class should be the only one to be public.The rest of the classes within this library must not have the public modifier. |
static int |
lastExitCode
|
static java.util.List<java.lang.String> |
lastFoundBinaryPaths
|
static int |
shellDelay
Change this to a lower/higher setting to speed up/slow down shell commands if things are taking too long or you are having constant crashes or timeout exceptions. |
static boolean |
useRoot
Many Functions here use root by default, but there may be times that you do not want them to use root. |
static java.lang.String |
utilPath
|
Constructor Summary | |
---|---|
RootTools()
|
Method Summary | |
---|---|
static boolean |
checkUtil(java.lang.String util)
This will check a given binary, determine if it exists and determine that it has either the permissions 755, 775, or 777. |
static boolean |
checkUtils(java.lang.String[] utils)
Deprecated. |
static boolean |
copyFile(java.lang.String source,
java.lang.String destination,
boolean remountAsRw,
boolean preserveFileAttributes)
Copys a file to a destination. |
static boolean |
findBinary(java.lang.String binaryName)
|
static void |
fixUtil(java.lang.String util,
java.lang.String utilPath)
This will try and fix a given binary. |
static boolean |
fixUtils(java.lang.String[] utils)
This will check an array of binaries, determine if they exist and determine that it has either the permissions 755, 775, or 777. |
static java.util.List<java.lang.String> |
getBusyBoxApplets()
This will return an List of Strings. |
static java.lang.String |
getBusyBoxVersion()
|
static Permissions |
getFilePermissions(java.lang.String file)
Deprecated. |
static Permissions |
getFilePermissionsSymlinks(java.lang.String file)
|
static java.lang.String |
getMountedAs(java.lang.String path)
This will tell you how the specified mount is mounted. |
static java.util.ArrayList<Mount> |
getMounts()
This will return an ArrayList of the class Mount. |
static java.util.Set<java.lang.String> |
getPath()
This will return the environment variable $PATH |
static long |
getSpace(java.lang.String path)
Get the space for a desired partition. |
static java.lang.String |
getSymlink(java.io.File file)
This will return a String that represent the symlink for a specified file. |
static java.util.ArrayList<Symlink> |
getSymlinks(java.lang.String path)
This will return an ArrayList of the class Symlink. |
static java.lang.String |
getWorkingToolbox()
This will return to you a string to be used in your shell commands which will represent the valid working toolbox with correct permissions. |
static boolean |
hasEnoughSpaceOnSdCard(long updateSize)
Checks if there is enough Space on SDCard |
static boolean |
hasUtil(java.lang.String util,
java.lang.String box)
Checks whether the toolbox or busybox binary contains a specific util |
static boolean |
installBinary(android.content.Context context,
int sourceId,
java.lang.String binaryName)
This method can be used to unpack a binary from the raw resources folder and store it in /data/data/app.package/files/ This is typically useful if you provide your own C- or C++-based binary. |
static boolean |
installBinary(android.content.Context context,
int sourceId,
java.lang.String destName,
java.lang.String mode)
This method can be used to unpack a binary from the raw resources folder and store it in /data/data/app.package/files/ This is typically useful if you provide your own C- or C++-based binary. |
static boolean |
isAccessGiven()
|
static boolean |
isAppletAvailable(java.lang.String Applet)
This will let you know if an applet is available from BusyBox |
static boolean |
isBusyboxAvailable()
|
static boolean |
isNativeToolsReady(int nativeToolsId,
android.content.Context context)
|
static boolean |
isProcessRunning(java.lang.String processName)
This method can be used to to check if a process is running |
static boolean |
isRootAvailable()
|
static boolean |
killProcess(java.lang.String processName)
This method can be used to kill a running process |
static void |
log(java.lang.String msg)
This method allows you to output debug messages only when debugging is on. |
static void |
log(java.lang.String TAG,
java.lang.String msg)
|
static void |
offerBusyBox(android.app.Activity activity)
This will launch the Android market looking for BusyBox |
static android.content.Intent |
offerBusyBox(android.app.Activity activity,
int requestCode)
This will launch the Android market looking for BusyBox, but will return the intent fired and starts the activity with startActivityForResult |
static void |
offerSuperUser(android.app.Activity activity)
This will launch the Android market looking for SuperUser |
static android.content.Intent |
offerSuperUser(android.app.Activity activity,
int requestCode)
This will launch the Android market looking for SuperUser, but will return the intent fired and starts the activity with startActivityForResult |
static boolean |
remount(java.lang.String file,
java.lang.String mountType)
This will take a path, which can contain the file name as well, and attempt to remount the underlying partition. |
static void |
restartAndroid()
This restarts only Android OS without rebooting the whole device. |
static void |
runBinary(android.content.Context context,
java.lang.String binaryName,
java.lang.String parameter)
Executes binary in a separated process. |
static java.util.List<java.lang.String> |
sendShell(java.lang.String[] commands,
int sleepTime,
int timeout)
Sends several shell command as su, unless useRoot is set to false |
static java.util.List<java.lang.String> |
sendShell(java.lang.String[] commands,
int sleepTime,
RootTools.Result result,
boolean useRoot,
int timeout)
Sends several shell command as su (attempts to) if useRoot is true; as the current user (app_xxx) otherwise. |
static java.util.List<java.lang.String> |
sendShell(java.lang.String[] commands,
int sleepTime,
RootTools.Result result,
int timeout)
Sends several shell command as su (attempts to) |
static java.util.List<java.lang.String> |
sendShell(java.lang.String command,
int timeout)
Sends one shell command as su, unless useRoot is set to false |
static java.util.List<java.lang.String> |
sendShell(java.lang.String command,
RootTools.Result result,
int timeout)
Sends one shell command as su, unless useRoot is set to false |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static boolean debugMode
public static java.util.List<java.lang.String> lastFoundBinaryPaths
public static int lastExitCode
public static java.lang.String utilPath
public static java.lang.String customShell
public static int shellDelay
public static boolean useRoot
Constructor Detail |
---|
public RootTools()
Method Detail |
---|
public static java.lang.String getWorkingToolbox()
public static boolean hasUtil(java.lang.String util, java.lang.String box)
util
- box
- Should contain "toolbox" or "busybox"
public static boolean checkUtils(java.lang.String[] utils) throws java.lang.Exception
String
- Name of the utility to check.
java.lang.Exception
- if the operation cannot be completed.public static boolean fixUtils(java.lang.String[] utils) throws java.lang.Exception
String
- Name of the utility to check.
java.lang.Exception
- if the operation cannot be completed.public static boolean checkUtil(java.lang.String util)
String
- Name of the utility to check.
public static void fixUtil(java.lang.String util, java.lang.String utilPath)
String
- Name of the utility to fix.String
- path to the toolbox that provides ln, rm, and chmod. This can be a blank string, a
path to a binary that will provide these, or you can use
RootTools.getWorkingToolbox()public static java.util.Set<java.lang.String> getPath() throws java.lang.Exception
Set
A Set of Strings representing the environment variable $PATH
java.lang.Exception
- if we cannot return the $PATH variablepublic static java.lang.String getMountedAs(java.lang.String path) throws java.lang.Exception
The
- mount you want to check
String
What the mount is mounted as.
java.lang.Exception
- if we cannot determine how the mount is mounted.public static java.util.ArrayList<Mount> getMounts() throws java.lang.Exception
ArrayList
an ArrayList of the class Mount.
java.lang.Exception
- if we cannot return the mount points.public static java.util.ArrayList<Symlink> getSymlinks(java.lang.String path) throws java.lang.Exception
The
- path to search for Symlinks.
ArrayList
an ArrayList of the class Symlink.
java.lang.Exception
- if we cannot return the Symlinks.public static java.lang.String getSymlink(java.io.File file)
The
- file to get the Symlink for. (must have absolute path)
String
a String that represent the symlink for a specified file or an
empty string if no symlink exists.public static boolean copyFile(java.lang.String source, java.lang.String destination, boolean remountAsRw, boolean preserveFileAttributes)
source
- example: /data/data/org.adaway/files/hostsdestination
- example: /system/etc/hostsremountAsRw
- remounts the destination as read/write before writing to itpreserveFileAttributes
- tries to copy file attributes from source to destination, if only cat is available
only permissions are preserved
public static void offerBusyBox(android.app.Activity activity)
activity
- pass in your Activitypublic static android.content.Intent offerBusyBox(android.app.Activity activity, int requestCode)
activity
- pass in your ActivityrequestCode
- pass in the request code
public static void offerSuperUser(android.app.Activity activity)
activity
- pass in your Activitypublic static android.content.Intent offerSuperUser(android.app.Activity activity, int requestCode)
activity
- pass in your ActivityrequestCode
- pass in the request code
public static boolean isRootAvailable()
true
if su was found.public static boolean isBusyboxAvailable()
true
if BusyBox was found.public static boolean findBinary(java.lang.String binaryName)
binaryName
- String that represent the binary to find.
true
if the specified binary was found. Also, the path the binary was
found at can be retrieved via the variable lastFoundBinaryPath, if the binary was
found in more than one location this will contain all of these locations.public static Permissions getFilePermissionsSymlinks(java.lang.String file)
file
- String that represent the file, including the full path to the file and its name.
public static Permissions getFilePermissions(java.lang.String file)
file
- String that represent the file, including the full path to the file and its name.
public static java.lang.String getBusyBoxVersion()
public static java.util.List<java.lang.String> getBusyBoxApplets() throws java.lang.Exception
List
a List of strings representing the applets available from
Busybox.
java.lang.Exception
- if we cannot return the applets available.public static boolean isAppletAvailable(java.lang.String Applet)
String
- The applet to check for.
true
if applet is available, false otherwise.public static boolean isAccessGiven()
true
if your app has been given root access.
java.util.concurrent.TimeoutException
- if this operation times out. (cannot determine if access is given)public static boolean isNativeToolsReady(int nativeToolsId, android.content.Context context)
public static boolean hasEnoughSpaceOnSdCard(long updateSize)
updateSize
- size to Check (long)
true
if the Update will fit on SDCard, false
if not enough
space on SDCard. Will also return false
, if the SDCard is not mounted as
read/writepublic static boolean remount(java.lang.String file, java.lang.String mountType)
file
- file pathmountType
- mount type: pass in RO (Read only) or RW (Read Write)
boolean
which indicates whether or not the partition has been
remounted as specified.public static boolean installBinary(android.content.Context context, int sourceId, java.lang.String destName, java.lang.String mode)
context
- the current activity's Context
sourceId
- resource id; typically R.raw.id
destName
- destination file name; appended to /data/data/app.package/files/mode
- chmod value for this file
boolean
which indicates whether or not we were able to create the new
file.public static boolean installBinary(android.content.Context context, int sourceId, java.lang.String binaryName)
context
- the current activity's Context
sourceId
- resource id; typically R.raw.id
binaryName
- destination file name; appended to /data/data/app.package/files/
boolean
which indicates whether or not we were able to create the new
file.public static void runBinary(android.content.Context context, java.lang.String binaryName, java.lang.String parameter)
context
- the current activity's Context
binaryName
- name of installed binaryparameter
- parameter to append to binary like "-vxf"public static boolean killProcess(java.lang.String processName)
processName
- name of process to kill
true
if process was found and killed successfullypublic static boolean isProcessRunning(java.lang.String processName)
processName
- name of process to check
true
if process was found
java.util.concurrent.TimeoutException
- (Could not determine if the process is running)public static void restartAndroid()
java.util.concurrent.TimeoutException
public static java.util.List<java.lang.String> sendShell(java.lang.String[] commands, int sleepTime, RootTools.Result result, int timeout) throws java.io.IOException, RootToolsException, java.util.concurrent.TimeoutException
commands
- array of commands to send to the shellsleepTime
- time to sleep between each command, delay.result
- injected result object that implements the Result classtimeout
- How long to wait before throwing TimeoutException, sometimes when running root
commands on certain devices or roms ANR's may occur because a process never
returns or readline never returns. This allows you to protect your application
from throwing an ANR.
if you pass -1, then the default timeout is 5 minutes.
LinkedList
containing each line that was returned by the shell after
executing or while trying to execute the given commands. You must iterate over this
list, it does not allow random access, so no specifying an index of an item you want,
not like you're going to know that anyways.
java.lang.InterruptedException
java.io.IOException
java.util.concurrent.TimeoutException
RootToolsException
public static java.util.List<java.lang.String> sendShell(java.lang.String[] commands, int sleepTime, RootTools.Result result, boolean useRoot, int timeout) throws java.io.IOException, RootToolsException, java.util.concurrent.TimeoutException
commands
- array of commands to send to the shellsleepTime
- time to sleep between each command, delay.result
- injected result object that implements the Result classuseRoot
- whether to use root or not when issuing these commands.timeout
- How long to wait before throwing TimeoutException, sometimes when running root
commands on certain devices or roms ANR's may occur because a process never
returns or readline never returns. This allows you to protect your application
from throwing an ANR.
if you pass -1, then the default timeout is 5 minutes.
LinkedList
containing each line that was returned by the shell after
executing or while trying to execute the given commands. You must iterate over this
list, it does not allow random access, so no specifying an index of an item you want,
not like you're going to know that anyways.
java.lang.InterruptedException
java.io.IOException
java.util.concurrent.TimeoutException
RootToolsException
public static java.util.List<java.lang.String> sendShell(java.lang.String[] commands, int sleepTime, int timeout) throws java.io.IOException, RootToolsException, java.util.concurrent.TimeoutException
commands
- array of commands to send to the shellsleepTime
- time to sleep between each command, delay.timeout
- How long to wait before throwing TimeoutException, sometimes when running root
commands on certain devices or roms ANR's may occur because a process never
returns or readline never returns. This allows you to protect your application
from throwing an ANR.
if you pass -1, then the default timeout is 5 minutes.
java.lang.InterruptedException
java.io.IOException
java.util.concurrent.TimeoutException
RootToolsException
public static java.util.List<java.lang.String> sendShell(java.lang.String command, RootTools.Result result, int timeout) throws java.io.IOException, RootToolsException, java.util.concurrent.TimeoutException
command
- command to send to the shellresult
- injected result object that implements the Result classtimeout
- How long to wait before throwing TimeoutException, sometimes when running root
commands on certain devices or roms ANR's may occur because a process never
returns or readline never returns. This allows you to protect your application
from throwing an ANR.
if you pass -1, then the default timeout is 5 minutes.
LinkedList
containing each line that was returned by the shell after
executing or while trying to execute the given commands. You must iterate over this
list, it does not allow random access, so no specifying an index of an item you want,
not like you're going to know that anyways.
java.lang.InterruptedException
java.io.IOException
RootToolsException
java.util.concurrent.TimeoutException
public static java.util.List<java.lang.String> sendShell(java.lang.String command, int timeout) throws java.io.IOException, RootToolsException, java.util.concurrent.TimeoutException
command
- command to send to the shelltimeout
- How long to wait before throwing TimeoutException, sometimes when running root
commands on certain devices or roms ANR's may occur because a process never
returns or readline never returns. This allows you to protect your application
from throwing an ANR.
if you pass -1, then the default timeout is 5 minutes.
java.lang.InterruptedException
java.io.IOException
java.util.concurrent.TimeoutException
RootToolsException
public static long getSpace(java.lang.String path)
path
- The partition to find the space for.
java.util.concurrent.TimeoutException
public static void log(java.lang.String msg)
TAG
- Optional parameter to define the tag that the Log will use.msg
- The message to output.public static void log(java.lang.String TAG, java.lang.String msg)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |