@yume-chan/adb 0.0.16 → 0.0.17
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 +12 -0
- package/CHANGELOG.md +8 -1
- package/esm/adb.d.ts +8 -3
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +11 -6
- package/esm/adb.js.map +1 -1
- package/esm/auth.d.ts.map +1 -1
- package/esm/auth.js.map +1 -1
- package/esm/backend.d.ts +2 -2
- package/esm/backend.d.ts.map +1 -1
- package/esm/commands/base.d.ts.map +1 -1
- package/esm/commands/base.js.map +1 -1
- package/esm/commands/framebuffer.d.ts +17 -1
- package/esm/commands/framebuffer.d.ts.map +1 -1
- package/esm/commands/framebuffer.js +4 -15
- package/esm/commands/framebuffer.js.map +1 -1
- package/esm/commands/install.d.ts +2 -2
- package/esm/commands/install.d.ts.map +1 -1
- package/esm/commands/install.js +3 -2
- package/esm/commands/install.js.map +1 -1
- package/esm/commands/power.d.ts +1 -1
- package/esm/commands/power.js +1 -1
- package/esm/commands/reverse.d.ts +3 -3
- package/esm/commands/reverse.d.ts.map +1 -1
- package/esm/commands/reverse.js +9 -9
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/command.d.ts +52 -0
- package/esm/commands/subprocess/command.d.ts.map +1 -0
- package/esm/commands/subprocess/command.js +83 -0
- package/esm/commands/subprocess/command.js.map +1 -0
- package/esm/commands/subprocess/index.d.ts +1 -53
- package/esm/commands/subprocess/index.d.ts.map +1 -1
- package/esm/commands/subprocess/index.js +1 -85
- package/esm/commands/subprocess/index.js.map +1 -1
- package/esm/commands/subprocess/protocols/none.d.ts +4 -4
- package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/none.js +5 -3
- package/esm/commands/subprocess/protocols/none.js.map +1 -1
- package/esm/commands/subprocess/protocols/shell.d.ts +4 -4
- package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/shell.js +6 -6
- package/esm/commands/subprocess/protocols/shell.js.map +1 -1
- package/esm/commands/subprocess/protocols/types.d.ts +7 -7
- package/esm/commands/subprocess/protocols/types.d.ts.map +1 -1
- package/esm/commands/sync/index.d.ts +1 -1
- package/esm/commands/sync/index.d.ts.map +1 -1
- package/esm/commands/sync/index.js +1 -1
- package/esm/commands/sync/index.js.map +1 -1
- package/esm/commands/sync/list.d.ts +2 -2
- package/esm/commands/sync/list.d.ts.map +1 -1
- package/esm/commands/sync/list.js +15 -43
- package/esm/commands/sync/list.js.map +1 -1
- package/esm/commands/sync/pull.d.ts +3 -2
- package/esm/commands/sync/pull.d.ts.map +1 -1
- package/esm/commands/sync/pull.js +15 -17
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/push.d.ts +2 -2
- package/esm/commands/sync/push.d.ts.map +1 -1
- package/esm/commands/sync/push.js +2 -5
- package/esm/commands/sync/push.js.map +1 -1
- package/esm/commands/sync/request.d.ts +1 -1
- package/esm/commands/sync/request.d.ts.map +1 -1
- package/esm/commands/sync/request.js +1 -1
- package/esm/commands/sync/request.js.map +1 -1
- package/esm/commands/sync/response.d.ts +4 -9
- package/esm/commands/sync/response.d.ts.map +1 -1
- package/esm/commands/sync/response.js +32 -23
- package/esm/commands/sync/response.js.map +1 -1
- package/esm/commands/sync/stat.d.ts +3 -3
- package/esm/commands/sync/stat.d.ts.map +1 -1
- package/esm/commands/sync/stat.js +13 -30
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.d.ts +2 -2
- package/esm/commands/sync/sync.d.ts.map +1 -1
- package/esm/commands/sync/sync.js +7 -5
- package/esm/commands/sync/sync.js.map +1 -1
- package/esm/crypto.js +1 -1
- package/esm/crypto.js.map +1 -1
- package/esm/index.d.ts +0 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +0 -1
- package/esm/index.js.map +1 -1
- package/esm/packet.d.ts +1 -1
- package/esm/packet.d.ts.map +1 -1
- package/esm/packet.js +1 -1
- package/esm/packet.js.map +1 -1
- package/esm/socket/dispatcher.d.ts +8 -3
- package/esm/socket/dispatcher.d.ts.map +1 -1
- package/esm/socket/dispatcher.js +9 -4
- package/esm/socket/dispatcher.js.map +1 -1
- package/esm/socket/index.d.ts +1 -1
- package/esm/socket/index.d.ts.map +1 -1
- package/esm/socket/index.js +1 -1
- package/esm/socket/index.js.map +1 -1
- package/esm/socket/socket.d.ts +3 -3
- package/esm/socket/socket.d.ts.map +1 -1
- package/esm/socket/socket.js +3 -3
- package/esm/socket/socket.js.map +1 -1
- package/esm/utils/base64.d.ts +23 -0
- package/esm/utils/base64.d.ts.map +1 -1
- package/esm/utils/base64.js +6 -0
- package/esm/utils/base64.js.map +1 -1
- package/package.json +13 -14
- package/src/adb.ts +12 -7
- package/src/auth.ts +1 -0
- package/src/backend.ts +3 -2
- package/src/commands/base.ts +1 -0
- package/src/commands/framebuffer.ts +21 -16
- package/src/commands/install.ts +6 -4
- package/src/commands/power.ts +1 -1
- package/src/commands/reverse.ts +11 -10
- package/src/commands/subprocess/command.ts +131 -0
- package/src/commands/subprocess/index.ts +1 -137
- package/src/commands/subprocess/protocols/none.ts +9 -6
- package/src/commands/subprocess/protocols/shell.ts +11 -10
- package/src/commands/subprocess/protocols/types.ts +8 -7
- package/src/commands/sync/index.ts +1 -1
- package/src/commands/sync/list.ts +18 -50
- package/src/commands/sync/pull.ts +17 -18
- package/src/commands/sync/push.ts +4 -7
- package/src/commands/sync/request.ts +3 -2
- package/src/commands/sync/response.ts +43 -39
- package/src/commands/sync/stat.ts +17 -39
- package/src/commands/sync/sync.ts +13 -12
- package/src/crypto.ts +1 -1
- package/src/features.ts +1 -1
- package/src/index.ts +0 -1
- package/src/packet.ts +1 -1
- package/src/socket/dispatcher.ts +9 -4
- package/src/socket/index.ts +1 -1
- package/src/socket/socket.ts +5 -4
- package/src/utils/base64.ts +23 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/esm/stream/buffered.d.ts +0 -39
- package/esm/stream/buffered.d.ts.map +0 -1
- package/esm/stream/buffered.js +0 -143
- package/esm/stream/buffered.js.map +0 -1
- package/esm/stream/detect.d.ts +0 -2
- package/esm/stream/detect.d.ts.map +0 -1
- package/esm/stream/detect.js +0 -6
- package/esm/stream/detect.js.map +0 -1
- package/esm/stream/detect.native.d.ts +0 -240
- package/esm/stream/detect.native.d.ts.map +0 -1
- package/esm/stream/detect.native.js +0 -60
- package/esm/stream/detect.native.js.map +0 -1
- package/esm/stream/detect.polyfill.d.ts +0 -18
- package/esm/stream/detect.polyfill.d.ts.map +0 -1
- package/esm/stream/detect.polyfill.js +0 -4
- package/esm/stream/detect.polyfill.js.map +0 -1
- package/esm/stream/index.d.ts +0 -4
- package/esm/stream/index.d.ts.map +0 -1
- package/esm/stream/index.js +0 -4
- package/esm/stream/index.js.map +0 -1
- package/esm/stream/transform.d.ts +0 -124
- package/esm/stream/transform.d.ts.map +0 -1
- package/esm/stream/transform.js +0 -379
- package/esm/stream/transform.js.map +0 -1
- package/src/stream/buffered.ts +0 -168
- package/src/stream/detect.native.ts +0 -362
- package/src/stream/detect.polyfill.ts +0 -22
- package/src/stream/detect.ts +0 -7
- package/src/stream/index.ts +0 -3
- package/src/stream/transform.ts +0 -474
- package/tsconfig.test.json +0 -9
- package/web-streams-polyfill-4.0.0-beta.2.tgz +0 -0
package/esm/socket/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/socket/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/socket/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC"}
|
package/esm/socket/socket.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Disposable } from
|
|
2
|
-
import { WritableStream, type ReadableStream, type ReadableWritablePair } from '
|
|
1
|
+
import type { Disposable } from '@yume-chan/event';
|
|
2
|
+
import { WritableStream, type ReadableStream, type ReadableWritablePair } from '@yume-chan/stream-extra';
|
|
3
3
|
import type { AdbPacketDispatcher, Closeable } from './dispatcher.js';
|
|
4
4
|
export interface AdbSocketInfo {
|
|
5
5
|
localId: number;
|
|
@@ -39,7 +39,7 @@ export declare class AdbSocketController implements AdbSocketInfo, ReadableWrita
|
|
|
39
39
|
dispose(): void;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* A duplex stream representing a socket to ADB daemon.
|
|
43
43
|
*
|
|
44
44
|
* To close it, call either `socket.close()`,
|
|
45
45
|
* `socket.readable.cancel()`, `socket.readable.getReader().cancel()`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../src/socket/socket.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../src/socket/socket.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAkE,cAAc,EAAqC,KAAK,cAAc,EAAE,KAAK,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAG5M,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEtE,MAAM,WAAW,aAAa;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IAEjB,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,4BAA6B,SAAQ,aAAa;IAC/D,UAAU,EAAE,mBAAmB,CAAC;IAEhC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC;AAED,qBAAa,mBAAoB,YAAW,aAAa,EAAE,o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
|
|
|
1
|
-
import { PromiseResolver } from
|
|
1
|
+
import { PromiseResolver } from '@yume-chan/async';
|
|
2
|
+
import { ChunkStream, DuplexStreamFactory, pipeFrom, PushReadableStream, WritableStream } from '@yume-chan/stream-extra';
|
|
2
3
|
import { AdbCommand } from '../packet.js';
|
|
3
|
-
import { ChunkStream, DuplexStreamFactory, pipeFrom, PushReadableStream, WritableStream } from '../stream/index.js';
|
|
4
4
|
export class AdbSocketController {
|
|
5
5
|
dispatcher;
|
|
6
6
|
localId;
|
|
@@ -74,7 +74,7 @@ export class AdbSocketController {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
77
|
+
* A duplex stream representing a socket to ADB daemon.
|
|
78
78
|
*
|
|
79
79
|
* To close it, call either `socket.close()`,
|
|
80
80
|
* `socket.readable.cancel()`, `socket.readable.getReader().cancel()`,
|
package/esm/socket/socket.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket.js","sourceRoot":"","sources":["../../src/socket/socket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"socket.js","sourceRoot":"","sources":["../../src/socket/socket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,QAAQ,EAAE,kBAAkB,EAAE,cAAc,EAAqF,MAAM,yBAAyB,CAAC;AAE5M,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAiB1C,MAAM,OAAO,mBAAmB;IACX,UAAU,CAAuB;IAElC,OAAO,CAAU;IACjB,QAAQ,CAAU;IAClB,YAAY,CAAW;IACvB,aAAa,CAAU;IAE/B,OAAO,CAA8C;IAErD,SAAS,CAA6B;IACtC,mBAAmB,CAA4C;IACvE,IAAW,QAAQ,KA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AW,CAAC,QAAQ,CAAC,CAAC,CAAC;IACnE,IAAW,YAAY,KAAc,OAAO,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC;IAC5E,IAAW,aAAa,KAAa,OAAO,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC;IAE7E,IAAW,QAAQ,KAAiC,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvF,IAAW,QAAQ,KAAiC,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEvF,YAAmB,UAA+B;QAC9C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAClC,CAAC;IAEM,KAAK;QACR,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IACpC,CAAC;CACJ"}
|
package/esm/utils/base64.d.ts
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate the required length of the output buffer for the given input length.
|
|
3
|
+
*
|
|
4
|
+
* @param inputLength Length of the input in bytes
|
|
5
|
+
* @returns Length of the output in bytes
|
|
6
|
+
*/
|
|
1
7
|
export declare function calculateBase64EncodedLength(inputLength: number): [outputLength: number, paddingLength: number];
|
|
8
|
+
/**
|
|
9
|
+
* Encode the given input buffer into base64.
|
|
10
|
+
*
|
|
11
|
+
* @param input The input buffer
|
|
12
|
+
* @returns The encoded output buffer
|
|
13
|
+
*/
|
|
2
14
|
export declare function encodeBase64(input: Uint8Array): Uint8Array;
|
|
15
|
+
/**
|
|
16
|
+
* Encode the given input into base64 and write it to the output buffer.
|
|
17
|
+
*
|
|
18
|
+
* The output buffer must be at least as long as the value returned by `calculateBase64EncodedLength`.
|
|
19
|
+
* It can points to the same buffer as the input, as long as `output.offset <= input.offset - input.length / 3`,
|
|
20
|
+
* or `output.offset >= input.offset - 1`
|
|
21
|
+
*
|
|
22
|
+
* @param input The input buffer
|
|
23
|
+
* @param output The output buffer
|
|
24
|
+
* @returns The number of bytes written to the output buffer
|
|
25
|
+
*/
|
|
3
26
|
export declare function encodeBase64(input: Uint8Array, output: Uint8Array): number;
|
|
4
27
|
export declare function decodeBase64(input: string): Uint8Array;
|
|
5
28
|
//# sourceMappingURL=base64.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../src/utils/base64.ts"],"names":[],"mappings":"AAqBA,wBAAgB,4BAA4B,CAAC,WAAW,EAAE,MAAM,GAAG,CAAC,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,CAI/G;AAED,wBAAgB,YAAY,CACxB,KAAK,EAAE,UAAU,GAClB,UAAU,CAAC;AACd,wBAAgB,YAAY,CACxB,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,UAAU,GACnB,MAAM,CAAC;AAoNV,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CA4DtD"}
|
|
1
|
+
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../src/utils/base64.ts"],"names":[],"mappings":"AAqBA;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,WAAW,EAAE,MAAM,GAAG,CAAC,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,CAI/G;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CACxB,KAAK,EAAE,UAAU,GAClB,UAAU,CAAC;AACd;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CACxB,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,UAAU,GACnB,MAAM,CAAC;AAoNV,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CA4DtD"}
|
package/esm/utils/base64.js
CHANGED
|
@@ -15,6 +15,12 @@ addRange('a', 'z');
|
|
|
15
15
|
addRange('0', '9');
|
|
16
16
|
addRange('+', '+');
|
|
17
17
|
addRange('/', '/');
|
|
18
|
+
/**
|
|
19
|
+
* Calculate the required length of the output buffer for the given input length.
|
|
20
|
+
*
|
|
21
|
+
* @param inputLength Length of the input in bytes
|
|
22
|
+
* @returns Length of the output in bytes
|
|
23
|
+
*/
|
|
18
24
|
export function calculateBase64EncodedLength(inputLength) {
|
|
19
25
|
const remainder = inputLength % 3;
|
|
20
26
|
const paddingLength = remainder !== 0 ? 3 - remainder : 0;
|
package/esm/utils/base64.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src/utils/base64.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,MAAM,WAAW,GAA2B,EAAE,CAAC;AAC/C,MAAM,WAAW,GAAa,EAAE,CAAC;AACjC,MAAM,WAAW,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAEtC,SAAS,QAAQ,CAAC,KAAa,EAAE,GAAW;IACxC,MAAM,aAAa,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC1C,MAAM,WAAW,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAEtC,KAAK,IAAI,QAAQ,GAAG,aAAa,EAAE,QAAQ,IAAI,WAAW,EAAE,QAAQ,IAAI,CAAC,EAAE;QACvE,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC;QAChE,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KAC9B;AACL,CAAC;AAED,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACnB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACnB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACnB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACnB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAEnB,MAAM,UAAU,4BAA4B,CAAC,WAAmB;IAC5D,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AAC,CAAC,GAAG,EAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QACnD,MAAM,IAAI,CAAC,CAAC;QAEZ,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAS,CAAC,IAAI,CAAC,CAAC,CAAC;KACjE;SAAM,IAAI,OAAO,KAAK,CAAC,EAAE;QACtB,MAAM,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM,CAAE,CAAE,CAAC;QACvC,MAAM,IAAI,CAAC,CAAC;QAEZ,MAAM,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM,CAAE,CAAE,CAAC;QAEvC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAS,CAAC,IAAI,CAAC,CAAC,CAAC;KACtD;IAED,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yume-chan/adb",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "TypeScript implementation of Android Debug Bridge (ADB) protocol.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adb",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"email": "cnsimonchan@live.com",
|
|
13
13
|
"url": "https://chensi.moe/blog"
|
|
14
14
|
},
|
|
15
|
-
"homepage": "https://github.com/yume-chan/ya-webadb/tree/
|
|
15
|
+
"homepage": "https://github.com/yume-chan/ya-webadb/tree/main/libraries/adb#readme",
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
18
18
|
"url": "git+https://github.com/yume-chan/ya-webadb.git",
|
|
@@ -25,26 +25,25 @@
|
|
|
25
25
|
"main": "esm/index.js",
|
|
26
26
|
"types": "esm/index.d.ts",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@yume-chan/async": "^2.
|
|
29
|
-
"@yume-chan/dataview-bigint-polyfill": "^0.0.
|
|
30
|
-
"@yume-chan/event": "^0.0.
|
|
31
|
-
"@yume-chan/
|
|
32
|
-
"
|
|
33
|
-
"
|
|
28
|
+
"@yume-chan/async": "^2.2.0",
|
|
29
|
+
"@yume-chan/dataview-bigint-polyfill": "^0.0.17",
|
|
30
|
+
"@yume-chan/event": "^0.0.17",
|
|
31
|
+
"@yume-chan/stream-extra": "^0.0.17",
|
|
32
|
+
"@yume-chan/struct": "^0.0.17",
|
|
33
|
+
"tslib": "^2.4.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@jest/globals": "^28.1.
|
|
36
|
+
"@jest/globals": "^28.1.2",
|
|
37
37
|
"@types/node": "^17.0.17",
|
|
38
38
|
"@yume-chan/ts-package-builder": "^1.0.0",
|
|
39
39
|
"cross-env": "^7.0.3",
|
|
40
|
-
"jest": "^28.1.
|
|
41
|
-
"ts-jest": "^28.0.
|
|
42
|
-
"typescript": "4.7.
|
|
40
|
+
"jest": "^28.1.2",
|
|
41
|
+
"ts-jest": "^28.0.5",
|
|
42
|
+
"typescript": "^4.7.4"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "tsc -b tsconfig.build.json",
|
|
46
46
|
"build:watch": "tsc -b tsconfig.build.json",
|
|
47
47
|
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage"
|
|
48
|
-
}
|
|
49
|
-
"readme": "# @yume-chan/adb\n\nTypeScript implementation of Android Debug Bridge (ADB) protocol.\n\n**WARNING:** The public API is UNSTABLE. If you have any questions, please open an issue.\n\n- [Compatibility](#compatibility)\n - [Basic usage](#basic-usage)\n - [Use without bundlers](#use-without-bundlers)\n- [Connection](#connection)\n - [Backend](#backend)\n - [`connect`](#connect)\n- [Authentication](#authentication)\n - [AdbCredentialStore](#adbcredentialstore)\n - [`generateKey`](#generatekey)\n - [`iterateKeys`](#iteratekeys)\n - [Implementations](#implementations)\n - [AdbAuthenticator](#adbauthenticator)\n - [`authenticate`](#authenticate)\n- [Stream multiplex](#stream-multiplex)\n- [Commands](#commands)\n - [subprocess](#subprocess)\n - [raw mode](#raw-mode)\n - [pty mode](#pty-mode)\n - [usb](#usb)\n - [tcpip](#tcpip)\n - [sync](#sync)\n - [LIST](#list)\n - [LIS2](#lis2)\n - [STAT](#stat)\n - [LST2](#lst2)\n - [STA2](#sta2)\n - [RECV](#recv)\n - [RCV2](#rcv2)\n - [SEND](#send)\n - [SND2](#snd2)\n- [Useful links](#useful-links)\n\n## Compatibility\n\nHere is a list of features, their used APIs, and their compatibilities. If an optional feature is not actually used, its requirements can be ignored.\n\nSome features can be polyfilled to support older runtimes, but this library doesn't ship with any polyfills.\n\nEach backend may have different requirements.\n\n### Basic usage\n\n| | Chrome | Edge | Firefox | Internet Explorer | Safari | Node.js |\n| ------------------------------- | ------ | ---- | ------- | ----------------- | ------ | ------------------- |\n| `@yume-chan/struct`<sup>1</sup> | 67 | 79 | 68 | No | 14 | 8.3<sup>2</sup>, 11 |\n| *Overall* | 67 | 79 | No | No | 14.1 | 16.5 |\n\n<sup>1</sup> `uint64` and `string` are used.\n\n<sup>2</sup> `TextEncoder` and `TextDecoder` are only available in `util` module. Need to be assigned to `globalThis`.\n\n### Use without bundlers\n\n| | Chrome | Edge | Firefox | Internet Explorer | Safari | Node.js |\n| --------------- | ------ | ---- | ------- | ----------------- | ------ | ------- |\n| Top-level await | 89 | 89 | 89 | No | 15 | 14.8 |\n\n## Connection\n\nThis library doesn't tie to a specific transportation method.\n\nInstead, a `Backend` is responsible for transferring data in its own way (USB, WebSocket, TCP, etc).\n\n### Backend\n\n#### `connect`\n\n```ts\nconnect(): ValueOrPromise<ReadableWritablePair<AdbPacketCore, AdbPacketInit>>\n```\n\nConnect to a device and create a pair of `AdbPacket` streams.\n\nThe backend, instead of the core library, is responsible for serializing and deserializing the packets. Because it's extreme slow for WebUSB backend (`@yume-chan/adb-backend-webusb`) to read packets with unknown size.\n\n## Authentication\n\nFor how does ADB authentication work, see https://chensi.moe/blog/2020/09/30/webadb-part2-connection/#auth.\n\nIn this library, authentication comes in two parts:\n\n#### AdbCredentialStore\n\nAn interface to generate, store and iterate ADB private keys on each runtime. (Because Node.js and Browsers have different APIs to do this)\n\n##### `generateKey`\n\n```ts\ngenerateKey(): ValueOrPromise<Uint8Array>\n```\n\nGenerate and store a RSA private key with modulus length `2048` and public exponent `65537`.\n\nThe returned `Uint8Array` is the private key in PKCS #8 format.\n\n##### `iterateKeys`\n\n```ts\niterateKeys(): Iterator<ArrayBuffer> | AsyncIterator<ArrayBuffer>\n```\n\nSynchronously or asynchronously iterate through all stored RSA private keys.\n\nEach call to `iterateKeys` must return a different iterator that iterate through all stored keys.\n\n##### Implementations\n\nThe `@yume-chan/adb-credential-web` package contains a `AdbWebCredentialStore` implementation using Web Crypto API for generating keys and Web Storage API for storing keys.\n\n#### AdbAuthenticator\n\nAn `AdbAuthenticator` generates `AUTH` responses for each `AUTH` request from server.\n\nThis package contains `AdbSignatureAuthenticator` and `AdbPublicKeyAuthenticator`, the two basic modes.\n\n#### `authenticate`\n\n```ts\nstatic async authenticate(\n connection: ReadableWritablePair<AdbPacketCore, AdbPacketCore>,\n credentialStore: AdbCredentialStore,\n authenticators = AdbDefaultAuthenticators,\n): Promise<Adb>\n```\n\nCall this method to authenticate the connection and create an `Adb` instance.\n\nIf an authentication process failed, it's possible to call `authenticate` again on the same connection (`AdbPacket` stream pair). Every time the device receives a `CNXN` packet, it resets all internal state, and starts a new authentication process.\n\n## Stream multiplex\n\nADB commands are all based on streams. Multiple streams can send and receive at the same time in one connection.\n\n1. Client sends an `OPEN` packet to create a stream.\n2. Server responds with `OKAY` or `FAIL`.\n3. Client and server read/write on the stream.\n4. Client/server sends a `CLSE` to close the stream.\n\n## Commands\n\n### subprocess\n\nADB has two subprocess invocation modes and two data protocols (4 combinations).\n\n#### raw mode\n\nIn raw mode, Shell protocol transfers `stdout` and `stderr` separately. It also supports returning exit code.\n\n| | Legacy protocol | Shell Protocol |\n| --------------------------- | --------------------------- | ---------------------------- |\n| Feature flag | - | `shell_v2` |\n| Implementation | `AdbNoneSubprocessProtocol` | `AdbShellSubprocessProtocol` |\n| Splitting stdout and stderr | No | Yes |\n| Returning exit code | No | Yes |\n\nUse `spawn` method to create a subprocess in raw mode.\n\n#### pty mode\n\nIn PTY mode, the subprocess has a pseudo-terminal, so it can send special control sequences like clear screen and set cursor position. The two protocols both send data in `stdout`, but Shell Protocol also supports resizing the terminal from client.\n\n| | Legacy protocol | Shell Protocol |\n| --------------------------- | --------------------------- | ---------------------------- |\n| Feature flag | - | `shell_v2` |\n| Implementation | `AdbNoneSubprocessProtocol` | `AdbShellSubprocessProtocol` |\n| Resizing window | No | Yes |\n\nUse `shell` method to create a subprocess in PTY mode.\n\n### usb\n\nDisable ADB over WiFi.\n\n### tcpip\n\nEnable ADB over WiFi.\n\n### sync\n\nClient and server will communicate with another protocol on the opened stream.\n\n#### LIST\n\nRequest server to list the content of a folder.\n\n#### LIS2\n\nVersion 2 of the LIST command, contains more information.\n\nSupported on devices with `ls_v2` feature.\n\n#### STAT\n\nRequest server to return the information of a file.\n\nIf path is a symbolic link, the returned information is about the link itself.\n\nSo it's actually the [`lstat`](https://linux.die.net/man/2/lstat) system call.\n\n#### LST2\n\nVersion 2 of the STAT command, contains more information.\n\nSupported on devices with `stat_v2` feature.\n\n#### STA2\n\nBasically identical to LST2, but if path is a symbolic link, the information is about the file it refers to.\n\nSupported on devices with `stat_v2` feature.\n\n#### RECV\n\nRequest server to send the content of a file.\n\n#### RCV2\n\n*(Not Implemented)*\n\nVersion 2 of the RECV command.\n\nSupported on devices with `sendrecv_v2` feature.\n\n#### SEND\n\n*(Not Implemented)*\n\nSend a file onto server's file system.\n\n#### SND2\n\n*(Not Implemented)*\n\nVersion 2 of the SEND command.\n\nSupported on devices with `sendrecv_v2` feature.\n\n## Useful links\n\n* [ADB protocol overview](https://android.googlesource.com/platform/packages/modules/adb/+/2fd69306184634c6d90db3ed3be5349e71dcc471/OVERVIEW.TXT)\n* [ADB commands](https://android.googlesource.com/platform/packages/modules/adb/+/2fd69306184634c6d90db3ed3be5349e71dcc471/SERVICES.TXT#145)\n"
|
|
48
|
+
}
|
|
50
49
|
}
|
package/src/adb.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// cspell: ignore libusb
|
|
2
2
|
|
|
3
3
|
import { PromiseResolver } from '@yume-chan/async';
|
|
4
|
+
import { AbortController, DecodeUtf8Stream, GatherStringStream, WritableStream, type ReadableWritablePair } from '@yume-chan/stream-extra';
|
|
5
|
+
|
|
4
6
|
import { AdbAuthenticationProcessor, ADB_DEFAULT_AUTHENTICATORS, type AdbCredentialStore } from './auth.js';
|
|
5
7
|
import { AdbPower, AdbReverseCommand, AdbSubprocess, AdbSync, AdbTcpIpCommand, escapeArg, framebuffer, install, type AdbFrameBuffer } from './commands/index.js';
|
|
6
8
|
import { AdbFeatures } from './features.js';
|
|
7
9
|
import { AdbCommand, calculateChecksum, type AdbPacketData, type AdbPacketInit } from './packet.js';
|
|
8
10
|
import { AdbIncomingSocketHandler, AdbPacketDispatcher, type AdbSocket, type Closeable } from './socket/index.js';
|
|
9
|
-
import {
|
|
10
|
-
import { decodeUtf8, encodeUtf8 } from "./utils/index.js";
|
|
11
|
+
import { decodeUtf8, encodeUtf8 } from './utils/index.js';
|
|
11
12
|
|
|
12
13
|
export enum AdbPropKey {
|
|
13
14
|
Product = 'ro.product.name',
|
|
@@ -62,6 +63,7 @@ export class Adb implements Closeable {
|
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
}), {
|
|
66
|
+
// Don't cancel the source ReadableStream on AbortSignal abort.
|
|
65
67
|
preventCancel: true,
|
|
66
68
|
signal: abortController.signal,
|
|
67
69
|
})
|
|
@@ -145,7 +147,7 @@ export class Adb implements Closeable {
|
|
|
145
147
|
private _device: string | undefined;
|
|
146
148
|
public get device() { return this._device; }
|
|
147
149
|
|
|
148
|
-
private _features: AdbFeatures[]
|
|
150
|
+
private _features: AdbFeatures[] = [];
|
|
149
151
|
public get features() { return this._features; }
|
|
150
152
|
|
|
151
153
|
public readonly subprocess: AdbSubprocess;
|
|
@@ -189,8 +191,6 @@ export class Adb implements Closeable {
|
|
|
189
191
|
}
|
|
190
192
|
|
|
191
193
|
private parseBanner(banner: string): void {
|
|
192
|
-
this._features = [];
|
|
193
|
-
|
|
194
194
|
const pieces = banner.split('::');
|
|
195
195
|
if (pieces.length > 1) {
|
|
196
196
|
const props = pieces[1]!;
|
|
@@ -223,8 +223,13 @@ export class Adb implements Closeable {
|
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
|
|
227
|
-
|
|
226
|
+
/**
|
|
227
|
+
* Add a handler for incoming socket.
|
|
228
|
+
* @param handler A function to call with new incoming sockets. It must return `true` if it accepts the socket.
|
|
229
|
+
* @returns A function to remove the handler.
|
|
230
|
+
*/
|
|
231
|
+
public onIncomingSocket(handler: AdbIncomingSocketHandler) {
|
|
232
|
+
return this.dispatcher.onIncomingSocket(handler);
|
|
228
233
|
}
|
|
229
234
|
|
|
230
235
|
public async createSocket(service: string): Promise<AdbSocket> {
|
package/src/auth.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PromiseResolver } from '@yume-chan/async';
|
|
2
2
|
import type { Disposable } from '@yume-chan/event';
|
|
3
3
|
import type { ValueOrPromise } from '@yume-chan/struct';
|
|
4
|
+
|
|
4
5
|
import { calculatePublicKey, calculatePublicKeyLength, sign } from './crypto.js';
|
|
5
6
|
import { AdbCommand, type AdbPacketData } from './packet.js';
|
|
6
7
|
import { calculateBase64EncodedLength, encodeBase64 } from './utils/index.js';
|
package/src/backend.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { ReadableWritablePair } from '@yume-chan/stream-extra';
|
|
1
2
|
import type { ValueOrPromise } from '@yume-chan/struct';
|
|
2
|
-
|
|
3
|
-
import type {
|
|
3
|
+
|
|
4
|
+
import type { AdbPacketData, AdbPacketInit } from './packet.js';
|
|
4
5
|
|
|
5
6
|
export interface AdbBackend {
|
|
6
7
|
readonly serial: string;
|
package/src/commands/base.ts
CHANGED
|
@@ -1,24 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { BufferedReadableStream } from '@yume-chan/stream-extra';
|
|
2
|
+
import Struct from '@yume-chan/struct';
|
|
3
|
+
|
|
2
4
|
import type { Adb } from '../adb.js';
|
|
3
|
-
import { AdbBufferedStream } from '../stream/index.js';
|
|
4
5
|
|
|
5
6
|
const Version =
|
|
6
7
|
new Struct({ littleEndian: true })
|
|
7
8
|
.uint32('version');
|
|
8
9
|
|
|
9
|
-
/*
|
|
10
|
-
* ADB uses 8 int32 fields to describe bit depths
|
|
11
|
-
* The only combination I have seen is RGBA8888, which is
|
|
12
|
-
* red_offset: 0
|
|
13
|
-
* red_length: 8
|
|
14
|
-
* blue_offset: 16
|
|
15
|
-
* blue_length: 8
|
|
16
|
-
* green_offset: 8
|
|
17
|
-
* green_length: 8
|
|
18
|
-
* alpha_offset: 24
|
|
19
|
-
* alpha_length: 8
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
10
|
export const AdbFrameBufferV1 =
|
|
23
11
|
new Struct({ littleEndian: true })
|
|
24
12
|
.uint32('bpp')
|
|
@@ -56,14 +44,31 @@ export const AdbFrameBufferV2 =
|
|
|
56
44
|
|
|
57
45
|
export type AdbFrameBufferV2 = typeof AdbFrameBufferV2['TDeserializeResult'];
|
|
58
46
|
|
|
47
|
+
/**
|
|
48
|
+
* ADB uses 8 int32 fields to describe bit depths
|
|
49
|
+
*
|
|
50
|
+
* The only combination I have seen is RGBA8888, which is
|
|
51
|
+
*
|
|
52
|
+
* red_offset: 0
|
|
53
|
+
* red_length: 8
|
|
54
|
+
* blue_offset: 16
|
|
55
|
+
* blue_length: 8
|
|
56
|
+
* green_offset: 8
|
|
57
|
+
* green_length: 8
|
|
58
|
+
* alpha_offset: 24
|
|
59
|
+
* alpha_length: 8
|
|
60
|
+
*
|
|
61
|
+
* But it doesn't mean that other combinations are not possible.
|
|
62
|
+
*/
|
|
59
63
|
export type AdbFrameBuffer = AdbFrameBufferV1 | AdbFrameBufferV2;
|
|
60
64
|
|
|
61
65
|
export async function framebuffer(adb: Adb): Promise<AdbFrameBuffer> {
|
|
62
66
|
const socket = await adb.createSocket('framebuffer:');
|
|
63
|
-
const stream = new
|
|
67
|
+
const stream = new BufferedReadableStream(socket.readable);
|
|
64
68
|
const { version } = await Version.deserialize(stream);
|
|
65
69
|
switch (version) {
|
|
66
70
|
case 1:
|
|
71
|
+
// TODO: AdbFrameBuffer: does all v1 responses uses the same color space? Add it so the command returns same format for all versions.
|
|
67
72
|
return AdbFrameBufferV1.deserialize(stream);
|
|
68
73
|
case 2:
|
|
69
74
|
return AdbFrameBufferV2.deserialize(stream);
|
package/src/commands/install.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import { WrapWritableStream, WritableStream } from '@yume-chan/stream-extra';
|
|
2
|
+
|
|
3
|
+
import type { Adb } from '../adb.js';
|
|
4
|
+
import { escapeArg } from './subprocess/index.js';
|
|
5
|
+
import type { AdbSync } from './sync/index.js';
|
|
5
6
|
|
|
6
7
|
export function install(
|
|
7
8
|
adb: Adb,
|
|
@@ -12,6 +13,7 @@ export function install(
|
|
|
12
13
|
return new WrapWritableStream<Uint8Array>({
|
|
13
14
|
async start() {
|
|
14
15
|
// TODO: install: support other install apk methods (streaming, etc.)
|
|
16
|
+
// TODO: install: support split apk formats (`adb install-multiple`)
|
|
15
17
|
|
|
16
18
|
// Upload apk file to tmp folder
|
|
17
19
|
sync = await adb.sync();
|
package/src/commands/power.ts
CHANGED
package/src/commands/reverse.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// cspell: ignore killforward
|
|
2
2
|
|
|
3
3
|
import { AutoDisposable } from '@yume-chan/event';
|
|
4
|
+
import { BufferedReadableStream, BufferedReadableStreamEndedError } from '@yume-chan/stream-extra';
|
|
4
5
|
import Struct from '@yume-chan/struct';
|
|
5
|
-
|
|
6
|
+
|
|
7
|
+
import type { Adb } from '../adb.js';
|
|
6
8
|
import type { AdbIncomingSocketHandler, AdbSocket } from '../socket/index.js';
|
|
7
|
-
import {
|
|
8
|
-
import { decodeUtf8 } from "../utils/index.js";
|
|
9
|
+
import { decodeUtf8 } from '../utils/index.js';
|
|
9
10
|
|
|
10
11
|
export interface AdbForwardListener {
|
|
11
12
|
deviceSerial: string;
|
|
@@ -40,7 +41,7 @@ export class AdbReverseCommand extends AutoDisposable {
|
|
|
40
41
|
super();
|
|
41
42
|
|
|
42
43
|
this.adb = adb;
|
|
43
|
-
this.addDisposable(this.adb.
|
|
44
|
+
this.addDisposable(this.adb.onIncomingSocket(this.handleIncomingSocket));
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
protected handleIncomingSocket = async (socket: AdbSocket) => {
|
|
@@ -52,7 +53,7 @@ export class AdbReverseCommand extends AutoDisposable {
|
|
|
52
53
|
|
|
53
54
|
private async createBufferedStream(service: string) {
|
|
54
55
|
const socket = await this.adb.createSocket(service);
|
|
55
|
-
return new
|
|
56
|
+
return new BufferedReadableStream(socket.readable);
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
private async sendRequest(service: string) {
|
|
@@ -79,8 +80,8 @@ export class AdbReverseCommand extends AutoDisposable {
|
|
|
79
80
|
/**
|
|
80
81
|
* @param deviceAddress The address adbd on device is listening on. Can be `tcp:0` to let adbd choose an available TCP port by itself.
|
|
81
82
|
* @param localAddress Native ADB client will open a connection to this address when reverse connection received. In WebADB, it's only used to uniquely identify a reverse tunnel registry, `handler` will be called to handle the connection.
|
|
82
|
-
* @param handler A callback to handle incoming connections
|
|
83
|
-
* @returns If `deviceAddress` is `tcp:0
|
|
83
|
+
* @param handler A callback to handle incoming connections. It must return `true` if it accepts the connection.
|
|
84
|
+
* @returns `tcp:{ACTUAL_LISTENING_PORT}`, If `deviceAddress` is `tcp:0`; otherwise, `deviceAddress`.
|
|
84
85
|
*/
|
|
85
86
|
public async add(
|
|
86
87
|
deviceAddress: string,
|
|
@@ -90,17 +91,17 @@ export class AdbReverseCommand extends AutoDisposable {
|
|
|
90
91
|
const stream = await this.sendRequest(`reverse:forward:${deviceAddress};${localAddress}`);
|
|
91
92
|
|
|
92
93
|
// `tcp:0` tells the device to pick an available port.
|
|
93
|
-
//
|
|
94
|
+
// On Android >=8, device will respond with the selected port for all `tcp:` requests.
|
|
94
95
|
if (deviceAddress.startsWith('tcp:')) {
|
|
95
96
|
let length: number | undefined;
|
|
96
97
|
try {
|
|
97
98
|
length = Number.parseInt(decodeUtf8(await stream.read(4)), 16);
|
|
98
99
|
} catch (e) {
|
|
99
|
-
if (!(e instanceof
|
|
100
|
+
if (!(e instanceof BufferedReadableStreamEndedError)) {
|
|
100
101
|
throw e;
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
//
|
|
104
|
+
// Android <8 doesn't have this response.
|
|
104
105
|
// (the stream is closed now)
|
|
105
106
|
// Can be safely ignored.
|
|
106
107
|
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { GatherStringStream, DecodeUtf8Stream } from '@yume-chan/stream-extra';
|
|
2
|
+
|
|
3
|
+
import { AdbCommandBase } from '../base.js';
|
|
4
|
+
import { AdbSubprocessNoneProtocol, AdbSubprocessProtocol, AdbSubprocessProtocolConstructor, AdbSubprocessShellProtocol } from './protocols/index.js';
|
|
5
|
+
|
|
6
|
+
export interface AdbSubprocessOptions {
|
|
7
|
+
/**
|
|
8
|
+
* A list of `AdbSubprocessProtocolConstructor`s to be used.
|
|
9
|
+
*
|
|
10
|
+
* Different `AdbSubprocessProtocol` has different capabilities, thus requires specific adaptations.
|
|
11
|
+
* Check their documentations for details.
|
|
12
|
+
*
|
|
13
|
+
* The first protocol whose `isSupported` returns `true` will be used.
|
|
14
|
+
* If no `AdbSubprocessProtocol` is supported, an error will be thrown.
|
|
15
|
+
*
|
|
16
|
+
* @default [AdbSubprocessShellProtocol, AdbSubprocessNoneProtocol]
|
|
17
|
+
*/
|
|
18
|
+
protocols: AdbSubprocessProtocolConstructor[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const DEFAULT_OPTIONS: AdbSubprocessOptions = {
|
|
22
|
+
protocols: [AdbSubprocessShellProtocol, AdbSubprocessNoneProtocol],
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export interface AdbSubprocessWaitResult {
|
|
26
|
+
stdout: string;
|
|
27
|
+
stderr: string;
|
|
28
|
+
exitCode: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class AdbSubprocess extends AdbCommandBase {
|
|
32
|
+
private async createProtocol(
|
|
33
|
+
mode: 'pty' | 'raw',
|
|
34
|
+
command?: string | string[],
|
|
35
|
+
options?: Partial<AdbSubprocessOptions>
|
|
36
|
+
): Promise<AdbSubprocessProtocol> {
|
|
37
|
+
const { protocols } = { ...DEFAULT_OPTIONS, ...options };
|
|
38
|
+
|
|
39
|
+
let Constructor: AdbSubprocessProtocolConstructor | undefined;
|
|
40
|
+
for (const item of protocols) {
|
|
41
|
+
// It's async so can't use `Array#find`
|
|
42
|
+
if (await item.isSupported(this.adb)) {
|
|
43
|
+
Constructor = item;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!Constructor) {
|
|
49
|
+
throw new Error('No specified protocol is supported by the device');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (Array.isArray(command)) {
|
|
53
|
+
command = command.join(' ');
|
|
54
|
+
} else if (command === undefined) {
|
|
55
|
+
// spawn the default shell
|
|
56
|
+
command = '';
|
|
57
|
+
}
|
|
58
|
+
return await Constructor[mode](this.adb, command);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Spawns an executable in PTY (interactive) mode.
|
|
63
|
+
* @param command The command to run. If omitted, the default shell will be spawned.
|
|
64
|
+
* @param options The options for creating the `AdbSubprocessProtocol`
|
|
65
|
+
* @returns A new `AdbSubprocessProtocol` instance connecting to the spawned process.
|
|
66
|
+
*/
|
|
67
|
+
public shell(
|
|
68
|
+
command?: string | string[],
|
|
69
|
+
options?: Partial<AdbSubprocessOptions>
|
|
70
|
+
): Promise<AdbSubprocessProtocol> {
|
|
71
|
+
return this.createProtocol('pty', command, options);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Spawns an executable and pipe the output.
|
|
76
|
+
* @param command The command to run, or an array of strings containing both command and args.
|
|
77
|
+
* @param options The options for creating the `AdbSubprocessProtocol`
|
|
78
|
+
* @returns A new `AdbSubprocessProtocol` instance connecting to the spawned process.
|
|
79
|
+
*/
|
|
80
|
+
public spawn(
|
|
81
|
+
command: string | string[],
|
|
82
|
+
options?: Partial<AdbSubprocessOptions>
|
|
83
|
+
): Promise<AdbSubprocessProtocol> {
|
|
84
|
+
return this.createProtocol('raw', command, options);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Spawns a new process, waits until it exits, and returns the entire output.
|
|
89
|
+
* @param command The command to run
|
|
90
|
+
* @param options The options for creating the `AdbSubprocessProtocol`
|
|
91
|
+
* @returns The entire output of the command
|
|
92
|
+
*/
|
|
93
|
+
public async spawnAndWait(
|
|
94
|
+
command: string | string[],
|
|
95
|
+
options?: Partial<AdbSubprocessOptions>
|
|
96
|
+
): Promise<AdbSubprocessWaitResult> {
|
|
97
|
+
const shell = await this.spawn(command, options);
|
|
98
|
+
|
|
99
|
+
const stdout = new GatherStringStream();
|
|
100
|
+
const stderr = new GatherStringStream();
|
|
101
|
+
|
|
102
|
+
const [, , exitCode] = await Promise.all([
|
|
103
|
+
shell.stdout
|
|
104
|
+
.pipeThrough(new DecodeUtf8Stream())
|
|
105
|
+
.pipeTo(stdout),
|
|
106
|
+
shell.stderr
|
|
107
|
+
.pipeThrough(new DecodeUtf8Stream())
|
|
108
|
+
.pipeTo(stderr),
|
|
109
|
+
shell.exit
|
|
110
|
+
]);
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
stdout: stdout.result,
|
|
114
|
+
stderr: stderr.result,
|
|
115
|
+
exitCode,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Spawns a new process, waits until it exits, and returns the entire output.
|
|
121
|
+
* @param command The command to run
|
|
122
|
+
* @returns The entire output of the command
|
|
123
|
+
*/
|
|
124
|
+
public async spawnAndWaitLegacy(command: string | string[]): Promise<string> {
|
|
125
|
+
const { stdout } = await this.spawnAndWait(
|
|
126
|
+
command,
|
|
127
|
+
{ protocols: [AdbSubprocessNoneProtocol] }
|
|
128
|
+
);
|
|
129
|
+
return stdout;
|
|
130
|
+
}
|
|
131
|
+
}
|