@yume-chan/adb 0.0.13 → 0.0.16
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 +57 -0
- package/CHANGELOG.md +29 -1
- package/LICENSE +21 -21
- package/README.md +247 -247
- package/esm/adb.d.ts +12 -4
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +29 -19
- package/esm/adb.js.map +1 -1
- package/esm/commands/reverse.d.ts +9 -12
- package/esm/commands/reverse.d.ts.map +1 -1
- package/esm/commands/reverse.js +44 -36
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/protocols/none.d.ts +2 -1
- package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/none.js +10 -9
- package/esm/commands/subprocess/protocols/none.js.map +1 -1
- package/esm/commands/sync/pull.d.ts.map +1 -1
- package/esm/commands/sync/pull.js +6 -3
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/stat.d.ts.map +1 -1
- package/esm/commands/sync/stat.js +2 -2
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.js +1 -1
- package/esm/commands/sync/sync.js.map +1 -1
- package/esm/socket/dispatcher.d.ts +25 -14
- package/esm/socket/dispatcher.d.ts.map +1 -1
- package/esm/socket/dispatcher.js +94 -63
- package/esm/socket/dispatcher.js.map +1 -1
- package/esm/socket/socket.d.ts +18 -4
- package/esm/socket/socket.d.ts.map +1 -1
- package/esm/socket/socket.js +36 -21
- package/esm/socket/socket.js.map +1 -1
- package/esm/stream/buffered.d.ts +7 -3
- package/esm/stream/buffered.d.ts.map +1 -1
- package/esm/stream/buffered.js +69 -49
- package/esm/stream/buffered.js.map +1 -1
- package/esm/stream/detect.js +1 -0
- package/esm/stream/detect.js.map +1 -1
- package/esm/stream/detect.polyfill.d.ts +1 -1
- package/esm/stream/detect.polyfill.d.ts.map +1 -1
- package/esm/stream/detect.polyfill.js +0 -5
- package/esm/stream/detect.polyfill.js.map +1 -1
- package/esm/stream/transform.d.ts +39 -13
- package/esm/stream/transform.d.ts.map +1 -1
- package/esm/stream/transform.js +67 -90
- package/esm/stream/transform.js.map +1 -1
- package/esm/utils/base64.js +5 -5
- package/esm/utils/base64.js.map +1 -1
- package/package.json +10 -10
- package/src/adb.ts +280 -270
- package/src/auth.ts +173 -173
- package/src/backend.ts +11 -11
- package/src/commands/base.ts +11 -11
- package/src/commands/framebuffer.ts +73 -73
- package/src/commands/index.ts +8 -8
- package/src/commands/install.ts +30 -30
- package/src/commands/power.ts +54 -54
- package/src/commands/reverse.ts +140 -136
- package/src/commands/subprocess/index.ts +139 -139
- package/src/commands/subprocess/protocols/none.ts +70 -68
- package/src/commands/subprocess/protocols/shell.ts +190 -190
- package/src/commands/subprocess/protocols/types.ts +59 -59
- package/src/commands/subprocess/utils.ts +20 -20
- package/src/commands/sync/index.ts +7 -7
- package/src/commands/sync/list.ts +86 -86
- package/src/commands/sync/pull.ts +46 -43
- package/src/commands/sync/push.ts +41 -41
- package/src/commands/sync/request.ts +50 -50
- package/src/commands/sync/response.ts +64 -64
- package/src/commands/sync/stat.ts +151 -150
- package/src/commands/sync/sync.ts +181 -181
- package/src/commands/tcpip.ts +21 -21
- package/src/crypto.ts +296 -296
- package/src/features.ts +9 -9
- package/src/index.ts +11 -11
- package/src/packet.ts +80 -80
- package/src/socket/dispatcher.ts +305 -270
- package/src/socket/index.ts +2 -2
- package/src/socket/socket.ts +155 -136
- package/src/stream/buffered.ts +168 -147
- package/src/stream/detect.native.ts +362 -362
- package/src/stream/detect.polyfill.ts +22 -28
- package/src/stream/detect.ts +7 -5
- package/src/stream/index.ts +3 -3
- package/src/stream/transform.ts +474 -483
- package/src/utils/auto-reset-event.ts +41 -41
- package/src/utils/base64.ts +306 -306
- package/src/utils/index.ts +3 -3
- package/tsconfig.build.json +3 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.test.json +9 -10
- package/web-streams-polyfill-4.0.0-beta.2.tgz +0 -0
- package/esm/commands/subprocess/legacy.d.ts +0 -35
- package/esm/commands/subprocess/legacy.d.ts.map +0 -1
- package/esm/commands/subprocess/legacy.js +0 -53
- package/esm/commands/subprocess/legacy.js.map +0 -1
- package/esm/commands/subprocess/protocol.d.ts +0 -39
- package/esm/commands/subprocess/protocol.d.ts.map +0 -1
- package/esm/commands/subprocess/protocol.js +0 -157
- package/esm/commands/subprocess/protocol.js.map +0 -1
- package/esm/commands/subprocess/types.d.ts +0 -50
- package/esm/commands/subprocess/types.d.ts.map +0 -1
- package/esm/commands/subprocess/types.js +0 -2
- package/esm/commands/subprocess/types.js.map +0 -1
- package/esm/socket/controller.d.ts +0 -37
- package/esm/socket/controller.d.ts.map +0 -1
- package/esm/socket/controller.js +0 -66
- package/esm/socket/controller.js.map +0 -1
- package/esm/stream/detect.bak.d.ts +0 -240
- package/esm/stream/detect.bak.d.ts.map +0 -1
- package/esm/stream/detect.bak.js +0 -60
- package/esm/stream/detect.bak.js.map +0 -1
- package/esm/utils/encoding.d.ts +0 -3
- package/esm/utils/encoding.d.ts.map +0 -1
- package/esm/utils/encoding.js +0 -11
- package/esm/utils/encoding.js.map +0 -1
|
@@ -1,139 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,68 +1,70 @@
|
|
|
1
|
-
import type { Adb } from "../../../adb.js";
|
|
2
|
-
import type { AdbSocket } from "../../../socket/index.js";
|
|
3
|
-
import { DuplexStreamFactory,
|
|
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
|
-
//
|
|
23
|
-
// But
|
|
24
|
-
return new AdbSubprocessNoneProtocol(await adb.createSocket(`
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
private readonly socket: AdbSocket;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
public
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
1
|
+
import type { Adb } from "../../../adb.js";
|
|
2
|
+
import type { AdbSocket } from "../../../socket/index.js";
|
|
3
|
+
import { DuplexStreamFactory, 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
|
+
// `shell,raw:${command}` also triggers raw mode,
|
|
23
|
+
// But is not supported before Android 7.
|
|
24
|
+
return new AdbSubprocessNoneProtocol(await adb.createSocket(`exec:${command}`));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private readonly socket: AdbSocket;
|
|
28
|
+
|
|
29
|
+
private readonly duplex: DuplexStreamFactory<Uint8Array, Uint8Array>;
|
|
30
|
+
|
|
31
|
+
// Legacy shell forwards all data to stdin.
|
|
32
|
+
public get stdin() { return this.socket.writable; }
|
|
33
|
+
|
|
34
|
+
private _stdout: ReadableStream<Uint8Array>;
|
|
35
|
+
/**
|
|
36
|
+
* Legacy shell mixes stdout and stderr.
|
|
37
|
+
*/
|
|
38
|
+
public get stdout() { return this._stdout; }
|
|
39
|
+
|
|
40
|
+
private _stderr: ReadableStream<Uint8Array>;
|
|
41
|
+
/**
|
|
42
|
+
* `stderr` will always be empty.
|
|
43
|
+
*/
|
|
44
|
+
public get stderr() { return this._stderr; }
|
|
45
|
+
|
|
46
|
+
private _exit: Promise<number>;
|
|
47
|
+
public get exit() { return this._exit; }
|
|
48
|
+
|
|
49
|
+
public constructor(socket: AdbSocket) {
|
|
50
|
+
this.socket = socket;
|
|
51
|
+
|
|
52
|
+
this.duplex = new DuplexStreamFactory<Uint8Array, Uint8Array>({
|
|
53
|
+
close: async () => {
|
|
54
|
+
await this.socket.close();
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
this._stdout = this.duplex.wrapReadable(this.socket.readable);
|
|
59
|
+
this._stderr = this.duplex.wrapReadable(new ReadableStream());
|
|
60
|
+
this._exit = this.duplex.closed.then(() => 0);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public resize() {
|
|
64
|
+
// Not supported
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public kill() {
|
|
68
|
+
return this.duplex.close();
|
|
69
|
+
}
|
|
70
|
+
}
|