Search in sources :

Example 11 with SimpleCommand

use of org.sufficientlysecure.rootcommands.command.SimpleCommand in project orWall by EthACKdotOrg.

the class Remounter method remount.

/**
     * This will take a path, which can contain the file name as well, and attempt to remount the
     * underlying partition.
     * <p/>
     * For example, passing in the following string:
     * "/system/bin/some/directory/that/really/would/never/exist" will result in /system ultimately
     * being remounted. However, keep in mind that the longer the path you supply, the more work
     * this has to do, and the slower it will run.
     * 
     * @param file
     *            file path
     * @param mountType
     *            mount type: pass in RO (Read only) or RW (Read Write)
     * @return a <code>boolean</code> which indicates whether or not the partition has been
     *         remounted as specified.
     */
protected boolean remount(String file, String mountType) {
    // if the path has a trailing slash get rid of it.
    if (file.endsWith("/") && !file.equals("/")) {
        file = file.substring(0, file.lastIndexOf("/"));
    }
    // Make sure that what we are trying to remount is in the mount list.
    boolean foundMount = false;
    while (!foundMount) {
        try {
            for (Mount mount : getMounts()) {
                Log.d(RootCommands.TAG, mount.getMountPoint().toString());
                if (file.equals(mount.getMountPoint().toString())) {
                    foundMount = true;
                    break;
                }
            }
        } catch (Exception e) {
            Log.e(RootCommands.TAG, "Exception", e);
            return false;
        }
        if (!foundMount) {
            try {
                file = (new File(file).getParent()).toString();
            } catch (Exception e) {
                Log.e(RootCommands.TAG, "Exception", e);
                return false;
            }
        }
    }
    Mount mountPoint = findMountPointRecursive(file);
    Log.d(RootCommands.TAG, "Remounting " + mountPoint.getMountPoint().getAbsolutePath() + " as " + mountType.toLowerCase(Locale.US));
    final boolean isMountMode = mountPoint.getFlags().contains(mountType.toLowerCase(Locale.US));
    if (!isMountMode) {
        // grab an instance of the internal class
        try {
            SimpleCommand command = new SimpleCommand("busybox mount -o remount," + mountType.toLowerCase(Locale.US) + " " + mountPoint.getDevice().getAbsolutePath() + " " + mountPoint.getMountPoint().getAbsolutePath(), "toolbox mount -o remount," + mountType.toLowerCase(Locale.US) + " " + mountPoint.getDevice().getAbsolutePath() + " " + mountPoint.getMountPoint().getAbsolutePath(), "mount -o remount," + mountType.toLowerCase(Locale.US) + " " + mountPoint.getDevice().getAbsolutePath() + " " + mountPoint.getMountPoint().getAbsolutePath(), "/system/bin/toolbox mount -o remount," + mountType.toLowerCase(Locale.US) + " " + mountPoint.getDevice().getAbsolutePath() + " " + mountPoint.getMountPoint().getAbsolutePath());
            // execute on shell
            shell.add(command).waitForFinish();
        } catch (Exception e) {
        }
        mountPoint = findMountPointRecursive(file);
    }
    if (mountPoint != null) {
        Log.d(RootCommands.TAG, mountPoint.getFlags() + " AND " + mountType.toLowerCase(Locale.US));
        if (mountPoint.getFlags().contains(mountType.toLowerCase(Locale.US))) {
            Log.d(RootCommands.TAG, mountPoint.getFlags().toString());
            return true;
        } else {
            Log.d(RootCommands.TAG, mountPoint.getFlags().toString());
        }
    } else {
        Log.d(RootCommands.TAG, "mountPoint is null");
    }
    return false;
}
Also used : SimpleCommand(org.sufficientlysecure.rootcommands.command.SimpleCommand) File(java.io.File) IOException(java.io.IOException)

Example 12 with SimpleCommand

use of org.sufficientlysecure.rootcommands.command.SimpleCommand in project orWall by EthACKdotOrg.

the class Toolbox method reboot.

/**
     * Shutdown or reboot device. Possible actions are REBOOT_HOTREBOOT, REBOOT_REBOOT,
     * REBOOT_SHUTDOWN, REBOOT_RECOVERY
     * 
     * @param action
     * @throws IOException
     * @throws TimeoutException
     * @throws BrokenBusyboxException
     */
public void reboot(int action) throws BrokenBusyboxException, TimeoutException, IOException {
    if (action == REBOOT_HOTREBOOT) {
        killAll("system_server");
    // or: killAll("zygote");
    } else {
        String command;
        switch(action) {
            case REBOOT_REBOOT:
                command = "reboot";
                break;
            case REBOOT_SHUTDOWN:
                command = "reboot -p";
                break;
            case REBOOT_RECOVERY:
                command = "reboot recovery";
                break;
            default:
                command = "reboot";
                break;
        }
        SimpleCommand rebootCommand = new SimpleCommand(command);
        shell.add(rebootCommand).waitForFinish();
        if (rebootCommand.getExitCode() == -1) {
            Log.e(RootCommands.TAG, "Reboot failed!");
        }
    }
}
Also used : SimpleCommand(org.sufficientlysecure.rootcommands.command.SimpleCommand)

