TapClient

class TapClient(val address: String, val channel: ManagedChannel, token: String? = null)(source)

A channel to a Tap host server. Discovery order: address; the tap.server system property / TAP_SERVER (host:port); a live daemon.json in the state dir (TAP_STATE_DIR, default ~/.tap). The client never starts the daemon: run tap start (or TapDaemonProcess.start) first. A started daemon stays up like the ADB server until tap stop.

Every RPC carries the daemon's bearer token (authorization: Bearer <token>): the one in daemon.json when the address was discovered there, else token / tap.token / TAP_TOKEN for an explicit address. A wrong or missing token fails every call with ServerException UNAUTHENTICATED.

Construction takes an explicit address and performs no I/O; use create to resolve one (which probes the server with Info). All RPCs are suspend over grpc-kotlin CoroutineStubs: per-call withDeadlineAfter is still applied server-side, while caller (or test-root) cancellation promptly cancels the gRPC call client-side. Closing is suspend and drops AutoCloseable: callers use try/finally inside a coroutine.

The primary constructor is an advanced seam (tests, custom transports): a client over an existing channel. Production callers use create.

Constructors

Link copied to clipboard
constructor(address: String, channel: ManagedChannel, token: String? = null)
constructor(address: String, token: String? = DaemonDiscovery.explicitToken())

Creates a client for address with its own channel, sending token (default: tap.token / TAP_TOKEN). Performs no I/O.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
val channel: ManagedChannel

Functions

Link copied to clipboard
suspend fun close()

Shuts the channel down. Runs under NonCancellable with bounded waits so teardown completes even when the caller is cancelled: shutdown, a bounded await, then shutdownNow plus a second bounded await for forced termination. Close every TapConnection first.

Link copied to clipboard
suspend fun connect(name: String): TapConnection

Opens a TapConnection and starts its liveness observation: if this process dies, the server detaches every device the connection owns. The observe stream is established before this returns (the first Observe event, observing, is awaited), so every later attachDevice belongs to a live connection. An empty stream, a closing first event or any failure before the first event fails the connect and closes the newly opened id under a bounded non-cancellable context. A later closing event (the daemon reaped this connection or is shutting down) makes the connection unusable with the daemon's reason.

Link copied to clipboard
suspend fun devices(): List<DeviceEntry>

Every device ADB lists, with its state (FREE, LEASED, QUARANTINED, OFFLINE, UNAUTHORIZED); only FREE and LEASED devices can be attached.

Link copied to clipboard
suspend fun info(): ServerInfo

Daemon version and pid, protocol version, ADB executable, state dir, whether a driver is available.

Link copied to clipboard
suspend fun <R> use(block: suspend (TapClient) -> R): R

Runs block with this client, then closes it. A block failure wins; a close failure after it is added as suppressed.