@yume-chan/adb 0.0.17 → 0.0.19

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.
Files changed (177) hide show
  1. package/CHANGELOG.json +27 -0
  2. package/CHANGELOG.md +16 -1
  3. package/LICENSE +1 -1
  4. package/esm/adb.d.ts +63 -60
  5. package/esm/adb.d.ts.map +1 -1
  6. package/esm/adb.js +257 -229
  7. package/esm/adb.js.map +1 -1
  8. package/esm/auth.d.ts +51 -51
  9. package/esm/auth.d.ts.map +1 -1
  10. package/esm/auth.js +95 -96
  11. package/esm/auth.js.map +1 -1
  12. package/esm/backend.d.ts +8 -8
  13. package/esm/backend.d.ts.map +1 -1
  14. package/esm/backend.js +1 -1
  15. package/esm/commands/base.d.ts +6 -6
  16. package/esm/commands/base.js +8 -8
  17. package/esm/commands/framebuffer.d.ts +53 -53
  18. package/esm/commands/framebuffer.d.ts.map +1 -1
  19. package/esm/commands/framebuffer.js +46 -47
  20. package/esm/commands/framebuffer.js.map +1 -1
  21. package/esm/commands/index.d.ts +7 -8
  22. package/esm/commands/index.d.ts.map +1 -1
  23. package/esm/commands/index.js +7 -8
  24. package/esm/commands/index.js.map +1 -1
  25. package/esm/commands/install.d.ts +9 -3
  26. package/esm/commands/install.d.ts.map +1 -1
  27. package/esm/commands/install.js +27 -21
  28. package/esm/commands/install.js.map +1 -1
  29. package/esm/commands/power.d.ts +22 -22
  30. package/esm/commands/power.d.ts.map +1 -1
  31. package/esm/commands/power.js +48 -44
  32. package/esm/commands/power.js.map +1 -1
  33. package/esm/commands/reverse.d.ts +41 -28
  34. package/esm/commands/reverse.d.ts.map +1 -1
  35. package/esm/commands/reverse.js +125 -98
  36. package/esm/commands/reverse.js.map +1 -1
  37. package/esm/commands/subprocess/command.d.ts +57 -51
  38. package/esm/commands/subprocess/command.d.ts.map +1 -1
  39. package/esm/commands/subprocess/command.js +86 -82
  40. package/esm/commands/subprocess/command.js.map +1 -1
  41. package/esm/commands/subprocess/index.d.ts +3 -3
  42. package/esm/commands/subprocess/index.js +3 -3
  43. package/esm/commands/subprocess/protocols/index.d.ts +3 -3
  44. package/esm/commands/subprocess/protocols/index.js +3 -3
  45. package/esm/commands/subprocess/protocols/none.d.ts +35 -35
  46. package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
  47. package/esm/commands/subprocess/protocols/none.js +65 -55
  48. package/esm/commands/subprocess/protocols/none.js.map +1 -1
  49. package/esm/commands/subprocess/protocols/shell.d.ts +39 -38
  50. package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -1
  51. package/esm/commands/subprocess/protocols/shell.js +166 -154
  52. package/esm/commands/subprocess/protocols/shell.js.map +1 -1
  53. package/esm/commands/subprocess/protocols/types.d.ts +49 -49
  54. package/esm/commands/subprocess/protocols/types.d.ts.map +1 -1
  55. package/esm/commands/subprocess/protocols/types.js +1 -1
  56. package/esm/commands/subprocess/utils.d.ts +1 -1
  57. package/esm/commands/subprocess/utils.js +18 -18
  58. package/esm/commands/sync/index.d.ts +8 -7
  59. package/esm/commands/sync/index.d.ts.map +1 -1
  60. package/esm/commands/sync/index.js +8 -7
  61. package/esm/commands/sync/index.js.map +1 -1
  62. package/esm/commands/sync/list.d.ts +42 -40
  63. package/esm/commands/sync/list.d.ts.map +1 -1
  64. package/esm/commands/sync/list.js +67 -35
  65. package/esm/commands/sync/list.js.map +1 -1
  66. package/esm/commands/sync/pull.d.ts +13 -11
  67. package/esm/commands/sync/pull.d.ts.map +1 -1
  68. package/esm/commands/sync/pull.js +35 -36
  69. package/esm/commands/sync/pull.js.map +1 -1
  70. package/esm/commands/sync/push.d.ts +46 -7
  71. package/esm/commands/sync/push.d.ts.map +1 -1
  72. package/esm/commands/sync/push.js +89 -23
  73. package/esm/commands/sync/push.js.map +1 -1
  74. package/esm/commands/sync/request.d.ts +26 -23
  75. package/esm/commands/sync/request.d.ts.map +1 -1
  76. package/esm/commands/sync/request.js +40 -42
  77. package/esm/commands/sync/request.js.map +1 -1
  78. package/esm/commands/sync/response.d.ts +19 -19
  79. package/esm/commands/sync/response.d.ts.map +1 -1
  80. package/esm/commands/sync/response.js +54 -54
  81. package/esm/commands/sync/response.js.map +1 -1
  82. package/esm/commands/sync/socket.d.ts +27 -0
  83. package/esm/commands/sync/socket.d.ts.map +1 -0
  84. package/esm/commands/sync/socket.js +66 -0
  85. package/esm/commands/sync/socket.js.map +1 -0
  86. package/esm/commands/sync/stat.d.ts +72 -72
  87. package/esm/commands/sync/stat.d.ts.map +1 -1
  88. package/esm/commands/sync/stat.js +116 -94
  89. package/esm/commands/sync/stat.js.map +1 -1
  90. package/esm/commands/sync/sync.d.ts +72 -60
  91. package/esm/commands/sync/sync.d.ts.map +1 -1
  92. package/esm/commands/sync/sync.js +127 -148
  93. package/esm/commands/sync/sync.js.map +1 -1
  94. package/esm/commands/tcpip.d.ts +5 -5
  95. package/esm/commands/tcpip.js +18 -18
  96. package/esm/crypto.d.ts +36 -36
  97. package/esm/crypto.d.ts.map +1 -1
  98. package/esm/crypto.js +248 -238
  99. package/esm/crypto.js.map +1 -1
  100. package/esm/features.d.ts +10 -7
  101. package/esm/features.d.ts.map +1 -1
  102. package/esm/features.js +13 -10
  103. package/esm/features.js.map +1 -1
  104. package/esm/index.d.ts +9 -9
  105. package/esm/index.d.ts.map +1 -1
  106. package/esm/index.js +9 -9
  107. package/esm/index.js.map +1 -1
  108. package/esm/packet.d.ts +45 -46
  109. package/esm/packet.d.ts.map +1 -1
  110. package/esm/packet.js +43 -46
  111. package/esm/packet.js.map +1 -1
  112. package/esm/socket/dispatcher.d.ts +59 -59
  113. package/esm/socket/dispatcher.d.ts.map +1 -1
  114. package/esm/socket/dispatcher.js +223 -231
  115. package/esm/socket/dispatcher.js.map +1 -1
  116. package/esm/socket/index.d.ts +2 -2
  117. package/esm/socket/index.js +2 -2
  118. package/esm/socket/socket.d.ts +59 -59
  119. package/esm/socket/socket.d.ts.map +1 -1
  120. package/esm/socket/socket.js +118 -98
  121. package/esm/socket/socket.js.map +1 -1
  122. package/esm/utils/auto-reset-event.d.ts +9 -9
  123. package/esm/utils/auto-reset-event.d.ts.map +1 -1
  124. package/esm/utils/auto-reset-event.js +33 -33
  125. package/esm/utils/auto-reset-event.js.map +1 -1
  126. package/esm/utils/base64.d.ts +27 -27
  127. package/esm/utils/base64.d.ts.map +1 -1
  128. package/esm/utils/base64.js +246 -245
  129. package/esm/utils/base64.js.map +1 -1
  130. package/esm/utils/conditional-variable.d.ts +9 -0
  131. package/esm/utils/conditional-variable.d.ts.map +1 -0
  132. package/esm/utils/conditional-variable.js +34 -0
  133. package/esm/utils/conditional-variable.js.map +1 -0
  134. package/esm/utils/index.d.ts +4 -3
  135. package/esm/utils/index.d.ts.map +1 -1
  136. package/esm/utils/index.js +4 -3
  137. package/esm/utils/index.js.map +1 -1
  138. package/package.json +17 -13
  139. package/src/adb.ts +160 -101
  140. package/src/auth.ts +31 -22
  141. package/src/backend.ts +6 -4
  142. package/src/commands/base.ts +2 -2
  143. package/src/commands/framebuffer.ts +37 -41
  144. package/src/commands/index.ts +7 -8
  145. package/src/commands/power.ts +15 -11
  146. package/src/commands/reverse.ts +74 -30
  147. package/src/commands/subprocess/command.ts +34 -23
  148. package/src/commands/subprocess/index.ts +3 -3
  149. package/src/commands/subprocess/protocols/index.ts +3 -3
  150. package/src/commands/subprocess/protocols/none.ts +26 -11
  151. package/src/commands/subprocess/protocols/shell.ts +110 -56
  152. package/src/commands/subprocess/protocols/types.ts +10 -6
  153. package/src/commands/subprocess/utils.ts +1 -1
  154. package/src/commands/sync/index.ts +8 -7
  155. package/src/commands/sync/list.ts +74 -28
  156. package/src/commands/sync/pull.ts +49 -37
  157. package/src/commands/sync/push.ts +153 -32
  158. package/src/commands/sync/request.ts +37 -34
  159. package/src/commands/sync/response.ts +34 -27
  160. package/src/commands/sync/socket.ts +97 -0
  161. package/src/commands/sync/stat.ts +98 -70
  162. package/src/commands/sync/sync.ts +78 -97
  163. package/src/commands/tcpip.ts +5 -5
  164. package/src/crypto.ts +60 -32
  165. package/src/features.ts +9 -6
  166. package/src/index.ts +9 -10
  167. package/src/packet.ts +41 -46
  168. package/src/socket/dispatcher.ts +130 -108
  169. package/src/socket/index.ts +2 -2
  170. package/src/socket/socket.ts +84 -34
  171. package/src/utils/auto-reset-event.ts +16 -17
  172. package/src/utils/base64.ts +51 -41
  173. package/src/utils/conditional-variable.ts +45 -0
  174. package/src/utils/index.ts +4 -3
  175. package/tsconfig.build.json +1 -1
  176. package/tsconfig.build.tsbuildinfo +1 -1
  177. package/src/commands/install.ts +0 -32
