@yume-chan/adb 0.0.19 → 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +33 -0
- package/CHANGELOG.md +15 -1
- package/README.md +220 -103
- package/esm/adb.d.ts +24 -44
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +14 -203
- package/esm/adb.js.map +1 -1
- package/esm/banner.d.ts +17 -0
- package/esm/banner.d.ts.map +1 -0
- package/esm/banner.js +67 -0
- package/esm/banner.js.map +1 -0
- package/esm/commands/power.d.ts +1 -1
- package/esm/commands/power.js +2 -2
- package/esm/commands/reverse.d.ts +17 -18
- package/esm/commands/reverse.d.ts.map +1 -1
- package/esm/commands/reverse.js +53 -48
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/protocols/none.d.ts +3 -8
- package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/none.js +16 -16
- package/esm/commands/subprocess/protocols/none.js.map +1 -1
- package/esm/commands/subprocess/protocols/shell.d.ts +3 -9
- package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/shell.js +48 -42
- package/esm/commands/subprocess/protocols/shell.js.map +1 -1
- package/esm/commands/subprocess/protocols/types.d.ts +1 -2
- package/esm/commands/subprocess/protocols/types.d.ts.map +1 -1
- package/esm/commands/sync/list.js +2 -2
- package/esm/commands/sync/push.d.ts +14 -3
- package/esm/commands/sync/push.d.ts.map +1 -1
- package/esm/commands/sync/push.js +8 -8
- package/esm/commands/sync/push.js.map +1 -1
- package/esm/commands/sync/request.js +1 -1
- package/esm/commands/sync/response.d.ts +3 -3
- package/esm/commands/sync/response.d.ts.map +1 -1
- package/esm/commands/sync/response.js +3 -3
- package/esm/commands/sync/response.js.map +1 -1
- package/esm/commands/sync/socket.d.ts +8 -13
- package/esm/commands/sync/socket.d.ts.map +1 -1
- package/esm/commands/sync/socket.js +32 -29
- package/esm/commands/sync/socket.js.map +1 -1
- package/esm/commands/sync/stat.js +2 -2
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.d.ts +11 -18
- package/esm/commands/sync/sync.d.ts.map +1 -1
- package/esm/commands/sync/sync.js +19 -23
- package/esm/commands/sync/sync.js.map +1 -1
- package/esm/commands/tcpip.d.ts +2 -2
- package/esm/commands/tcpip.d.ts.map +1 -1
- package/esm/commands/tcpip.js +4 -2
- package/esm/commands/tcpip.js.map +1 -1
- package/esm/{auth.d.ts → daemon/auth.d.ts} +1 -2
- package/esm/daemon/auth.d.ts.map +1 -0
- package/esm/{auth.js → daemon/auth.js} +14 -14
- package/esm/daemon/auth.js.map +1 -0
- package/esm/daemon/connection.d.ts +11 -0
- package/esm/daemon/connection.d.ts.map +1 -0
- package/esm/daemon/connection.js +2 -0
- package/esm/daemon/connection.js.map +1 -0
- package/esm/{crypto.d.ts → daemon/crypto.d.ts} +5 -5
- package/esm/daemon/crypto.d.ts.map +1 -0
- package/esm/{crypto.js → daemon/crypto.js} +23 -27
- package/esm/daemon/crypto.js.map +1 -0
- package/esm/{backend.d.ts → daemon/device.d.ts} +2 -2
- package/esm/daemon/device.d.ts.map +1 -0
- package/esm/daemon/device.js +2 -0
- package/esm/daemon/device.js.map +1 -0
- package/esm/{socket → daemon}/dispatcher.d.ts +8 -26
- package/esm/daemon/dispatcher.d.ts.map +1 -0
- package/esm/{socket → daemon}/dispatcher.js +65 -63
- package/esm/daemon/dispatcher.js.map +1 -0
- package/esm/daemon/index.d.ts +8 -0
- package/esm/daemon/index.d.ts.map +1 -0
- package/esm/daemon/index.js +8 -0
- package/esm/daemon/index.js.map +1 -0
- package/esm/{packet.d.ts → daemon/packet.d.ts} +4 -4
- package/esm/daemon/packet.d.ts.map +1 -0
- package/esm/{packet.js → daemon/packet.js} +1 -1
- package/esm/daemon/packet.js.map +1 -0
- package/esm/{socket → daemon}/socket.d.ts +15 -17
- package/esm/daemon/socket.d.ts.map +1 -0
- package/esm/{socket → daemon}/socket.js +38 -35
- package/esm/daemon/socket.js.map +1 -0
- package/esm/daemon/transport.d.ts +45 -0
- package/esm/daemon/transport.d.ts.map +1 -0
- package/esm/daemon/transport.js +184 -0
- package/esm/daemon/transport.js.map +1 -0
- package/esm/index.d.ts +3 -5
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +3 -5
- package/esm/index.js.map +1 -1
- package/esm/server/client.d.ts +78 -0
- package/esm/server/client.d.ts.map +1 -0
- package/esm/server/client.js +329 -0
- package/esm/server/client.js.map +1 -0
- package/esm/server/index.d.ts +3 -0
- package/esm/server/index.d.ts.map +1 -0
- package/esm/server/index.js +3 -0
- package/esm/server/index.js.map +1 -0
- package/esm/server/transport.d.ts +19 -0
- package/esm/server/transport.d.ts.map +1 -0
- package/esm/server/transport.js +44 -0
- package/esm/server/transport.js.map +1 -0
- package/esm/utils/auto-reset-event.d.ts +1 -2
- package/esm/utils/auto-reset-event.d.ts.map +1 -1
- package/esm/utils/auto-reset-event.js +12 -12
- package/esm/utils/auto-reset-event.js.map +1 -1
- package/esm/utils/base64.js +5 -5
- package/esm/utils/base64.js.map +1 -1
- package/esm/utils/conditional-variable.d.ts +1 -2
- package/esm/utils/conditional-variable.d.ts.map +1 -1
- package/esm/utils/conditional-variable.js +10 -10
- package/esm/utils/conditional-variable.js.map +1 -1
- package/esm/utils/hex.d.ts +3 -0
- package/esm/utils/hex.d.ts.map +1 -0
- package/esm/utils/hex.js +55 -0
- package/esm/utils/hex.js.map +1 -0
- package/esm/utils/index.d.ts +2 -0
- package/esm/utils/index.d.ts.map +1 -1
- package/esm/utils/index.js +2 -0
- package/esm/utils/index.js.map +1 -1
- package/esm/utils/no-op.d.ts +7 -0
- package/esm/utils/no-op.d.ts.map +1 -0
- package/esm/utils/no-op.js +12 -0
- package/esm/utils/no-op.js.map +1 -0
- package/package.json +11 -10
- package/src/adb.ts +41 -252
- package/src/banner.ts +82 -0
- package/src/commands/power.ts +2 -2
- package/src/commands/reverse.ts +68 -73
- package/src/commands/subprocess/protocols/none.ts +17 -18
- package/src/commands/subprocess/protocols/shell.ts +54 -56
- package/src/commands/subprocess/protocols/types.ts +1 -2
- package/src/commands/sync/list.ts +2 -2
- package/src/commands/sync/push.ts +22 -10
- package/src/commands/sync/request.ts +1 -1
- package/src/commands/sync/response.ts +6 -6
- package/src/commands/sync/socket.ts +37 -35
- package/src/commands/sync/sync.ts +25 -28
- package/src/commands/tcpip.ts +6 -4
- package/src/{auth.ts → daemon/auth.ts} +17 -17
- package/src/{crypto.ts → daemon/crypto.ts} +25 -33
- package/src/{backend.ts → daemon/device.ts} +1 -1
- package/src/{socket → daemon}/dispatcher.ts +71 -78
- package/src/daemon/index.ts +7 -0
- package/src/{packet.ts → daemon/packet.ts} +5 -5
- package/src/{socket → daemon}/socket.ts +50 -44
- package/src/daemon/transport.ts +269 -0
- package/src/index.ts +3 -5
- package/src/server/client.ts +476 -0
- package/src/server/index.ts +2 -0
- package/src/server/transport.ts +77 -0
- package/src/utils/auto-reset-event.ts +12 -12
- package/src/utils/conditional-variable.ts +10 -10
- package/src/utils/hex.ts +58 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/no-op.ts +12 -0
- package/tsconfig.build.json +12 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/esm/auth.d.ts.map +0 -1
- package/esm/auth.js.map +0 -1
- package/esm/backend.d.ts.map +0 -1
- package/esm/backend.js +0 -2
- package/esm/backend.js.map +0 -1
- package/esm/commands/install.d.ts +0 -10
- package/esm/commands/install.d.ts.map +0 -1
- package/esm/commands/install.js +0 -29
- package/esm/commands/install.js.map +0 -1
- package/esm/crypto.d.ts.map +0 -1
- package/esm/crypto.js.map +0 -1
- package/esm/packet.d.ts.map +0 -1
- package/esm/packet.js.map +0 -1
- package/esm/socket/dispatcher.d.ts.map +0 -1
- package/esm/socket/dispatcher.js.map +0 -1
- package/esm/socket/index.d.ts +0 -3
- package/esm/socket/index.d.ts.map +0 -1
- package/esm/socket/index.js +0 -3
- package/esm/socket/index.js.map +0 -1
- package/esm/socket/socket.d.ts.map +0 -1
- package/esm/socket/socket.js.map +0 -1
- package/src/socket/index.ts +0 -2
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { PromiseResolver } from "@yume-chan/async";
|
|
2
2
|
import { ConsumableWritableStream, DistributionStream, DuplexStreamFactory, PushReadableStream, pipeFrom, } from "@yume-chan/stream-extra";
|
|
3
|
-
import { AdbCommand } from "
|
|
4
|
-
export class
|
|
3
|
+
import { AdbCommand } from "./packet.js";
|
|
4
|
+
export class AdbDaemonSocketController {
|
|
5
5
|
dispatcher;
|
|
6
6
|
localId;
|
|
7
7
|
remoteId;
|
|
8
8
|
localCreated;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
service;
|
|
10
|
+
#duplex;
|
|
11
|
+
#readable;
|
|
12
|
+
#readableController;
|
|
13
13
|
get readable() {
|
|
14
|
-
return this
|
|
14
|
+
return this.#readable;
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
#writePromise;
|
|
17
17
|
writable;
|
|
18
|
-
|
|
18
|
+
#closed = false;
|
|
19
19
|
/**
|
|
20
20
|
* Whether the socket is half-closed (i.e. the local side initiated the close).
|
|
21
21
|
*
|
|
22
22
|
* It's only used by dispatcher to avoid sending another `CLSE` packet to remote.
|
|
23
23
|
*/
|
|
24
24
|
get closed() {
|
|
25
|
-
return this
|
|
25
|
+
return this.#closed;
|
|
26
26
|
}
|
|
27
27
|
_socket;
|
|
28
28
|
get socket() {
|
|
@@ -33,52 +33,52 @@ export class AdbSocketController {
|
|
|
33
33
|
// Check this image to help you understand the stream graph
|
|
34
34
|
// cspell: disable-next-line
|
|
35
35
|
// https://www.plantuml.com/plantuml/png/TL0zoeGm4ErpYc3l5JxyS0yWM6mX5j4C6p4cxcJ25ejttuGX88ZftizxUKmJI275pGhXl0PP_UkfK_CAz5Z2hcWsW9Ny2fdU4C1f5aSchFVxA8vJjlTPRhqZzDQMRB7AklwJ0xXtX0ZSKH1h24ghoKAdGY23FhxC4nS2pDvxzIvxb-8THU0XlEQJ-ZB7SnXTAvc_LhOckhMdLBnbtndpb-SB7a8q2SRD_W00
|
|
36
|
-
this
|
|
36
|
+
this.#duplex = new DuplexStreamFactory({
|
|
37
37
|
close: async () => {
|
|
38
|
-
this
|
|
38
|
+
this.#closed = true;
|
|
39
39
|
await this.dispatcher.sendPacket(AdbCommand.Close, this.localId, this.remoteId);
|
|
40
40
|
// Don't `dispose` here, we need to wait for `CLSE` response packet.
|
|
41
41
|
return false;
|
|
42
42
|
},
|
|
43
43
|
dispose: () => {
|
|
44
44
|
// Error out the pending writes
|
|
45
|
-
this
|
|
45
|
+
this.#writePromise?.reject(new Error("Socket closed"));
|
|
46
46
|
},
|
|
47
47
|
});
|
|
48
|
-
this
|
|
49
|
-
this
|
|
48
|
+
this.#readable = this.#duplex.wrapReadable(new PushReadableStream((controller) => {
|
|
49
|
+
this.#readableController = controller;
|
|
50
50
|
}, {
|
|
51
51
|
highWaterMark: options.highWaterMark ?? 16 * 1024,
|
|
52
52
|
size(chunk) {
|
|
53
53
|
return chunk.byteLength;
|
|
54
54
|
},
|
|
55
55
|
}));
|
|
56
|
-
this.writable = pipeFrom(this.
|
|
56
|
+
this.writable = pipeFrom(this.#duplex.createWritable(new ConsumableWritableStream({
|
|
57
57
|
write: async (chunk) => {
|
|
58
58
|
// Wait for an ack packet
|
|
59
|
-
this
|
|
59
|
+
this.#writePromise = new PromiseResolver();
|
|
60
60
|
await this.dispatcher.sendPacket(AdbCommand.Write, this.localId, this.remoteId, chunk);
|
|
61
|
-
await this.
|
|
61
|
+
await this.#writePromise.promise;
|
|
62
62
|
},
|
|
63
63
|
})), new DistributionStream(this.dispatcher.options.maxPayloadSize));
|
|
64
|
-
this._socket = new
|
|
64
|
+
this._socket = new AdbDaemonSocket(this);
|
|
65
65
|
}
|
|
66
66
|
async enqueue(data) {
|
|
67
67
|
// Consumer may abort the `ReadableStream` to close the socket,
|
|
68
68
|
// it's OK to throw away further packets in this case.
|
|
69
|
-
if (this.
|
|
69
|
+
if (this.#readableController.abortSignal.aborted) {
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
|
-
await this.
|
|
72
|
+
await this.#readableController.enqueue(data);
|
|
73
73
|
}
|
|
74
74
|
ack() {
|
|
75
|
-
this
|
|
75
|
+
this.#writePromise?.resolve();
|
|
76
76
|
}
|
|
77
77
|
async close() {
|
|
78
|
-
await this.
|
|
78
|
+
await this.#duplex.close();
|
|
79
79
|
}
|
|
80
80
|
dispose() {
|
|
81
|
-
return this.
|
|
81
|
+
return this.#duplex.dispose();
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
@@ -89,31 +89,34 @@ export class AdbSocketController {
|
|
|
89
89
|
* `socket.writable.abort()`, `socket.writable.getWriter().abort()`,
|
|
90
90
|
* `socket.writable.close()` or `socket.writable.getWriter().close()`.
|
|
91
91
|
*/
|
|
92
|
-
export class
|
|
93
|
-
|
|
92
|
+
export class AdbDaemonSocket {
|
|
93
|
+
#controller;
|
|
94
94
|
get localId() {
|
|
95
|
-
return this.
|
|
95
|
+
return this.#controller.localId;
|
|
96
96
|
}
|
|
97
97
|
get remoteId() {
|
|
98
|
-
return this.
|
|
98
|
+
return this.#controller.remoteId;
|
|
99
99
|
}
|
|
100
100
|
get localCreated() {
|
|
101
|
-
return this.
|
|
101
|
+
return this.#controller.localCreated;
|
|
102
102
|
}
|
|
103
|
-
get
|
|
104
|
-
return this.
|
|
103
|
+
get service() {
|
|
104
|
+
return this.#controller.service;
|
|
105
105
|
}
|
|
106
106
|
get readable() {
|
|
107
|
-
return this.
|
|
107
|
+
return this.#controller.readable;
|
|
108
108
|
}
|
|
109
109
|
get writable() {
|
|
110
|
-
return this.
|
|
110
|
+
return this.#controller.writable;
|
|
111
|
+
}
|
|
112
|
+
get closed() {
|
|
113
|
+
return this.#controller.closed;
|
|
111
114
|
}
|
|
112
115
|
constructor(controller) {
|
|
113
|
-
this
|
|
116
|
+
this.#controller = controller;
|
|
114
117
|
}
|
|
115
118
|
close() {
|
|
116
|
-
return this.
|
|
119
|
+
return this.#controller.close();
|
|
117
120
|
}
|
|
118
121
|
}
|
|
119
122
|
//# sourceMappingURL=socket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket.js","sourceRoot":"","sources":["../../src/daemon/socket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AASnD,OAAO,EACH,wBAAwB,EACxB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,QAAQ,GACX,MAAM,yBAAyB,CAAC;AAKjC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAiBzC,MAAM,OAAO,yBAAyB;IAOjB,UAAU,CAAuB;IAElC,OAAO,CAAU;IACjB,QAAQ,CAAU;IAClB,YAAY,CAAW;IACvB,OAAO,CAAU;IAEjC,OAAO,CAA0D;IAEjE,SAAS,CAA6B;IACtC,mBAAmB,CAA4C;IAC/D,IAAW,QAAQ;QACf,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED,aAAa,CAAoC;IACjC,QAAQ,CAAyC;IAEjE,OAAO,GAAG,KAAK,CAAC;IAChB;;;;OAIG;IACH,IAAW,MAAM;QACb,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAEO,OAAO,CAAkB;IACjC,IAAW,MAAM;QACb,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,YAAmB,OAA2C;QAC1D,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAE7B,2DAA2D;QAC3D,4BAA4B;QAC5B,6QAA6Q;QAE7Q,IAAI,CAAC,OAAO,GAAG,IAAI,mBAAmB,CAGpC;YACE,KAAK,EAAE,KAAK,IAAI,EAAE;gBACd,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;gBAEp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,KAAK,EAAE,CAAC;IACpC,CAAC;CACJ"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Consumable, ReadableWritablePair } from "@yume-chan/stream-extra";
|
|
2
|
+
import type { ValueOrPromise } from "@yume-chan/struct";
|
|
3
|
+
import type { AdbIncomingSocketHandler, AdbSocket, AdbTransport } from "../adb.js";
|
|
4
|
+
import { AdbBanner } from "../banner.js";
|
|
5
|
+
import type { AdbAuthenticator, AdbCredentialStore } from "./auth.js";
|
|
6
|
+
import type { AdbPacketData, AdbPacketInit } from "./packet.js";
|
|
7
|
+
export declare const ADB_DAEMON_VERSION_OMIT_CHECKSUM = 16777217;
|
|
8
|
+
interface AdbDaemonAuthenticationOptions {
|
|
9
|
+
serial: string;
|
|
10
|
+
connection: ReadableWritablePair<AdbPacketData, Consumable<AdbPacketInit>>;
|
|
11
|
+
credentialStore: AdbCredentialStore;
|
|
12
|
+
authenticators?: AdbAuthenticator[];
|
|
13
|
+
}
|
|
14
|
+
interface AdbDaemonSocketConnectorConstructionOptions {
|
|
15
|
+
serial: string;
|
|
16
|
+
connection: ReadableWritablePair<AdbPacketData, Consumable<AdbPacketInit>>;
|
|
17
|
+
version: number;
|
|
18
|
+
maxPayloadSize: number;
|
|
19
|
+
banner: string;
|
|
20
|
+
}
|
|
21
|
+
export declare class AdbDaemonTransport implements AdbTransport {
|
|
22
|
+
#private;
|
|
23
|
+
/**
|
|
24
|
+
* Authenticates the connection and creates an `AdbDaemonTransport` instance
|
|
25
|
+
* that can be used by `Adb` class.
|
|
26
|
+
*
|
|
27
|
+
* If an authentication process failed, it's possible to call `authenticate` again
|
|
28
|
+
* on the same connection. Because every time the device receives a `CNXN` packet,
|
|
29
|
+
* it resets all internal state, and starts a new authentication process.
|
|
30
|
+
*/
|
|
31
|
+
static authenticate({ serial, connection, credentialStore, authenticators, }: AdbDaemonAuthenticationOptions): Promise<AdbDaemonTransport>;
|
|
32
|
+
get serial(): string;
|
|
33
|
+
get protocolVersion(): number;
|
|
34
|
+
get maxPayloadSize(): number;
|
|
35
|
+
get banner(): AdbBanner;
|
|
36
|
+
get disconnected(): Promise<void>;
|
|
37
|
+
constructor({ serial, connection, version, maxPayloadSize, banner, }: AdbDaemonSocketConnectorConstructionOptions);
|
|
38
|
+
connect(service: string): ValueOrPromise<AdbSocket>;
|
|
39
|
+
addReverseTunnel(handler: AdbIncomingSocketHandler, address?: string): string;
|
|
40
|
+
removeReverseTunnel(address: string): void;
|
|
41
|
+
clearReverseTunnels(): void;
|
|
42
|
+
close(): ValueOrPromise<void>;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/daemon/transport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAMhF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,OAAO,KAAK,EACR,wBAAwB,EACxB,SAAS,EACT,YAAY,EACf,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAMtE,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGhE,eAAO,MAAM,gCAAgC,WAAa,CAAC;AAE3D,UAAU,8BAA8B;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,oBAAoB,CAAC,aAAa,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC;IAC3E,eAAe,EAAE,kBAAkB,CAAC;IACpC,cAAc,CAAC,EAAE,gBAAgB,EAAE,CAAC;CACvC;AAED,UAAU,2CAA2C;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,oBAAoB,CAAC,aAAa,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC;IAC3E,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,kBAAmB,YAAW,YAAY;;IACnD;;;;;;;OAOG;WACiB,YAAY,CAAC,EAC7B,MAAM,EACN,UAAU,EACV,eAAe,EACf,cAA2C,GAC9C,EAAE,8BAA8B,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAkI/D,IAAW,MAAM,WAEhB;IAGD,IAAW,eAAe,WAEzB;IAGD,IAAW,cAAc,WAExB;IAGD,IAAW,MAAM,cAEhB;IAED,IAAW,YAAY,kBAEtB;gBAEkB,EACf,MAAM,EACN,UAAU,EACV,OAAO,EACP,cAAc,EACd,MAAM,GACT,EAAE,2CAA2C;IAwBvC,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,CAAC,SAAS,CAAC;IAInD,gBAAgB,CACnB,OAAO,EAAE,wBAAwB,EACjC,OAAO,CAAC,EAAE,MAAM,GACjB,MAAM;IASF,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAI1C,mBAAmB,IAAI,IAAI;IAI3B,KAAK,IAAI,cAAc,CAAC,IAAI,CAAC;CAGvC"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { PromiseResolver } from "@yume-chan/async";
|
|
2
|
+
import { AbortController, ConsumableWritableStream, WritableStream, } from "@yume-chan/stream-extra";
|
|
3
|
+
import { decodeUtf8, encodeUtf8 } from "@yume-chan/struct";
|
|
4
|
+
import { AdbBanner } from "../banner.js";
|
|
5
|
+
import { AdbFeature } from "../features.js";
|
|
6
|
+
import { ADB_DEFAULT_AUTHENTICATORS, AdbAuthenticationProcessor, } from "./auth.js";
|
|
7
|
+
import { AdbPacketDispatcher } from "./dispatcher.js";
|
|
8
|
+
import { AdbCommand, calculateChecksum } from "./packet.js";
|
|
9
|
+
export const ADB_DAEMON_VERSION_OMIT_CHECKSUM = 0x01000001;
|
|
10
|
+
export class AdbDaemonTransport {
|
|
11
|
+
/**
|
|
12
|
+
* Authenticates the connection and creates an `AdbDaemonTransport` instance
|
|
13
|
+
* that can be used by `Adb` class.
|
|
14
|
+
*
|
|
15
|
+
* If an authentication process failed, it's possible to call `authenticate` again
|
|
16
|
+
* on the same connection. Because every time the device receives a `CNXN` packet,
|
|
17
|
+
* it resets all internal state, and starts a new authentication process.
|
|
18
|
+
*/
|
|
19
|
+
static async authenticate({ serial, connection, credentialStore, authenticators = ADB_DEFAULT_AUTHENTICATORS, }) {
|
|
20
|
+
// Initially, set to highest-supported version and payload size.
|
|
21
|
+
let version = 0x01000001;
|
|
22
|
+
// Android 4: 4K, Android 7: 256K, Android 9: 1M
|
|
23
|
+
let maxPayloadSize = 1024 * 1024;
|
|
24
|
+
const resolver = new PromiseResolver();
|
|
25
|
+
const authProcessor = new AdbAuthenticationProcessor(authenticators, credentialStore);
|
|
26
|
+
// Here is similar to `AdbPacketDispatcher`,
|
|
27
|
+
// But the received packet types and send packet processing are different.
|
|
28
|
+
const abortController = new AbortController();
|
|
29
|
+
const pipe = connection.readable
|
|
30
|
+
.pipeTo(new WritableStream({
|
|
31
|
+
async write(packet) {
|
|
32
|
+
switch (packet.command) {
|
|
33
|
+
case AdbCommand.Connect:
|
|
34
|
+
version = Math.min(version, packet.arg0);
|
|
35
|
+
maxPayloadSize = Math.min(maxPayloadSize, packet.arg1);
|
|
36
|
+
resolver.resolve(decodeUtf8(packet.payload));
|
|
37
|
+
break;
|
|
38
|
+
case AdbCommand.Auth: {
|
|
39
|
+
const response = await authProcessor.process(packet);
|
|
40
|
+
await sendPacket(response);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
default:
|
|
44
|
+
// Maybe the previous ADB client exited without reading all packets,
|
|
45
|
+
// so they are still waiting in OS internal buffer.
|
|
46
|
+
// Just ignore them.
|
|
47
|
+
// Because a `Connect` packet will reset the device,
|
|
48
|
+
// Eventually there will be `Connect` and `Auth` response packets.
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
}), {
|
|
53
|
+
// Don't cancel the source ReadableStream on AbortSignal abort.
|
|
54
|
+
preventCancel: true,
|
|
55
|
+
signal: abortController.signal,
|
|
56
|
+
})
|
|
57
|
+
.then(() => {
|
|
58
|
+
if (resolver.state === "running") {
|
|
59
|
+
resolver.reject(new Error("Connection closed unexpectedly"));
|
|
60
|
+
}
|
|
61
|
+
}, (e) => {
|
|
62
|
+
resolver.reject(e);
|
|
63
|
+
});
|
|
64
|
+
const writer = connection.writable.getWriter();
|
|
65
|
+
async function sendPacket(init) {
|
|
66
|
+
// Always send checksum in auth steps
|
|
67
|
+
// Because we don't know if the device needs it or not.
|
|
68
|
+
init.checksum = calculateChecksum(init.payload);
|
|
69
|
+
init.magic = init.command ^ 0xffffffff;
|
|
70
|
+
await ConsumableWritableStream.write(writer, init);
|
|
71
|
+
}
|
|
72
|
+
let banner;
|
|
73
|
+
try {
|
|
74
|
+
// https://android.googlesource.com/platform/packages/modules/adb/+/79010dc6d5ca7490c493df800d4421730f5466ca/transport.cpp#1252
|
|
75
|
+
// There are some other feature constants, but some of them are only used by ADB server, not devices (daemons).
|
|
76
|
+
const features = [
|
|
77
|
+
AdbFeature.ShellV2,
|
|
78
|
+
AdbFeature.Cmd,
|
|
79
|
+
AdbFeature.StatV2,
|
|
80
|
+
AdbFeature.ListV2,
|
|
81
|
+
AdbFeature.FixedPushMkdir,
|
|
82
|
+
"apex",
|
|
83
|
+
AdbFeature.Abb,
|
|
84
|
+
// only tells the client the symlink timestamp issue in `adb push --sync` has been fixed.
|
|
85
|
+
// No special handling required.
|
|
86
|
+
"fixed_push_symlink_timestamp",
|
|
87
|
+
AdbFeature.AbbExec,
|
|
88
|
+
"remount_shell",
|
|
89
|
+
"track_app",
|
|
90
|
+
"sendrecv_v2",
|
|
91
|
+
"sendrecv_v2_brotli",
|
|
92
|
+
"sendrecv_v2_lz4",
|
|
93
|
+
"sendrecv_v2_zstd",
|
|
94
|
+
"sendrecv_v2_dry_run_send",
|
|
95
|
+
].join(",");
|
|
96
|
+
await sendPacket({
|
|
97
|
+
command: AdbCommand.Connect,
|
|
98
|
+
arg0: version,
|
|
99
|
+
arg1: maxPayloadSize,
|
|
100
|
+
// The terminating `;` is required in formal definition
|
|
101
|
+
// But ADB daemon (all versions) can still work without it
|
|
102
|
+
payload: encodeUtf8(`host::features=${features}`),
|
|
103
|
+
});
|
|
104
|
+
banner = await resolver.promise;
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
// When failed, release locks on `connection` so the caller can try again.
|
|
108
|
+
// When success, also release locks so `AdbPacketDispatcher` can use them.
|
|
109
|
+
abortController.abort();
|
|
110
|
+
writer.releaseLock();
|
|
111
|
+
// Wait until pipe stops (`ReadableStream` lock released)
|
|
112
|
+
await pipe;
|
|
113
|
+
}
|
|
114
|
+
return new AdbDaemonTransport({
|
|
115
|
+
serial,
|
|
116
|
+
connection,
|
|
117
|
+
version,
|
|
118
|
+
maxPayloadSize,
|
|
119
|
+
banner,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
#dispatcher;
|
|
123
|
+
#serial;
|
|
124
|
+
get serial() {
|
|
125
|
+
return this.#serial;
|
|
126
|
+
}
|
|
127
|
+
#protocolVersion;
|
|
128
|
+
get protocolVersion() {
|
|
129
|
+
return this.#protocolVersion;
|
|
130
|
+
}
|
|
131
|
+
#maxPayloadSize;
|
|
132
|
+
get maxPayloadSize() {
|
|
133
|
+
return this.#maxPayloadSize;
|
|
134
|
+
}
|
|
135
|
+
#banner;
|
|
136
|
+
get banner() {
|
|
137
|
+
return this.#banner;
|
|
138
|
+
}
|
|
139
|
+
get disconnected() {
|
|
140
|
+
return this.#dispatcher.disconnected;
|
|
141
|
+
}
|
|
142
|
+
constructor({ serial, connection, version, maxPayloadSize, banner, }) {
|
|
143
|
+
this.#serial = serial;
|
|
144
|
+
this.#banner = AdbBanner.parse(banner);
|
|
145
|
+
let calculateChecksum;
|
|
146
|
+
let appendNullToServiceString;
|
|
147
|
+
if (version >= ADB_DAEMON_VERSION_OMIT_CHECKSUM) {
|
|
148
|
+
calculateChecksum = false;
|
|
149
|
+
appendNullToServiceString = false;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
calculateChecksum = true;
|
|
153
|
+
appendNullToServiceString = true;
|
|
154
|
+
}
|
|
155
|
+
this.#dispatcher = new AdbPacketDispatcher(connection, {
|
|
156
|
+
calculateChecksum,
|
|
157
|
+
appendNullToServiceString,
|
|
158
|
+
maxPayloadSize,
|
|
159
|
+
});
|
|
160
|
+
this.#protocolVersion = version;
|
|
161
|
+
this.#maxPayloadSize = maxPayloadSize;
|
|
162
|
+
}
|
|
163
|
+
connect(service) {
|
|
164
|
+
return this.#dispatcher.createSocket(service);
|
|
165
|
+
}
|
|
166
|
+
addReverseTunnel(handler, address) {
|
|
167
|
+
if (!address) {
|
|
168
|
+
const id = Math.random().toString().substring(2);
|
|
169
|
+
address = `localabstract:reverse_${id}`;
|
|
170
|
+
}
|
|
171
|
+
this.#dispatcher.addReverseTunnel(address, handler);
|
|
172
|
+
return address;
|
|
173
|
+
}
|
|
174
|
+
removeReverseTunnel(address) {
|
|
175
|
+
this.#dispatcher.removeReverseTunnel(address);
|
|
176
|
+
}
|
|
177
|
+
clearReverseTunnels() {
|
|
178
|
+
this.#dispatcher.clearReverseTunnels();
|
|
179
|
+
}
|
|
180
|
+
close() {
|
|
181
|
+
return this.#dispatcher.close();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/daemon/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EACH,eAAe,EACf,wBAAwB,EACxB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mB,CAAC,OAAe;QACtC,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC;IAEM,mBAAmB;QACtB,IAAI,CAAC,WAAW,CAAC,mBAAmB,EAAE,CAAC;IAC3C,CAAC;IAEM,KAAK;QACR,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IACpC,CAAC;CACJ"}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export * from "./adb.js";
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./backend.js";
|
|
2
|
+
export * from "./banner.js";
|
|
4
3
|
export * from "./commands/index.js";
|
|
5
|
-
export * from "./
|
|
4
|
+
export * from "./daemon/index.js";
|
|
6
5
|
export * from "./features.js";
|
|
7
|
-
export * from "./
|
|
8
|
-
export * from "./socket/index.js";
|
|
6
|
+
export * from "./server/index.js";
|
|
9
7
|
export * from "./utils/index.js";
|
|
10
8
|
//# sourceMappingURL=index.d.ts.map
|
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
|
package/esm/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export * from "./adb.js";
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./backend.js";
|
|
2
|
+
export * from "./banner.js";
|
|
4
3
|
export * from "./commands/index.js";
|
|
5
|
-
export * from "./
|
|
4
|
+
export * from "./daemon/index.js";
|
|
6
5
|
export * from "./features.js";
|
|
7
|
-
export * from "./
|
|
8
|
-
export * from "./socket/index.js";
|
|
6
|
+
export * from "./server/index.js";
|
|
9
7
|
export * from "./utils/index.js";
|
|
10
8
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { AbortSignal, ReadableWritablePair, WritableStreamDefaultWriter } from "@yume-chan/stream-extra";
|
|
2
|
+
import type { AsyncExactReadable, ExactReadable, ValueOrPromise } from "@yume-chan/struct";
|
|
3
|
+
import type { AdbIncomingSocketHandler, AdbSocket } from "../adb.js";
|
|
4
|
+
import type { AdbFeature } from "../features.js";
|
|
5
|
+
import { AdbServerTransport } from "./transport.js";
|
|
6
|
+
export interface AdbServerConnectionOptions {
|
|
7
|
+
unref?: boolean | undefined;
|
|
8
|
+
signal?: AbortSignal | undefined;
|
|
9
|
+
}
|
|
10
|
+
export interface AdbServerConnection {
|
|
11
|
+
connect(options?: AdbServerConnectionOptions): ValueOrPromise<ReadableWritablePair<Uint8Array, Uint8Array>>;
|
|
12
|
+
addReverseTunnel(handler: AdbIncomingSocketHandler, address?: string): ValueOrPromise<string>;
|
|
13
|
+
removeReverseTunnel(address: string): ValueOrPromise<void>;
|
|
14
|
+
clearReverseTunnels(): ValueOrPromise<void>;
|
|
15
|
+
}
|
|
16
|
+
export interface AdbServerSocket extends AdbSocket {
|
|
17
|
+
transportId: bigint;
|
|
18
|
+
}
|
|
19
|
+
export type AdbServerDeviceSelector = {
|
|
20
|
+
serial: string;
|
|
21
|
+
} | {
|
|
22
|
+
transportId: bigint;
|
|
23
|
+
} | {
|
|
24
|
+
usb: true;
|
|
25
|
+
} | {
|
|
26
|
+
tcp: true;
|
|
27
|
+
} | undefined;
|
|
28
|
+
export interface AdbServerDevice {
|
|
29
|
+
serial: string;
|
|
30
|
+
product?: string | undefined;
|
|
31
|
+
model?: string | undefined;
|
|
32
|
+
device?: string | undefined;
|
|
33
|
+
transportId: bigint;
|
|
34
|
+
}
|
|
35
|
+
export declare class AdbServerClient {
|
|
36
|
+
static readonly VERSION = 41;
|
|
37
|
+
readonly connection: AdbServerConnection;
|
|
38
|
+
constructor(connection: AdbServerConnection);
|
|
39
|
+
static readString(stream: ExactReadable): string;
|
|
40
|
+
static readString(stream: AsyncExactReadable): PromiseLike<string>;
|
|
41
|
+
static writeString(writer: WritableStreamDefaultWriter<Uint8Array>, value: string): Promise<void>;
|
|
42
|
+
static readOkay(stream: ExactReadable | AsyncExactReadable): Promise<void>;
|
|
43
|
+
connect(request: string, options?: AdbServerConnectionOptions): Promise<ReadableWritablePair<Uint8Array, Uint8Array>>;
|
|
44
|
+
getVersion(): Promise<number>;
|
|
45
|
+
validateVersion(): Promise<void>;
|
|
46
|
+
killServer(): Promise<void>;
|
|
47
|
+
getServerFeatures(): Promise<AdbFeature[]>;
|
|
48
|
+
getDevices(): Promise<AdbServerDevice[]>;
|
|
49
|
+
formatDeviceService(device: AdbServerDeviceSelector, command: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* Gets the features supported by the device.
|
|
52
|
+
* The transport ID of the selected device is also returned,
|
|
53
|
+
* so the caller can execute other commands against the same device.
|
|
54
|
+
* @param device The device selector
|
|
55
|
+
* @returns The transport ID of the selected device, and the features supported by the device.
|
|
56
|
+
*/
|
|
57
|
+
getDeviceFeatures(device: AdbServerDeviceSelector): Promise<{
|
|
58
|
+
transportId: bigint;
|
|
59
|
+
features: AdbFeature[];
|
|
60
|
+
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Creates a connection that will forward the service to device.
|
|
63
|
+
* @param device The device selector
|
|
64
|
+
* @param service The service to forward
|
|
65
|
+
* @returns An `AdbServerSocket` that can be used to communicate with the service
|
|
66
|
+
*/
|
|
67
|
+
connectDevice(device: AdbServerDeviceSelector, service: string): Promise<AdbServerSocket>;
|
|
68
|
+
/**
|
|
69
|
+
* Wait for a device to be connected or disconnected.
|
|
70
|
+
* @param device The device selector
|
|
71
|
+
* @param state The state to wait for
|
|
72
|
+
* @param options The options
|
|
73
|
+
* @returns A promise that resolves when the condition is met.
|
|
74
|
+
*/
|
|
75
|
+
waitFor(device: AdbServerDeviceSelector, state: "device" | "disconnect", options?: AdbServerConnectionOptions): Promise<void>;
|
|
76
|
+
createTransport(device: AdbServerDeviceSelector): Promise<AdbServerTransport>;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/server/client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACR,WAAW,EAEX,oBAAoB,EACpB,2BAA2B,EAC9B,MAAM,yBAAyB,CAAC;AAOjC,OAAO,KAAK,EACR,kBAAkB,EAClB,aAAa,EACb,cAAc,EACjB,MAAM,mBAAmB,CAAC;AAQ3B,OAAO,KAAK,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAErE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,MAAM,WAAW,0BAA0B;IACvC,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B,MAAM,CAAC,EAAE,WAAW,GAA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