com.stericson.RootTools.internal
Class RootToolsInternalMethods

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

public final class RootToolsInternalMethods
extends java.lang.Object


Constructor Summary
protected RootToolsInternalMethods()
           
 
Method Summary
 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.
 boolean copyFile(java.lang.String source, java.lang.String destination, boolean remountAsRw, boolean preserveFileAttributes)
          Copys a file to a destination.
 boolean deleteFileOrDirectory(java.lang.String target, boolean remountAsRw)
          Deletes a file or directory
 boolean exists(java.lang.String file)
          Use this to check whether or not a file exists on the filesystem.
 boolean findBinary(java.lang.String binaryName)
           
 void fixUtil(java.lang.String util, java.lang.String utilPath)
          This will try and fix a given binary.
 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.
 java.util.List<java.lang.String> getBusyBoxApplets(java.lang.String path)
          This will return an List of Strings.
 java.lang.String getBusyBoxVersion(java.lang.String path)
           
 long getConvertedSpace(java.lang.String spaceStr)
           
 Permissions getFilePermissionsSymlinks(java.lang.String file)
           
 java.lang.String getInode(java.lang.String file)
          This method will return the inode number of a file.
static void getInstance()
           
 java.lang.String getMountedAs(java.lang.String path)
          This will tell you how the specified mount is mounted.
 java.util.ArrayList<Mount> getMounts()
          This will return an ArrayList of the class Mount.
 java.util.Set<java.lang.String> getPath()
          This will return the environment variable $PATH
 Permissions getPermissions(java.lang.String line)
           
 long getSpace(java.lang.String path)
          Get the space for a desired partition.
 java.lang.String getSymlink(java.lang.String file)
          This will return a String that represent the symlink for a specified file.
 java.util.ArrayList<Symlink> getSymLinks()
           
 java.util.ArrayList<Symlink> getSymlinks(java.lang.String path)
          This will return an ArrayList of the class Symlink.
 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.
 boolean hasEnoughSpaceOnSdCard(long updateSize)
          Checks if there is enough Space on SDCard
 boolean hasUtil(java.lang.String util, java.lang.String box)
          Checks whether the toolbox or busybox binary contains a specific util
 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.
 boolean isAccessGiven()
           
 boolean isAppletAvailable(java.lang.String applet, java.lang.String binaryPath)
          This will let you know if an applet is available from BusyBox

 boolean isBinaryAvailable(android.content.Context context, java.lang.String binaryName)
          This method checks whether a binary is installed.
 boolean isNativeToolsReady(int nativeToolsId, android.content.Context context)
           
 boolean isProcessRunning(java.lang.String processName)
          This method can be used to to check if a process is running
 boolean killProcess(java.lang.String processName)
          This method can be used to kill a running process
 void offerBusyBox(android.app.Activity activity)
          This will launch the Android market looking for BusyBox
 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
 void offerSuperUser(android.app.Activity activity)
          This will launch the Android market looking for SuperUser
 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
 int parsePermissions(java.lang.String permission)
           
 int parseSpecialPermissions(java.lang.String permission)
           
 boolean returnPath()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RootToolsInternalMethods

protected RootToolsInternalMethods()
Method Detail

getInstance

public static void getInstance()

returnPath

public boolean returnPath()
                   throws java.util.concurrent.TimeoutException
Throws:
java.util.concurrent.TimeoutException

getSymLinks

public java.util.ArrayList<Symlink> getSymLinks()
                                         throws java.io.IOException
Throws:
java.io.IOException

getPermissions

public Permissions getPermissions(java.lang.String line)

parsePermissions

public int parsePermissions(java.lang.String permission)

parseSpecialPermissions

public int parseSpecialPermissions(java.lang.String permission)

copyFile

public boolean copyFile(java.lang.String source,
                        java.lang.String destination,
                        boolean remountAsRw,
                        boolean preserveFileAttributes)
Copys a file to a destination. Because cp is not available on all android devices, we have a fallback on the cat command

Parameters:
source - example: /data/data/org.adaway/files/hosts
destination - example: /system/etc/hosts
remountAsRw - remounts the destination as read/write before writing to it
preserveFileAttributes - tries to copy file attributes from source to destination, if only cat is available only permissions are preserved
Returns:
true if it was successfully copied

checkUtil

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

Parameters:
util - Name of the utility to check.
Returns:
boolean to indicate whether the binary is installed and has appropriate permissions.

deleteFileOrDirectory

public boolean deleteFileOrDirectory(java.lang.String target,
                                     boolean remountAsRw)
Deletes a file or directory

Parameters:
target - example: /data/data/org.adaway/files/hosts
remountAsRw - remounts the destination as read/write before writing to it
Returns:
true if it was successfully deleted

exists

public boolean exists(java.lang.String file)
Use this to check whether or not a file exists on the filesystem.

Parameters:
file - String that represent the file, including the full path to the file and its name.
Returns:
a boolean that will indicate whether or not the file exists.

fixUtil

public void fixUtil(java.lang.String util,
                    java.lang.String utilPath)
This will try and fix a given binary. (This is for Busybox applets or Toolbox applets) By "fix", I mean it will try and symlink the binary from either toolbox or Busybox and fix the permissions if the permissions are not correct.

