# 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)

*** ** * ** ***


```
object Shell
```

<br />

*** ** * ** ***

Allows to execute commands. This class builds on top of `https://developer.android.com/reference/kotlin/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/kotlin/androidx/test/shell/ShellProcess` is created for each executed command, using a `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellServer` that can be reset by `https://developer.android.com/reference/kotlin/androidx/test/shell/Shell#setShellServer(androidx.test.shell.ShellServer)`.

## Summary

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

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/shell/Shell.CommandOutput` | `https://developer.android.com/reference/kotlin/androidx/test/shell/Shell#command(kotlin.String)(command: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Executes a given command and returns the ongoing `https://developer.android.com/reference/kotlin/androidx/test/shell/Shell.CommandOutput`. |
| `https://developer.android.com/reference/kotlin/androidx/test/shell/command/PermissionCommands` | `https://developer.android.com/reference/kotlin/androidx/test/shell/Shell#permission(kotlin.String)(packageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Commands for permissions. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/shell/Shell#setShellServer(androidx.test.shell.ShellServer)(shellServer: https://developer.android.com/reference/kotlin/androidx/test/shell/ShellServer)` Allows configuring the underlying `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellProcess` utilized to execute the commands. |

| ### Public properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/shell/command/ApplicationCommands` | `https://developer.android.com/reference/kotlin/androidx/test/shell/Shell#application()` Commands for application. |
| `https://developer.android.com/reference/kotlin/androidx/test/shell/command/ProcessCommands` | `https://developer.android.com/reference/kotlin/androidx/test/shell/Shell#process()` Commands for processes. |
| `https://developer.android.com/reference/kotlin/androidx/test/shell/command/RecorderCommands` | `https://developer.android.com/reference/kotlin/androidx/test/shell/Shell#recorder()` Commands for screen recorder. |
| `https://developer.android.com/reference/kotlin/androidx/test/shell/command/ScreenCommands` | `https://developer.android.com/reference/kotlin/androidx/test/shell/Shell#screen()` Commands for screen. |
| `https://developer.android.com/reference/kotlin/androidx/test/shell/command/WifiCommands` | `https://developer.android.com/reference/kotlin/androidx/test/shell/Shell#wifi()` Commands for controlling Wi-Fi. |

## Public functions

### command

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

```
fun command(command: String): Shell.CommandOutput
```

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

| Parameters |
|---|---|
| `command: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | a string containing the command to launch. |

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

### permission

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

```
fun permission(packageName: String): PermissionCommands
```

Commands for permissions.

| Parameters |
|---|---|
| `packageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | the application package name |

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

### setShellServer

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

```
fun setShellServer(shellServer: ShellServer): Unit
```

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

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

## Public properties

### application

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

```
val application: ApplicationCommands
```

Commands for application.

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

### process

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

```
val process: ProcessCommands
```

Commands for processes.

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

### recorder

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

```
val recorder: RecorderCommands
```

Commands for screen recorder.

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

### screen

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

```
val screen: ScreenCommands
```

Commands for screen.

### wifi

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

```
val wifi: WifiCommands
```

Commands for controlling Wi-Fi.

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