# ShellServer

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/ShellServer.kt+class:androidx.test.shell.ShellServer) Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

*** ** * ** ***


```
class ShellServer : AutoCloseable
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellServer` starts a new long running process on device that is capable of establishing and executing multiple concurrent `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellProcess` with "/system/bin/sh". Each `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellProcess` represents an executing `sh` process. To interact with it, the 3 standard streams are exposed (stdin, stdout, stderr) via `https://developer.android.com/reference/java/io/OutputStream.html`s and `https://developer.android.com/reference/java/io/InputStream.html`. At a high-level, you can think of a `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellServer` as a "factory" for `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellProcess`, which is useful to re-use for performance, or to configure which ports `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellServer` opens on-device.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/shell/Shell#setShellServer(androidx.test.shell.ShellServer)` |   |

## Summary

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellServer` | `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellServer#start(kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Boolean,kotlin.Long)( stdInSocketPort: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, stdOutSocketPort: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, stdErrSocketPort: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, nativeLogs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, connectTimeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html )` Starts a new `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellServer` with the given configuration. |

| ### Public functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellServer#close()()` Turns off the `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellServer`. |
| `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellProcess` | `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellServer#newProcess()()` Creates a new `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellProcess`. |

## Public companion functions

### start

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

```
fun start(
    stdInSocketPort: Int = 0,
    stdOutSocketPort: Int = 0,
    stdErrSocketPort: Int = 0,
    nativeLogs: Boolean = false,
    connectTimeoutMs: Long = 1000
): ShellServer
```

Starts a new `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellServer` with the given configuration.

| Parameters |
|---|---|
| `stdInSocketPort: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | the port utilized for stdin. If not specified, an available port is chosen. |
| `stdOutSocketPort: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | the port utilized for stdout. If not specified, an available port is chosen. |
| `stdErrSocketPort: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | the port utilized for stderr. If not specified, an available port is chosen. |
| `nativeLogs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = false` | controls whether the native shell server should print logs. |
| `connectTimeoutMs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html = 1000` | a timeout in millis to connect to the local shell server. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellServer` | a started `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellServer` |

## Public functions

### close

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

```
open fun close(): Unit
```

Turns off the `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellServer`. After the closing, no more `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellProcess` can be created.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if the shell server did not start correctly. |

### newProcess

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

```
fun newProcess(): ShellProcess
```

Creates a new `https://developer.android.com/reference/kotlin/androidx/test/shell/ShellProcess`.