RootTools.jar API

如需转载请标明出处:http://blog.****.net/itas109


RootTools.jar是一个很好的Root应用开发辅助工具。以下是其相关API函数。

 http://roottools.googlecode.com/svn/trunk/Developmental/doc/index.html

https://github.com/Stericson/RootTools

Field Detail

debugMode

public static boolean debugMode


lastFoundBinaryPaths

public staticjava.util.List<java.lang.String> lastFoundBinaryPaths


utilPath

public static java.lang.String utilPath


handlerEnabled

public static boolean handlerEnabled

Settingthis to false will disable the handler that is used by default for the 3callback methods for Command. By disabling this all callbacks will be calledfrom a thread other than the main UI thread.


default_Command_Timeout

public static int default_Command_Timeout

Settingthis will change the default command timeout. The default is 20000ms

Constructor Detail

RootTools

public RootTools()

 

 

Method Detail

setRim

public static void setRim(RootToolsInternalMethods rim)


checkUtil

public static boolean checkUtil(java.lang.String util)

Thiswill check a given binary, determine if it exists and determine that it haseither the permissions 755, 775, or 777.

Parameters:

util -Name of the utility to check.

Returns:

booleanto indicate whether the binary is installed and has appropriate permissions.


closeAllShells

public static void closeAllShells()

                           throwsjava.io.IOException

Thiswill close all open shells.

Throws:

java.io.IOException


closeCustomShell

public static void closeCustomShell()

                             throwsjava.io.IOException

Thiswill close the custom shell that you opened.

Throws:

java.io.IOException


closeShell

public static void closeShell(boolean root)

                       throws java.io.IOException

Thiswill close either the root shell or the standard shell depending on what youspecify.

Parameters:

root - a boolean to specify whether to close the root shellor the standard shell.

Throws:

java.io.IOException


copyFile

public static boolean copyFile(java.lang.String source,

                              java.lang.String destination,

                              boolean remountAsRw,

                              boolean preserveFileAttributes)

Copysa file to a destination. Because cp is not available on all android devices, wehave 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 todestination, if only cat is available only permissions are preserved

Returns:

trueif it was successfully copied


deleteFileOrDirectory

public static boolean deleteFileOrDirectory(java.lang.String target,

                                           boolean remountAsRw)

Deletesa file or directory

Parameters:

target -example: /data/data/org.adaway/files/hosts

remountAsRw -remounts the destination as read/write before writing to it

Returns:

trueif it was successfully deleted


exists

public static boolean exists(java.lang.String file)

Usethis 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 itsname.

Returns:

aboolean that will indicate whether or not the file exists.


fixUtil

public static void fixUtil(java.lang.String util,

                           java.lang.String utilPath)

Thiswill try and fix a given binary. (This is for Busybox applets or Toolboxapplets) By "fix", I mean it will try and symlink the binary fromeither toolbox or Busybox and fix the permissions if the permissions are notcorrect.

Parameters:

util -Name of the utility to fix.

utilPath -path to the toolbox that provides ln, rm, and chmod. This can be a blankstring, a path to a binary that will provide these, or you can useRootTools.getWorkingToolbox()


fixUtils

public static boolean fixUtils(java.lang.String[] utils)

                        throwsjava.lang.Exception

Thiswill check an array of binaries, determine if they exist and determine that ithas either the permissions 755, 775, or 777. If an applet is not setup correctlyit will try and fix it. (This is for Busybox applets or Toolbox applets)

Parameters:

utils -Name of the utility to check.

Returns:

booleanto indicate whether the operation completed. Note that this is not indicativeof whether the problem was fixed, just that the method did not encounter anyexceptions.

Throws:

java.lang.Exception - if the operation cannot be completed.


findBinary

public static boolean findBinary(java.lang.String binaryName)

Parameters:

binaryName -String that represent the binary to find.

Returns:

true ifthe specified binary was found. Also, the path the binary was found at can beretrieved via the variable lastFoundBinaryPath, if the binary was found in morethan one location this will contain all of these locations.


getBusyBoxVersion

public static java.lang.String getBusyBoxVersion(java.lang.String path)

Parameters:

path -String that represents the path to the Busybox binary you want to retrieve theversion of.

Returns:

BusyBoxversion is found, "" if not found.


getBusyBoxVersion

public static java.lang.String getBusyBoxVersion()

Returns:

BusyBoxversion is found, "" if not found.


getBusyBoxApplets

public staticjava.util.List<java.lang.String> getBusyBoxApplets()

                                                         throws java.lang.Exception

Thiswill return an List of Strings. Each string represents an applet available fromBusyBox.

Returns:

null If wecannot return the list of applets.

Throws:

java.lang.Exception


getBusyBoxApplets

public staticjava.util.List<java.lang.String> getBusyBoxApplets(java.lang.String path)

                                                         throws java.lang.Exception

Thiswill return an List of Strings. Each string represents an applet available fromBusyBox.

Parameters:

path -Path to the busybox binary that you want the list of applets from.

Returns:

null If wecannot return the list of applets.

Throws:

java.lang.Exception


getCustomShell

public static Shell getCustomShell(java.lang.String shellPath,

                                  int timeout)

                            throwsjava.io.IOException,

                                  java.util.concurrent.TimeoutException,

                                   RootDeniedException

Thiswill open or return, if one is already open, a custom shell, you areresponsible for managing the shell, reading the output and for closing theshell when you are done using it.

Parameters:

shellPath - a String to Indicate the path to the shell that youwant to open.

timeout - an int to Indicate the length of time before givingup on opening a shell.

Throws:

java.util.concurrent.TimeoutException

RootDeniedException

java.io.IOException


getCustomShell

public static Shell getCustomShell(java.lang.String shellPath)

                            throwsjava.io.IOException,

                                  java.util.concurrent.TimeoutException,

                                   RootDeniedException

Thiswill open or return, if one is already open, a custom shell, you areresponsible for managing the shell, reading the output and for closing theshell when you are done using it.

Parameters:

shellPath - a String to Indicate the path to the shell that youwant to open.

Throws:

java.util.concurrent.TimeoutException

RootDeniedException

java.io.IOException


getFilePermissionsSymlinks

public static Permissions getFilePermissionsSymlinks(java.lang.String file)

Parameters:

file -String that represent the file, including the full path to the file and itsname.

Returns:

Aninstance of the class permissions from which you can get the permissions of thefile or if the file could not be found or permissions couldn‘t be determinedthen permissions will be null.


getInode

public static java.lang.String getInode(java.lang.String file)

Thismethod will return the inode number of a file. This method is dependent onhaving a version of ls that supports the -i parameter.

Parameters:

file -path to the file that you wish to return the inode number

Returns:

StringThe inode number for this file or "" if the inode number could not befound.


getMounts

public static java.util.ArrayList<Mount> getMounts()

                                           throws java.lang.Exception

Thiswill return an ArrayList of the class Mount. The class mount contains thefollowing property‘s: device mountPoint type flags

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

Returns:

ArrayList anArrayList of the class Mount.

Throws:

java.lang.Exception - if we cannot return the mount points.


getMountedAs

public static java.lang.String getMountedAs(java.lang.String path)

                                     throwsjava.lang.Exception

Thiswill tell you how the specified mount is mounted. rw, ro, etc...

Parameters:

path - Themount you want to check

Returns:

String Whatthe mount is mounted as.

Throws:

java.lang.Exception - if we cannot determine how the mount is mounted.


getPath

public staticjava.util.Set<java.lang.String> getPath()

                                              throws java.lang.Exception

Thiswill return the environment variable $PATH

Returns:

Set A Setof Strings representing the environment variable $PATH

Throws:

java.lang.Exception - if we cannot return the $PATH variable


getShell

public static Shell getShell(boolean root,

                             int timeout,

                             int retry)

                      throwsjava.io.IOException,

                            java.util.concurrent.TimeoutException,

                             RootDeniedException

Thiswill open or return, if one is already open, a shell, you are responsible formanaging the shell, reading the output and for closing the shell when you aredone using it.

Parameters:

retry - a int to indicate how many times the ROOT shellshould try to open with root priviliges...

root - a boolean to Indicate whether or not you want to opena root shell or a standard shell

timeout - an int to Indicate the length of time to waitbefore giving up on opening a shell.

Throws:

java.util.concurrent.TimeoutException

RootDeniedException

java.io.IOException


getShell

public static Shell getShell(boolean root,

                             int timeout)

                      throws java.io.IOException,

                            java.util.concurrent.TimeoutException,

                             RootDeniedException

Thiswill open or return, if one is already open, a shell, you are responsible formanaging the shell, reading the output and for closing the shell when you aredone using it.

Parameters:

root - a boolean to Indicate whether or not you want to opena root shell or a standard shell

timeout - an int to Indicate the length of time to waitbefore giving up on opening a shell.

Throws:

java.util.concurrent.TimeoutException

RootDeniedException

java.io.IOException


getShell

public static Shell getShell(boolean root)

                      throwsjava.io.IOException,

                            java.util.concurrent.TimeoutException,

                             RootDeniedException

Thiswill open or return, if one is already open, a shell, you are responsible formanaging the shell, reading the output and for closing the shell when you aredone using it.

Parameters:

root - a boolean to Indicate whether or not you want to opena root shell or a standard shell

Throws:

java.util.concurrent.TimeoutException

RootDeniedException

java.io.IOException


getSpace

public static long getSpace(java.lang.String path)

Getthe space for a desired partition.

