@yume-chan/adb 0.0.10 → 0.0.13
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 +50 -0
- package/CHANGELOG.md +29 -1
- package/LICENSE +1 -1
- package/README.md +71 -51
- package/esm/adb.d.ts +48 -0
- package/esm/adb.d.ts.map +1 -0
- package/esm/adb.js +149 -136
- package/esm/adb.js.map +1 -1
- package/{dts → esm}/auth.d.ts +11 -11
- package/esm/auth.d.ts.map +1 -0
- package/esm/auth.js +72 -110
- package/esm/auth.js.map +1 -1
- package/esm/backend.d.ts +9 -0
- package/esm/backend.d.ts.map +1 -0
- package/{dts → esm}/commands/base.d.ts +1 -1
- package/esm/commands/base.d.ts.map +1 -0
- package/esm/commands/base.js +1 -0
- package/esm/commands/base.js.map +1 -1
- package/{dts → esm}/commands/framebuffer.d.ts +3 -3
- package/esm/commands/framebuffer.d.ts.map +1 -0
- package/esm/commands/framebuffer.js +15 -18
- package/esm/commands/framebuffer.js.map +1 -1
- package/esm/commands/index.d.ts +9 -0
- package/esm/commands/index.d.ts.map +1 -0
- package/esm/commands/index.js +8 -8
- package/esm/commands/index.js.map +1 -1
- package/esm/commands/install.d.ts +4 -0
- package/esm/commands/install.d.ts.map +1 -0
- package/esm/commands/install.js +19 -13
- package/esm/commands/install.js.map +1 -1
- package/esm/commands/power.d.ts +23 -0
- package/esm/commands/power.d.ts.map +1 -0
- package/esm/commands/power.js +45 -0
- package/esm/commands/power.js.map +1 -0
- package/{dts → esm}/commands/reverse.d.ts +3 -3
- package/esm/commands/reverse.d.ts.map +1 -0
- package/esm/commands/reverse.js +49 -60
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/index.d.ts +56 -0
- package/esm/commands/subprocess/index.d.ts.map +1 -0
- package/esm/commands/subprocess/index.js +88 -0
- package/esm/commands/subprocess/index.js.map +1 -0
- package/esm/commands/subprocess/legacy.d.ts +35 -0
- package/esm/commands/subprocess/legacy.d.ts.map +1 -0
- package/esm/commands/subprocess/legacy.js +53 -0
- package/esm/commands/subprocess/legacy.js.map +1 -0
- package/esm/commands/subprocess/protocol.d.ts +39 -0
- package/esm/commands/subprocess/protocol.d.ts.map +1 -0
- package/esm/commands/subprocess/protocol.js +157 -0
- package/esm/commands/subprocess/protocol.js.map +1 -0
- package/esm/commands/subprocess/protocols/index.d.ts +4 -0
- package/esm/commands/subprocess/protocols/index.d.ts.map +1 -0
- package/esm/commands/subprocess/protocols/index.js +4 -0
- package/esm/commands/subprocess/protocols/index.js.map +1 -0
- package/esm/commands/subprocess/protocols/none.d.ts +35 -0
- package/esm/commands/subprocess/protocols/none.d.ts.map +1 -0
- package/esm/commands/subprocess/protocols/none.js +53 -0
- package/esm/commands/subprocess/protocols/none.js.map +1 -0
- package/esm/commands/subprocess/protocols/shell.d.ts +39 -0
- package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -0
- package/esm/commands/subprocess/protocols/shell.js +155 -0
- package/esm/commands/subprocess/protocols/shell.js.map +1 -0
- package/esm/commands/subprocess/protocols/types.d.ts +50 -0
- package/esm/commands/subprocess/protocols/types.d.ts.map +1 -0
- package/esm/commands/{shell → subprocess/protocols}/types.js +0 -0
- package/esm/commands/subprocess/protocols/types.js.map +1 -0
- package/esm/commands/subprocess/types.d.ts +50 -0
- package/esm/commands/subprocess/types.d.ts.map +1 -0
- package/esm/commands/subprocess/types.js +2 -0
- package/esm/commands/{shell → subprocess}/types.js.map +1 -1
- package/{dts/commands/shell → esm/commands/subprocess}/utils.d.ts +0 -0
- package/esm/commands/subprocess/utils.d.ts.map +1 -0
- package/esm/commands/{shell → subprocess}/utils.js +0 -0
- package/esm/commands/subprocess/utils.js.map +1 -0
- package/esm/commands/sync/index.d.ts +8 -0
- package/esm/commands/sync/index.d.ts.map +1 -0
- package/esm/commands/sync/index.js +7 -7
- package/esm/commands/sync/index.js.map +1 -1
- package/esm/commands/sync/list.d.ts +41 -0
- package/esm/commands/sync/list.d.ts.map +1 -0
- package/esm/commands/sync/list.js +52 -20
- package/esm/commands/sync/list.js.map +1 -1
- package/esm/commands/sync/pull.d.ts +11 -0
- package/esm/commands/sync/pull.d.ts.map +1 -0
- package/esm/commands/sync/pull.js +17 -11
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/push.d.ts +8 -0
- package/esm/commands/sync/push.d.ts.map +1 -0
- package/esm/commands/sync/push.js +19 -37
- package/esm/commands/sync/push.js.map +1 -1
- package/{dts → esm}/commands/sync/request.d.ts +4 -3
- package/esm/commands/sync/request.d.ts.map +1 -0
- package/esm/commands/sync/request.js +25 -27
- package/esm/commands/sync/request.js.map +1 -1
- package/{dts → esm}/commands/sync/response.d.ts +4 -3
- package/esm/commands/sync/response.d.ts.map +1 -0
- package/esm/commands/sync/response.js +17 -20
- package/esm/commands/sync/response.js.map +1 -1
- package/{dts → esm}/commands/sync/stat.d.ts +16 -4
- package/esm/commands/sync/stat.d.ts.map +1 -0
- package/esm/commands/sync/stat.js +38 -30
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.d.ts +61 -0
- package/esm/commands/sync/sync.d.ts.map +1 -0
- package/esm/commands/sync/sync.js +122 -89
- package/esm/commands/sync/sync.js.map +1 -1
- package/{dts → esm}/commands/tcpip.d.ts +1 -1
- package/{dts → esm}/commands/tcpip.d.ts.map +1 -1
- package/esm/commands/tcpip.js +14 -19
- package/esm/commands/tcpip.js.map +1 -1
- package/esm/crypto.d.ts +37 -0
- package/esm/crypto.d.ts.map +1 -0
- package/esm/crypto.js +77 -62
- package/esm/crypto.js.map +1 -1
- package/esm/features.d.ts +8 -0
- package/esm/features.d.ts.map +1 -0
- package/esm/features.js +7 -3
- package/esm/features.js.map +1 -1
- package/esm/index.d.ts +11 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +10 -10
- package/esm/index.js.map +1 -1
- package/esm/packet.d.ts +47 -0
- package/esm/packet.d.ts.map +1 -0
- package/esm/packet.js +27 -52
- package/esm/packet.js.map +1 -1
- package/esm/socket/controller.d.ts +37 -0
- package/esm/socket/controller.d.ts.map +1 -0
- package/esm/socket/controller.js +52 -66
- package/esm/socket/controller.js.map +1 -1
- package/esm/socket/dispatcher.d.ts +44 -0
- package/esm/socket/dispatcher.d.ts.map +1 -0
- package/esm/socket/dispatcher.js +146 -165
- package/esm/socket/dispatcher.js.map +1 -1
- package/esm/socket/index.d.ts +3 -0
- package/esm/socket/index.d.ts.map +1 -0
- package/esm/socket/index.js +2 -6
- package/esm/socket/index.js.map +1 -1
- package/esm/socket/socket.d.ts +46 -0
- package/esm/socket/socket.d.ts.map +1 -0
- package/esm/socket/socket.js +77 -13
- package/esm/socket/socket.js.map +1 -1
- package/esm/stream/buffered.d.ts +35 -0
- package/esm/stream/buffered.d.ts.map +1 -0
- package/esm/stream/buffered.js +123 -0
- package/esm/stream/buffered.js.map +1 -0
- package/esm/stream/detect.bak.d.ts +240 -0
- package/esm/stream/detect.bak.d.ts.map +1 -0
- package/esm/stream/detect.bak.js +60 -0
- package/esm/stream/detect.bak.js.map +1 -0
- package/esm/stream/detect.d.ts +2 -0
- package/esm/stream/detect.d.ts.map +1 -0
- package/esm/stream/detect.js +5 -0
- package/esm/stream/detect.js.map +1 -0
- package/esm/stream/detect.native.d.ts +240 -0
- package/esm/stream/detect.native.d.ts.map +1 -0
- package/esm/stream/detect.native.js +60 -0
- package/esm/stream/detect.native.js.map +1 -0
- package/esm/stream/detect.polyfill.d.ts +18 -0
- package/esm/stream/detect.polyfill.d.ts.map +1 -0
- package/esm/stream/detect.polyfill.js +9 -0
- package/esm/stream/detect.polyfill.js.map +1 -0
- package/esm/stream/index.d.ts +4 -0
- package/esm/stream/index.d.ts.map +1 -0
- package/esm/stream/index.js +3 -2
- package/esm/stream/index.js.map +1 -1
- package/esm/stream/transform.d.ts +98 -0
- package/esm/stream/transform.d.ts.map +1 -0
- package/esm/stream/transform.js +402 -0
- package/esm/stream/transform.js.map +1 -0
- package/{dts → esm}/utils/auto-reset-event.d.ts +1 -1
- package/esm/utils/auto-reset-event.d.ts.map +1 -0
- package/esm/utils/auto-reset-event.js +2 -1
- package/esm/utils/auto-reset-event.js.map +1 -1
- package/esm/utils/base64.d.ts +5 -0
- package/esm/utils/base64.d.ts.map +1 -0
- package/esm/utils/base64.js +116 -80
- package/esm/utils/base64.js.map +1 -1
- package/esm/utils/encoding.d.ts +3 -0
- package/esm/utils/encoding.d.ts.map +1 -0
- package/esm/utils/encoding.js +1 -1
- package/esm/utils/encoding.js.map +1 -1
- package/esm/utils/index.d.ts +4 -0
- package/esm/utils/index.d.ts.map +1 -0
- package/esm/utils/index.js +3 -5
- package/esm/utils/index.js.map +1 -1
- package/package.json +50 -44
- package/src/adb.ts +177 -150
- package/src/auth.ts +37 -30
- package/src/backend.ts +3 -12
- package/src/commands/base.ts +1 -1
- package/src/commands/framebuffer.ts +4 -4
- package/src/commands/index.ts +8 -8
- package/src/commands/install.ts +24 -15
- package/src/commands/power.ts +54 -0
- package/src/commands/reverse.ts +10 -8
- package/src/commands/subprocess/index.ts +139 -0
- package/src/commands/subprocess/protocols/index.ts +3 -0
- package/src/commands/subprocess/protocols/none.ts +68 -0
- package/src/commands/subprocess/protocols/shell.ts +190 -0
- package/src/commands/subprocess/protocols/types.ts +59 -0
- package/src/commands/{shell → subprocess}/utils.ts +0 -0
- package/src/commands/sync/index.ts +7 -7
- package/src/commands/sync/list.ts +56 -9
- package/src/commands/sync/pull.ts +27 -18
- package/src/commands/sync/push.ts +25 -30
- package/src/commands/sync/request.ts +8 -7
- package/src/commands/sync/response.ts +12 -6
- package/src/commands/sync/stat.ts +43 -14
- package/src/commands/sync/sync.ts +102 -34
- package/src/commands/tcpip.ts +3 -3
- package/src/crypto.ts +95 -84
- package/src/features.ts +6 -2
- package/src/index.ts +11 -10
- package/src/packet.ts +49 -53
- package/src/socket/dispatcher.ts +110 -109
- package/src/socket/index.ts +2 -6
- package/src/socket/socket.ts +125 -17
- package/src/stream/buffered.ts +147 -0
- package/src/stream/detect.native.ts +362 -0
- package/src/stream/detect.polyfill.ts +28 -0
- package/src/stream/detect.ts +5 -0
- package/src/stream/index.ts +3 -2
- package/src/stream/transform.ts +483 -0
- package/src/utils/auto-reset-event.ts +1 -1
- package/src/utils/base64.ts +161 -129
- package/src/utils/index.ts +3 -5
- package/tsconfig.build.json +3 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.test.json +10 -0
- package/dts/adb.d.ts +0 -46
- package/dts/adb.d.ts.map +0 -1
- package/dts/auth.d.ts.map +0 -1
- package/dts/backend.d.ts +0 -13
- package/dts/backend.d.ts.map +0 -1
- package/dts/commands/base.d.ts.map +0 -1
- package/dts/commands/demo-mode.d.ts +0 -41
- package/dts/commands/demo-mode.d.ts.map +0 -1
- package/dts/commands/framebuffer.d.ts.map +0 -1
- package/dts/commands/index.d.ts +0 -9
- package/dts/commands/index.d.ts.map +0 -1
- package/dts/commands/install.d.ts +0 -3
- package/dts/commands/install.d.ts.map +0 -1
- package/dts/commands/reverse.d.ts.map +0 -1
- package/dts/commands/shell/index.d.ts +0 -46
- package/dts/commands/shell/index.d.ts.map +0 -1
- package/dts/commands/shell/legacy.d.ts +0 -38
- package/dts/commands/shell/legacy.d.ts.map +0 -1
- package/dts/commands/shell/protocol.d.ts +0 -45
- package/dts/commands/shell/protocol.d.ts.map +0 -1
- package/dts/commands/shell/types.d.ts +0 -47
- package/dts/commands/shell/types.d.ts.map +0 -1
- package/dts/commands/shell/utils.d.ts.map +0 -1
- package/dts/commands/sync/index.d.ts +0 -8
- package/dts/commands/sync/index.d.ts.map +0 -1
- package/dts/commands/sync/list.d.ts +0 -17
- package/dts/commands/sync/list.d.ts.map +0 -1
- package/dts/commands/sync/pull.d.ts +0 -11
- package/dts/commands/sync/pull.d.ts.map +0 -1
- package/dts/commands/sync/push.d.ts +0 -8
- package/dts/commands/sync/push.d.ts.map +0 -1
- package/dts/commands/sync/request.d.ts.map +0 -1
- package/dts/commands/sync/response.d.ts.map +0 -1
- package/dts/commands/sync/stat.d.ts.map +0 -1
- package/dts/commands/sync/sync.d.ts +0 -68
- package/dts/commands/sync/sync.d.ts.map +0 -1
- package/dts/crypto.d.ts +0 -24
- package/dts/crypto.d.ts.map +0 -1
- package/dts/features.d.ts +0 -6
- package/dts/features.d.ts.map +0 -1
- package/dts/index.d.ts +0 -11
- package/dts/index.d.ts.map +0 -1
- package/dts/packet.d.ts +0 -27
- package/dts/packet.d.ts.map +0 -1
- package/dts/socket/close-event-emitter.d.ts +0 -8
- package/dts/socket/close-event-emitter.d.ts.map +0 -1
- package/dts/socket/controller.d.ts +0 -43
- package/dts/socket/controller.d.ts.map +0 -1
- package/dts/socket/data-event-emitter.d.ts +0 -10
- package/dts/socket/data-event-emitter.d.ts.map +0 -1
- package/dts/socket/dispatcher.d.ts +0 -53
- package/dts/socket/dispatcher.d.ts.map +0 -1
- package/dts/socket/index.d.ts +0 -7
- package/dts/socket/index.d.ts.map +0 -1
- package/dts/socket/logger.d.ts +0 -9
- package/dts/socket/logger.d.ts.map +0 -1
- package/dts/socket/socket.d.ts +0 -22
- package/dts/socket/socket.d.ts.map +0 -1
- package/dts/stream/buffered-stream.d.ts +0 -28
- package/dts/stream/buffered-stream.d.ts.map +0 -1
- package/dts/stream/index.d.ts +0 -3
- package/dts/stream/index.d.ts.map +0 -1
- package/dts/stream/stream.d.ts +0 -15
- package/dts/stream/stream.d.ts.map +0 -1
- package/dts/utils/auto-reset-event.d.ts.map +0 -1
- package/dts/utils/base64.d.ts +0 -7
- package/dts/utils/base64.d.ts.map +0 -1
- package/dts/utils/chunk.d.ts +0 -3
- package/dts/utils/chunk.d.ts.map +0 -1
- package/dts/utils/encoding.d.ts +0 -3
- package/dts/utils/encoding.d.ts.map +0 -1
- package/dts/utils/event-queue.d.ts +0 -35
- package/dts/utils/event-queue.d.ts.map +0 -1
- package/dts/utils/index.d.ts +0 -6
- package/dts/utils/index.d.ts.map +0 -1
- package/esm/commands/demo-mode.js +0 -170
- package/esm/commands/demo-mode.js.map +0 -1
- package/esm/commands/shell/index.js +0 -62
- package/esm/commands/shell/index.js.map +0 -1
- package/esm/commands/shell/legacy.js +0 -49
- package/esm/commands/shell/legacy.js.map +0 -1
- package/esm/commands/shell/protocol.js +0 -106
- package/esm/commands/shell/protocol.js.map +0 -1
- package/esm/commands/shell/utils.js.map +0 -1
- package/esm/socket/close-event-emitter.js +0 -28
- package/esm/socket/close-event-emitter.js.map +0 -1
- package/esm/socket/data-event-emitter.js +0 -25
- package/esm/socket/data-event-emitter.js.map +0 -1
- package/esm/socket/logger.js +0 -2
- package/esm/socket/logger.js.map +0 -1
- package/esm/stream/buffered-stream.js +0 -67
- package/esm/stream/buffered-stream.js.map +0 -1
- package/esm/stream/stream.js +0 -41
- package/esm/stream/stream.js.map +0 -1
- package/esm/utils/chunk.js +0 -70
- package/esm/utils/chunk.js.map +0 -1
- package/esm/utils/event-queue.js +0 -104
- package/esm/utils/event-queue.js.map +0 -1
- package/src/commands/demo-mode.ts +0 -160
- package/src/commands/shell/index.ts +0 -87
- package/src/commands/shell/legacy.ts +0 -59
- package/src/commands/shell/protocol.ts +0 -121
- package/src/commands/shell/types.ts +0 -55
- package/src/socket/close-event-emitter.ts +0 -28
- package/src/socket/controller.ts +0 -105
- package/src/socket/data-event-emitter.ts +0 -27
- package/src/socket/logger.ts +0 -12
- package/src/stream/buffered-stream.ts +0 -92
- package/src/stream/stream.ts +0 -50
- package/src/utils/chunk.ts +0 -70
- package/src/utils/encoding.ts +0 -13
- package/src/utils/event-queue.ts +0 -145
package/src/commands/install.ts
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
|
-
import { Adb } from "../adb";
|
|
2
|
-
import {
|
|
1
|
+
import type { Adb } from "../adb.js";
|
|
2
|
+
import { WrapWritableStream, WritableStream } from "../stream/index.js";
|
|
3
|
+
import { escapeArg } from "./subprocess/index.js";
|
|
4
|
+
import type { AdbSync } from "./sync/index.js";
|
|
3
5
|
|
|
4
|
-
export
|
|
6
|
+
export function install(
|
|
5
7
|
adb: Adb,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
): Promise<void> {
|
|
9
|
-
const filename = `/data/local/tmp/${Math.random().toString().substr(2)}.apk`;
|
|
8
|
+
): WritableStream<Uint8Array> {
|
|
9
|
+
const filename = `/data/local/tmp/${Math.random().toString().substring(2)}.apk`;
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
let sync!: AdbSync;
|
|
12
|
+
return new WrapWritableStream<Uint8Array>({
|
|
13
|
+
async start() {
|
|
14
|
+
// TODO: install: support other install apk methods (streaming, etc.)
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
// Upload apk file to tmp folder
|
|
17
|
+
sync = await adb.sync();
|
|
18
|
+
return sync.write(filename, undefined, undefined);
|
|
19
|
+
},
|
|
20
|
+
async close() {
|
|
21
|
+
sync.dispose();
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
// Invoke `pm install` to install it
|
|
24
|
+
await adb.subprocess.spawnAndWaitLegacy(['pm', 'install', escapeArg(filename)]);
|
|
25
|
+
|
|
26
|
+
// Remove the temp file
|
|
27
|
+
await adb.rm(filename);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
21
30
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// cspell: ignore bootloader
|
|
2
|
+
// cspell: ignore fastboot
|
|
3
|
+
// cspell: ignore keyevent
|
|
4
|
+
// cspell: ignore longpress
|
|
5
|
+
|
|
6
|
+
import { AdbCommandBase } from "./base.js";
|
|
7
|
+
|
|
8
|
+
export class AdbPower extends AdbCommandBase {
|
|
9
|
+
public reboot(name: string = '') {
|
|
10
|
+
return this.adb.createSocketAndWait(`reboot:${name}`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public bootloader() {
|
|
14
|
+
return this.reboot('bootloader');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public fastboot() {
|
|
18
|
+
return this.reboot('fastboot');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public recovery() {
|
|
22
|
+
return this.reboot('recovery');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public sideload() {
|
|
26
|
+
return this.reboot('sideload');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Reboot to Qualcomm Emergency Download (EDL) Mode.
|
|
31
|
+
*
|
|
32
|
+
* Only works on some Qualcomm devices.
|
|
33
|
+
*/
|
|
34
|
+
public qualcommEdlMode() {
|
|
35
|
+
return this.reboot('edl');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public powerOff() {
|
|
39
|
+
return this.adb.subprocess.spawnAndWaitLegacy(['reboot', '-p']);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public powerButton(longPress: boolean = false) {
|
|
43
|
+
return this.adb.subprocess.spawnAndWaitLegacy(['input', 'keyevent', longPress ? '--longpress POWER' : 'POWER']);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Reboot to Samsung Odin download mode.
|
|
48
|
+
*
|
|
49
|
+
* Only works on Samsung devices.
|
|
50
|
+
*/
|
|
51
|
+
public samsungOdin() {
|
|
52
|
+
return this.reboot('download');
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/commands/reverse.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
// cspell: ignore killforward
|
|
2
|
+
|
|
1
3
|
import { AutoDisposable } from '@yume-chan/event';
|
|
2
4
|
import Struct from '@yume-chan/struct';
|
|
3
|
-
import type {
|
|
4
|
-
import type { AdbIncomingSocketEventArgs, AdbPacketDispatcher, AdbSocket } from '../socket';
|
|
5
|
-
import { AdbBufferedStream } from '../stream';
|
|
6
|
-
import { decodeUtf8 } from "../utils";
|
|
5
|
+
import type { AdbPacketData } from '../packet.js';
|
|
6
|
+
import type { AdbIncomingSocketEventArgs, AdbPacketDispatcher, AdbSocket } from '../socket/index.js';
|
|
7
|
+
import { AdbBufferedStream } from '../stream/index.js';
|
|
8
|
+
import { decodeUtf8 } from "../utils/index.js";
|
|
7
9
|
|
|
8
10
|
export interface AdbReverseHandler {
|
|
9
|
-
onSocket(packet:
|
|
11
|
+
onSocket(packet: AdbPacketData, socket: AdbSocket): void;
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
export interface AdbForwardListener {
|
|
@@ -50,8 +52,8 @@ export class AdbReverseCommand extends AutoDisposable {
|
|
|
50
52
|
return;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
const address = decodeUtf8(e.packet.payload
|
|
54
|
-
// tcp:
|
|
55
|
+
const address = decodeUtf8(e.packet.payload);
|
|
56
|
+
// Address format: `tcp:12345\0`
|
|
55
57
|
const port = Number.parseInt(address.substring(4));
|
|
56
58
|
if (this.localPortToHandler.has(port)) {
|
|
57
59
|
this.localPortToHandler.get(port)!.onSocket(e.packet, e.socket);
|
|
@@ -78,7 +80,7 @@ export class AdbReverseCommand extends AutoDisposable {
|
|
|
78
80
|
|
|
79
81
|
const response = await AdbReverseStringResponse.deserialize(stream);
|
|
80
82
|
return response.content!.split('\n').map(line => {
|
|
81
|
-
const [deviceSerial, localName, remoteName] = line.split(' ');
|
|
83
|
+
const [deviceSerial, localName, remoteName] = line.split(' ') as [string, string, string];
|
|
82
84
|
return { deviceSerial, localName, remoteName };
|
|
83
85
|
});
|
|
84
86
|
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { Adb } from '../../adb.js';
|
|
2
|
+
import { DecodeUtf8Stream, GatherStringStream } from "../../stream/index.js";
|
|
3
|
+
import { AdbSubprocessNoneProtocol, AdbSubprocessShellProtocol, type AdbSubprocessProtocol, type AdbSubprocessProtocolConstructor } from './protocols/index.js';
|
|
4
|
+
|
|
5
|
+
export * from './protocols/index.js';
|
|
6
|
+
export * from './utils.js';
|
|
7
|
+
|
|
8
|
+
export interface AdbSubprocessOptions {
|
|
9
|
+
/**
|
|
10
|
+
* A list of `AdbSubprocessProtocolConstructor`s to be used.
|
|
11
|
+
*
|
|
12
|
+
* Different `AdbSubprocessProtocol` has different capabilities, thus requires specific adaptations.
|
|
13
|
+
* Check their documentations for details.
|
|
14
|
+
*
|
|
15
|
+
* The first protocol whose `isSupported` returns `true` will be used.
|
|
16
|
+
* If no `AdbSubprocessProtocol` is supported, an error will be thrown.
|
|
17
|
+
*
|
|
18
|
+
* @default [AdbSubprocessShellProtocol, AdbSubprocessNoneProtocol]
|
|
19
|
+
*/
|
|
20
|
+
protocols: AdbSubprocessProtocolConstructor[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const DEFAULT_OPTIONS: AdbSubprocessOptions = {
|
|
24
|
+
protocols: [AdbSubprocessShellProtocol, AdbSubprocessNoneProtocol],
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export interface AdbSubprocessWaitResult {
|
|
28
|
+
stdout: string;
|
|
29
|
+
stderr: string;
|
|
30
|
+
exitCode: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class AdbSubprocess {
|
|
34
|
+
public readonly adb: Adb;
|
|
35
|
+
|
|
36
|
+
public constructor(adb: Adb) {
|
|
37
|
+
this.adb = adb;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private async createProtocol(
|
|
41
|
+
mode: 'pty' | 'raw',
|
|
42
|
+
command?: string | string[],
|
|
43
|
+
options?: Partial<AdbSubprocessOptions>
|
|
44
|
+
): Promise<AdbSubprocessProtocol> {
|
|
45
|
+
const { protocols } = { ...DEFAULT_OPTIONS, ...options };
|
|
46
|
+
|
|
47
|
+
let Constructor: AdbSubprocessProtocolConstructor | undefined;
|
|
48
|
+
for (const item of protocols) {
|
|
49
|
+
// It's async so can't use `Array#find`
|
|
50
|
+
if (await item.isSupported(this.adb)) {
|
|
51
|
+
Constructor = item;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!Constructor) {
|
|
57
|
+
throw new Error('No specified protocol is supported by the device');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (Array.isArray(command)) {
|
|
61
|
+
command = command.join(' ');
|
|
62
|
+
} else if (command === undefined) {
|
|
63
|
+
// spawn the default shell
|
|
64
|
+
command = '';
|
|
65
|
+
}
|
|
66
|
+
return await Constructor[mode](this.adb, command);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Spawns an executable in PTY (interactive) mode.
|
|
71
|
+
* @param command The command to run. If omitted, the default shell will be spawned.
|
|
72
|
+
* @param options The options for creating the `AdbSubprocessProtocol`
|
|
73
|
+
* @returns A new `AdbSubprocessProtocol` instance connecting to the spawned process.
|
|
74
|
+
*/
|
|
75
|
+
public shell(
|
|
76
|
+
command?: string | string[],
|
|
77
|
+
options?: Partial<AdbSubprocessOptions>
|
|
78
|
+
): Promise<AdbSubprocessProtocol> {
|
|
79
|
+
return this.createProtocol('pty', command, options);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Spawns an executable and pipe the output.
|
|
84
|
+
* @param command The command to run, or an array of strings containing both command and args.
|
|
85
|
+
* @param options The options for creating the `AdbSubprocessProtocol`
|
|
86
|
+
* @returns A new `AdbSubprocessProtocol` instance connecting to the spawned process.
|
|
87
|
+
*/
|
|
88
|
+
public spawn(
|
|
89
|
+
command: string | string[],
|
|
90
|
+
options?: Partial<AdbSubprocessOptions>
|
|
91
|
+
): Promise<AdbSubprocessProtocol> {
|
|
92
|
+
return this.createProtocol('raw', command, options);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Spawns a new process, waits until it exits, and returns the entire output.
|
|
97
|
+
* @param command The command to run
|
|
98
|
+
* @param options The options for creating the `AdbSubprocessProtocol`
|
|
99
|
+
* @returns The entire output of the command
|
|
100
|
+
*/
|
|
101
|
+
public async spawnAndWait(
|
|
102
|
+
command: string | string[],
|
|
103
|
+
options?: Partial<AdbSubprocessOptions>
|
|
104
|
+
): Promise<AdbSubprocessWaitResult> {
|
|
105
|
+
const shell = await this.spawn(command, options);
|
|
106
|
+
|
|
107
|
+
const stdout = new GatherStringStream();
|
|
108
|
+
const stderr = new GatherStringStream();
|
|
109
|
+
|
|
110
|
+
const [, , exitCode] = await Promise.all([
|
|
111
|
+
shell.stdout
|
|
112
|
+
.pipeThrough(new DecodeUtf8Stream())
|
|
113
|
+
.pipeTo(stdout),
|
|
114
|
+
shell.stderr
|
|
115
|
+
.pipeThrough(new DecodeUtf8Stream())
|
|
116
|
+
.pipeTo(stderr),
|
|
117
|
+
shell.exit
|
|
118
|
+
]);
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
stdout: stdout.result,
|
|
122
|
+
stderr: stderr.result,
|
|
123
|
+
exitCode,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Spawns a new process, waits until it exits, and returns the entire output.
|
|
129
|
+
* @param command The command to run
|
|
130
|
+
* @returns The entire output of the command
|
|
131
|
+
*/
|
|
132
|
+
public async spawnAndWaitLegacy(command: string | string[]): Promise<string> {
|
|
133
|
+
const { stdout } = await this.spawnAndWait(
|
|
134
|
+
command,
|
|
135
|
+
{ protocols: [AdbSubprocessNoneProtocol] }
|
|
136
|
+
);
|
|
137
|
+
return stdout;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Adb } from "../../../adb.js";
|
|
2
|
+
import type { AdbSocket } from "../../../socket/index.js";
|
|
3
|
+
import { DuplexStreamFactory, type ReadableStream } from "../../../stream/index.js";
|
|
4
|
+
import type { AdbSubprocessProtocol } from "./types.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The legacy shell
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* * `stderr`: No
|
|
11
|
+
* * `exit` exit code: No
|
|
12
|
+
* * `resize`: No
|
|
13
|
+
*/
|
|
14
|
+
export class AdbSubprocessNoneProtocol implements AdbSubprocessProtocol {
|
|
15
|
+
public static isSupported() { return true; }
|
|
16
|
+
|
|
17
|
+
public static async pty(adb: Adb, command: string) {
|
|
18
|
+
return new AdbSubprocessNoneProtocol(await adb.createSocket(`shell:${command}`));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public static async raw(adb: Adb, command: string) {
|
|
22
|
+
// Native ADB client doesn't allow none protocol + raw mode,
|
|
23
|
+
// But ADB daemon supports it.
|
|
24
|
+
return new AdbSubprocessNoneProtocol(await adb.createSocket(`shell,raw:${command}`));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private readonly socket: AdbSocket;
|
|
28
|
+
|
|
29
|
+
// Legacy shell forwards all data to stdin.
|
|
30
|
+
public get stdin() { return this.socket.writable; }
|
|
31
|
+
|
|
32
|
+
private _stdout: ReadableStream<Uint8Array>;
|
|
33
|
+
/**
|
|
34
|
+
* Legacy shell mixes stdout and stderr.
|
|
35
|
+
*/
|
|
36
|
+
public get stdout() { return this._stdout; }
|
|
37
|
+
|
|
38
|
+
private _stderr: ReadableStream<Uint8Array>;
|
|
39
|
+
/**
|
|
40
|
+
* `stderr` will always be empty.
|
|
41
|
+
*/
|
|
42
|
+
public get stderr() { return this._stderr; }
|
|
43
|
+
|
|
44
|
+
private _exit: Promise<number>;
|
|
45
|
+
public get exit() { return this._exit; }
|
|
46
|
+
|
|
47
|
+
public constructor(socket: AdbSocket) {
|
|
48
|
+
this.socket = socket;
|
|
49
|
+
|
|
50
|
+
const factory = new DuplexStreamFactory<Uint8Array, Uint8Array>({
|
|
51
|
+
close: async () => {
|
|
52
|
+
await this.socket.close();
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
this._stdout = factory.createWrapReadable(this.socket.readable);
|
|
57
|
+
this._stderr = factory.createReadable();
|
|
58
|
+
this._exit = factory.closed.then(() => 0);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public resize() {
|
|
62
|
+
// Not supported
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public kill() {
|
|
66
|
+
return this.socket.close();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { PromiseResolver } from "@yume-chan/async";
|
|
2
|
+
import Struct, { placeholder, type StructValueType } from "@yume-chan/struct";
|
|
3
|
+
import type { Adb } from "../../../adb.js";
|
|
4
|
+
import { AdbFeatures } from "../../../features.js";
|
|
5
|
+
import type { AdbSocket } from "../../../socket/index.js";
|
|
6
|
+
import { pipeFrom, PushReadableStream, ReadableStream, StructDeserializeStream, StructSerializeStream, TransformStream, WritableStream, WritableStreamDefaultWriter, type PushReadableStreamController } from "../../../stream/index.js";
|
|
7
|
+
import { encodeUtf8 } from "../../../utils/index.js";
|
|
8
|
+
import type { AdbSubprocessProtocol } from "./types.js";
|
|
9
|
+
|
|
10
|
+
export enum AdbShellProtocolId {
|
|
11
|
+
Stdin,
|
|
12
|
+
Stdout,
|
|
13
|
+
Stderr,
|
|
14
|
+
Exit,
|
|
15
|
+
CloseStdin,
|
|
16
|
+
WindowSizeChange,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// This packet format is used in both direction.
|
|
20
|
+
const AdbShellProtocolPacket =
|
|
21
|
+
new Struct({ littleEndian: true })
|
|
22
|
+
.uint8('id', placeholder<AdbShellProtocolId>())
|
|
23
|
+
.uint32('length')
|
|
24
|
+
.uint8Array('data', { lengthField: 'length' });
|
|
25
|
+
|
|
26
|
+
type AdbShellProtocolPacketInit = typeof AdbShellProtocolPacket['TInit'];
|
|
27
|
+
|
|
28
|
+
type AdbShellProtocolPacket = StructValueType<typeof AdbShellProtocolPacket>;
|
|
29
|
+
|
|
30
|
+
class StdinSerializeStream extends TransformStream<Uint8Array, AdbShellProtocolPacketInit>{
|
|
31
|
+
constructor() {
|
|
32
|
+
super({
|
|
33
|
+
transform(chunk, controller) {
|
|
34
|
+
controller.enqueue({
|
|
35
|
+
id: AdbShellProtocolId.Stdin,
|
|
36
|
+
data: chunk,
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
flush() {
|
|
40
|
+
// TODO: AdbShellSubprocessProtocol: support closing stdin
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
class StdoutDeserializeStream extends TransformStream<AdbShellProtocolPacket, Uint8Array>{
|
|
47
|
+
constructor(type: AdbShellProtocolId.Stdout | AdbShellProtocolId.Stderr) {
|
|
48
|
+
super({
|
|
49
|
+
transform(chunk, controller) {
|
|
50
|
+
if (chunk.id === type) {
|
|
51
|
+
controller.enqueue(chunk.data);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
class MultiplexStream<T>{
|
|
59
|
+
private _readable: PushReadableStream<T>;
|
|
60
|
+
private _readableController!: PushReadableStreamController<T>;
|
|
61
|
+
public get readable() { return this._readable; }
|
|
62
|
+
|
|
63
|
+
private _activeCount = 0;
|
|
64
|
+
|
|
65
|
+
constructor() {
|
|
66
|
+
this._readable = new PushReadableStream(controller => {
|
|
67
|
+
this._readableController = controller;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public createWriteable() {
|
|
72
|
+
return new WritableStream<T>({
|
|
73
|
+
start: () => {
|
|
74
|
+
this._activeCount += 1;
|
|
75
|
+
},
|
|
76
|
+
write: async (chunk) => {
|
|
77
|
+
await this._readableController.enqueue(chunk);
|
|
78
|
+
},
|
|
79
|
+
abort: async (e) => {
|
|
80
|
+
this._activeCount -= 1;
|
|
81
|
+
if (this._activeCount === 0) {
|
|
82
|
+
this._readableController.close();
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
close: async () => {
|
|
86
|
+
this._activeCount -= 1;
|
|
87
|
+
if (this._activeCount === 0) {
|
|
88
|
+
this._readableController.close();
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Shell v2 a.k.a Shell Protocol
|
|
97
|
+
*
|
|
98
|
+
* Features:
|
|
99
|
+
* * `stderr`: Yes
|
|
100
|
+
* * `exit` exit code: Yes
|
|
101
|
+
* * `resize`: Yes
|
|
102
|
+
*/
|
|
103
|
+
export class AdbSubprocessShellProtocol implements AdbSubprocessProtocol {
|
|
104
|
+
public static isSupported(adb: Adb) {
|
|
105
|
+
return adb.features!.includes(AdbFeatures.ShellV2);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public static async pty(adb: Adb, command: string) {
|
|
109
|
+
// TODO: AdbShellSubprocessProtocol: Support setting `XTERM` environment variable
|
|
110
|
+
return new AdbSubprocessShellProtocol(await adb.createSocket(`shell,v2,pty:${command}`));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public static async raw(adb: Adb, command: string) {
|
|
114
|
+
return new AdbSubprocessShellProtocol(await adb.createSocket(`shell,v2,raw:${command}`));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private readonly _socket: AdbSocket;
|
|
118
|
+
private _socketWriter: WritableStreamDefaultWriter<AdbShellProtocolPacketInit>;
|
|
119
|
+
|
|
120
|
+
private _stdin: WritableStream<Uint8Array>;
|
|
121
|
+
public get stdin() { return this._stdin; }
|
|
122
|
+
|
|
123
|
+
private _stdout: ReadableStream<Uint8Array>;
|
|
124
|
+
public get stdout() { return this._stdout; }
|
|
125
|
+
|
|
126
|
+
private _stderr: ReadableStream<Uint8Array>;
|
|
127
|
+
public get stderr() { return this._stderr; }
|
|
128
|
+
|
|
129
|
+
private readonly _exit = new PromiseResolver<number>();
|
|
130
|
+
public get exit() { return this._exit.promise; }
|
|
131
|
+
|
|
132
|
+
public constructor(socket: AdbSocket) {
|
|
133
|
+
this._socket = socket;
|
|
134
|
+
|
|
135
|
+
// Check this image to help you understand the stream graph
|
|
136
|
+
// cspell: disable-next-line
|
|
137
|
+
// https://www.plantuml.com/plantuml/png/bL91QiCm4Bpx5SAdv90lb1JISmiw5XzaQKf5PIkiLZIqzEyLSg8ks13gYtOykpFhiOw93N6UGjVDqK7rZsxKqNw0U_NTgVAy4empOy2mm4_olC0VEVEE47GUpnGjKdgXoD76q4GIEpyFhOwP_m28hW0NNzxNUig1_JdW0bA7muFIJDco1daJ_1SAX9bgvoPJPyIkSekhNYctvIGXrCH6tIsPL5fs-s6J5yc9BpWXhKtNdF2LgVYPGM_6GlMwfhWUsIt4lbScANrwlgVVUifPSVi__t44qStnwPvZwobdSmHHlL57p2vFuHS0
|
|
138
|
+
|
|
139
|
+
// TODO: AdbShellSubprocessProtocol: Optimize stream graph
|
|
140
|
+
|
|
141
|
+
const [stdout, stderr] = socket.readable
|
|
142
|
+
.pipeThrough(new StructDeserializeStream(AdbShellProtocolPacket))
|
|
143
|
+
.pipeThrough(new TransformStream<AdbShellProtocolPacket, AdbShellProtocolPacket>({
|
|
144
|
+
transform: (chunk, controller) => {
|
|
145
|
+
if (chunk.id === AdbShellProtocolId.Exit) {
|
|
146
|
+
this._exit.resolve(new Uint8Array(chunk.data)[0]!);
|
|
147
|
+
// We can let `StdoutDeserializeStream` to process `AdbShellProtocolId.Exit`,
|
|
148
|
+
// but since we need this `TransformStream` to capture the exit code anyway,
|
|
149
|
+
// terminating child streams here is killing two birds with one stone.
|
|
150
|
+
controller.terminate();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
controller.enqueue(chunk);
|
|
154
|
+
}
|
|
155
|
+
}))
|
|
156
|
+
.tee();
|
|
157
|
+
this._stdout = stdout
|
|
158
|
+
.pipeThrough(new StdoutDeserializeStream(AdbShellProtocolId.Stdout));
|
|
159
|
+
this._stderr = stderr
|
|
160
|
+
.pipeThrough(new StdoutDeserializeStream(AdbShellProtocolId.Stderr));
|
|
161
|
+
|
|
162
|
+
const multiplexer = new MultiplexStream<AdbShellProtocolPacketInit>();
|
|
163
|
+
multiplexer.readable
|
|
164
|
+
.pipeThrough(new StructSerializeStream(AdbShellProtocolPacket))
|
|
165
|
+
.pipeTo(socket.writable);
|
|
166
|
+
|
|
167
|
+
this._stdin = pipeFrom(
|
|
168
|
+
multiplexer.createWriteable(),
|
|
169
|
+
new StdinSerializeStream()
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
this._socketWriter = multiplexer.createWriteable().getWriter();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
public async resize(rows: number, cols: number) {
|
|
176
|
+
await this._socketWriter.write({
|
|
177
|
+
id: AdbShellProtocolId.WindowSizeChange,
|
|
178
|
+
data: encodeUtf8(
|
|
179
|
+
// The "correct" format is `${rows}x${cols},${x_pixels}x${y_pixels}`
|
|
180
|
+
// However, according to https://linux.die.net/man/4/tty_ioctl
|
|
181
|
+
// `x_pixels` and `y_pixels` are not used, so always passing `0` is fine.
|
|
182
|
+
`${rows}x${cols},0x0\0`
|
|
183
|
+
),
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
public kill() {
|
|
188
|
+
return this._socket.close();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ValueOrPromise } from "@yume-chan/struct";
|
|
2
|
+
import type { Adb } from "../../../adb.js";
|
|
3
|
+
import type { AdbSocket } from "../../../socket/index.js";
|
|
4
|
+
import type { ReadableStream, WritableStream } from "../../../stream/index.js";
|
|
5
|
+
|
|
6
|
+
export interface AdbSubprocessProtocol {
|
|
7
|
+
/**
|
|
8
|
+
* A WritableStream that writes to the `stdin` pipe.
|
|
9
|
+
*/
|
|
10
|
+
readonly stdin: WritableStream<Uint8Array>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The `stdout` pipe of the process.
|
|
14
|
+
*/
|
|
15
|
+
readonly stdout: ReadableStream<Uint8Array>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The `stderr` pipe of the process.
|
|
19
|
+
*
|
|
20
|
+
* Note: Some `AdbSubprocessProtocol` doesn't separate `stdout` and `stderr`,
|
|
21
|
+
* All output will be sent to `stdout`.
|
|
22
|
+
*/
|
|
23
|
+
readonly stderr: ReadableStream<Uint8Array>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A `Promise` that resolves to the exit code of the process.
|
|
27
|
+
*
|
|
28
|
+
* Note: Some `AdbSubprocessProtocol` doesn't support exit code,
|
|
29
|
+
* They will always resolve it with `0`.
|
|
30
|
+
*/
|
|
31
|
+
readonly exit: Promise<number>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Resizes the current shell.
|
|
35
|
+
*
|
|
36
|
+
* Some `AdbSubprocessProtocol`s may not support resizing
|
|
37
|
+
* and will ignore calls to this method.
|
|
38
|
+
*/
|
|
39
|
+
resize(rows: number, cols: number): ValueOrPromise<void>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Kills the current process.
|
|
43
|
+
*/
|
|
44
|
+
kill(): ValueOrPromise<void>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface AdbSubprocessProtocolConstructor {
|
|
48
|
+
/** Returns `true` if the `adb` instance supports this shell */
|
|
49
|
+
isSupported(adb: Adb): ValueOrPromise<boolean>;
|
|
50
|
+
|
|
51
|
+
/** Spawns an executable in PTY (interactive) mode. */
|
|
52
|
+
pty(adb: Adb, command: string): ValueOrPromise<AdbSubprocessProtocol>;
|
|
53
|
+
|
|
54
|
+
/** Spawns an executable and pipe the output. */
|
|
55
|
+
raw(adb: Adb, command: string): ValueOrPromise<AdbSubprocessProtocol>;
|
|
56
|
+
|
|
57
|
+
/** Creates a new `AdbShell` by attaching to an exist `AdbSocket` */
|
|
58
|
+
new(socket: AdbSocket): AdbSubprocessProtocol;
|
|
59
|
+
}
|
|
File without changes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './list';
|
|
2
|
-
export * from './pull';
|
|
3
|
-
export * from './request';
|
|
4
|
-
export * from './response';
|
|
5
|
-
export * from './push';
|
|
6
|
-
export * from './stat';
|
|
7
|
-
export * from './sync';
|
|
1
|
+
export * from './list.js';
|
|
2
|
+
export * from './pull.js';
|
|
3
|
+
export * from './request.js';
|
|
4
|
+
export * from './response.js';
|
|
5
|
+
export * from './push.js';
|
|
6
|
+
export * from './stat.js';
|
|
7
|
+
export * from './sync.js';
|