Skip to main content

Module adb

Module adb 

Source
Expand description

Client for the adb server’s smart-socket protocol (design D3).

The driver talks to the local adb server on port 5037 directly instead of spawning the adb binary, which costs 16 to 22 ms more per operation (spike S6). Each request opens its own server connection, so no state is shared between calls and a failed request never affects the next one.

  • AdbServer::devices keeps every connection state, including unauthorized, offline and no permissions, and AdbServer::targets adds what the driver reports about each target.
  • Device::shell uses shell protocol v2, which keeps the exit status and a separate stderr.
  • Device::push sends sync SEND in 64 KiB chunks, each header written together with its data.
  • Device::forward and Device::reverse read through the second status, so a refusal by the server or by adbd surfaces as Error::Fail.
  • Device::open_service opens a device service such as localabstract:<name> without installing a rule; a missing listener fails the open with closed. This is how the driver reaches the agent.

The client is blocking. Every connection has a connect deadline and read and write deadlines (10 s by default), and each call takes a few milliseconds, so async callers run it on a blocking thread.

Structs§

AdbServer
An adb server, reached over TCP on the loopback interface.
Device
One device on an AdbServer, named by its serial.
DeviceEntry
One line of the listing.
Rule
A forward or reverse rule, named by its two sides.
ShellOutput
Output of one command run through shell protocol v2.
ShellStream
A running shell v2 command whose packets are read as they arrive.
Target
A listed target with what the driver reports about it.

Enums§

Error
Why an adb request failed.
ShellPacket
One shell protocol v2 packet from the device.
State
Connection state of a listed target, as the adb server names it.
Stdio
How adbd connects a shell command’s standard streams.

Constants§

CONNECT_TIMEOUT
Deadline for connecting to the server.
DEFAULT_IO_TIMEOUT
Default deadline for each read and write on a server connection.
DEFAULT_SERVER_PORT
Port of the adb server when SERVER_PORT_VAR is unset.
PROP_QUERY
The shell command crate::adb::AdbServer::targets runs on each online target, one property per output line in this order.
SERVER_PORT_VAR
Environment variable naming the adb server’s port, as the adb binary reads it.
SYNC_MAX_CHUNK
Largest DATA chunk the sync protocol allows.

Functions§

parse_devices
Parses a host:devices or host:devices-l answer. Header, blank and * daemon ... lines are skipped, as is any line without a state, so one odd line never hides the other targets.
server_port
The port in a SERVER_PORT_VAR value; the default port when the value is absent, empty or not a port number.

Type Aliases§

Result
Result of an adb request.