Parameters:

path - Thepartition to find the space for.

Returns:

theamount if space found within the desired partition. If the space was not foundthen the value is -1

Throws:

java.util.concurrent.TimeoutException


getSymlink

public static java.lang.String getSymlink(java.lang.String file)

Thiswill return a String that represent the symlink for a specified file.

Parameters:

file -path to the file to get the Symlink for. (must have absolute path)

Returns:

String aString that represent the symlink for a specified file or an empty string if nosymlink exists.


getSymlinks

public static java.util.ArrayList<Symlink> getSymlinks(java.lang.String path)

                                               throws java.lang.Exception

Thiswill return an ArrayList of the class Symlink. The class Symlink contains thefollowing property‘s: path SymplinkPath

These will provide you with any Symlinks inthe given path.

Parameters:

path -path to search for Symlinks.

Returns:

ArrayList anArrayList of the class Symlink.

Throws:

java.lang.Exception - if we cannot return the Symlinks.


getWorkingToolbox

public static java.lang.String getWorkingToolbox()

Thiswill return to you a string to be used in your shell commands which willrepresent the valid working toolbox with correct permissions. For instance, ifBusybox is available it will return "busybox", if busybox is notavailable but toolbox is then it will return "toolbox"

Returns:

Stringthat indicates the available toolbox to use for accessing applets.


hasEnoughSpaceOnSdCard

public static boolean hasEnoughSpaceOnSdCard(long updateSize)

Checksif there is enough Space on SDCard

Parameters:

updateSize -size to Check (long)

Returns:

true ifthe Update will fit on SDCard, false ifnot enough space on SDCard. Will also return false, if the SDCard is not mounted as read/write


hasUtil

public static boolean hasUtil(java.lang.String util,

                             java.lang.String box)

Checkswhether the toolbox or busybox binary contains a specific util

Parameters:

util -

box -Should contain "toolbox" or "busybox"

Returns:

trueif it contains this util


installBinary

public static boolean installBinary(android.content.Context context,

                                   int sourceId,

                                   java.lang.String destName,

                                   java.lang.String mode)

Thismethod can be used to unpack a binary from the raw resources folder and storeit in /data/data/app.package/files/ This is typically useful if you provideyour own C- or C++-based binary. This binary can then be executed usingsendShell() and its full path.

Parameters:

context - thecurrent 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 ableto create the new file.


installBinary

public static boolean installBinary(android.content.Context context,

                                   int sourceId,

                                   java.lang.String binaryName)

Thismethod can be used to unpack a binary from the raw resources folder and storeit in /data/data/app.package/files/ This is typically useful if you provideyour own C- or C++-based binary. This binary can then be executed usingsendShell() and its full path.

Parameters:

context - thecurrent activity‘s Context

sourceId -resource id; typically R.raw.id

binaryName -destination file name; appended to /data/data/app.package/files/

Returns:

a boolean which indicates whether or not we were ableto create the new file.


hasBinary

public static boolean hasBinary(android.content.Context context,

                               java.lang.String binaryName)

Thismethod checks whether a binary is installed.

Parameters:

context - thecurrent activity‘s Context

binaryName - binaryfile name; appended to /data/data/app.package/files/

Returns:

a boolean which indicates whether or not the binaryalready exists.


isAppletAvailable

public static boolean isAppletAvailable(java.lang.String applet,

                                       java.lang.String path)

Thiswill let you know if an applet is available from BusyBox

Parameters:

applet - Theapplet to check for.

path -Path to the busybox binary that you want to check. (do not include binary name)

Returns:

true ifapplet is available, false otherwise.


isAppletAvailable

public static boolean isAppletAvailable(java.lang.String applet)

Thiswill let you know if an applet is available from BusyBox

Parameters:

applet - Theapplet to check for.

Returns:

true ifapplet is available, false otherwise.


isAccessGiven

public static boolean isAccessGiven()

Returns:

true ifyour app has been given root access.

Throws:

java.util.concurrent.TimeoutException - if this operation times out. (cannotdetermine if access is given)


isBusyboxAvailable

public static boolean isBusyboxAvailable()

Returns:

true ifBusyBox was found.


isNativeToolsReady

public static boolean isNativeToolsReady(int nativeToolsId,

                                        android.content.Context context)


isProcessRunning

public static boolean isProcessRunning(java.lang.String processName)

Thismethod can be used to to check if a process is running

Parameters:

processName -name of process to check

Returns:

true ifprocess was found

Throws:

java.util.concurrent.TimeoutException - (Could not determine if the process isrunning)


isRootAvailable

public static boolean isRootAvailable()

Returns:

true if suwas found.


killProcess

public static boolean killProcess(java.lang.String processName)

Thismethod can be used to kill a running process

Parameters:

processName -name of process to kill

Returns:

