chao faf16d266e update | 3 mesi fa | |
---|---|---|
.. | ||
src | 3 mesi fa | |
.npmignore | 3 mesi fa | |
CHANGELOG.json | 3 mesi fa | |
CHANGELOG.md | 3 mesi fa | |
LICENSE | 3 mesi fa | |
README.md | 3 mesi fa | |
jest.config.js | 3 mesi fa | |
package.json | 3 mesi fa | |
tsconfig.build.json | 3 mesi fa | |
tsconfig.json | 3 mesi fa | |
tsconfig.test.json | 3 mesi fa |
TypeScript implementation of Android Debug Bridge (ADB) protocol.
WARNING: The public API is UNSTABLE. If you have any questions, please open an issue.
Here is a list of features, their used APIs, and their compatibilities. If an optional feature is not actually used, its requirements can be ignored.
Some features can be polyfilled to support older runtimes, but this library doesn't ship with any polyfills.
Each backend may have different requirements.
Chrome | Edge | Firefox | Internet Explorer | Safari | Node.js | |
---|---|---|---|---|---|---|
@yume-chan/struct 1 |
67 | 79 | 68 | No | 14 | 8.32, 11 |
Overall | 67 | 79 | No | No | 14.1 | 16.5 |
1 uint64
and string
are used.
2 TextEncoder
and TextDecoder
are only available in util
module. Need to be assigned to globalThis
.
Chrome | Edge | Firefox | Internet Explorer | Safari | Node.js | |
---|---|---|---|---|---|---|
Top-level await | 89 | 89 | 89 | No | 15 | 14.8 |
This library doesn't tie to a specific transportation method.
Instead, a Backend
is responsible for transferring data in its own way (USB, WebSocket, TCP, etc).
connect
connect(): ValueOrPromise<ReadableWritablePair<AdbPacketCore, AdbPacketInit>>
Connect to a device and create a pair of AdbPacket
streams.
The backend, instead of the core library, is responsible for serializing and deserializing the packets. Because it's extreme slow for WebUSB backend (@yume-chan/adb-backend-webusb
) to read packets with unknown size.
For how does ADB authentication work, see https://chensi.moe/blog/2020/09/30/webadb-part2-connection/#auth.
In this library, authentication comes in two parts:
An interface to generate, store and iterate ADB private keys on each runtime. (Because Node.js and Browsers have different APIs to do this)
generateKey
generateKey(): ValueOrPromise<Uint8Array>
Generate and store a RSA private key with modulus length 2048
and public exponent 65537
.
The returned Uint8Array
is the private key in PKCS #8 format.
iterateKeys
iterateKeys(): Iterator<ArrayBuffer> | AsyncIterator<ArrayBuffer>
Synchronously or asynchronously iterate through all stored RSA private keys.
Each call to iterateKeys
must return a different iterator that iterate through all stored keys.
The @yume-chan/adb-credential-web
package contains a AdbWebCredentialStore
implementation using Web Crypto API for generating keys and Web Storage API for storing keys.
An AdbAuthenticator
generates AUTH
responses for each AUTH
request from server.
This package contains AdbSignatureAuthenticator
and AdbPublicKeyAuthenticator
, the two basic modes.
authenticate
static async authenticate(
connection: ReadableWritablePair<AdbPacketCore, AdbPacketCore>,
credentialStore: AdbCredentialStore,
authenticators = AdbDefaultAuthenticators,
): Promise<Adb>
Call this method to authenticate the connection and create an Adb
instance.
If an authentication process failed, it's possible to call authenticate
again on the same connection (AdbPacket
stream pair). Every time the device receives a CNXN
packet, it resets all internal state, and starts a new authentication process.
ADB commands are all based on streams. Multiple streams can send and receive at the same time in one connection.
OPEN
packet to create a stream.OKAY
or FAIL
.CLSE
to close the stream.ADB has two subprocess invocation modes and two data protocols (4 combinations).
In raw mode, Shell protocol transfers stdout
and stderr
separately. It also supports returning exit code.
Legacy protocol | Shell Protocol | |
---|---|---|
Feature flag | - | shell_v2 |
Implementation | AdbNoneSubprocessProtocol |
AdbShellSubprocessProtocol |
Splitting stdout and stderr | No | Yes |
Returning exit code | No | Yes |
Use spawn
method to create a subprocess in raw mode.
In PTY mode, the subprocess has a pseudo-terminal, so it can send special control sequences like clear screen and set cursor position. The two protocols both send data in stdout
, but Shell Protocol also supports resizing the terminal from client.
Legacy protocol | Shell Protocol | |
---|---|---|
Feature flag | - | shell_v2 |
Implementation | AdbNoneSubprocessProtocol |
AdbShellSubprocessProtocol |
Resizing window | No | Yes |
Use shell
method to create a subprocess in PTY mode.
Disable ADB over WiFi.
Enable ADB over WiFi.
Client and server will communicate with another protocol on the opened stream.
Request server to list the content of a folder.
Version 2 of the LIST command, contains more information.
Supported on devices with ls_v2
feature.
Request server to return the information of a file.
If path is a symbolic link, the returned information is about the link itself.
So it's actually the lstat
system call.
Version 2 of the STAT command, contains more information.
Supported on devices with stat_v2
feature.
Basically identical to LST2, but if path is a symbolic link, the information is about the file it refers to.
Supported on devices with stat_v2
feature.
Request server to send the content of a file.
(Not Implemented)
Version 2 of the RECV command.
Supported on devices with sendrecv_v2
feature.
(Not Implemented)
Send a file onto server's file system.
(Not Implemented)
Version 2 of the SEND command.
Supported on devices with sendrecv_v2
feature.