Server commands
Google ADB client/server has a separate protocol and a separated command set. Some commands are handled by the server itself, and others operates on a specific device.
Commands handled by server
Get version
declare class AdbServerClient {
getVersion(): Promise<number>;
}
The protocol between ADB client and server has its own version number. This is not Android version (like 13.0
), nor ADB protocol version (like 0x10000001
), nor platform tools version (like 34.0.1
).
This is the version you see in the error message when you use a wrong ADB client to connect to a server:
adb server version (39) doesn't match this client (41); killing...
Tango doesn't check the version number, although not thoroughly tested, most of the commands should work on any version of ADB server.
adb version
If it prints Android Debug Bridge version 1.0.41
, the protocol version is 41
.
Kill server
declare class AdbServerClient {
killServer(): Promise<void>;
}
Stops the server.
adb kill-server
Get server features
declare class AdbServerClient {
getServerFeatures(): Promise<string[]>;
}
Gets the ADB features supported by the server. For Google ADB client, the supported feature list is same between client and server, so this reflects how ADB commands will behave.
But in Tango, all ADB commands are generated from Tango, not the ADB client, so this list is not very useful.
Some interesting features:
libusb
: The server is usinglibusb
to communicate with devices.delayed_ack
The server supports Delayed Acknowledgment for lower latency. Delayed Acknowledgment is a low-level ADB protocol feature, so not controlled by Tango.
adb host-features
Get devices
namespace AdbServerClient {
interface Device {
serial: string;
authenticating: boolean;
product?: string;
model?: string;
device?: string;
transportId: bigint;
}
}
declare class AdbServerClient {
getDevices(): Promise<AdbServerClient.Device[]>;
}
Gets all connected devices.
See Get devices page for more information about the getDevices
method.
adb devices -l
Track devices
declare class AdbServerClient {
trackDevices(
signal?: AbortSignal
): AsyncGenerator<AdbServerClient.Device[], void, void>;
}
Get notified when a device is connected or disconnected.
See Watch devices page for more information about the trackDevices
method.
There is no equivalent ADB command.
Commands that operates device
Device selector
All commands that operates on a device requires a DeviceSelector
object to specify the target device.
See Device selector page for more information about DeviceSelector
.
Get device features
declare class AdbServerClient {
getDeviceFeatures(
selector: AdbServerClient.DeviceSelector
): Promise<{ transportId: bigint; features: AdbFeature[] }>;
}
Gets the ADB features supported by the device. It's required for Tango to coordinate the behavior of ADB commands with the device.
For example, if Shell protocol is not supported by the device, using AdbSubprocessShellProtocol
will immediately throw an error.
Usually you don't need to call this method directly, the AdbServerClient#createTransport
method uses it to create a AdbTransport
object.
adb features
Create device socket
namespace AdbServerClient {
interface Socket extends AdbSocket {
transportId: bigint;
}
}
declare class AdbServerClient {
createDeviceConnection(
device: AdbServerClient.DeviceSelector,
service: string
): Promise<AdbServerClient.Socket>;
}
Creates a socket to the ADB daemon on the device, letting the server forward packets between the client and the device.
The socket can be used to run an ADB command, or connect to a socket on device.
Usually you don't need to call this method directly, the AdbServerClient#createTransport
method uses it to implement AdbTransport
.
There is no equivalent ADB command.
Wait for device
interface AdbServerConnectionOptions {
unref?: boolean | undefined;
signal?: AbortSignal | undefined;
}
declare class AdbServerClient {
waitFor(
device: AdbServerClient.DeviceSelector,
state: "device" | "disconnect",
options?: AdbServerConnectionOptions
): Promise<void>;
}
Wait for a device to be connected or disconnected. This method returns a Promise
that resolves when the condition is met.
If the selector is usb
, tcp
or undefined
, it won't tell which device is connected or disconnected.
Options:
unref
: If the underlying connection is using Node.jsnet
module, thenunref
the socket so the process can exit even if the connection is still alive.signal
: Stops the wait when the signal is aborted.
adb wait-for[-TRANSPORT]-STATE
For example:
adb wait-for-device
adb wait-for-usb-device
adb wait-for-disconnect
adb wait-for-usb-disconnect
Create transport
declare class AdbServerTransport implements AdbTransport {}
declare class AdbServerClient {
createTransport(
device: AdbServerClient.DeviceSelector
): Promise<AdbServerTransport>;
}
Creates an AdbTransport
object for the device. It's not one server command, it uses multiple server commands internally to implement the transport.
The returned transport object can be used to construct an Adb
instance:
- JavaScript
- TypeScript
import { Adb } from "@yume-chan/adb";
const transport = await client.createTransport({
transportId: 123n,
});
const adb = new Adb(transport);
import { Adb } from "@yume-chan/adb";
const transport: AdbServerTransport = await client.createTransport({
transportId: 123n,
});
const adb: Adb = new Adb(transport);