true ifprocess was found and killed successfully


offerBusyBox

public static void offerBusyBox(android.app.Activity activity)

Thiswill 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)

Thiswill launch the Android market looking for BusyBox, but will return the intentfired and starts the activity with startActivityForResult

Parameters:

activity -pass in your Activity

requestCode -pass in the request code

Returns:

intentfired


offerSuperUser

public static void offerSuperUser(android.app.Activity activity)

Thiswill launch the Android market looking for SuperUser

Parameters:

activity - passin your Activity


offerSuperUser

public static android.content.Intent offerSuperUser(android.app.Activity activity,

                                                   int requestCode)

Thiswill launch the Android market looking for SuperUser, but will return theintent fired and starts the activity with startActivityForResult

Parameters:

activity -pass in your Activity

requestCode -pass in the request code

Returns:

intentfired


remount

public static boolean remount(java.lang.String file,

                             java.lang.String mountType)

Thiswill take a path, which can contain the file name as well, and attempt toremount the underlying partition.

For example, passing in the following string:"/system/bin/some/directory/that/really/would/never/exist" willresult in /system ultimately being remounted. However, keep in mind that thelonger the path you supply, the more work this has to do, and the slower itwill 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 partitionhas been remounted as specified.


restartAndroid

public static void restartAndroid()

Thisrestarts only Android OS without rebooting the whole device. This does NOT workon all devices. This is done by killing the main init process named zygote.Zygote is restarted automatically by Android after killing it.

Throws:

java.util.concurrent.TimeoutException


runBinary

public static void runBinary(android.content.Context context,

                            java.lang.String binaryName,

                            java.lang.String parameter)

Executesbinary in a separated process. Before using this method, the binary has to beinstalled in /data/data/app.package/files/ using the installBinary method.

Parameters:

context - thecurrent activity‘s Context

binaryName -name of installed binary

parameter -parameter to append to binary like "-vxf"


runShellCommand

public static void runShellCommand(Shell shell,

                                   Command command)

                            throwsjava.io.IOException

Executesa given command with root access or without depending on the value of theboolean passed. This will also start a root shell or a standard shell withoutyou having to open it specifically.

You will still need to close the shell afteryou are done using the shell.

Parameters:

shell - Theshell to execute the command on, this can be a root shell or a standard shell.

command - Thecommand to execute in the shell

Throws:

java.io.IOException


log

public static void log(java.lang.String msg)

Thismethod allows you to output debug messages only when debugging is on. This willallow you to add a debug option to your app, which by default can be left offfor performance. However, when you need debugging information, a simple switchcan enable it and provide you with detailed logging.

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

Parameters:

msg - Themessage to output.


log

public static void log(java.lang.String TAG,

                      java.lang.String msg)

Thismethod allows you to output debug messages only when debugging is on. This willallow you to add a debug option to your app, which by default can be left offfor performance. However, when you need debugging information, a simple switchcan enable it and provide you with detailed logging.

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

Parameters:

TAG -Optional parameter to define the tag that the Log will use.

msg - Themessage to output.


log

public static void log(java.lang.String msg,

                       int type,

                      java.lang.Exception e)

Thismethod allows you to output debug messages only when debugging is on. This willallow you to add a debug option to your app, which by default can be left offfor performance. However, when you need debugging information, a simple switchcan enable it and provide you with detailed logging.

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

Parameters:

msg - Themessage to output.

type - Thetype of log, 1 for verbose, 2 for error, 3 for debug

e - Theexception that was thrown (Needed for errors)


islog

public static boolean islog()

Thismethod allows you to check whether logging is enabled. Yes, it has a goofyname, but that‘s to keep it as short as possible. After all writing loggingcalls should be painless. This method exists to save Android going through thevarious Java layers that are traversed any time a string is created (i.e. whatyou are logging) Example usage: if(islog) { StrinbBuilder sb = newStringBuilder(); // ... // build string // ... log(sb.toString()); }

Returns:

trueif logging is enabled


log

public static void log(java.lang.String TAG,

                      java.lang.String msg,

                       int type,

                      java.lang.Exception e)

Thismethod allows you to output debug messages only when debugging is on. This willallow you to add a debug option to your app, which by default can be left offfor performance. However, when you need debugging information, a simple switchcan enable it and provide you with detailed logging.

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

Parameters:

TAG -Optional parameter to define the tag that the Log will use.

msg - Themessage to output.

type - Thetype of log, 1 for verbose, 2 for error, 3 for debug

e - Theexception that was thrown (Needed for errors)


如需转载请标明出处:http://blog.****.net/itas109



 

RootTools.jar API

上一篇:与众不同 windows phone (10) - Push Notification(推送通知)之推送 Tile 通知, 推送自定义信息


下一篇:WINDOWS 下 修改APACHE 并发数