|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.stericson.RootTools.RootTools
public final class RootTools
Field Summary | |
---|---|
static boolean |
debugMode
|
static int |
default_Command_Timeout
Setting this will change the default command timeout. |
static boolean |
handlerEnabled
Setting this to false will disable the handler that is used by default for the 3 callback methods for Command. |
static java.util.List<java.lang.String> |
lastFoundBinaryPaths
|
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 void |
closeAllShells()
This will close all open shells. |
static void |
closeCustomShell()
This will close the custom shell that you opened. |
static void |
closeShell(boolean root)
This will close either the root shell or the standard shell depending on what you specify. |
static boolean |
copyFile(java.lang.String source,
java.lang.String destination,
boolean remountAsRw,
boolean preserveFileAttributes)
Copys a file to a destination. |
static boolean |
deleteFileOrDirectory(java.lang.String target,
boolean remountAsRw)
Deletes a file or directory |
static boolean |
exists(java.lang.String file)
Use this to check whether or not a file exists on the filesystem. |
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.util.List<java.lang.String> |
getBusyBoxApplets(java.lang.String path)
This will return an List of Strings. |
static java.lang.String |
getBusyBoxVersion()
|
static java.lang.String |
getBusyBoxVersion(java.lang.String path)
|
static Shell |
getCustomShell(java.lang.String shellPath)
This will open or return, if one is already open, a custom shell, you are responsible for managing the shell, reading the output and for closing the shell when you are done using it. |
static Shell |
getCustomShell(java.lang.String shellPath,
int timeout)
This will open or return, if one is already open, a custom shell, you are responsible for managing the shell, reading the output and for closing the shell when you are done using it. |
static Permissions |
getFilePermissionsSymlinks(java.lang.String file)
|
static java.lang.String |
getInode(java.lang.String file)
This method will return the inode number of a 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 Shell |
getShell(boolean root)
This will open or return, if one is already open, a shell, you are responsible for managing the shell, reading the output and for closing the shell when you are done using it. |
static Shell |
getShell(boolean root,
int timeout)
This will open or return, if one is already open, a shell, you are responsible for managing the shell, reading the output and for closing the shell when you are done using it. |
static Shell |
getShell(boolean root,
int timeout,
int retry)
This will open or return, if one is already open, a shell, you are responsible for managing the shell, reading the output and for closing the shell when you are done using it. |
static long |
getSpace(java.lang.String path)
Get the space for a desired partition. |
static java.lang.String |
getSymlink(java.lang.String 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 |
hasBinary(android.content.Context context,
java.lang.String binaryName)
This method checks whether a binary is installed. |
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 |
isAppletAvailable(java.lang.String applet,
java.lang.String path)
This will let you know if an applet is available from BusyBox |
static boolean |
isBusyboxAvailable()
|
static boolean |
islog()
This method allows you to check whether logging is enabled. |
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 msg,
int type,
java.lang.Exception e)
This method allows you to output debug messages only when debugging is on. |
static void |
log(java.lang.String TAG,
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,
int type,
java.lang.Exception e)
This method allows you to output debug messages only when debugging is on. |
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 void |
runShellCommand(Shell shell,
Command command)
Executes a given command with root access or without depending on the value of the boolean passed. |
static void |
setRim(RootToolsInternalMethods rim)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, 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 java.lang.String utilPath
public static boolean handlerEnabled
public static int default_Command_Timeout
Constructor Detail |
---|
public RootTools()
Method Detail |
---|
public static void setRim(RootToolsInternalMethods rim)
public static boolean checkUtil(java.lang.String util)
util
- Name of the utility to check.
public static void closeAllShells() throws java.io.IOException
java.io.IOException
public static void closeCustomShell() throws java.io.IOException
java.io.IOException
public static void closeShell(boolean root) throws java.io.IOException
root
- a boolean
to specify whether to close the root shell or the standard shell.
java.io.IOException
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 boolean deleteFileOrDirectory(java.lang.String target, boolean remountAsRw)
target
- example: /data/data/org.adaway/files/hostsremountAsRw
- remounts the destination as read/write before writing to it
public static boolean exists(java.lang.String file)
file
- String that represent the file, including the full path to the
file and its name.
public static void fixUtil(java.lang.String util, java.lang.String utilPath)
util
- Name of the utility to fix.utilPath
- 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 boolean fixUtils(java.lang.String[] utils) throws java.lang.Exception
utils
- Name of the utility to check.
java.lang.Exception
- if the operation cannot be completed.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 java.lang.String getBusyBoxVersion(java.lang.String path)
path
- String that represents the path to the Busybox binary you want to retrieve the version of.
public static java.lang.String getBusyBoxVersion()
public static java.util.List<java.lang.String> getBusyBoxApplets() throws java.lang.Exception
null
If we cannot return the list of applets.
java.lang.Exception
public static java.util.List<java.lang.String> getBusyBoxApplets(java.lang.String path) throws java.lang.Exception
path
- Path to the busybox binary that you want the list of applets from.
null
If we cannot return the list of applets.
java.lang.Exception
public static Shell getCustomShell(java.lang.String shellPath, int timeout) throws java.io.IOException, java.util.concurrent.TimeoutException, RootDeniedException
shellPath
- a String
to Indicate the path to the shell that you want to open.timeout
- an int
to Indicate the length of time before giving up on opening a shell.
java.util.concurrent.TimeoutException
RootDeniedException
java.io.IOException
public static Shell getCustomShell(java.lang.String shellPath) throws java.io.IOException, java.util.concurrent.TimeoutException, RootDeniedException
shellPath
- a String
to Indicate the path to the shell that you want to open.
java.util.concurrent.TimeoutException
RootDeniedException
java.io.IOException
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 java.lang.String getInode(java.lang.String file)
file
- path to the file that you wish to return the inode number
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.lang.String getMountedAs(java.lang.String path) throws java.lang.Exception
path
- 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.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 Shell getShell(boolean root, int timeout, int retry) throws java.io.IOException, java.util.concurrent.TimeoutException, RootDeniedException
retry
- a int
to indicate how many times the ROOT shell should try to open with root priviliges...root
- a boolean
to Indicate whether or not you want to open a root shell or a standard shelltimeout
- an int
to Indicate the length of time to wait before giving up on opening a shell.
java.util.concurrent.TimeoutException
RootDeniedException
java.io.IOException
public static Shell getShell(boolean root, int timeout) throws java.io.IOException, java.util.concurrent.TimeoutException, RootDeniedException
root
- a boolean
to Indicate whether or not you want to open a root shell or a standard shelltimeout
- an int
to Indicate the length of time to wait before giving up on opening a shell.
java.util.concurrent.TimeoutException
RootDeniedException
java.io.IOException
public static Shell getShell(boolean root) throws java.io.IOException, java.util.concurrent.TimeoutException, RootDeniedException
root
- a boolean
to Indicate whether or not you want to open a root shell or a standard shell
java.util.concurrent.TimeoutException
RootDeniedException
java.io.IOException
public static long getSpace(java.lang.String path)
path
- The partition to find the space for.
java.util.concurrent.TimeoutException
public static java.lang.String getSymlink(java.lang.String file)
file
- path to 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 java.util.ArrayList<Symlink> getSymlinks(java.lang.String path) throws java.lang.Exception
path
- 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 getWorkingToolbox()
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 hasUtil(java.lang.String util, java.lang.String box)
util
- box
- Should contain "toolbox" or "busybox"
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 boolean hasBinary(android.content.Context context, java.lang.String binaryName)
context
- the current activity's Context
binaryName
- binary file name; appended to /data/data/app.package/files/
boolean
which indicates whether or not
the binary already exists.public static boolean isAppletAvailable(java.lang.String applet, java.lang.String path)
applet
- The applet to check for.path
- Path to the busybox binary that you want to check. (do not include binary name)
true
if applet is available, false otherwise.public static boolean isAppletAvailable(java.lang.String applet)
applet
- 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 isBusyboxAvailable()
true
if BusyBox was found.public static boolean isNativeToolsReady(int nativeToolsId, android.content.Context context)
public 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 boolean isRootAvailable()
true
if su was found.public static boolean killProcess(java.lang.String processName)
processName
- name of process to kill
true
if process was found and killed successfullypublic 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 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 void restartAndroid()
java.util.concurrent.TimeoutException
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 void runShellCommand(Shell shell, Command command) throws java.io.IOException
shell
- The shell to execute the command on, this can be a root shell or a standard shell.command
- The command to execute in the shell
java.io.IOException
public static void log(java.lang.String msg)
msg
- The message to output.public static void log(java.lang.String TAG, 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 msg, int type, java.lang.Exception e)
msg
- The message to output.type
- The type of log, 1 for verbose, 2 for error, 3 for debuge
- The exception that was thrown (Needed for errors)public static boolean islog()
public static void log(java.lang.String TAG, java.lang.String msg, int type, java.lang.Exception e)
TAG
- Optional parameter to define the tag that the Log will use.msg
- The message to output.type
- The type of log, 1 for verbose, 2 for error, 3 for debuge
- The exception that was thrown (Needed for errors)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |