use of org.sufficientlysecure.rootcommands.Shell 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.Shell in project orWall by EthACKdotOrg.
the class Iptables method doInstallScripts.
/**
* Really install init-script (copies it from app RAW directory)
* @param src_file String matching source init-script
* @param dst_file String matching destination init-script
*/
private static void doInstallScripts(String src_file, String dst_file) {
Shell shell;
try {
shell = Shell.startRootShell();
} catch (IOException e) {
Log.e("Shell", "Unable to get shell");
return;
}
if (shell != null) {
String CMD = String.format("cp %s %s", src_file, dst_file);
SimpleCommand command1 = new SimpleCommand("mount -o remount,rw /system");
SimpleCommand command2 = new SimpleCommand(CMD);
CMD = String.format("chmod 0755 %s", dst_file);
SimpleCommand command3 = new SimpleCommand(CMD);
SimpleCommand command4 = new SimpleCommand("mount -o remount,ro /system");
try {
shell.add(command1).waitForFinish();
shell.add(command2).waitForFinish();
shell.add(command3).waitForFinish();
shell.add(command4).waitForFinish();
} catch (IOException e) {
Log.e("Shell", "Unable to run simple command");
} catch (TimeoutException e) {
Log.e("Shell", "Error while closing the Shell");
} finally {
try {
shell.close();
} catch (IOException e) {
}
}
}
}
use of org.sufficientlysecure.rootcommands.Shell in project orWall by EthACKdotOrg.
the class Iptables method removeIniScript.
/**
* Removes init-script.
*/
public static void removeIniScript(Context context) {
Shell shell;
try {
shell = Shell.startRootShell();
} catch (IOException e) {
Log.e("Shell", "Unable to get shell");
return;
}
if (shell != null) {
SimpleCommand command1 = new SimpleCommand("mount -o remount,rw /system");
SimpleCommand command2 = new SimpleCommand("rm -f " + DST_FILE);
SimpleCommand command3 = new SimpleCommand("mount -o remount,ro /system");
try {
shell.add(command1).waitForFinish();
shell.add(command2).waitForFinish();
shell.add(command3).waitForFinish();
} catch (IOException e) {
Log.e("Shell", "Unable to run simple command");
} catch (TimeoutException e) {
Log.e("Shell", "Error while closing the Shell");
} finally {
Preferences.setEnforceInitScript(context, false);
try {
shell.close();
} catch (IOException e) {
}
}
}
}
Aggregations