com.stericson.RootShell.exceptions.RootDeniedException Java Examples

The following examples show how to use com.stericson.RootShell.exceptions.RootDeniedException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Shell.java    From PhoneProfilesPlus with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"WeakerAccess", "UnusedReturnValue"})
public Shell switchRootShellContext(ShellContext shellContext) throws IOException, TimeoutException, RootDeniedException {
    if (this.shellType == ShellType.ROOT) {
        try {
            Shell.closeRootShell();
        } catch (Exception e) {
            RootShell.log("Problem closing shell while trying to switch context...");
        }

        //create new root shell with new context...

        return Shell.startRootShell(this.shellTimeout, shellContext, 3);
    } else {
        //can only switch context on a root shell...
        RootShell.log("Can only switch context on a root shell!");
        return this;
    }
}
 
Example #2
Source File: Shell.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
public static Shell startShell(int timeout) throws IOException, TimeoutException {

        try {
            if (Shell.shell == null) {
                RootShell.log("Starting Shell!");
                Shell.shell = new Shell("/system/bin/sh", ShellType.NORMAL, ShellContext.NORMAL, timeout);
            } else {
                RootShell.log("Using Existing Shell!");
            }
            return Shell.shell;
        } catch (RootDeniedException e) {
            //Root Denied should never be thrown.
            throw new IOException();
        }
    }
 
Example #3
Source File: Shell.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("WeakerAccess")
public static Shell startCustomShell(String shellPath, int timeout) throws IOException, TimeoutException, RootDeniedException {

    if (Shell.customShell == null) {
        RootShell.log("Starting Custom Shell!");
        Shell.customShell = new Shell(shellPath, ShellType.CUSTOM, ShellContext.NORMAL, timeout);
    } else {
        RootShell.log("Using Existing Custom Shell!");
    }

    return Shell.customShell;
}
 
Example #4
Source File: Shell.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"RedundantThrows", "unused"})
public final void useCWD(Context context) throws IOException, TimeoutException, RootDeniedException {
    add(
            new Command(
                    -1,
                    false,
                    "cd " + context.getApplicationInfo().dataDir)
    );
}
 
Example #5
Source File: Shell.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unused")
public static Shell startCustomShell(String shellPath) throws IOException, TimeoutException, RootDeniedException {
    return Shell.startCustomShell(shellPath, 0);
}
 
Example #6
Source File: Shell.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
public static Shell startRootShell(int timeout, int retry) throws IOException, TimeoutException, RootDeniedException {
    return Shell.startRootShell(timeout, Shell.defaultContext, retry);
}
 
Example #7
Source File: Shell.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unused")
public static Shell startRootShell(int timeout) throws IOException, TimeoutException, RootDeniedException {
    return Shell.startRootShell(timeout, 3);
}
 
Example #8
Source File: Shell.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
public static Shell startRootShell() throws IOException, TimeoutException, RootDeniedException {
    return Shell.startRootShell(0, 3);
}
 
Example #9
Source File: Shell.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unused")
public static Command runRootCommand(Command command) throws IOException, TimeoutException, RootDeniedException {
    return Shell.startRootShell().add(command);
}
 
Example #10
Source File: RootShell.java    From PhoneProfilesPlus with Apache License 2.0 3 votes vote down vote up
/**
 * This will open or return, if one is already open, a shell, you are responsible for managing the shell, reading the output
 * and for closing the shell when you are done using it.
 *
 * @param root         a <code>boolean</code> to Indicate whether or not you want to open a root shell or a standard shell
 * @param timeout      an <code>int</code> to Indicate the length of time to wait before giving up on opening a shell.
 * @param shellContext the context to execute the shell with
 * @param retry        a <code>int</code> to indicate how many times the ROOT shell should try to open with root priviliges...
 */
public static Shell getShell(boolean root, int timeout, Shell.ShellContext shellContext, int retry) throws IOException, TimeoutException, RootDeniedException {
    if (root) {
        return Shell.startRootShell(timeout, shellContext, retry);
    } else {
        return Shell.startShell(timeout);
    }
}
 
Example #11
Source File: RootShell.java    From PhoneProfilesPlus with Apache License 2.0 2 votes vote down vote up
/**
 * This will open or return, if one is already open, a shell, you are responsible for managing the shell, reading the output
 * and for closing the shell when you are done using it.
 *
 * @param root    a <code>boolean</code> to Indicate whether or not you want to open a root shell or a standard shell
 * @param timeout an <code>int</code> to Indicate the length of time to wait before giving up on opening a shell.
 */
