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

*** ** * ** ***


```
public final class ShellServer implements AutoCloseable
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/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/androidx/test/shell/ShellProcess` with "/system/bin/sh". Each `https://developer.android.com/reference/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/androidx/test/shell/ShellServer` as a "factory" for `https://developer.android.com/reference/androidx/test/shell/ShellProcess`, which is useful to re-use for performance, or to configure which ports `https://developer.android.com/reference/androidx/test/shell/ShellServer` opens on-device.

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

## Summary

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/test/shell/ShellServer#close()()` Turns off the `https://developer.android.com/reference/androidx/test/shell/ShellServer`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/ShellProcess` | `https://developer.android.com/reference/androidx/test/shell/ShellServer#newProcess()()` Creates a new `https://developer.android.com/reference/androidx/test/shell/ShellProcess`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/ShellServer` | `https://developer.android.com/reference/androidx/test/shell/ShellServer#start(kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Boolean,kotlin.Long)( int stdInSocketPort, int stdOutSocketPort, int stdErrSocketPort, boolean nativeLogs, long connectTimeoutMs )` Starts a new `https://developer.android.com/reference/androidx/test/shell/ShellServer` with the given configuration. |

## Public methods

### close

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

```
public void close()
```

Turns off the `https://developer.android.com/reference/androidx/test/shell/ShellServer`. After the closing, no more `https://developer.android.com/reference/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)

```
public final @NonNull ShellProcess newProcess()
```

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

### start

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

```
public static final @NonNull ShellServer start(
    int stdInSocketPort,
    int stdOutSocketPort,
    int stdErrSocketPort,
    boolean nativeLogs,
    long connectTimeoutMs
)
```

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

| Parameters |
|---|---|
| `int stdInSocketPort` | the port utilized for stdin. If not specified, an available port is chosen. |
| `int stdOutSocketPort` | the port utilized for stdout. If not specified, an available port is chosen. |
| `int stdErrSocketPort` | the port utilized for stderr. If not specified, an available port is chosen. |
| `boolean nativeLogs` | controls whether the native shell server should print logs. |
| `long connectTimeoutMs` | a timeout in millis to connect to the local shell server. |

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