Search in sources :

Example 1 with SimpleCommand

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);
    }
}
Also used : FailedExecuteCommand(org.sufficientlysecure.rootcommands.util.FailedExecuteCommand) SimpleCommand(org.sufficientlysecure.rootcommands.command.SimpleCommand) IOException(java.io.IOException) RootAccessDeniedException(org.sufficientlysecure.rootcommands.util.RootAccessDeniedException)

Example 2 with SimpleCommand

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);
    }
}
Also used : SimpleCommand(org.sufficientlysecure.rootcommands.command.SimpleCommand)

Example 3 with SimpleCommand

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) {
                }
            }
        }
    }
}
Also used : Shell(org.sufficientlysecure.rootcommands.Shell) SimpleCommand(org.sufficientlysecure.rootcommands.command.SimpleCommand) IOException(java.io.IOException) File(java.io.File) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with SimpleCommand

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;
    }
}
Also used : SimpleCommand(org.sufficientlysecure.rootcommands.command.SimpleCommand)

Example 5 with SimpleCommand

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;
    }
}
Also used : SimpleCommand(org.sufficientlysecure.rootcommands.command.SimpleCommand)

Aggregations

SimpleCommand (org.sufficientlysecure.rootcommands.command.SimpleCommand)14 IOException (java.io.IOException)6 File (java.io.File)3 TimeoutException (java.util.concurrent.TimeoutException)3 Shell (org.sufficientlysecure.rootcommands.Shell)3 FileNotFoundException (java.io.FileNotFoundException)1 FailedExecuteCommand (org.sufficientlysecure.rootcommands.util.FailedExecuteCommand)1 RootAccessDeniedException (org.sufficientlysecure.rootcommands.util.RootAccessDeniedException)1