@@ -1,232 +1,224 @@
1
- import { AsyncOperationManager, PromiseResolver } from '@yume-chan/async';
2
- import { AbortController, WritableStream } from '@yume-chan/stream-extra';
3
- import { EMPTY_UINT8_ARRAY } from '@yume-chan/struct';
4
- import { AdbCommand, calculateChecksum } from '../packet.js';
5
- import { decodeUtf8, encodeUtf8 } from '../utils/index.js';
6
- import { AdbSocketController } from './socket.js';
7
- /**
8
- * The dispatcher is the "dumb" part of the connection handling logic.
9
- *
10
- * Except some options to change some minor behaviors,
11
- * its only job is forwarding packets between authenticated underlying streams
12
- * and abstracted socket objects.
13
- *
14
- * The `Adb` class is responsible for doing the authentication,
15
- * negotiating the options, and has shortcuts to high-level services.
16
- */
17
- export class AdbPacketDispatcher {
18
- // ADB socket id starts from 1
19
- // (0 means open failed)
20
- initializers = new AsyncOperationManager(1);
21
- /**
22
- * Socket local ID to the socket controller.
23
- */
24
- sockets = new Map();
25
- _writer;
26
- options;
27
- _closed = false;
28
- _disconnected = new PromiseResolver();
29
- get disconnected() { return this._disconnected.promise; }
30
- _incomingSocketHandlers = new Set();
31
- _abortController = new AbortController();
32
- constructor(connection, options) {
33
- this.options = options;
34
- connection.readable
35
- .pipeTo(new WritableStream({
36
- write: async (packet) => {
37
- switch (packet.command) {
38
- case AdbCommand.OK:
39
- this.handleOk(packet);
40
- break;
41
- case AdbCommand.Close:
42
- await this.handleClose(packet);
43
- break;
44
- case AdbCommand.Write:
45
- if (this.sockets.has(packet.arg1)) {
46
- await this.sockets.get(packet.arg1).enqueue(packet.payload);
47
- await this.sendPacket(AdbCommand.OK, packet.arg1, packet.arg0);
48
- break;
49
- }
50
- throw new Error(`Unknown local socket id: ${packet.arg1}`);
51
- case AdbCommand.Open:
52
- await this.handleOpen(packet);
53
- break;
54
- default:
55
- // Junk data may only appear in the authentication phase,
56
- // since the dispatcher only works after authentication,
57
- // all packets should have a valid command.
58
- // (although it's possible that Adb added new commands in the future)
59
- throw new Error(`Unknown command: ${packet.command.toString(16)}`);
60
- }
61
- },
62
- }), {
63
- // There are multiple reasons for the pipe to stop,
64
- // (device disconnection, protocol error, or user abortion)
65
- // if the underlying streams are still open,
66
- // it's still possible to create another ADB connection.
67
- // So don't close `readable` here.
68
- preventCancel: true,
69
- signal: this._abortController.signal,
70
- })
71
- .then(() => {
72
- this.dispose();
73
- }, (e) => {
74
- // https://github.com/MattiasBuelens/web-streams-polyfill/issues/115
75
- // `e` is always `AbortError` (instead of what I give in `abortController.abort()`)
76
- // so we can't check if `e` is a real error.
77
- if (!this._closed) {
78
- this._disconnected.reject(e);
79
- }
80
- this.dispose();
81
- });
82
- this._writer = connection.writable.getWriter();
83
- }
84
- handleOk(packet) {
85
- if (this.initializers.resolve(packet.arg1, packet.arg0)) {
86
- // Device successfully created the socket
87
- return;
88
- }
89
- const socket = this.sockets.get(packet.arg1);
90
- if (socket) {
91
- // Device has received last `WRTE` to the socket
92
- socket.ack();
93
- return;
94
- }
95
- // Maybe the device is responding to a packet of last connection
96
- // Tell the device to close the socket
97
- this.sendPacket(AdbCommand.Close, packet.arg1, packet.arg0);
98
- }
99
- async handleClose(packet) {
100
- // If the socket is still pending
101
- if (packet.arg0 === 0 &&
102
- this.initializers.reject(packet.arg1, new Error('Socket open failed'))) {
103
- // Device failed to create the socket
104
- // (unknown service string, failed to execute command, etc.)
105
- // it doesn't break the connection,
106
- // so only reject the socket creation promise,
107
- // don't throw an error here.
108
- return;
109
- }
110
- // From https://android.googlesource.com/platform/packages/modules/adb/+/65d18e2c1cc48b585811954892311b28a4c3d188/adb.cpp#459
111
- /* According to protocol.txt, p->msg.arg0 might be 0 to indicate
112
- * a failed OPEN only. However, due to a bug in previous ADB
113
- * versions, CLOSE(0, remote-id, "") was also used for normal
114
- * CLOSE() operations.
115
- */
116
- // Ignore `arg0` and search for the socket
117
- const socket = this.sockets.get(packet.arg1);
118
- if (socket) {
119
- // The device want to close the socket
120
- if (!socket.closed) {
121
- await this.sendPacket(AdbCommand.Close, packet.arg1, packet.arg0);
122
- }
123
- socket.dispose();
124
- this.sockets.delete(packet.arg1);
125
- return;
126
- }
127
- // TODO: adb: is double closing an socket a catastrophic error?
128
- // If the client sends two `CLSE` packets for one socket,
129
- // the device may also respond with two `CLSE` packets.
130
- }
131
- /**
132
- * Add a handler for incoming socket.
133
- * @param handler A function to call with new incoming sockets. It must return `true` if it accepts the socket.
134
- * @returns A function to remove the handler.
135
- */
136
- onIncomingSocket(handler) {
137
- this._incomingSocketHandlers.add(handler);
138
- const remove = () => {
139
- this._incomingSocketHandlers.delete(handler);
140
- };
141
- remove.dispose = remove;
142
- return remove;
143
- }
144
- async handleOpen(packet) {
145
- // `AsyncOperationManager` doesn't support skipping IDs
146
- // Use `add` + `resolve` to simulate this behavior
147
- const [localId] = this.initializers.add();
148
- this.initializers.resolve(localId, undefined);
149
- const remoteId = packet.arg0;
150
- const serviceString = decodeUtf8(packet.payload);
151
- const controller = new AdbSocketController({
152
- dispatcher: this,
153
- localId,
154
- remoteId,
155
- localCreated: false,
156
- serviceString,
157
- });
158
- for (const handler of this._incomingSocketHandlers) {
159
- if (await handler(controller.socket)) {
160
- this.sockets.set(localId, controller);
161
- await this.sendPacket(AdbCommand.OK, localId, remoteId);
162
- return;
163
- }
164
- }
165
- await this.sendPacket(AdbCommand.Close, 0, remoteId);
166
- }
167
- async createSocket(serviceString) {
168
- if (this.options.appendNullToServiceString) {
169
- serviceString += '\0';
170
- }
171
- const [localId, initializer] = this.initializers.add();
172
- await this.sendPacket(AdbCommand.Open, localId, 0, serviceString);
173
- // Fulfilled by `handleOk`
174
- const remoteId = await initializer;
175
- const controller = new AdbSocketController({
176
- dispatcher: this,
177
- localId,
178
- remoteId,
179
- localCreated: true,
180
- serviceString,
181
- });
182
- this.sockets.set(localId, controller);
183
- return controller.socket;
184
- }
185
- async sendPacket(packetOrCommand, arg0, arg1, payload = EMPTY_UINT8_ARRAY) {
186
- let init;
187
- if (arg0 === undefined) {
188
- init = packetOrCommand;
189
- }
190
- else {
191
- if (typeof payload === 'string') {
192
- payload = encodeUtf8(payload);
193
- }
194
- init = {
195
- command: packetOrCommand,
196
- arg0: arg0,
197
- arg1: arg1,
198
- payload,
199
- };
200
- }
201
- if (init.payload &&
202
- init.payload.byteLength > this.options.maxPayloadSize) {
203
- throw new Error('payload too large');
204
- }
205
- if (this.options.calculateChecksum) {
206
- calculateChecksum(init);
207
- }
208
- else {
209
- init.checksum = 0;
210
- }
211
- await this._writer.ready;
212
- await this._writer.write(init);
213
- }
214
- async close() {
215
- // Send `CLSE` packets for all sockets
216
- await Promise.all(Array.from(this.sockets.values(), socket => socket.close()));
217
- // Stop receiving
218
- // It's possible that we haven't received all `CLSE` confirm packets,
219
- // but it doesn't matter, the next connection can cope with them.
220
- this._closed = true;
221
- this._abortController.abort();
222
- this._writer.releaseLock();
223
- // `pipe().then()` will call `dispose`
224
- }
225
- dispose() {
226
- for (const socket of this.sockets.values()) {
227
- socket.dispose();
228
- }
229
- this._disconnected.resolve();
230
- }
231
- }
1
+ import { AsyncOperationManager, PromiseResolver } from "@yume-chan/async";
2
+ import { AbortController, ConsumableWritableStream, WritableStream, } from "@yume-chan/stream-extra";
3
+ import { EMPTY_UINT8_ARRAY } from "@yume-chan/struct";
4
+ import { AdbCommand, calculateChecksum } from "../packet.js";
5
+ import { decodeUtf8, encodeUtf8 } from "../utils/index.js";
6
+ import { AdbSocketController } from "./socket.js";
7
+ /**
8
+ * The dispatcher is the "dumb" part of the connection handling logic.
9
+ *
10
+ * Except some options to change some minor behaviors,
11
+ * its only job is forwarding packets between authenticated underlying streams
12
+ * and abstracted socket objects.
13
+ *
14
+ * The `Adb` class is responsible for doing the authentication,
15
+ * negotiating the options, and has shortcuts to high-level services.
16
+ */
17
+ export class AdbPacketDispatcher {
18
+ // ADB socket id starts from 1
19
+ // (0 means open failed)
20
+ initializers = new AsyncOperationManager(1);
21
+ /**
22
+ * Socket local ID to the socket controller.
23
+ */
24
+ sockets = new Map();
25
+ _writer;
26
+ options;
27
+ _closed = false;
28
+ _disconnected = new PromiseResolver();
29
+ get disconnected() {
30
+ return this._disconnected.promise;
31
+ }
32
+ _incomingSocketHandlers = new Set();
33
+ _abortController = new AbortController();
34
+ constructor(connection, options) {
35
+ this.options = options;
36
+ connection.readable
37
+ .pipeTo(new WritableStream({
38
+ write: async (packet) => {
39
+ switch (packet.command) {
40
+ case AdbCommand.OK:
41
+ this.handleOk(packet);
42
+ break;
43
+ case AdbCommand.Close:
44
+ await this.handleClose(packet);
45
+ break;
46
+ case AdbCommand.Write:
47
+ if (this.sockets.has(packet.arg1)) {
48
+ await this.sockets
49
+ .get(packet.arg1)
50
+ .enqueue(packet.payload);
51
+ await this.sendPacket(AdbCommand.OK, packet.arg1, packet.arg0);
52
+ break;
53
+ }
54
+ throw new Error(`Unknown local socket id: ${packet.arg1}`);
55
+ case AdbCommand.Open:
56
+ await this.handleOpen(packet);
57
+ break;
58
+ default:
59
+ // Junk data may only appear in the authentication phase,
60
+ // since the dispatcher only works after authentication,
61
+ // all packets should have a valid command.
62
+ // (although it's possible that Adb added new commands in the future)
63
+ throw new Error(`Unknown command: ${packet.command.toString(16)}`);
64
+ }
65
+ },
66
+ }), {
67
+ // There are multiple reasons for the pipe to stop,
68
+ // (device disconnection, protocol error, or user abortion)
69
+ // if the underlying streams are still open,
70
+ // it's still possible to create another ADB connection.
71
+ // So don't close `readable` here.
72
+ preventCancel: true,
73
+ signal: this._abortController.signal,
74
+ })
75
+ .then(() => {
76
+ this.dispose();
77
+ }, (e) => {
78
+ if (!this._closed) {
79
+ this._disconnected.reject(e);
80
+ }
81
+ this.dispose();
82
+ });
83
+ this._writer = connection.writable.getWriter();
84
+ }
85
+ handleOk(packet) {
86
+ if (this.initializers.resolve(packet.arg1, packet.arg0)) {
87
+ // Device successfully created the socket
88
+ return;
89
+ }
90
+ const socket = this.sockets.get(packet.arg1);
91
+ if (socket) {
92
+ // Device has received last `WRTE` to the socket
93
+ socket.ack();
94
+ return;
95
+ }
96
+ // Maybe the device is responding to a packet of last connection
97
+ // Tell the device to close the socket
98
+ void this.sendPacket(AdbCommand.Close, packet.arg1, packet.arg0);
99
+ }
100
+ async handleClose(packet) {
101
+ // If the socket is still pending
102
+ if (packet.arg0 === 0 &&
103
+ this.initializers.reject(packet.arg1, new Error("Socket open failed"))) {
104
+ // Device failed to create the socket
105
+ // (unknown service string, failed to execute command, etc.)
106
+ // it doesn't break the connection,
107
+ // so only reject the socket creation promise,
108
+ // don't throw an error here.
109
+ return;
110
+ }
111
+ // From https://android.googlesource.com/platform/packages/modules/adb/+/65d18e2c1cc48b585811954892311b28a4c3d188/adb.cpp#459
112
+ /* According to protocol.txt, p->msg.arg0 might be 0 to indicate
113
+ * a failed OPEN only. However, due to a bug in previous ADB
114
+ * versions, CLOSE(0, remote-id, "") was also used for normal
115
+ * CLOSE() operations.
116
+ */
117
+ // Ignore `arg0` and search for the socket
118
+ const socket = this.sockets.get(packet.arg1);
119
+ if (socket) {
120
+ // The device want to close the socket
121
+ if (!socket.closed) {
122
+ await this.sendPacket(AdbCommand.Close, packet.arg1, packet.arg0);
123
+ }
124
+ await socket.dispose();
125
+ this.sockets.delete(packet.arg1);
126
+ return;
127
+ }
128
+ // TODO: adb: is double closing an socket a catastrophic error?
129
+ // If the client sends two `CLSE` packets for one socket,
130
+ // the device may also respond with two `CLSE` packets.
131
+ }
132
+ /**
133
+ * Add a handler for incoming socket.
134
+ * @param handler A function to call with new incoming sockets. It must return `true` if it accepts the socket.
135
+ * @returns A function to remove the handler.
136
+ */
137
+ onIncomingSocket(handler) {
138
+ this._incomingSocketHandlers.add(handler);
139
+ const remove = () => {
140
+ this._incomingSocketHandlers.delete(handler);
141
+ };
142
+ remove.dispose = remove;
143
+ return remove;
144
+ }
145
+ async handleOpen(packet) {
146
+ // `AsyncOperationManager` doesn't support skipping IDs
147
+ // Use `add` + `resolve` to simulate this behavior
148
+ const [localId] = this.initializers.add();
149
+ this.initializers.resolve(localId, undefined);
150
+ const remoteId = packet.arg0;
151
+ const serviceString = decodeUtf8(packet.payload);
152
+ const controller = new AdbSocketController({
153
+ dispatcher: this,
154
+ localId,
155
+ remoteId,
156
+ localCreated: false,
157
+ serviceString,
158
+ });
159
+ for (const handler of this._incomingSocketHandlers) {
160
+ if (await handler(controller.socket)) {
161
+ this.sockets.set(localId, controller);
162
+ await this.sendPacket(AdbCommand.OK, localId, remoteId);
163
+ return;
164
+ }
165
+ }
166
+ await this.sendPacket(AdbCommand.Close, 0, remoteId);
167
+ }
168
+ async createSocket(serviceString) {
169
+ if (this.options.appendNullToServiceString) {
170
+ serviceString += "\0";
171
+ }
172
+ const [localId, initializer] = this.initializers.add();
173
+ await this.sendPacket(AdbCommand.Open, localId, 0, serviceString);
174
+ // Fulfilled by `handleOk`
175
+ const remoteId = await initializer;
176
+ const controller = new AdbSocketController({
177
+ dispatcher: this,
178
+ localId,
179
+ remoteId,
180
+ localCreated: true,
181
+ serviceString,
182
+ });
183
+ this.sockets.set(localId, controller);
184
+ return controller.socket;
185
+ }
186
+ async sendPacket(command, arg0, arg1, payload = EMPTY_UINT8_ARRAY) {
187
+ if (typeof payload === "string") {
188
+ payload = encodeUtf8(payload);
189
+ }
190
+ if (payload.byteLength > this.options.maxPayloadSize) {
191
+ throw new Error("payload too large");
192
+ }
193
+ await ConsumableWritableStream.write(this._writer, {
194
+ command,
195
+ arg0,
196
+ arg1,
197
+ payload,
198
+ checksum: this.options.calculateChecksum
199
+ ? calculateChecksum(payload)
200
+ : 0,
201
+ magic: command ^ 0xffffffff,
202
+ });
203
+ }
204
+ async close() {
205
+ // Send `CLSE` packets for all sockets
206
+ await Promise.all(Array.from(this.sockets.values(), (socket) => socket.close()));
207
+ // Stop receiving
208
+ // It's possible that we haven't received all `CLSE` confirm packets,
209
+ // but it doesn't matter, the next connection can cope with them.
210
+ this._closed = true;
211
+ this._abortController.abort();
212
+ this._writer.releaseLock();
213
+ // `pipe().then()` will call `dispose`
214
+ }
215
+ dispose() {
216
+ for (const socket of this.sockets.values()) {
217
+ socket.dispose().catch((e) => {
218
+ void e;
219
+ });
220
+ }
221
+ this._disconnected.resolve();
222
+ }
223
+ }
232
224
  //# sourceMappingURL=dispatcher.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../../src/socket/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,cAAc,EAA0D,MAAM,yBAAyB,CAAC;AAClI,OAAO,EAAE,iBAAiB,EAAuB,MAAM,mBAAmB,CAAC;AAE3E,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAA0C,MAAM,cAAc,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAa,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAoB7D;;;;;;;;;GASG;AACH,MAAM,OAAO,mBAAmB;IAC5B,8BAA8B;IAC9B,wBAAwB;IACP,YAAY,GAAG,IAAI,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC7D;;OAEG;IACc,OAAO,GAAG,IAAI,GAAG,EAA+B,CAAC;IAE1D,OAAO,CAA8C;IAE7C,OAAO,CAA6B;IAE5C,OAAO,GAAG,KAAK,CAAC;IAChB,aAAa,GAAG,IAAI,eAAe,EAAQ,CAAC;IACpD,IAAW,YAAY,KAAK,OAAO,IAAI,CA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