Parameters:
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()

fixUtils

public boolean fixUtils(java.lang.String[] utils)
                 throws java.lang.Exception
This will check an array of binaries, determine if they exist and determine that it has either the permissions 755, 775, or 777. If an applet is not setup correctly it will try and fix it. (This is for Busybox applets or Toolbox applets)

Parameters:
utils - Name of the utility to check.
Returns:
boolean to indicate whether the operation completed. Note that this is not indicative of whether the problem was fixed, just that the method did not encounter any exceptions.
Throws:
java.lang.Exception - if the operation cannot be completed.

findBinary

public boolean findBinary(java.lang.String binaryName)
Parameters:
binaryName - String that represent the binary to find.
Returns:
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.

getBusyBoxApplets

public java.util.List<java.lang.String> getBusyBoxApplets(java.lang.String path)
                                                   throws java.lang.Exception
This will return an List of Strings. Each string represents an applet available from BusyBox.

Parameters:
path - Path to the busybox binary that you want the list of applets from.
Returns:
null If we cannot return the list of applets.
Throws:
java.lang.Exception

getBusyBoxVersion

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

getConvertedSpace

public long getConvertedSpace(java.lang.String spaceStr)
Returns:
long Size, converted to kilobytes (from xxx or xxxm or xxxk etc.)

getInode

public java.lang.String getInode(java.lang.String file)
This method will return the inode number of a file. This method is dependent on having a version of ls that supports the -i parameter.

Parameters:
file - path to the file that you wish to return the inode number
Returns:
String The inode number for this file or "" if the inode number could not be found.

isAccessGiven

public boolean isAccessGiven()
Returns:
true if your app has been given root access.
Throws:
java.util.concurrent.TimeoutException - if this operation times out. (cannot determine if access is given)

isNativeToolsReady

public boolean isNativeToolsReady(int nativeToolsId,
                                  android.content.Context context)

getFilePermissionsSymlinks

public Permissions getFilePermissionsSymlinks(java.lang.String file)
Parameters:
file - String that represent the file, including the full path to the file and its name.
Returns:
An instance of the class permissions from which you can get the permissions of the file or if the file could not be found or permissions couldn't be determined then permissions will be null.

getMounts

public java.util.ArrayList<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.

getMountedAs

public java.lang.String getMountedAs(java.lang.String path)
                              throws java.lang.Exception
This will tell you how the specified mount is mounted. rw, ro, etc...

Parameters:
path - mount you want to check
Returns:
String What the mount is mounted as.
Throws:
java.lang.Exception - if we cannot determine how the mount is mounted.

getPath

public 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

getSpace

public 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
Throws:
java.util.concurrent.TimeoutException

getSymlink

public java.lang.String getSymlink(java.lang.String file)
This will return a String that represent the symlink for a specified file.

Parameters:
file - file to get the Symlink for. (must have absolute path)
Returns:
String a String that represent the symlink for a specified file or an empty string if no symlink exists.

getSymlinks

public java.util.ArrayList<Symlink> getSymlinks(java.lang.String path)
                                         throws java.lang.Exception
This will return an ArrayList of the class Symlink. The class Symlink contains the following property's: path SymplinkPath

These will provide you with any Symlinks in the given path.

Parameters:
path - path to search for Symlinks.
Returns:
ArrayList an ArrayList of the class Symlink.
Throws:
java.lang.Exception - if we cannot return the Symlinks.

getWorkingToolbox

public 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. For instance, if Busybox is available it will return "busybox", if busybox is not available but toolbox is then it will return "toolbox"

Returns:
String that indicates the available toolbox to use for accessing applets.

hasEnoughSpaceOnSdCard

public 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

hasUtil

public boolean hasUtil(java.lang.String util,
                       java.lang.String box)
Checks whether the toolbox or busybox binary contains a specific util

Parameters:
util -
box - Should contain "toolbox" or "busybox"
Returns:
true if it contains this util

installBinary

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

isBinaryAvailable

public boolean isBinaryAvailable(android.content.Context context,
                                 java.lang.String binaryName)
This method checks whether a binary is installed.

Parameters:
context - the current activity's Context
binaryName - binary file name; appended to /data/data/app.package/files/
Returns:
a boolean which indicates whether or not the binary already exists.

isAppletAvailable

public boolean isAppletAvailable(java.lang.String applet,
                                 java.lang.String binaryPath)
This will let you know if an applet is available from BusyBox

Parameters:
applet - The applet to check for.
Returns:
true if applet is available, false otherwise.

isProcessRunning

public boolean isProcessRunning(java.lang.String processName)
This method can be used to to check if a process is running

Parameters:
processName - name of process to check
Returns:
true if process was found
Throws:
java.util.concurrent.TimeoutException - (Could not determine if the process is running)

killProcess

public boolean killProcess(java.lang.String processName)
This method can be used to kill a running process

Parameters:
processName - name of process to kill
Returns:
true if process was found and killed successfully

offerBusyBox

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

Parameters:
activity - pass in your Activity

offerBusyBox

public 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 void offerSuperUser(android.app.Activity activity)
This will launch the Android market looking for SuperUser

Parameters:
activity - pass in your Activity

offerSuperUser

public 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