@SuppressWarnings("WeakerAccess")
public static Shell getShell(boolean root, int timeout) throws IOException, TimeoutException, RootDeniedException {
    return getShell(root, timeout, Shell.defaultContext, 3);
}
 
Example #12
Source File: HostsManager.java    From hosts-editor-android with Apache License 2.0 2 votes vote down vote up
/**
 * Executes a single argument root command.
 * <p><b>Must be in an async call.</b></p>
 *
 * @param command   a command, ie {@code "rm -f"}, {@code "chmod 644"}...
 * @param uniqueArg the unique argument for the command, usually the file name
 */
private void runRootCommand(String command, String uniqueArg) throws IOException, TimeoutException, RootDeniedException {
    Command cmd = new Command(0, false, String.format(Locale.US, "%s %s", command, uniqueArg));
    RootShell.getShell(true).add(cmd);
}
 
Example #13
Source File: RootShell.java    From PhoneProfilesPlus with Apache License 2.0 2 votes vote down vote up
/**
 * This will open or return, if one is already open, a shell, you are responsible for managing the shell, reading the output
 * and for closing the shell when you are done using it.
 *
 * @param root a <code>boolean</code> to Indicate whether or not you want to open a root shell or a standard shell
 */
public static Shell getShell(boolean root) throws IOException, TimeoutException, RootDeniedException {
    return RootShell.getShell(root, 0);
}
 
Example #14
Source File: RootTools.java    From PhoneProfilesPlus with Apache License 2.0 2 votes vote down vote up
/**
 * This will open or return, if one is already open, a custom shell, you are responsible for managing the shell, reading the output
 * and for closing the shell when you are done using it.
 *
 * @param shellPath a <code>String</code> to Indicate the path to the shell that you want to open.
 * @param timeout   an <code>int</code> to Indicate the length of time before giving up on opening a shell.
 * @throws TimeoutException
 * @throws com.stericson.RootShell.exceptions.RootDeniedException
 * @throws IOException
 */
@SuppressWarnings("WeakerAccess")
public static Shell getCustomShell(String shellPath, int timeout) throws IOException, TimeoutException, RootDeniedException {
    return RootShell.getCustomShell(shellPath, timeout);
}
 
Example #15
Source File: RootShell.java    From PhoneProfilesPlus with Apache License 2.0 2 votes vote down vote up
/**
 * This will open or return, if one is already open, a shell, you are responsible for managing the shell, reading the output
 * and for closing the shell when you are done using it.
 *
 * @param root         a <code>boolean</code> to Indicate whether or not you want to open a root shell or a standard shell
 * @param shellContext the context to execute the shell with
 */
@SuppressWarnings("unused")
public static Shell getShell(boolean root, Shell.ShellContext shellContext) throws IOException, TimeoutException, RootDeniedException {
    return getShell(root, 0, shellContext, 3);
}
 
Example #16
Source File: RootShell.java    From PhoneProfilesPlus with Apache License 2.0 2 votes vote down vote up
/**
 * This will open or return, if one is already open, a shell, you are responsible for managing the shell, reading the output
 * and for closing the shell when you are done using it.
 *
 * @param root         a <code>boolean</code> to Indicate whether or not you want to open a root shell or a standard shell
 * @param timeout      an <code>int</code> to Indicate the length of time to wait before giving up on opening a shell.
 * @param shellContext the context to execute the shell with
 */
@SuppressWarnings("unused")
public static Shell getShell(boolean root, int timeout, Shell.ShellContext shellContext) throws IOException, TimeoutException, RootDeniedException {
    return getShell(root, timeout, shellContext, 3);
}
 
Example #17
Source File: RootShell.java    From PhoneProfilesPlus with Apache License 2.0 2 votes vote down vote up
/**
 * This will open or return, if one is already open, a custom shell, you are responsible for managing the shell, reading the output
 * and for closing the shell when you are done using it.
 *
 * @param shellPath a <code>String</code> to Indicate the path to the shell that you want to open.
 * @param timeout   an <code>int</code> to Indicate the length of time before giving up on opening a shell.
 * @throws TimeoutException
 * @throws com.stericson.RootShell.exceptions.RootDeniedException
 * @throws IOException
 */
public static Shell getCustomShell(String shellPath, int timeout) throws IOException, TimeoutException, RootDeniedException
{
    //return RootShell.getCustomShell(shellPath, timeout);
    return Shell.startCustomShell(shellPath, timeout);
}
 
