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::deviceskeeps every connection state, including unauthorized, offline andno permissions, andAdbServer::targetsadds what the driver reports about each target.Device::shelluses shell protocol v2, which keeps the exit status and a separate stderr.Device::pushsends syncSENDin 64 KiB chunks, each header written together with its data.Device::forwardandDevice::reverseread through the second status, so a refusal by the server or by adbd surfaces asError::Fail.Device::open_serviceopens a device service such aslocalabstract:<name>without installing a rule; a missing listener fails the open withclosed. 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. - Device
Entry - One line of the listing.
- Rule
- A forward or reverse rule, named by its two sides.
- Shell
Output - Output of one command run through shell protocol v2.
- Shell
Stream - 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.
- Shell
Packet - 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_VARis unset. - PROP_
QUERY - The shell command
crate::adb::AdbServer::targetsruns 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
adbbinary reads it. - SYNC_
MAX_ CHUNK - Largest
DATAchunk the sync protocol allows.
Functions§
- parse_
devices - Parses a
host:devicesorhost:devices-lanswer. 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_VARvalue; the default port when the value is absent, empty or not a port number.
Type Aliases§
- Result
- Result of an adb request.