Package 

Class Shell.Builder


  • 
    public abstract class Shell.Builder
    
                        

    Builder class for Shell instances.

    Set the default builder for the main shell instance with setDefaultBuilder, or directly use a builder object to create new Shell instances.

    Do not subclass this class! Use create to get a new Builder object.

    • Method Detail

      • setFlags

        @NonNull() abstract Shell.Builder setFlags(int flags)

        Set flags to control how a new {@code Shell} will be constructed.

        Parameters:
        flags - the desired flags.
      • setTimeout

        @NonNull() abstract Shell.Builder setTimeout(long timeout)

        Set the maximum time to wait for shell verification.

        After the timeout occurs and the shell still has no response,the shell process will be force-closed and throw NoShellException.

        Parameters:
        timeout - the maximum time to wait in seconds.The default timeout is 20 seconds.
      • setContext

        @NonNull() final Shell.Builder setContext(@NonNull() Context context)

        Set the Context to use when creating a shell.

        The ContextImpl of the application will be obtained through the provided context,and that will be passed to onInit.

        Calling this method is not usually necessary but recommended, as the library canobtain the current application context through Android internal APIs. However, if yourapplication uses sharedUserId, or a shell/root service can becreated during the application attach process, then setting a Context explicitlyusing this method is required.

        Parameters:
        context - a context of the current package.
      • build

        @NonNull() abstract Shell build()

        Combine all of the options that have been set and build a new {@code Shell} instance.

        If not setCommands, there are 3 methods to construct a Unix shell;if any method fails, it will fallback to the next method:

        • If FLAG_NON_ROOT_SHELL is not set and FLAG_MOUNT_MASTER is set, construct a Unix shell by calling {@code su --mount-master}.It may fail if the root implementation does not support mount master.
        • If FLAG_NON_ROOT_SHELL is not set, construct a Unix shell by calling{@code su}. It may fail if the device is not rooted, or root permission isnot granted.
        • Construct a Unix shell by calling {@code sh}. This would never fail in normalconditions, but should it fail, it will throw NoShellException
        The developer should check the status of the returned {@code Shell} with getStatus since it may be constructed with calling {@code sh}.

        If setCommands is called, the provided commands will be used tocreate a new Process directly. If the process fails to create, or the processis not a valid shell, it will throw NoShellException.

      • build

        @NonNull() final Shell build(Array<String> commands)

        Combine all of the options that have been set and build a new {@code Shell} instancewith the provided commands.

        Parameters:
        commands - commands that will be passed to exec to createa new Process.
      • build

        @NonNull() abstract Shell build(Process process)

        Combine all of the options that have been set and build a new {@code Shell} instancewith the provided process.

        Parameters:
        process - a shell Process that has already been created.