本文整理汇总了Java中com.stericson.RootTools.execution.CommandCapture类的典型用法代码示例。如果您正苦于以下问题:Java CommandCapture类的具体用法?Java CommandCapture怎么用?Java CommandCapture使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CommandCapture类属于com.stericson.RootTools.execution包,在下文中一共展示了CommandCapture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cleanDirectory
import com.stericson.RootTools.execution.CommandCapture; //导入依赖的package包/类
public void cleanDirectory() {
for (final File file : mEmulatedDirectory.listFiles()) {
Command mountCommand = new CommandCapture(0, "umount " + mMountDirectory.getAbsolutePath() + "/" + file.getName()) {
@Override
public void commandCompleted(int id, int exitcode) {
super.commandCompleted(id, exitcode);
file.delete();
}
};
try {
mRootShell.add(mountCommand);
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例2: getInode
import com.stericson.RootTools.execution.CommandCapture; //导入依赖的package包/类
/**
* 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.
*
* @param file path to the file that you wish to return the inode number
* @return String The inode number for this file or "" if the inode number could not be found.
*/
public String getInode(String file) {
try {
CommandCapture command = new CommandCapture(Constants.GI, false, "/data/local/ls -i " + file) {
@Override
public void output(int id, String line) {
if (id == Constants.GI) {
if (!line.trim().equals("") && Character.isDigit((char) line.trim().substring(0, 1).toCharArray()[0])) {
InternalVariables.inode = line.trim().split(" ")[0];
}
}
}
};
Shell.startRootShell().add(command);
commandWait(Shell.startRootShell(), command);
return InternalVariables.inode;
} catch (Exception ignore) {
return "";
}
}
示例3: isProcessRunning
import com.stericson.RootTools.execution.CommandCapture; //导入依赖的package包/类
/**
* This method can be used to to check if a process is running
*
* @param processName name of process to check
* @return <code>true</code> if process was found
* @throws TimeoutException (Could not determine if the process is running)
*/
public boolean isProcessRunning(final String processName) {
RootTools.log("Checks if process is running: " + processName);
InternalVariables.processRunning = false;
try {
CommandCapture command = new CommandCapture(0, false, "ps") {
@Override
public void output(int id, String line) {
if (line.contains(processName)) {
InternalVariables.processRunning = true;
}
}
};
RootTools.getShell(true).add(command);
commandWait(RootTools.getShell(true), command);
} catch (Exception e) {
RootTools.log(e.getMessage());
}
return InternalVariables.processRunning;
}
示例4: getInode
import com.stericson.RootTools.execution.CommandCapture; //导入依赖的package包/类
/**
* 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.
*
* @param file path to the file that you wish to return the inode number
* @return String The inode number for this file or "" if the inode number could not be found.
*/
public String getInode(String file) {
try {
CommandCapture command = new CommandCapture(Constants.GI, false, "/data/local/ls -i " + file) {
@Override
public void output(int id, String line) {
if (id == Constants.GI) {
if (!line.trim().equals("") && Character.isDigit((char) line.trim().substring(0, 1).toCharArray()[0])) {
InternalVariables.inode = line.trim().split(" ")[0];
}
}
}
};
Shell.startRootShell().add(command);
commandWait(command);
return InternalVariables.inode;
} catch (Exception ignore) {
return "";
}
}
示例5: isProcessRunning
import com.stericson.RootTools.execution.CommandCapture; //导入依赖的package包/类
/**
* This method can be used to to check if a process is running
*
* @param processName name of process to check
* @return <code>true</code> if process was found
* @throws TimeoutException (Could not determine if the process is running)
*/
public boolean isProcessRunning(final String processName) {
RootTools.log("Checks if process is running: " + processName);
InternalVariables.processRunning = false;
try {
CommandCapture command = new CommandCapture(0, false, "ps") {
@Override
public void output(int id, String line) {
if (line.contains(processName)) {
InternalVariables.processRunning = true;
}
}
};
RootTools.getShell(true).add(command);
commandWait(command);
} catch (Exception e) {
RootTools.log(e.getMessage());
}
return InternalVariables.processRunning;
}
示例6: initUsbMuxd
import com.stericson.RootTools.execution.CommandCapture; //导入依赖的package包/类
public void initUsbMuxd(final Context context){
if(!RootTools.isProcessRunning(usbmuxdd)){
IDeviceHelper.getInstance().installBinary(context);
CommandCapture command = new CommandCapture(0,
exportLib(context),
getBinPath(context, usbmuxdd + " -v")){
@Override
protected void output(int id, String line) {
super.output(id, line);
LogUtils.e(line);
}
};
runCommand(command);
}else{
LogUtils.e("usbmuxd is running...");
}
}
示例7: getDeviceId
import com.stericson.RootTools.execution.CommandCapture; //导入依赖的package包/类
public StringBuffer getDeviceId(final Context context){
final StringBuffer sb = new StringBuffer();
CommandCapture command = new CommandCapture(0,
exportLib(context),
getBinPath(context, ideviceid + " -l")){
@Override
protected void output(int id, String line) {
super.output(id, line);
sb.append(line);
sb.append("\n");
}
};
runCommand(command);
LogUtils.e(sb.toString());
return sb;
}
示例8: hackBrightnessFile
import com.stericson.RootTools.execution.CommandCapture; //导入依赖的package包/类
private static CommandCapture hackBrightnessFile(String path, File target) {
// AlertDialog.Builder dlgBuilder = new AlertDialog.Builder(
// getActivity());
// dlgBuilder.setMessage("putting "+path+" to "+
// target.getAbsolutePath());
// dlgBuilder.setTitle("Debug");
// dlgBuilder.show();
return new CommandCapture(0, "chmod 666 " + path,
"rm -f " + target.getAbsolutePath(),
"ln -s " + path + " " + target.getAbsolutePath());
}
示例9: unmount
import com.stericson.RootTools.execution.CommandCapture; //导入依赖的package包/类
public void unmount(Shell shell, final UnmountListener listener) throws IOException {
Command mountCommand = new CommandCapture(0, "umount " + getTarget()) {
@Override
public void commandCompleted(int id, int exitcode) {
super.commandCompleted(id, exitcode);
if (exitcode == 0) {
getDevice().removeMount(Mount.this);
listener.onUnmountSuccess(Mount.this);
} else {
listener.onUnmountError(Mount.this, null);
}
}
};
shell.add(mountCommand);
}
示例10: getBusyBoxApplets
import com.stericson.RootTools.execution.CommandCapture; //导入依赖的package包/类
/**
* This will return an List of Strings. Each string represents an applet available from BusyBox.
* <p/>
*
* @param path Path to the busybox binary that you want the list of applets from.
* @return <code>null</code> If we cannot return the list of applets.
*/
public List<String> getBusyBoxApplets(String path) throws Exception {
if (path != null && !path.endsWith("/") && !path.equals("")) {
path += "/";
} else if (path == null) {
//Don't know what the user wants to do...what am I pshycic?
throw new Exception("Path is null, please specifiy a path");
}
final List<String> results = new ArrayList<String>();
CommandCapture command = new CommandCapture(Constants.BBA, false, path + "busybox --list") {
@Override
public void output(int id, String line) {
if (id == Constants.BBA) {
if (!line.trim().equals("") && !line.trim().contains("not found")) {
results.add(line);
}
}
}
};
//try without root first...
Shell.startShell().add(command);
commandWait(Shell.startShell(), command);
if(results.size() <= 0) {
//try with root...
Shell.startRootShell().add(command);
commandWait(Shell.startRootShell(), command);
}
return results;
}
示例11: isAccessGiven
import com.stericson.RootTools.execution.CommandCapture; //导入依赖的package包/类
/**
* @return <code>true</code> if your app has been given root access.
* @throws TimeoutException if this operation times out. (cannot determine if access is given)
*/
public boolean isAccessGiven() {
try {
RootTools.log("Checking for Root access");
InternalVariables.accessGiven = false;
CommandCapture command = new CommandCapture(Constants.IAG, false, "id") {
@Override
public void output(int id, String line) {
if (id == Constants.IAG) {
Set<String> ID = new HashSet<String>(Arrays.asList(line.split(" ")));
for (String userid : ID) {
RootTools.log(userid);
if (userid.toLowerCase().contains("uid=0")) {
InternalVariables.accessGiven = true;
RootTools.log("Access Given");
break;
}
}
if (!InternalVariables.accessGiven) {
RootTools.log("Access Denied?");
}
}
}
};
Shell.startRootShell().add(command);
commandWait(Shell.startRootShell(), command);
return InternalVariables.accessGiven;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例12: changePermission
import com.stericson.RootTools.execution.CommandCapture; //导入依赖的package包/类
/**
* Mtodo para dar permisso pasta, necessita do comando su
* @param path pasta para qual ser dada permisso (Ex.: /dev)
* @param permission permisso que ser dada pasta (Ex.: 777)
*/
public void changePermission(String path, int permission) {
String command = "chmod -R " + permission + " " + path;
try {
CommandCapture commandCapture = new CommandCapture(0, command);
RootTools.getShell(true).add(commandCapture).waitForFinish();
} catch (Exception exception) {
exception.printStackTrace();
}
}
示例13: setSettingForce
import com.stericson.RootTools.execution.CommandCapture; //导入依赖的package包/类
public void setSettingForce(String path, String value) throws Exception {
Shell shell = RootTools.getShell(true);
CommandCapture command = new CommandCapture(0, "chmod 777 " + path);
shell.add(command);
commandWait(command);
try {
CommandCapture command2 = new CommandCapture(0, "echo " + value + " > " + path);
shell.add(command2);
commandWait(command2);
} catch (Exception e) {
}
}
示例14: setFilePermissions
import com.stericson.RootTools.execution.CommandCapture; //导入依赖的package包/类
protected int setFilePermissions(Shell shell, String permissions, String file) throws Exception{
if (shell == null) shell = RootTools.getShell(true);
CommandCapture command = new CommandCapture(0, "chmod " + permissions + " " + file);
shell.add(command);
commandWait(command);
return command.getExitCode();
}
示例15: run
import com.stericson.RootTools.execution.CommandCapture; //导入依赖的package包/类
public synchronized List<String> run(String command)
{
final List<String> res = new ArrayList<String>();
if (m_shell == null)
{
// reopen if for whatever reason the shell got closed
NonRootShell.getInstance();
}
CommandCapture shellCommand = new CommandCapture(0, command)
{
@Override
public void output(int id, String line)
{
res.add(line);
}
};
try
{
m_shell.add(shellCommand);
// we need to make this synchronous
while (!shellCommand.isFinished())
{
Thread.sleep(100);
}
}
catch (Exception e)
{
}
return res;
}