@yume-chan/adb 0.0.15 → 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 +33 -0
- package/CHANGELOG.md +18 -1
- package/LICENSE +21 -21
- package/README.md +247 -247
- package/esm/adb.d.ts +15 -3
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +18 -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 +5 -4
- package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/none.js +11 -8
- 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 +11 -3
- package/esm/socket/dispatcher.d.ts.map +1 -1
- package/esm/socket/dispatcher.js +19 -11
- 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 +9 -4
- package/esm/socket/socket.d.ts.map +1 -1
- package/esm/socket/socket.js +20 -10
- 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 +285 -273
- package/src/auth.ts +174 -173
- package/src/backend.ts +12 -11
- package/src/commands/base.ts +12 -11
- package/src/commands/framebuffer.ts +78 -73
- package/src/commands/index.ts +8 -8
- package/src/commands/install.ts +32 -30
- package/src/commands/power.ts +54 -54
- package/src/commands/reverse.ts +141 -140
- package/src/commands/subprocess/command.ts +131 -0
- package/src/commands/subprocess/index.ts +3 -139
- package/src/commands/subprocess/protocols/none.ts +73 -68
- package/src/commands/subprocess/protocols/shell.ts +191 -190
- package/src/commands/subprocess/protocols/types.ts +60 -59
- package/src/commands/subprocess/utils.ts +20 -20
- package/src/commands/sync/index.ts +7 -7
- package/src/commands/sync/list.ts +54 -86
- package/src/commands/sync/pull.ts +45 -46
- package/src/commands/sync/push.ts +38 -41
- package/src/commands/sync/request.ts +51 -50
- package/src/commands/sync/response.ts +68 -64
- package/src/commands/sync/stat.ts +129 -150
- package/src/commands/sync/sync.ts +182 -181
- package/src/commands/tcpip.ts +21 -21
- package/src/crypto.ts +296 -296
- package/src/features.ts +9 -9
- package/src/index.ts +10 -11
- package/src/packet.ts +80 -80
- package/src/socket/dispatcher.ts +310 -304
- package/src/socket/index.ts +2 -2
- package/src/socket/socket.ts +156 -144
- package/src/utils/auto-reset-event.ts +41 -41
- package/src/utils/base64.ts +329 -306
- package/src/utils/index.ts +3 -3
- package/tsconfig.build.json +3 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- 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/buffered.d.ts +0 -35
- package/esm/stream/buffered.d.ts.map +0 -1
- package/esm/stream/buffered.js +0 -123
- package/esm/stream/buffered.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/stream/detect.d.ts +0 -2
- package/esm/stream/detect.d.ts.map +0 -1
- package/esm/stream/detect.js +0 -5
- 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 -9
- 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 -104
- package/esm/stream/transform.d.ts.map +0 -1
- package/esm/stream/transform.js +0 -373
- package/esm/stream/transform.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
- package/src/stream/buffered.ts +0 -147
- package/src/stream/detect.native.ts +0 -362
- package/src/stream/detect.polyfill.ts +0 -28
- package/src/stream/detect.ts +0 -5
- package/src/stream/index.ts +0 -3
- package/src/stream/transform.ts +0 -447
- package/tsconfig.test.json +0 -10
|
@@ -1,181 +1,182 @@
|
|
|
1
|
-
import { AutoDisposable } from '@yume-chan/event';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
* @
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
this.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this.
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
this.
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this.
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* @param
|
|
140
|
-
* @
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
//
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
1
|
+
import { AutoDisposable } from '@yume-chan/event';
|
|
2
|
+
import { BufferedReadableStream, ReadableStream, WrapReadableStream, WrapWritableStream, WritableStream, WritableStreamDefaultWriter } from '@yume-chan/stream-extra';
|
|
3
|
+
|
|
4
|
+
import type { Adb } from '../../adb.js';
|
|
5
|
+
import { AdbFeatures } from '../../features.js';
|
|
6
|
+
import type { AdbSocket } from '../../socket/index.js';
|
|
7
|
+
import { AutoResetEvent } from '../../utils/index.js';
|
|
8
|
+
import { escapeArg } from '../subprocess/index.js';
|
|
9
|
+
import { adbSyncOpenDir, type AdbSyncEntry } from './list.js';
|
|
10
|
+
import { adbSyncPull } from './pull.js';
|
|
11
|
+
import { adbSyncPush } from './push.js';
|
|
12
|
+
import { adbSyncLstat, adbSyncStat } from './stat.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A simplified `dirname` function that only handles absolute unix paths.
|
|
16
|
+
* @param path an absolute unix path
|
|
17
|
+
* @returns the directory name of the input path
|
|
18
|
+
*/
|
|
19
|
+
export function dirname(path: string): string {
|
|
20
|
+
const end = path.lastIndexOf('/');
|
|
21
|
+
if (end === -1) {
|
|
22
|
+
throw new Error(`Invalid path`);
|
|
23
|
+
}
|
|
24
|
+
if (end === 0) {
|
|
25
|
+
return '/';
|
|
26
|
+
}
|
|
27
|
+
return path.substring(0, end);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class AdbSync extends AutoDisposable {
|
|
31
|
+
protected adb: Adb;
|
|
32
|
+
|
|
33
|
+
protected stream: BufferedReadableStream;
|
|
34
|
+
// Getting another writer on a locked WritableStream will throw.
|
|
35
|
+
// We don't want this behavior on higher-level APIs.
|
|
36
|
+
// So we acquire the writer early and use a blocking lock to guard it.
|
|
37
|
+
protected writer: WritableStreamDefaultWriter<Uint8Array>;
|
|
38
|
+
protected sendLock = this.addDisposable(new AutoResetEvent());
|
|
39
|
+
|
|
40
|
+
public get supportsStat(): boolean {
|
|
41
|
+
return this.adb.features.includes(AdbFeatures.StatV2);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public get supportsList2(): boolean {
|
|
45
|
+
return this.adb.features.includes(AdbFeatures.ListV2);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public get fixedPushMkdir(): boolean {
|
|
49
|
+
return this.adb.features.includes(AdbFeatures.FixedPushMkdir);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public get needPushMkdirWorkaround(): boolean {
|
|
53
|
+
// https://android.googlesource.com/platform/packages/modules/adb/+/91768a57b7138166e0a3d11f79cd55909dda7014/client/file_sync_client.cpp#1361
|
|
54
|
+
return this.adb.features.includes(AdbFeatures.ShellV2) && !this.fixedPushMkdir;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public constructor(adb: Adb, socket: AdbSocket) {
|
|
58
|
+
super();
|
|
59
|
+
|
|
60
|
+
this.adb = adb;
|
|
61
|
+
this.stream = new BufferedReadableStream(socket.readable);
|
|
62
|
+
this.writer = socket.writable.getWriter();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public async lstat(path: string) {
|
|
66
|
+
await this.sendLock.wait();
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
return adbSyncLstat(this.stream, this.writer, path, this.supportsStat);
|
|
70
|
+
} finally {
|
|
71
|
+
this.sendLock.notify();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public async stat(path: string) {
|
|
76
|
+
if (!this.supportsStat) {
|
|
77
|
+
throw new Error('Not supported');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
await this.sendLock.wait();
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
return adbSyncStat(this.stream, this.writer, path);
|
|
84
|
+
} finally {
|
|
85
|
+
this.sendLock.notify();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public async isDirectory(path: string): Promise<boolean> {
|
|
90
|
+
try {
|
|
91
|
+
await this.lstat(path + '/');
|
|
92
|
+
return true;
|
|
93
|
+
} catch (e) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public async *opendir(
|
|
99
|
+
path: string
|
|
100
|
+
): AsyncGenerator<AdbSyncEntry, void, void> {
|
|
101
|
+
await this.sendLock.wait();
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
yield* adbSyncOpenDir(this.stream, this.writer, path, this.supportsList2);
|
|
105
|
+
} finally {
|
|
106
|
+
this.sendLock.notify();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public async readdir(path: string) {
|
|
111
|
+
const results: AdbSyncEntry[] = [];
|
|
112
|
+
for await (const entry of this.opendir(path)) {
|
|
113
|
+
results.push(entry);
|
|
114
|
+
}
|
|
115
|
+
return results;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Read the content of a file on device.
|
|
120
|
+
*
|
|
121
|
+
* @param filename The full path of the file on device to read.
|
|
122
|
+
* @returns A `ReadableStream` that reads from the file.
|
|
123
|
+
*/
|
|
124
|
+
public read(filename: string): ReadableStream<Uint8Array> {
|
|
125
|
+
return new WrapReadableStream({
|
|
126
|
+
start: async () => {
|
|
127
|
+
await this.sendLock.wait();
|
|
128
|
+
return adbSyncPull(this.stream, this.writer, filename);
|
|
129
|
+
},
|
|
130
|
+
close: async () => {
|
|
131
|
+
this.sendLock.notify();
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Write (or overwrite) a file on device.
|
|
138
|
+
*
|
|
139
|
+
* @param filename The full path of the file on device to write.
|
|
140
|
+
* @param mode The unix permissions of the file.
|
|
141
|
+
* @param mtime The modified time of the file.
|
|
142
|
+
* @returns A `WritableStream` that writes to the file.
|
|
143
|
+
*/
|
|
144
|
+
public write(
|
|
145
|
+
filename: string,
|
|
146
|
+
mode?: number,
|
|
147
|
+
mtime?: number,
|
|
148
|
+
): WritableStream<Uint8Array> {
|
|
149
|
+
return new WrapWritableStream({
|
|
150
|
+
start: async () => {
|
|
151
|
+
await this.sendLock.wait();
|
|
152
|
+
|
|
153
|
+
if (this.needPushMkdirWorkaround) {
|
|
154
|
+
// It may fail if the path is already existed.
|
|
155
|
+
// Ignore the result.
|
|
156
|
+
// TODO: sync: test push mkdir workaround (need an Android 8 device)
|
|
157
|
+
await this.adb.subprocess.spawnAndWait([
|
|
158
|
+
'mkdir',
|
|
159
|
+
'-p',
|
|
160
|
+
escapeArg(dirname(filename)),
|
|
161
|
+
]);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return adbSyncPush(
|
|
165
|
+
this.stream,
|
|
166
|
+
this.writer,
|
|
167
|
+
filename,
|
|
168
|
+
mode,
|
|
169
|
+
mtime,
|
|
170
|
+
);
|
|
171
|
+
},
|
|
172
|
+
close: async () => {
|
|
173
|
+
this.sendLock.notify();
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
public override async dispose() {
|
|
179
|
+
super.dispose();
|
|
180
|
+
await this.writer.close();
|
|
181
|
+
}
|
|
182
|
+
}
|
package/src/commands/tcpip.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { AdbCommandBase } from './base.js';
|
|
2
|
-
|
|
3
|
-
export class AdbTcpIpCommand extends AdbCommandBase {
|
|
4
|
-
public async setPort(port: number): Promise<void> {
|
|
5
|
-
if (port <= 0) {
|
|
6
|
-
throw new Error(`Invalid port ${port}`);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const output = await this.adb.createSocketAndWait(`tcpip:${port}`);
|
|
10
|
-
if (output !== `restarting in TCP mode port: ${port}\n`) {
|
|
11
|
-
throw new Error('Invalid response');
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public async disable(): Promise<void> {
|
|
16
|
-
const output = await this.adb.createSocketAndWait('usb:');
|
|
17
|
-
if (output !== 'restarting in USB mode\n') {
|
|
18
|
-
throw new Error('Invalid response');
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
1
|
+
import { AdbCommandBase } from './base.js';
|
|
2
|
+
|
|
3
|
+
export class AdbTcpIpCommand extends AdbCommandBase {
|
|
4
|
+
public async setPort(port: number): Promise<void> {
|
|
5
|
+
if (port <= 0) {
|
|
6
|
+
throw new Error(`Invalid port ${port}`);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const output = await this.adb.createSocketAndWait(`tcpip:${port}`);
|
|
10
|
+
if (output !== `restarting in TCP mode port: ${port}\n`) {
|
|
11
|
+
throw new Error('Invalid response');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public async disable(): Promise<void> {
|
|
16
|
+
const output = await this.adb.createSocketAndWait('usb:');
|
|
17
|
+
if (output !== 'restarting in USB mode\n') {
|
|
18
|
+
throw new Error('Invalid response');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|