- export * from './socket.js';
1
+ export * from "./dispatcher.js";
2
+ export * from "./socket.js";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,3 @@
1
- export * from './dispatcher.js';
2
- export * from './socket.js';
1
+ export * from "./dispatcher.js";
2
+ export * from "./socket.js";
3
3
  //# sourceMappingURL=index.js.map
@@ -1,60 +1,60 @@
1
- import type { Disposable } from '@yume-chan/event';
2
- import { WritableStream, type ReadableStream, type ReadableWritablePair } from '@yume-chan/stream-extra';
3
- import type { AdbPacketDispatcher, Closeable } from './dispatcher.js';
4
- export interface AdbSocketInfo {
5
- localId: number;
6
- remoteId: number;
7
- localCreated: boolean;
8
- serviceString: string;
9
- }
10
- export interface AdbSocketConstructionOptions extends AdbSocketInfo {
11
- dispatcher: AdbPacketDispatcher;
12
- highWaterMark?: number | undefined;
13
- }
14
- export declare class AdbSocketController implements AdbSocketInfo, ReadableWritablePair<Uint8Array, Uint8Array>, Closeable, Disposable {
15
- private readonly dispatcher;
16
- readonly localId: number;
17
- readonly remoteId: number;
18
- readonly localCreated: boolean;
19
- readonly serviceString: string;
20
- private _duplex;
21
- private _readable;
22
- private _readableController;
23
- get readable(): ReadableStream<Uint8Array>;
24
- private _writePromise;
25
- readonly writable: WritableStream<Uint8Array>;
26
- private _closed;
27
- /**
28
- * Whether the socket is half-closed (i.e. the local side initiated the close).
29
- *
30
- * It's only used by dispatcher to avoid sending another `CLSE` packet to remote.
31
- */
32
- get closed(): boolean;
33
- private _socket;
34
- get socket(): AdbSocket;
35
- constructor(options: AdbSocketConstructionOptions);
36
- enqueue(packet: Uint8Array): Promise<void>;
37
- ack(): void;
38
- close(): Promise<void>;
39
- dispose(): void;
40
- }
41
- /**
42
- * A duplex stream representing a socket to ADB daemon.
43
- *
44
- * To close it, call either `socket.close()`,
45
- * `socket.readable.cancel()`, `socket.readable.getReader().cancel()`,
46
- * `socket.writable.abort()`, `socket.writable.getWriter().abort()`,
47
- * `socket.writable.close()` or `socket.writable.getWriter().close()`.
48
- */
49
- export declare class AdbSocket implements AdbSocketInfo, ReadableWritablePair<Uint8Array, Uint8Array> {
50
- private _controller;
51
- get localId(): number;
52
- get remoteId(): number;
53
- get localCreated(): boolean;
54
- get serviceString(): string;
55
- get readable(): ReadableStream<Uint8Array>;
56
- get writable(): WritableStream<Uint8Array>;
57
- constructor(controller: AdbSocketController);
58
- close(): Promise<void>;
59
- }
1
+ import type { Disposable } from "@yume-chan/event";
2
+ import type { Consumable, ReadableStream, ReadableWritablePair, WritableStream } from "@yume-chan/stream-extra";
3
+ import type { AdbPacketDispatcher, Closeable } from "./dispatcher.js";
4
+ export interface AdbSocketInfo {
5
+ localId: number;
6
+ remoteId: number;
7
+ localCreated: boolean;
8
+ serviceString: string;
9
+ }
10
+ export interface AdbSocketConstructionOptions extends AdbSocketInfo {
11
+ dispatcher: AdbPacketDispatcher;
12
+ highWaterMark?: number | undefined;
13
+ }
14
+ export declare class AdbSocketController implements AdbSocketInfo, ReadableWritablePair<Uint8Array, Consumable<Uint8Array>>, Closeable, Disposable {
15
+ private readonly dispatcher;
16
+ readonly localId: number;
17
+ readonly remoteId: number;
18
+ readonly localCreated: boolean;
19
+ readonly serviceString: string;
20
+ private _duplex;
21
+ private _readable;
22
+ private _readableController;
23
+ get readable(): ReadableStream<Uint8Array>;
24
+ private _writePromise;
25
+ readonly writable: WritableStream<Consumable<Uint8Array>>;
26
+ private _closed;
27
+ /**
28
+ * Whether the socket is half-closed (i.e. the local side initiated the close).
29
+ *
30
+ * It's only used by dispatcher to avoid sending another `CLSE` packet to remote.
31
+ */
32
+ get closed(): boolean;
33
+ private _socket;
34
+ get socket(): AdbSocket;
35
+ constructor(options: AdbSocketConstructionOptions);
36
+ enqueue(data: Uint8Array): Promise<void>;
37
+ ack(): void;
38
+ close(): Promise<void>;
39
+ dispose(): Promise<void>;
40
+ }
41
+ /**
42
+ * A duplex stream representing a socket to ADB daemon.
43
+ *
44
+ * To close it, call either `socket.close()`,
45
+ * `socket.readable.cancel()`, `socket.readable.getReader().cancel()`,
46
+ * `socket.writable.abort()`, `socket.writable.getWriter().abort()`,
47
+ * `socket.writable.close()` or `socket.writable.getWriter().close()`.
48
+ */
49
+ export declare class AdbSocket implements AdbSocketInfo, ReadableWritablePair<Uint8Array, Consumable<Uint8Array>> {
50
+ private _controller;
51
+ get localId(): number;
52
+ get remoteId(): number;
53
+ get localCreated(): boolean;
54
+ get serviceString(): string;
55
+ get readable(): ReadableStream<Uint8Array>;
56
+ get writable(): WritableStream<Consumable<Uint8Array>>;
57
+ constructor(controller: AdbSocketController);
58
+ close(): Promise<void>;
59
+ }
60
60
  //# sourceMappingURL=socket.d.ts.map