use of org.sufficientlysecure.rootcommands.command.SimpleCommand in project Rashr by DsLNeXuS.
the class Shell method execCommand.
public String execCommand(String Command, boolean waitForFinish, boolean logCommand) throws FailedExecuteCommand {
final SimpleCommand command = new SimpleCommand(Command);
try {
Log.i(TAG, Command);
if (waitForFinish) {
this.add(command).waitForFinish();
} else {
this.add(command);
}
String output = command.getOutput();
if (logCommand)
logCommand(command);
Log.i(TAG, output);
if (command.getExitCode() != 0) {
throw new Exception("Exit-Code not 0");
}
return output;
} catch (Exception e) {
if (logCommand)
logCommand(command);
Log.i(TAG, "Failed: " + command.getOutput());
throw new FailedExecuteCommand(command);
}
}
use of org.sufficientlysecure.rootcommands.command.SimpleCommand in project Rashr by DsLNeXuS.
the class Toolbox method toggleAdbDaemon.
/**
* TODO: Not tested!
*
* @param toggle
* @throws IOException
* @throws TimeoutException
* @throws BrokenBusyboxException
*/
public void toggleAdbDaemon(boolean toggle) throws FailedExecuteCommand {
SimpleCommand disableAdb = new SimpleCommand("setprop persist.service.adb.enable 0", "stop adbd");
SimpleCommand enableAdb = new SimpleCommand("setprop persist.service.adb.enable 1", "stop adbd", "sleep 1", "start adbd");
if (toggle) {
shell.execCommand(enableAdb);
} else {
shell.execCommand(disableAdb);
}
}
use of org.sufficientlysecure.rootcommands.command.SimpleCommand in project orWall by EthACKdotOrg.
the class Util method enableCaptiveDetection.
/**
* Apply or remove rules for captive portal detection.
* Captive portal detection works with DNS and redirection detection.
* Once the device is connected, Android will probe the network in order to get a page, located on Google servers.
* If it can connect to it, this means we're not in a captive network; otherwise, it will prompt for network login.
* @param status boolean, true if we want to enable this probe.
* @param context application context
*/
public static void enableCaptiveDetection(boolean status, Context context) {
// This seems to be done with a System app only. orWall may become a system app.
if (Build.VERSION.SDK_INT > 18) {
String CMD;
if (status) {
CMD = new File(context.getDir("bin", 0), "activate_portal.sh").getAbsolutePath();
} else {
CMD = new File(context.getDir("bin", 0), "deactivate_portal.sh").getAbsolutePath();
}
Shell shell = null;
try {
shell = Shell.startRootShell();
} catch (IOException e) {
Log.e("Shell", "Unable to get shell");
}
if (shell != null) {
SimpleCommand command = new SimpleCommand(CMD);
try {
shell.add(command).waitForFinish();
} catch (IOException e) {
Log.e("Shell", "IO Error");
} catch (TimeoutException e) {
Log.e("Shell", "Timeout");
} finally {
try {
shell.close();
} catch (IOException e) {
}
}
}
}
}
use of org.sufficientlysecure.rootcommands.command.SimpleCommand in project orWall by EthACKdotOrg.
the class Toolbox method setFilePermissions.
/**
* Sets permission of file
*
* @param file
* absolute path to file
* @param permissions
* String like 777
* @return true if command worked
* @throws BrokenBusyboxException
* @throws TimeoutException
* @throws IOException
*/
public boolean setFilePermissions(String file, String permissions) throws BrokenBusyboxException, TimeoutException, IOException {
Log.d(RootCommands.TAG, "Set permissions of " + file + " to " + permissions);
SimpleCommand chmodCommand = new SimpleCommand("chmod " + permissions + " " + file);
shell.add(chmodCommand).waitForFinish();
if (chmodCommand.getExitCode() == 0) {
return true;
} else {
return false;
}
}
use of org.sufficientlysecure.rootcommands.command.SimpleCommand in project orWall by EthACKdotOrg.
the class Toolbox method isRootAccessGiven.
/**
* Checks if user accepted root access
*
* (commands: id)
*
* @return true if user has given root access
* @throws IOException
* @throws TimeoutException
* @throws BrokenBusyboxException
*/
public boolean isRootAccessGiven() throws BrokenBusyboxException, TimeoutException, IOException {
SimpleCommand idCommand = new SimpleCommand("id");
shell.add(idCommand).waitForFinish();
if (idCommand.getOutput().contains("uid=0")) {
return true;
} else {
return false;
}
}
Aggregations