{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

ShellExecutor

interface ShellExecutor

Known direct subclasses

Executes a shell command in a similar manner and environment as #executeShellCommand , (i.e. as either root or shell user).

Unlike UiAutomation this is available on all API levels and will not conflict with other instances of UiAutomation.

Summary

Public methods

abstract InputStream
executeShellCommand(
    String command,
    List<String> parameters,
    Map<StringString> shellEnv,
    boolean executeThroughShell,
    long timeoutMs
)

Execute a command with elevated permissions and return immediately.

abstract InputStream
executeShellCommand(
    String command,
    List<String> parameters,
    Map<StringString> shellEnv,
    boolean executeThroughShell
)

Execute a command with elevated permissions and return immediately.

abstract String
executeShellCommandSync(
    String command,
    List<String> parameters,
    Map<StringString> shellEnv,
    boolean executeThroughShell,
    long timeoutMs
)

Execute a command with elevated permissions and block.

abstract String
executeShellCommandSync(
    String command,
    List<String> parameters,
    Map<StringString> shellEnv,
    boolean executeThroughShell
)

Execute a command with elevated permissions and block.

abstract String

Public methods

executeShellCommand

abstract InputStream executeShellCommand(
    String command,
    List<String> parameters,
    Map<StringString> shellEnv,
    boolean executeThroughShell,
    long timeoutMs
)

Execute a command with elevated permissions and return immediately.

Parameters
String command

The shell command to be executed.

List<String> parameters

A Map parameters to be given to the shell command

Map<StringString> shellEnv

A Map of shell environment variables to be set

boolean executeThroughShell

If set to true, the command string will be executed through the shell with parameters given as additional shell arguments.

long timeoutMs

Optional, destroys the executing subprocess if it runs longer than this timeout.

Returns
InputStream

java.io.InputStream representing the shell output of the command.

Throws
java.io.IOException java.io.IOException

if cannot execute command on executor service.

androidx.test.services.shellexecutor.ClientNotConnected androidx.test.services.shellexecutor.ClientNotConnected

executeShellCommand

abstract InputStream executeShellCommand(
    String command,
    List<String> parameters,
    Map<StringString> shellEnv,
    boolean executeThroughShell
)

Execute a command with elevated permissions and return immediately.

Parameters
String command

The shell command to be executed.

List<String> parameters

A Map parameters to be given to the shell command

Map<StringString> shellEnv

A Map of shell environment variables to be set

boolean executeThroughShell

If set to true, the command string will be executed through the shell with parameters given as additional shell arguments.

Returns
InputStream

java.io.InputStream representing the shell output of the command.

Throws
java.io.IOException java.io.IOException

if cannot execute command on executor service.

androidx.test.services.shellexecutor.ClientNotConnected androidx.test.services.shellexecutor.ClientNotConnected

executeShellCommandSync

abstract String executeShellCommandSync(
    String command,
    List<String> parameters,
    Map<StringString> shellEnv,
    boolean executeThroughShell,
    long timeoutMs
)

Execute a command with elevated permissions and block.

Parameters
String command

The shell command to be executed.

List<String> parameters

A Map parameters to be given to the shell command

Map<StringString> shellEnv

A Map of shell environment variables to be set

boolean executeThroughShell

If set to true, the command string will be executed through the shell with parameters given as additional shell arguments.

long timeoutMs

Optional, destroys the executing subprocess if it runs longer than this timeout.

Returns
String

String representing the contents of the shell output of the command.

Throws
java.io.IOException java.io.IOException

if cannot execute command on executor service.

androidx.test.services.shellexecutor.ClientNotConnected androidx.test.services.shellexecutor.ClientNotConnected

executeShellCommandSync

abstract String executeShellCommandSync(
    String command,
    List<String> parameters,
    Map<StringString> shellEnv,
    boolean executeThroughShell
)

Execute a command with elevated permissions and block.

Parameters
String command

The shell command to be executed.

List<String> parameters

A Map parameters to be given to the shell command

Map<StringString> shellEnv

A Map of shell environment variables to be set

boolean executeThroughShell

If set to true, the command string will be executed through the shell with parameters given as additional shell arguments.

Returns
String

String representing the contents of the shell output of the command.

Throws
java.io.IOException java.io.IOException

if cannot execute command on executor service.

androidx.test.services.shellexecutor.ClientNotConnected androidx.test.services.shellexecutor.ClientNotConnected

getBinderKey

abstract String getBinderKey()