Example #18
Source File: RootTools.java    From PhoneProfilesPlus with Apache License 2.0 2 votes vote down vote up
/**
 * This will open or return, if one is already open, a shell, you are responsible for managing the shell, reading the output
 * and for closing the shell when you are done using it.
 *
 * @param root a <code>boolean</code> to Indicate whether or not you want to open a root shell or a standard shell
 * @throws TimeoutException
 * @throws com.stericson.RootShell.exceptions.RootDeniedException
 * @throws IOException
 */
public static Shell getShell(boolean root) throws IOException, TimeoutException, RootDeniedException {
    return RootTools.getShell(root, 0);
}
 
Example #19
Source File: RootTools.java    From PhoneProfilesPlus with Apache License 2.0 2 votes vote down vote up
/**
 * This will open or return, if one is already open, a shell, you are responsible for managing the shell, reading the output
 * and for closing the shell when you are done using it.
 *
 * @param root    a <code>boolean</code> to Indicate whether or not you want to open a root shell or a standard shell
 * @param timeout an <code>int</code> to Indicate the length of time to wait before giving up on opening a shell.
 * @throws TimeoutException
 * @throws com.stericson.RootShell.exceptions.RootDeniedException
 * @throws IOException
 */
@SuppressWarnings("WeakerAccess")
public static Shell getShell(boolean root, int timeout) throws IOException, TimeoutException, RootDeniedException {
    return getShell(root, timeout, Shell.defaultContext, 3);
}
 
Example #20
Source File: RootTools.java    From PhoneProfilesPlus with Apache License 2.0 2 votes vote down vote up
/**
 * This will open or return, if one is already open, a shell, you are responsible for managing the shell, reading the output
 * and for closing the shell when you are done using it.
 *
 * @param root         a <code>boolean</code> to Indicate whether or not you want to open a root shell or a standard shell
 * @param shellContext the context to execute the shell with
 * @throws TimeoutException
 * @throws com.stericson.RootShell.exceptions.RootDeniedException
 * @throws IOException
 */
public static Shell getShell(boolean root, Shell.ShellContext shellContext) throws IOException, TimeoutException, RootDeniedException {
    return getShell(root, 0, shellContext, 3);
}
 
Example #21
Source File: RootTools.java    From PhoneProfilesPlus with Apache License 2.0 2 votes vote down vote up
/**
 * This will open or return, if one is already open, a shell, you are responsible for managing the shell, reading the output
 * and for closing the shell when you are done using it.
 *
 * @param root         a <code>boolean</code> to Indicate whether or not you want to open a root shell or a standard shell
 * @param timeout      an <code>int</code> to Indicate the length of time to wait before giving up on opening a shell.
 * @param shellContext the context to execute the shell with
 * @throws TimeoutException
 * @throws com.stericson.RootShell.exceptions.RootDeniedException
 * @throws IOException
 */
@SuppressWarnings("unused")
public static Shell getShell(boolean root, int timeout, Shell.ShellContext shellContext) throws IOException, TimeoutException, RootDeniedException {
    return getShell(root, timeout, shellContext, 3);
}
 
Example #22
Source File: RootTools.java    From PhoneProfilesPlus with Apache License 2.0 2 votes vote down vote up
/**
 * This will open or return, if one is already open, a shell, you are responsible for managing the shell, reading the output
 * and for closing the shell when you are done using it.
 *
 * @param root         a <code>boolean</code> to Indicate whether or not you want to open a root shell or a standard shell
 * @param timeout      an <code>int</code> to Indicate the length of time to wait before giving up on opening a shell.
 * @param shellContext the context to execute the shell with
 * @param retry        a <code>int</code> to indicate how many times the ROOT shell should try to open with root priviliges...
 * @throws TimeoutException
 * @throws com.stericson.RootShell.exceptions.RootDeniedException
 * @throws IOException
 */
@SuppressWarnings("WeakerAccess")
public static Shell getShell(boolean root, int timeout, Shell.ShellContext shellContext, int retry) throws IOException, TimeoutException, RootDeniedException {
    return RootShell.getShell(root, timeout, shellContext, retry);
}
 
Example #23
Source File: RootTools.java    From PhoneProfilesPlus with Apache License 2.0 2 votes vote down vote up
/**
 * This will open or return, if one is already open, a custom shell, you are responsible for managing the shell, reading the output
 * and for closing the shell when you are done using it.
 *
 * @param shellPath a <code>String</code> to Indicate the path to the shell that you want to open.
 * @throws TimeoutException
 * @throws com.stericson.RootShell.exceptions.RootDeniedException
 * @throws IOException
 */
@SuppressWarnings("unused")
public static Shell getCustomShell(String shellPath) throws IOException, TimeoutException, RootDeniedException {
    return RootTools.getCustomShell(shellPath, 10000);
}