Example 13 with SimpleCommand

use of org.sufficientlysecure.rootcommands.command.SimpleCommand in project Rashr by DsLNeXuS.

the class Remounter method remount.

/**
 * This will take a path, which can contain the file name as well, and attempt to remount the
 * underlying partition.
 * <p/>
 * For example, passing in the following string:
 * "/system/bin/some/directory/that/really/would/never/exist" will result in /system ultimately
 * being remounted. However, keep in mind that the longer the path you supply, the more work
 * this has to do, and the slower it will run.
 *
 * @param file      file path
 * @param mountType mount type: pass in RO (Read only) or RW (Read Write)
 * @return a <code>boolean</code> which indicates whether or not the partition has been
 * remounted as specified.
 */
protected boolean remount(String file, String mountType) {
    // if the path has a trailing slash get rid of it.
    if (file.endsWith("/") && !file.equals("/")) {
        file = file.substring(0, file.lastIndexOf("/"));
    }
    // Make sure that what we are trying to remount is in the mount list.
    boolean foundMount = false;
    while (!foundMount) {
        try {
            for (Mount mount : getMounts()) {
                Log.d(RootCommands.TAG, mount.getMountPoint().toString());
                if (file.equals(mount.getMountPoint().toString())) {
                    foundMount = true;
                    break;
                }
            }
        } catch (Exception e) {
            Log.e(RootCommands.TAG, "Exception", e);
            return false;
        }
        if (!foundMount) {
            try {
                file = (new File(file).getParent());
            } catch (Exception e) {
                Log.e(RootCommands.TAG, "Exception", e);
                return false;
            }
        }
    }
    Mount mountPoint = findMountPointRecursive(file);
    Log.d(RootCommands.TAG, "Remounting " + mountPoint.getMountPoint().getAbsolutePath() + " as " + mountType.toLowerCase(Locale.US));
    final boolean isMountMode = mountPoint.getFlags().contains(mountType.toLowerCase(Locale.US));
    if (!isMountMode) {
        // grab an instance of the internal class
        try {
            SimpleCommand command = new SimpleCommand("busybox mount -o remount," + mountType.toLowerCase(Locale.US) + " " + mountPoint.getDevice().getAbsolutePath() + " " + mountPoint.getMountPoint().getAbsolutePath(), "toolbox mount -o remount," + mountType.toLowerCase(Locale.US) + " " + mountPoint.getDevice().getAbsolutePath() + " " + mountPoint.getMountPoint().getAbsolutePath(), "mount -o remount," + mountType.toLowerCase(Locale.US) + " " + mountPoint.getDevice().getAbsolutePath() + " " + mountPoint.getMountPoint().getAbsolutePath(), "/system/bin/toolbox mount -o remount," + mountType.toLowerCase(Locale.US) + " " + mountPoint.getDevice().getAbsolutePath() + " " + mountPoint.getMountPoint().getAbsolutePath());
            // execute on shell
            shell.add(command).waitForFinish();
        } catch (Exception e) {
        }
        mountPoint = findMountPointRecursive(file);
    }
    Log.d(RootCommands.TAG, mountPoint.getFlags() + " AND " + mountType.toLowerCase(Locale.US));
    if (mountPoint.getFlags().contains(mountType.toLowerCase(Locale.US))) {
        Log.d(RootCommands.TAG, mountPoint.getFlags().toString());
        return true;
    } else {
        Log.d(RootCommands.TAG, mountPoint.getFlags().toString());
        return false;
    }
}
Also used : SimpleCommand(org.sufficientlysecure.rootcommands.command.SimpleCommand) File(java.io.File) IOException(java.io.IOException)

Example 14 with SimpleCommand

use of org.sufficientlysecure.rootcommands.command.SimpleCommand in project Rashr by DsLNeXuS.

the class Toolbox method killAll.

/**
 * This method can be used to kill a running process
 * <p/>
 * (commands: ps, kill)
 *
 * @param processName name of process to kill
 * @return <code>true</code> if process was found and killed successfully
 * @throws IOException
 * @throws TimeoutException
 * @throws BrokenBusyboxException
 */
public boolean killAll(String processName) throws FailedExecuteCommand {
    Log.d(RootCommands.TAG, "Killing process " + processName);
    PsCommand psCommand = new PsCommand(processName);
    shell.execCommand(psCommand);
    // kill processes
    if (!psCommand.getPids().isEmpty()) {
        // example: kill -9 1234 1222 5343
        SimpleCommand killCommand = new SimpleCommand("toolbox kill -9 " + psCommand.getPidsString());
        shell.execCommand(killCommand);
        return killCommand.getExitCode() == 0;
    } else {
        Log.d(RootCommands.TAG, "No pid found! Nothing was killed!");
        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