# Shell

Artifact: [androidx.test.uiautomator:uiautomator-shell](https://developer.android.com/jetpack/androidx/releases/test-uiautomator) [View Source](https://cs.android.com/search?q=file:androidx/test/shell/Shell.kt+class:androidx.test.shell.Shell) Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

*** ** * ** ***


```
public static class Shell
```

<br />

*** ** * ** ***

Allows to execute commands. This class builds on top of `https://developer.android.com/reference/androidx/test/shell/ShellProcess` and abstracts the shell streams to focus on the output of a single command execution. A `https://developer.android.com/reference/androidx/test/shell/ShellProcess` is created for each executed command, using a `https://developer.android.com/reference/androidx/test/shell/ShellServer` that can be reset by `https://developer.android.com/reference/androidx/test/shell/Shell#setShellServer(androidx.test.shell.ShellServer)`.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/test/shell/Shell.CommandOutput` The output of a shell command executed via `https://developer.android.com/reference/androidx/test/shell/Shell#command(kotlin.String)`. |

| ### Public fields |
|---|---|
| `static @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/Shell` | `https://developer.android.com/reference/androidx/test/shell/Shell#INSTANCE()` |

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/Shell.CommandOutput` | `https://developer.android.com/reference/androidx/test/shell/Shell#command(kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html command)` Executes a given command and returns the ongoing `https://developer.android.com/reference/androidx/test/shell/Shell.CommandOutput`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/command/ApplicationCommands` | `https://developer.android.com/reference/androidx/test/shell/Shell#getApplication()()` Commands for application. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/command/ProcessCommands` | `https://developer.android.com/reference/androidx/test/shell/Shell#getProcess()()` Commands for processes. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/command/RecorderCommands` | `https://developer.android.com/reference/androidx/test/shell/Shell#getRecorder()()` Commands for screen recorder. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/command/ScreenCommands` | `https://developer.android.com/reference/androidx/test/shell/Shell#getScreen()()` Commands for screen. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/command/WifiCommands` | `https://developer.android.com/reference/androidx/test/shell/Shell#getWifi()()` Commands for controlling Wi-Fi. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/command/PermissionCommands` | `https://developer.android.com/reference/androidx/test/shell/Shell#permission(kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html packageName)` Commands for permissions. |
| `final void` | `https://developer.android.com/reference/androidx/test/shell/Shell#setShellServer(androidx.test.shell.ShellServer)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/ShellServer shellServer)` Allows configuring the underlying `https://developer.android.com/reference/androidx/test/shell/ShellProcess` utilized to execute the commands. |

## Public fields

### INSTANCE

Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public static @NonNull Shell INSTANCE
```

## Public methods

### command

Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public final @NonNull Shell.CommandOutput command(@NonNull String command)
```

Executes a given command and returns the ongoing `https://developer.android.com/reference/androidx/test/shell/Shell.CommandOutput`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html command` | a string containing the command to launch. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/Shell.CommandOutput` | a `https://developer.android.com/reference/androidx/test/shell/Shell.CommandOutput` that allows to access the stream of the command output. |

### getApplication

Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public final @NonNull ApplicationCommands getApplication()
```

Commands for application.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/command/ApplicationCommands` | an instance of `https://developer.android.com/reference/androidx/test/shell/command/ApplicationCommands`. |

### getProcess

Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public final @NonNull ProcessCommands getProcess()
```

Commands for processes.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/command/ProcessCommands` | an instance of `https://developer.android.com/reference/androidx/test/shell/command/ProcessCommands`. |

### getRecorder

Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public final @NonNull RecorderCommands getRecorder()
```

Commands for screen recorder.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/command/RecorderCommands` | an instance of `https://developer.android.com/reference/androidx/test/shell/command/RecorderCommands`. |

### getScreen

Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public final @NonNull ScreenCommands getScreen()
```

Commands for screen.

### getWifi

Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public final @NonNull WifiCommands getWifi()
```

Commands for controlling Wi-Fi.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/command/WifiCommands` | an instance of `https://developer.android.com/reference/androidx/test/shell/command/WifiCommands`. |

### permission

Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public final @NonNull PermissionCommands permission(@NonNull String packageName)
```

Commands for permissions.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html packageName` | the application package name |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/command/PermissionCommands` | an instance of `https://developer.android.com/reference/androidx/test/shell/command/PermissionCommands`. |

### setShellServer

Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public final void setShellServer(@NonNull ShellServer shellServer)
```

Allows configuring the underlying `https://developer.android.com/reference/androidx/test/shell/ShellProcess` utilized to execute the commands. The current `https://developer.android.com/reference/androidx/test/shell/ShellServer` backing `https://developer.android.com/reference/androidx/test/shell/Shell` is always closed when setting a new one.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/ShellServer shellServer` | The new shell server to produce `https://developer.android.com/reference/androidx/test/shell/ShellProcess` to launch commands. |