Daemon Transport
AdbDaemonTransport connects to ADB Daemons directly. This means it can run on devices without Google ADB (for example, on Web platforms where connecting to Google ADB Server is not supported, or on mobile devices where Google ADB is not available).
This is the lowest-level transport, it controls all the steps, including authentication, message encoding and decoding, and connection management.
Installation
This class is included in the core package:
- npm
- Yarn
- pnpm
npm i @yume-chan/adb
yarn add @yume-chan/adb
pnpm add @yume-chan/adb
To support different runtime and connection method, AdbDaemonTransport
class itself only defines how to serialize and deserialize Daemon Protocol packets. An AdbDaemonConnection
implementation is required to send and receive those packets, and an AdbCredentialStore
implementation is required to manage client certificates.
Overview
Here are the steps to create an Adb
instance with AdbDaemonTransport
:
- User creates an
AdbDaemonConnection
for the desired connection method. - User creates an
AdbCredentialStore
that works on the target runtime environment. - User creates an
AdbDaemonTransport
instance with the connection and credential store.- The transport instance uses the connection to send and receive handshake packets.
- The transport instance uses the credential store to authenticate with the device.
- If authentication is successful, user creates an
Adb
instance with the transport object.
Connections
Daemon Transport has three connection methods:
- USB: Uses USB API to communicate with devices connected via USB.
- ADB over Wi-Fi a.k.a TCP/IP Mode: Uses TCP sockets to communicate with devices over the network.
- Wireless Debugging: Added in Android 11. Uses TLS over TCP sockets and a new authentication process.
The Wireless Debugging connection is not implemented yet, as it needs a full TLS implementation.
We expect it to be a separate package if it uses third-party libraries, but we haven't found a suitable library yet. Any help is appreciated!
Due to runtime API limitations, not all connections are supported on all environments:
Connection | Web | Node.js |
---|---|---|
USB | Supported on Chromium-based browsers 1 | Supported |
ADB over Wi-Fi | Not supported | Supported |
1 Chrome for Android is supported, but Chrome for iOS is based on Safari and not supported.
AdbDaemonTransport
also accepts custom connection implementations. For example, with a Node.js WebSocket server that forwards packets to devices, a WebSocket connection can connect to that server and enable unsupported connections on Web platforms.
USB Connection
USB connection is the oldest and most common way to connect to Android devices.
Because USB connections are exclusive, Daemon Transport can't access a USB device at the same time with Google ADB or other ADB clients. To do that, use the Server Transport.
@yume-chan/adb-daemon-webusb
package provides an AdbDaemonConnection
implementation based on WebUSB API:
- Chromium-based browsers support WebUSB natively. Chrome for Android is supported, but Chrome for iOS is based on Safari and not supported.
- Node.js can use the WebUSB implementation in the
usb
package.
TCP Connection
ADB over Wi-Fi (a.k.a TCP/IP mode) uses TCP sockets to communicate with devices over the network. Google Android Emulators are also supported. The data protocol is completely same as USB connection, just on a different transport layer.
Currently, there is no built-in TCP connection for Web platforms, as TCP sockets are not supported there. This documentation provides a reference implementation for Node.js.
Custom Connection
In addition to the built-in connection methods, Tango also accepts custom connection implementations. For example, with a Node.js WebSocket server that forwards packets to devices, a WebSocket connection can connect to that server and enable unsupported connections on Web platforms.