@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
package/esm/adb.js
CHANGED
|
@@ -1,217 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AbortController, ConsumableWritableStream, DecodeUtf8Stream, GatherStringStream, WritableStream, } from "@yume-chan/stream-extra";
|
|
3
|
-
import { ADB_DEFAULT_AUTHENTICATORS, AdbAuthenticationProcessor, } from "./auth.js";
|
|
1
|
+
import { DecodeUtf8Stream, GatherStringStream } from "@yume-chan/stream-extra";
|
|
4
2
|
import { AdbPower, AdbReverseCommand, AdbSubprocess, AdbSync, AdbTcpIpCommand, escapeArg, framebuffer, } from "./commands/index.js";
|
|
5
|
-
import { AdbFeature } from "./features.js";
|
|
6
|
-
import { AdbCommand, calculateChecksum } from "./packet.js";
|
|
7
|
-
import { AdbPacketDispatcher } from "./socket/index.js";
|
|
8
|
-
import { decodeUtf8, encodeUtf8 } from "./utils/index.js";
|
|
9
|
-
export var AdbPropKey;
|
|
10
|
-
(function (AdbPropKey) {
|
|
11
|
-
AdbPropKey["Product"] = "ro.product.name";
|
|
12
|
-
AdbPropKey["Model"] = "ro.product.model";
|
|
13
|
-
AdbPropKey["Device"] = "ro.product.device";
|
|
14
|
-
AdbPropKey["Features"] = "features";
|
|
15
|
-
})(AdbPropKey = AdbPropKey || (AdbPropKey = {}));
|
|
16
|
-
export const VERSION_OMIT_CHECKSUM = 0x01000001;
|
|
17
3
|
export class Adb {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* and starts a new authentication process.
|
|
22
|
-
*/
|
|
23
|
-
static async authenticate(connection, credentialStore, authenticators = ADB_DEFAULT_AUTHENTICATORS) {
|
|
24
|
-
// Initially, set to highest-supported version and payload size.
|
|
25
|
-
let version = 0x01000001;
|
|
26
|
-
// Android 4: 4K, Android 7: 256K, Android 9: 1M
|
|
27
|
-
let maxPayloadSize = 1024 * 1024;
|
|
28
|
-
const resolver = new PromiseResolver();
|
|
29
|
-
const authProcessor = new AdbAuthenticationProcessor(authenticators, credentialStore);
|
|
30
|
-
// Here is similar to `AdbPacketDispatcher`,
|
|
31
|
-
// But the received packet types and send packet processing are different.
|
|
32
|
-
const abortController = new AbortController();
|
|
33
|
-
const pipe = connection.readable
|
|
34
|
-
.pipeTo(new WritableStream({
|
|
35
|
-
async write(packet) {
|
|
36
|
-
switch (packet.command) {
|
|
37
|
-
case AdbCommand.Connect:
|
|
38
|
-
version = Math.min(version, packet.arg0);
|
|
39
|
-
maxPayloadSize = Math.min(maxPayloadSize, packet.arg1);
|
|
40
|
-
resolver.resolve(decodeUtf8(packet.payload));
|
|
41
|
-
break;
|
|
42
|
-
case AdbCommand.Auth: {
|
|
43
|
-
const response = await authProcessor.process(packet);
|
|
44
|
-
await sendPacket(response);
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
default:
|
|
48
|
-
// Maybe the previous ADB client exited without reading all packets,
|
|
49
|
-
// so they are still waiting in OS internal buffer.
|
|
50
|
-
// Just ignore them.
|
|
51
|
-
// Because a `Connect` packet will reset the device,
|
|
52
|
-
// Eventually there will be `Connect` and `Auth` response packets.
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
}), {
|
|
57
|
-
// Don't cancel the source ReadableStream on AbortSignal abort.
|
|
58
|
-
preventCancel: true,
|
|
59
|
-
signal: abortController.signal,
|
|
60
|
-
})
|
|
61
|
-
.catch((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 Adb(connection, version, maxPayloadSize, banner);
|
|
4
|
+
transport;
|
|
5
|
+
get serial() {
|
|
6
|
+
return this.transport.serial;
|
|
115
7
|
}
|
|
116
|
-
dispatcher;
|
|
117
|
-
get disconnected() {
|
|
118
|
-
return this.dispatcher.disconnected;
|
|
119
|
-
}
|
|
120
|
-
_protocolVersion;
|
|
121
|
-
get protocolVersion() {
|
|
122
|
-
return this._protocolVersion;
|
|
123
|
-
}
|
|
124
|
-
_maxPayloadSize;
|
|
125
8
|
get maxPayloadSize() {
|
|
126
|
-
return this.
|
|
127
|
-
}
|
|
128
|
-
_product;
|
|
129
|
-
get product() {
|
|
130
|
-
return this._product;
|
|
9
|
+
return this.transport.maxPayloadSize;
|
|
131
10
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return this._model;
|
|
11
|
+
get banner() {
|
|
12
|
+
return this.transport.banner;
|
|
135
13
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return this._device;
|
|
139
|
-
}
|
|
140
|
-
_features = [];
|
|
141
|
-
get features() {
|
|
142
|
-
return this._features;
|
|
14
|
+
get disconnected() {
|
|
15
|
+
return this.transport.disconnected;
|
|
143
16
|
}
|
|
144
17
|
subprocess;
|
|
145
18
|
power;
|
|
146
19
|
reverse;
|
|
147
20
|
tcpip;
|
|
148
|
-
constructor(
|
|
149
|
-
this.
|
|
150
|
-
let calculateChecksum;
|
|
151
|
-
let appendNullToServiceString;
|
|
152
|
-
if (version >= VERSION_OMIT_CHECKSUM) {
|
|
153
|
-
calculateChecksum = false;
|
|
154
|
-
appendNullToServiceString = false;
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
calculateChecksum = true;
|
|
158
|
-
appendNullToServiceString = true;
|
|
159
|
-
}
|
|
160
|
-
this.dispatcher = new AdbPacketDispatcher(connection, {
|
|
161
|
-
calculateChecksum,
|
|
162
|
-
appendNullToServiceString,
|
|
163
|
-
maxPayloadSize,
|
|
164
|
-
});
|
|
165
|
-
this._protocolVersion = version;
|
|
166
|
-
this._maxPayloadSize = maxPayloadSize;
|
|
21
|
+
constructor(transport) {
|
|
22
|
+
this.transport = transport;
|
|
167
23
|
this.subprocess = new AdbSubprocess(this);
|
|
168
24
|
this.power = new AdbPower(this);
|
|
169
25
|
this.reverse = new AdbReverseCommand(this);
|
|
170
26
|
this.tcpip = new AdbTcpIpCommand(this);
|
|
171
27
|
}
|
|
172
|
-
parseBanner(banner) {
|
|
173
|
-
const pieces = banner.split("::");
|
|
174
|
-
if (pieces.length > 1) {
|
|
175
|
-
const props = pieces[1];
|
|
176
|
-
for (const prop of props.split(";")) {
|
|
177
|
-
if (!prop) {
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
const keyValue = prop.split("=");
|
|
181
|
-
if (keyValue.length !== 2) {
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
184
|
-
const [key, value] = keyValue;
|
|
185
|
-
switch (key) {
|
|
186
|
-
case AdbPropKey.Product:
|
|
187
|
-
this._product = value;
|
|
188
|
-
break;
|
|
189
|
-
case AdbPropKey.Model:
|
|
190
|
-
this._model = value;
|
|
191
|
-
break;
|
|
192
|
-
case AdbPropKey.Device:
|
|
193
|
-
this._device = value;
|
|
194
|
-
break;
|
|
195
|
-
case AdbPropKey.Features:
|
|
196
|
-
this._features = value.split(",");
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
28
|
supportsFeature(feature) {
|
|
203
|
-
return this.
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Add a handler for incoming socket.
|
|
207
|
-
* @param handler A function to call with new incoming sockets. It must return `true` if it accepts the socket.
|
|
208
|
-
* @returns A function to remove the handler.
|
|
209
|
-
*/
|
|
210
|
-
onIncomingSocket(handler) {
|
|
211
|
-
return this.dispatcher.onIncomingSocket(handler);
|
|
29
|
+
return this.banner.features.includes(feature);
|
|
212
30
|
}
|
|
213
31
|
async createSocket(service) {
|
|
214
|
-
return this.
|
|
32
|
+
return this.transport.connect(service);
|
|
215
33
|
}
|
|
216
34
|
async createSocketAndWait(service) {
|
|
217
35
|
const socket = await this.createSocket(service);
|
|
@@ -244,15 +62,8 @@ export class Adb {
|
|
|
244
62
|
async framebuffer() {
|
|
245
63
|
return framebuffer(this);
|
|
246
64
|
}
|
|
247
|
-
/**
|
|
248
|
-
* Close the ADB connection.
|
|
249
|
-
*
|
|
250
|
-
* Note that it won't close the streams from backends.
|
|
251
|
-
* The streams are both physically and logically intact,
|
|
252
|
-
* and can be reused.
|
|
253
|
-
*/
|
|
254
65
|
async close() {
|
|
255
|
-
await this.
|
|
66
|
+
await this.transport.close();
|
|
256
67
|
}
|
|
257
68
|
}
|
|
258
69
|
//# sourceMappingURL=adb.js.map
|
package/esm/adb.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adb.js","sourceRoot":"","sources":["../src/adb.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"adb.js","sourceRoot":"","sources":["../src/adb.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAK/E,OAAO,EACH,QAAQ,EACR,iBAAiB,EACjB,aAAa,EACb,OAAO,EACP,eAAe,EACf,SAAS,EACT,WAAW,GACd,MAAM,qBAAqB,CAAC;AAsC7B,MAAM,OAAO,GAAG;IACI,SAAS,CAAe;IAExC,IAAW,MAAM;QACb,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;IACjC,CAAC;IAED,IAAW,cAAc;QACrB,OAAO,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC;IACzC,CAAC;IAED,IAAW,MAAM;QACb,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;IACjC,CAAC;IAED,IAAW,YAAY;QACnB,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC;IACvC,CAAC;IAEe,UAAU,CAAgB;IAC1B,KAAK,CAAW;IAChB,OAAO,C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,UAAU,CAAC,kBAAkB,CAAC;YACpD,IAAI;YACJ,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACzC,YAAY;SACf,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAClB,CAAC;IAEM,KAAK,CAAC,IAAI;QACb,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAChD,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC;IAEM,KAAK,CAAC,WAAW;QACpB,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAEM,KAAK,CAAC,KAAK;QACd,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACjC,CAAC;CACJ"}
|
package/esm/banner.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AdbFeature } from "./features.js";
|
|
2
|
+
export declare enum AdbBannerKey {
|
|
3
|
+
Product = "ro.product.name",
|
|
4
|
+
Model = "ro.product.model",
|
|
5
|
+
Device = "ro.product.device",
|
|
6
|
+
Features = "features"
|
|
7
|
+
}
|
|
8
|
+
export declare class AdbBanner {
|
|
9
|
+
#private;
|
|
10
|
+
static parse(banner: string): AdbBanner;
|
|
11
|
+
get product(): string | undefined;
|
|
12
|
+
get model(): string | undefined;
|
|
13
|
+
get device(): string | undefined;
|
|
14
|
+
get features(): AdbFeature[];
|
|
15
|
+
constructor(product: string | undefined, model: string | undefined, device: string | undefined, features: AdbFeature[]);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=banner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"banner.d.ts","sourceRoot":"","sources":["../src/banner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,oBAAY,YAAY;IACpB,OAAO,oBAAoB;IAC3B,KAAK,qBAAqB;IAC1B,MAAM,sBAAsB;IAC5B,QAAQ,aAAa;CACxB;AAED,qBAAa,SAAS;;WACJ,KAAK,CAAC,MAAM,EAAE,MAAM;IAyClC,IAAW,OAAO,uBAEjB;IAGD,IAAW,KAAK,uBAEf;IAGD,IAAW,MAAM,uBAEhB;IAGD,IAAW,QAAQ,iBAElB;gBAGG,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,QAAQ,EAAE,UAAU,EAAE;CAO7B"}
|
package/esm/banner.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export var AdbBannerKey;
|
|
2
|
+
(function (AdbBannerKey) {
|
|
3
|
+
AdbBannerKey["Product"] = "ro.product.name";
|
|
4
|
+
AdbBannerKey["Model"] = "ro.product.model";
|
|
5
|
+
AdbBannerKey["Device"] = "ro.product.device";
|
|
6
|
+
AdbBannerKey["Features"] = "features";
|
|
7
|
+
})(AdbBannerKey = AdbBannerKey || (AdbBannerKey = {}));
|
|
8
|
+
export class AdbBanner {
|
|
9
|
+
static parse(banner) {
|
|
10
|
+
let product;
|
|
11
|
+
let model;
|
|
12
|
+
let device;
|
|
13
|
+
let features = [];
|
|
14
|
+
const pieces = banner.split("::");
|
|
15
|
+
if (pieces.length > 1) {
|
|
16
|
+
const props = pieces[1];
|
|
17
|
+
for (const prop of props.split(";")) {
|
|
18
|
+
if (!prop) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const keyValue = prop.split("=");
|
|
22
|
+
if (keyValue.length !== 2) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const [key, value] = keyValue;
|
|
26
|
+
switch (key) {
|
|
27
|
+
case AdbBannerKey.Product:
|
|
28
|
+
product = value;
|
|
29
|
+
break;
|
|
30
|
+
case AdbBannerKey.Model:
|
|
31
|
+
model = value;
|
|
32
|
+
break;
|
|
33
|
+
case AdbBannerKey.Device:
|
|
34
|
+
device = value;
|
|
35
|
+
break;
|
|
36
|
+
case AdbBannerKey.Features:
|
|
37
|
+
features = value.split(",");
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return new AdbBanner(product, model, device, features);
|
|
43
|
+
}
|
|
44
|
+
#product;
|
|
45
|
+
get product() {
|
|
46
|
+
return this.#product;
|
|
47
|
+
}
|
|
48
|
+
#model;
|
|
49
|
+
get model() {
|
|
50
|
+
return this.#model;
|
|
51
|
+
}
|
|
52
|
+
#device;
|
|
53
|
+
get device() {
|
|
54
|
+
return this.#device;
|
|
55
|
+
}
|
|
56
|
+
#features = [];
|
|
57
|
+
get features() {
|
|
58
|
+
return this.#features;
|
|
59
|
+
}
|
|
60
|
+
constructor(product, model, device, features) {
|
|
61
|
+
this.#product = product;
|
|
62
|
+
this.#model = model;
|
|
63
|
+
this.#device = device;
|
|
64
|
+
this.#features = features;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=banner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"banner.js","sourceRoot":"","sources":["../src/banner.ts"],"names":[],"mappings":"AAEA,MAAM,CAAN,IAAY,YAKX;AALD,WAAY,YAAY;IACpB,2CAA2B,CAAA;IAC3B,0CAA0B,CAAA;IAC1B,4CAA4B,CAAA;IAC5B,qCAAqB,CAAA;AACzB,CAAC,EALW,YAAY,GAAZ,YAAY,KAAZ,YAAY,QAKvB;AAED,MAAM,OAAO,SAAS;IACX,MAAM,CAAC,KAAK,CAAC,MAAc;QAC9B,IAAI,OAA2B,CAAC;QAChC,IAAI,KAAyB,CAAC;QAC9B,IAAI,MAA0B,CAAC;QAC/B,IAAI,QAAQ,GAAiB,EAAE,CAAC;QAEhC,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;Q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,CAAC;IAC1B,CAAC;IAED,YACI,OAA2B,EAC3B,KAAyB,EACzB,MAA0B,EAC1B,QAAsB;QAEtB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;CACJ"}
|
package/esm/commands/power.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AdbCommandBase } from "./base.js";
|
|
2
2
|
export declare class AdbPower extends AdbCommandBase {
|
|
3
|
-
reboot(
|
|
3
|
+
reboot(mode?: string): Promise<string>;
|
|
4
4
|
bootloader(): Promise<string>;
|
|
5
5
|
fastboot(): Promise<string>;
|
|
6
6
|
recovery(): Promise<string>;
|
package/esm/commands/power.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
// cspell: ignore longpress
|
|
5
5
|
import { AdbCommandBase } from "./base.js";
|
|
6
6
|
export class AdbPower extends AdbCommandBase {
|
|
7
|
-
reboot(
|
|
8
|
-
return this.adb.createSocketAndWait(`reboot:${
|
|
7
|
+
reboot(mode = "") {
|
|
8
|
+
return this.adb.createSocketAndWait(`reboot:${mode}`);
|
|
9
9
|
}
|
|
10
10
|
bootloader() {
|
|
11
11
|
return this.reboot("bootloader");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AutoDisposable } from "@yume-chan/event";
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
2
|
+
import { BufferedReadableStream } from "@yume-chan/stream-extra";
|
|
3
|
+
import type { Adb, AdbIncomingSocketHandler } from "../adb.js";
|
|
4
4
|
export interface AdbForwardListener {
|
|
5
5
|
deviceSerial: string;
|
|
6
6
|
localName: string;
|
|
@@ -9,33 +9,32 @@ export interface AdbForwardListener {
|
|
|
9
9
|
export declare class AdbReverseError extends Error {
|
|
10
10
|
constructor(message: string);
|
|
11
11
|
}
|
|
12
|
-
export declare class AdbReverseNotSupportedError extends
|
|
12
|
+
export declare class AdbReverseNotSupportedError extends AdbReverseError {
|
|
13
13
|
constructor();
|
|
14
14
|
}
|
|
15
15
|
export declare class AdbReverseCommand extends AutoDisposable {
|
|
16
|
-
|
|
17
|
-
protected deviceAddressToLocalAddress: Map<string, string>;
|
|
16
|
+
#private;
|
|
18
17
|
protected adb: Adb;
|
|
19
|
-
protected listening: boolean;
|
|
20
18
|
constructor(adb: Adb);
|
|
21
|
-
protected
|
|
22
|
-
|
|
23
|
-
private sendRequest;
|
|
19
|
+
protected createBufferedStream(service: string): Promise<BufferedReadableStream>;
|
|
20
|
+
protected sendRequest(service: string): Promise<BufferedReadableStream>;
|
|
24
21
|
list(): Promise<AdbForwardListener[]>;
|
|
25
22
|
/**
|
|
26
|
-
*
|
|
27
|
-
* The address to be listened on device by ADB daemon. Or `tcp:0` to choose an available TCP port.
|
|
28
|
-
* @param localAddress
|
|
29
|
-
*
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* @param
|
|
23
|
+
* Add an already existing reverse tunnel. Depends on the transport type, this may not do anything.
|
|
24
|
+
* @param deviceAddress The address to be listened on device by ADB daemon. Or `tcp:0` to choose an available TCP port.
|
|
25
|
+
* @param localAddress The address that listens on the local machine.
|
|
26
|
+
* @returns `tcp:{ACTUAL_LISTENING_PORT}`, If `deviceAddress` is `tcp:0`; otherwise, `deviceAddress`.
|
|
27
|
+
*/
|
|
28
|
+
addExternal(deviceAddress: string, localAddress: string): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* @param deviceAddress The address to be listened on device by ADB daemon. Or `tcp:0` to choose an available TCP port.
|
|
31
|
+
* @param handler A callback to handle incoming connections.
|
|
32
|
+
* @param localAddressThe The address that listens on the local machine. May be `undefined` to let the transport choose an appropriate one.
|
|
34
33
|
* @returns `tcp:{ACTUAL_LISTENING_PORT}`, If `deviceAddress` is `tcp:0`; otherwise, `deviceAddress`.
|
|
35
34
|
* @throws {AdbReverseNotSupportedError} If ADB reverse tunnel is not supported on this device when connected wirelessly.
|
|
36
35
|
* @throws {AdbReverseError} If ADB daemon returns an error.
|
|
37
36
|
*/
|
|
38
|
-
add(deviceAddress: string,
|
|
37
|
+
add(deviceAddress: string, handler: AdbIncomingSocketHandler, localAddress?: string): Promise<string>;
|
|
39
38
|
remove(deviceAddress: string): Promise<void>;
|
|
40
39
|
removeAll(): Promise<void>;
|
|
41
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reverse.d.ts","sourceRoot":"","sources":["../../src/commands/reverse.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"reverse.d.ts","sourceRoot":"","sources":["../../src/commands/reverse.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAGjE,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAG/D,MAAM,WAAW,kBAAkB;IAC/B,YAAY,EAAE,MAAM,CAAC;IAErB,SAAS,EAAE,MAAM,CAAC;IAElB,UAAU,EAAE,MAAM,CAAC;CACtB;AAMD,qBAAa,eAAgB,SAAQ,KAAK;gBACnB,OAAO,EAAE,MAAM;CAIrC;AAED,qBAAa,2BAA4B,SAAQ,eAAe;;CAM/D;AAoBD,qBAAa,iBAAkB,SAAQ,cAAc;;IACjD,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC;gBAIA,GAAG,EAAE,GAAG;cAMX,oBAAoB,CAAC,OAAO,EAAE,MAAM;cAKpC,WAAW,CAAC,OAAO,EAAE,MAAM;IAS9B,IAAI,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAgBlD;;;;;OAKG;IACU,WAAW,CAAC,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;IA8BpE;;;;;;;OAOG;IACU,GAAG,CACZ,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,wBAAwB,EACjC,YAAY,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,MAAM,CAAC;IAgBL,MAAM,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY5C,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ1C"}
|
package/esm/commands/reverse.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
// cspell: ignore killforward
|
|
2
2
|
import { AutoDisposable } from "@yume-chan/event";
|
|
3
|
-
import { BufferedReadableStream
|
|
4
|
-
import Struct from "@yume-chan/struct";
|
|
5
|
-
import { decodeUtf8 } from "../utils/index.js";
|
|
3
|
+
import { BufferedReadableStream } from "@yume-chan/stream-extra";
|
|
4
|
+
import Struct, { ExactReadableEndedError } from "@yume-chan/struct";
|
|
5
|
+
import { decodeUtf8, hexToNumber } from "../utils/index.js";
|
|
6
6
|
const AdbReverseStringResponse = new Struct()
|
|
7
7
|
.string("length", { length: 4 })
|
|
8
8
|
.string("content", { lengthField: "length", lengthFieldRadix: 16 });
|
|
9
9
|
export class AdbReverseError extends Error {
|
|
10
10
|
constructor(message) {
|
|
11
11
|
super(message);
|
|
12
|
-
Object.setPrototypeOf(this,
|
|
12
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
export class AdbReverseNotSupportedError extends
|
|
15
|
+
export class AdbReverseNotSupportedError extends AdbReverseError {
|
|
16
16
|
constructor() {
|
|
17
17
|
super("ADB reverse tunnel is not supported on this device when connected wirelessly.");
|
|
18
|
-
Object.setPrototypeOf(this, AdbReverseNotSupportedError.prototype);
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
20
|
const AdbReverseErrorResponse = new Struct()
|
|
22
|
-
.
|
|
21
|
+
.concat(AdbReverseStringResponse)
|
|
23
22
|
.postDeserialize((value) => {
|
|
24
23
|
// https://issuetracker.google.com/issues/37066218
|
|
25
24
|
// ADB on Android <9 can't create reverse tunnels when connected wirelessly (ADB over WiFi),
|
|
@@ -31,29 +30,24 @@ const AdbReverseErrorResponse = new Struct()
|
|
|
31
30
|
throw new AdbReverseError(value.content);
|
|
32
31
|
}
|
|
33
32
|
});
|
|
33
|
+
async function readString(stream, length) {
|
|
34
|
+
const buffer = await stream.readExactly(length);
|
|
35
|
+
return decodeUtf8(buffer);
|
|
36
|
+
}
|
|
34
37
|
export class AdbReverseCommand extends AutoDisposable {
|
|
35
|
-
localAddressToHandler = new Map();
|
|
36
|
-
deviceAddressToLocalAddress = new Map();
|
|
37
38
|
adb;
|
|
38
|
-
|
|
39
|
+
#deviceAddressToLocalAddress = new Map();
|
|
39
40
|
constructor(adb) {
|
|
40
41
|
super();
|
|
41
42
|
this.adb = adb;
|
|
42
|
-
this.addDisposable(this.adb.onIncomingSocket(this.handleIncomingSocket));
|
|
43
43
|
}
|
|
44
|
-
handleIncomingSocket = async (socket) => {
|
|
45
|
-
let address = socket.serviceString;
|
|
46
|
-
// ADB daemon appends `\0` to the service string
|
|
47
|
-
address = address.replace(/\0/g, "");
|
|
48
|
-
return !!(await this.localAddressToHandler.get(address)?.(socket));
|
|
49
|
-
};
|
|
50
44
|
async createBufferedStream(service) {
|
|
51
45
|
const socket = await this.adb.createSocket(service);
|
|
52
46
|
return new BufferedReadableStream(socket.readable);
|
|
53
47
|
}
|
|
54
48
|
async sendRequest(service) {
|
|
55
49
|
const stream = await this.createBufferedStream(service);
|
|
56
|
-
const success =
|
|
50
|
+
const success = (await readString(stream, 4)) === "OKAY";
|
|
57
51
|
if (!success) {
|
|
58
52
|
await AdbReverseErrorResponse.deserialize(stream);
|
|
59
53
|
}
|
|
@@ -69,57 +63,68 @@ export class AdbReverseCommand extends AutoDisposable {
|
|
|
69
63
|
// No need to close the stream, device will close it
|
|
70
64
|
}
|
|
71
65
|
/**
|
|
72
|
-
*
|
|
73
|
-
* The address to be listened on device by ADB daemon. Or `tcp:0` to choose an available TCP port.
|
|
74
|
-
* @param localAddress
|
|
75
|
-
* An identifier for the reverse tunnel.
|
|
76
|
-
*
|
|
77
|
-
* When a socket wants to connect to {@link deviceAddress}, native ADB client will forward that connection to {@link localAddress}.
|
|
78
|
-
* However in this library, the {@link handler} is invoked instead. So this parameter is only used to identify the reverse tunnel.
|
|
79
|
-
* @param handler A callback to handle incoming connections. It must return `true` if it accepts the connection.
|
|
66
|
+
* Add an already existing reverse tunnel. Depends on the transport type, this may not do anything.
|
|
67
|
+
* @param deviceAddress The address to be listened on device by ADB daemon. Or `tcp:0` to choose an available TCP port.
|
|
68
|
+
* @param localAddress The address that listens on the local machine.
|
|
80
69
|
* @returns `tcp:{ACTUAL_LISTENING_PORT}`, If `deviceAddress` is `tcp:0`; otherwise, `deviceAddress`.
|
|
81
|
-
* @throws {AdbReverseNotSupportedError} If ADB reverse tunnel is not supported on this device when connected wirelessly.
|
|
82
|
-
* @throws {AdbReverseError} If ADB daemon returns an error.
|
|
83
70
|
*/
|
|
84
|
-
async
|
|
71
|
+
async addExternal(deviceAddress, localAddress) {
|
|
85
72
|
const stream = await this.sendRequest(`reverse:forward:${deviceAddress};${localAddress}`);
|
|
86
73
|
// `tcp:0` tells the device to pick an available port.
|
|
87
74
|
// On Android >=8, device will respond with the selected port for all `tcp:` requests.
|
|
88
75
|
if (deviceAddress.startsWith("tcp:")) {
|
|
89
|
-
|
|
76
|
+
const position = stream.position;
|
|
90
77
|
try {
|
|
91
|
-
length =
|
|
78
|
+
const length = hexToNumber(await stream.readExactly(4));
|
|
79
|
+
const port = await readString(stream, length);
|
|
80
|
+
deviceAddress = `tcp:${Number.parseInt(port, 10)}`;
|
|
92
81
|
}
|
|
93
82
|
catch (e) {
|
|
94
|
-
if (
|
|
83
|
+
if (e instanceof ExactReadableEndedError &&
|
|
84
|
+
stream.position === position) {
|
|
85
|
+
// Android <8 doesn't have this response.
|
|
86
|
+
// (the stream is closed now)
|
|
87
|
+
// Can be safely ignored.
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
95
90
|
throw e;
|
|
96
91
|
}
|
|
97
|
-
// Android <8 doesn't have this response.
|
|
98
|
-
// (the stream is closed now)
|
|
99
|
-
// Can be safely ignored.
|
|
100
|
-
}
|
|
101
|
-
if (length !== undefined) {
|
|
102
|
-
const port = decodeUtf8(await stream.read(length));
|
|
103
|
-
deviceAddress = `tcp:${Number.parseInt(port, 10)}`;
|
|
104
92
|
}
|
|
105
93
|
}
|
|
106
|
-
this.localAddressToHandler.set(localAddress, handler);
|
|
107
|
-
this.deviceAddressToLocalAddress.set(deviceAddress, localAddress);
|
|
108
94
|
return deviceAddress;
|
|
109
|
-
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* @param deviceAddress The address to be listened on device by ADB daemon. Or `tcp:0` to choose an available TCP port.
|
|
98
|
+
* @param handler A callback to handle incoming connections.
|
|
99
|
+
* @param localAddressThe The address that listens on the local machine. May be `undefined` to let the transport choose an appropriate one.
|
|
100
|
+
* @returns `tcp:{ACTUAL_LISTENING_PORT}`, If `deviceAddress` is `tcp:0`; otherwise, `deviceAddress`.
|
|
101
|
+
* @throws {AdbReverseNotSupportedError} If ADB reverse tunnel is not supported on this device when connected wirelessly.
|
|
102
|
+
* @throws {AdbReverseError} If ADB daemon returns an error.
|
|
103
|
+
*/
|
|
104
|
+
async add(deviceAddress, handler, localAddress) {
|
|
105
|
+
localAddress = await this.adb.transport.addReverseTunnel(handler, localAddress);
|
|
106
|
+
try {
|
|
107
|
+
deviceAddress = await this.addExternal(deviceAddress, localAddress);
|
|
108
|
+
this.#deviceAddressToLocalAddress.set(deviceAddress, localAddress);
|
|
109
|
+
return deviceAddress;
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
await this.adb.transport.removeReverseTunnel(localAddress);
|
|
113
|
+
throw e;
|
|
114
|
+
}
|
|
110
115
|
}
|
|
111
116
|
async remove(deviceAddress) {
|
|
112
|
-
|
|
113
|
-
if (
|
|
114
|
-
this.
|
|
115
|
-
this.deviceAddressToLocalAddress.delete(deviceAddress);
|
|
117
|
+
const localAddress = this.#deviceAddressToLocalAddress.get(deviceAddress);
|
|
118
|
+
if (localAddress) {
|
|
119
|
+
await this.adb.transport.removeReverseTunnel(localAddress);
|
|
116
120
|
}
|
|
121
|
+
await this.sendRequest(`reverse:killforward:${deviceAddress}`);
|
|
117
122
|
// No need to close the stream, device will close it
|
|
118
123
|
}
|
|
119
124
|
async removeAll() {
|
|
125
|
+
await this.adb.transport.clearReverseTunnels();
|
|
126
|
+
this.#deviceAddressToLocalAddress.clear();
|
|
120
127
|
await this.sendRequest(`reverse:killforward-all`);
|
|
121
|
-
this.deviceAddressToLocalAddress.clear();
|
|
122
|
-
this.localAddressToHandler.clear();
|
|
123
128
|
// No need to close the stream, device will close it
|
|
124
129
|
}
|
|
125
130
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reverse.js","sourceRoot":"","sources":["../../src/commands/reverse.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAE7B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,
|
|
1
|
+
{"version":3,"file":"reverse.js","sourceRoot":"","sources":["../../src/commands/reverse.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAE7B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,MAAM,EAAE,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAGpE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAU5D,MAAM,wBAAwB,GAAG,IAAI,MAAM,EAAE;KACxC,MAAM,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;KAC/B,MAAM,CAAC,SAAS,EAAE,EAAE,WAAW,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