com.stericson.RootTools
Class RootTools

java.lang.Object
  extended by com.stericson.RootTools.RootTools

public class RootTools
extends java.lang.Object


Nested Class Summary
static class RootTools.Result
           
 
Field Summary
static boolean debugMode
           
 
Constructor Summary
RootTools()
           
 
Method Summary
static boolean accessGiven()
          Deprecated. As of release 0.7, replaced by isAccessGiven()
static boolean busyboxAvailable()
          Deprecated. As of release 0.7, replaced by isBusyboxAvailable()
static boolean EnoughSpaceOnSdCard(long updateSize)
          Deprecated. As of release 0.7, replaced by hasEnoughSpaceOnSdCard(long)
static boolean findBinary(java.lang.String binaryName)
           
static java.lang.String getBusyBoxVersion()
           
static int getFilePermissions(java.lang.String file)
           
static java.util.ArrayList<com.stericson.RootTools.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 boolean hasEnoughSpaceOnSdCard(long updateSize)
          Checks if there is enough Space on SDCard
static boolean installBinary(android.content.Context context, int sourceId, java.lang.String destName)
          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 isBusyboxAvailable()
           
static boolean isRootAvailable()
           
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)
          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 boolean rootAvailable()
          Deprecated. As of release 0.7, replaced by isRootAvailable()
static java.util.List<java.lang.String> sendShell(java.lang.String command)
          Sends one shell command as su (attempts to)
static java.util.List<java.lang.String> sendShell(java.lang.String[] commands, int sleepTime)
          Sends several shell command as su (attempts to)
static java.util.List<java.lang.String> sendShell(java.lang.String[] commands, int sleepTime, RootTools.Result result)
          Sends several shell command as su (attempts to)
static java.util.List<java.lang.String> sendShell(java.lang.String command, RootTools.Result result)
          Sends one shell command as su (attempts to)
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debugMode

public static boolean debugMode
Constructor Detail

RootTools

public RootTools()
Method Detail

getPath

public static java.util.Set<java.lang.String> getPath()
                                               throws java.lang.Exception
This will return the environment variable $PATH

Returns:
Set A Set of Strings representing the environment variable $PATH
Throws:
java.lang.Exception - if we cannot return the $PATH variable

getMounts

public static java.util.ArrayList<com.stericson.RootTools.Mount> getMounts()
                                                                    throws java.lang.Exception
This will return an ArrayList of the class Mount. The class mount contains the following property's: device mountPoint type flags

These will provide you with any information you need to work with the mount points.

Returns:
ArrayList an ArrayList of the class Mount.
Throws:
java.lang.Exception - if we cannot return the mount points.

offerBusyBox

public static void offerBusyBox(android.app.Activity activity)
This will launch the Android market looking for BusyBox

Parameters:
activity - pass in your Activity

offerBusyBox

public 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

Parameters:
activity - pass in your Activity
requestCode - pass in the request code
Returns:
intent fired

offerSuperUser

public static void offerSuperUser(android.app.Activity activity)
This will launch the Android market looking for SuperUser

Parameters:
activity - pass in your Activity

offerSuperUser

public 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

Parameters:
activity - pass in your Activity
requestCode - pass in the request code
Returns:
intent fired

rootAvailable

@Deprecated
public static boolean rootAvailable()
Deprecated. As of release 0.7, replaced by isRootAvailable()

Returns:
true if su was found

isRootAvailable

public static boolean isRootAvailable()
Returns:
true if su was found.

busyboxAvailable

@Deprecated
public static boolean busyboxAvailable()
Deprecated. As of release 0.7, replaced by isBusyboxAvailable()

Returns:
true if BusyBox was found

isBusyboxAvailable

public static boolean isBusyboxAvailable()
Returns:
true if BusyBox was found.

findBinary

public static boolean findBinary(java.lang.String binaryName)
Parameters:
binaryName - String that represent the binary to find.
Returns:
true if the specified binary was found.

getFilePermissions

public static int getFilePermissions(java.lang.String file)
Parameters:
file - String that represent the file, including the full path to the file and its name.
Returns:
An int detailing the permissions of the file or -1 if the file could not be found or permissions couldn't be determined.

getBusyBoxVersion

public static java.lang.String getBusyBoxVersion()
Returns:
BusyBox version is found, null if not found.

accessGiven

@Deprecated
public static boolean accessGiven()
Deprecated. As of release 0.7, replaced by isAccessGiven()

Returns:
true if your app has been given root access.

isAccessGiven

public static boolean isAccessGiven()
Returns:
true if your app has been given root access.

EnoughSpaceOnSdCard

