-
public abstract class Shell.BuilderBuilder 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 Summary
Modifier and Type Method Description static Shell.Buildercreate()Create a new Builder. final Shell.BuildersetInitializers(@NonNull() Array<Class<out Shell.Initializer>> classes)Set the desired Initializers. abstract Shell.BuildersetFlags(int flags)Set flags to control how a new {@code Shell}will be constructed.abstract Shell.BuildersetTimeout(long timeout)Set the maximum time to wait for shell verification. abstract Shell.BuildersetCommands(Array<String> commands)Set the commands that will be used to create a new {@code Shell}.final Shell.BuildersetContext(@NonNull() Context context)Set the Context to use when creating a shell. abstract Shellbuild()Combine all of the options that have been set and build a new {@code Shell}instance.final Shellbuild(Array<String> commands)Combine all of the options that have been set and build a new {@code Shell}instancewith the provided commands.abstract Shellbuild(Process process)Combine all of the options that have been set and build a new {@code Shell}instancewith the provided process.-
-
Method Detail
-
create
@NonNull() static Shell.Builder create()
Create a new Builder.
-
setInitializers
@SafeVarargs()@NonNull() final Shell.Builder setInitializers(@NonNull() Array<Class<out Shell.Initializer>> classes)
Set the desired Initializers.
- Parameters:
classes- the classes of desired initializers.
-
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.
-
setCommands
@NonNull() abstract Shell.Builder setCommands(Array<String> commands)
Set the commands that will be used to create a new
{@code Shell}.
-
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
{@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.
- If FLAG_NON_ROOT_SHELL is not set and FLAG_MOUNT_MASTER is set, construct a Unix shell by calling
-
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.
-
-
-
-