@Deprecated
public static boolean EnoughSpaceOnSdCard(long updateSize)
Deprecated. As of release 0.7, replaced by hasEnoughSpaceOnSdCard(long)

Checks if there is enough Space on SDCard

Parameters:
updateSize - size to Check (long)
Returns:
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/write

hasEnoughSpaceOnSdCard

public static boolean hasEnoughSpaceOnSdCard(long updateSize)
Checks if there is enough Space on SDCard

Parameters:
updateSize - size to Check (long)
Returns:
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/write

remount

public 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.

For example, passing in the following string: "/system/bin/some/directory/that/really/would/never/exist" will result in /system ultimately being remounted. However, keep in mind that the longer the path you supply, the more work this has to do, and the slower it will run.

Parameters:
file - file path
mountType - mount type: pass in RO (Read only) or RW (Read Write)
Returns:
a boolean which indicates whether or not the partition has been remounted as specified.

installBinary

public 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. This binary can then be executed using sendShell() and its full path.

Parameters:
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
Returns:
a boolean which indicates whether or not we were able to create the new file.

installBinary

public static boolean installBinary(android.content.Context context,
                                    int sourceId,
                                    java.lang.String destName)
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. This binary can then be executed using sendShell() and its full path.

Parameters:
context - the current activity's Context
sourceId - resource id; typically R.raw.id
destName - destination file name; appended to /data/data/app.package/files/
Returns:
a boolean which indicates whether or not we were able to create the new file.

sendShell

public static java.util.List<java.lang.String> sendShell(java.lang.String[] commands,
                                                         int sleepTime,
                                                         RootTools.Result result)
                                                  throws java.io.IOException,
                                                         java.lang.InterruptedException,
                                                         com.stericson.RootTools.RootToolsException
Sends several shell command as su (attempts to)

Parameters:
commands - array of commands to send to the shell
sleepTime - time to sleep between each command, delay.
result - injected result object that implements the Result class
Returns:
a 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.
Throws:
java.lang.InterruptedException
java.io.IOException
com.stericson.RootTools.RootToolsException

sendShell

public static java.util.List<java.lang.String> sendShell(java.lang.String[] commands,
                                                         int sleepTime)
                                                  throws java.io.IOException,
                                                         java.lang.InterruptedException,
                                                         com.stericson.RootTools.RootToolsException
Sends several shell command as su (attempts to)

Parameters:
commands - array of commands to send to the shell
sleepTime - time to sleep between each command, delay.
Returns:
a 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.
Throws:
java.lang.InterruptedException
java.io.IOException
com.stericson.RootTools.RootToolsException

sendShell

public static java.util.List<java.lang.String> sendShell(java.lang.String command,
                                                         RootTools.Result result)
                                                  throws java.io.IOException,
                                                         java.lang.InterruptedException,
                                                         com.stericson.RootTools.RootToolsException
Sends one shell command as su (attempts to)

Parameters:
command - command to send to the shell
result - injected result object that implements the Result class
Returns:
a 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.
Throws:
java.lang.InterruptedException
java.io.IOException
com.stericson.RootTools.RootToolsException

sendShell

public static java.util.List<java.lang.String> sendShell(java.lang.String command)
                                                  throws java.io.IOException,
                                                         java.lang.InterruptedException,
                                                         com.stericson.RootTools.RootToolsException
Sends one shell command as su (attempts to)

Parameters:
command - command to send to the shell
Returns:
a 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.
Throws:
java.lang.InterruptedException
java.io.IOException
com.stericson.RootTools.RootToolsException

getSpace

public static long getSpace(java.lang.String path)
Get the space for a desired partition.

Parameters:
path - The partition to find the space for.
Returns:
the amount if space found within the desired partition. If the space was not found then the value is -1

log

public static void log(java.lang.String msg)
This method allows you to output debug messages only when debugging is on. This will allow you to add a debug option to your app, which by default can be left off for performance. However, when you need debugging information, a simple switch can enable it and provide you with detailed logging.

This method handles whether or not to log the information you pass it depending whether or not RootTools.debugMode is on. So you can use this and not have to worry about handling it yourself.

Parameters:
msg - The message to output.

log

public static void log(java.lang.String TAG,
                       java.lang.String msg)
This method allows you to output debug messages only when debugging is on. This will allow you to add a debug option to your app, which by default can be left off for performance. However, when you need debugging information, a simple switch can enable it and provide you with detailed logging.

This method handles whether or not to log the information you pass it depending whether or not RootTools.debugMode is on. So you can use this and not have to worry about handling it yourself.

Parameters:
msg - The message to output.
TAG - Optional parameter to define the tag that the Log will use.