manageos 1.0.2 → 2.0.2
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/dist/Android/adb.d.ts +221 -0
- package/dist/Android/adb.d.ts.map +1 -0
- package/dist/Android/adb.js +1153 -0
- package/dist/Android/adb.js.map +1 -0
- package/dist/Android/fastboot.d.ts +48 -0
- package/dist/Android/fastboot.d.ts.map +1 -0
- package/dist/Android/fastboot.js +173 -0
- package/dist/Android/fastboot.js.map +1 -0
- package/dist/Android/index.d.ts +7 -0
- package/dist/Android/index.d.ts.map +1 -0
- package/dist/Android/index.js +7 -0
- package/dist/Android/index.js.map +1 -0
- package/dist/antivirus.d.ts +23 -0
- package/dist/antivirus.d.ts.map +1 -0
- package/dist/antivirus.js +124 -0
- package/dist/antivirus.js.map +1 -0
- package/dist/audio.js +18 -24
- package/dist/audio.js.map +1 -1
- package/dist/bitlocker.d.ts +43 -0
- package/dist/bitlocker.d.ts.map +1 -0
- package/dist/bitlocker.js +212 -0
- package/dist/bitlocker.js.map +1 -0
- package/dist/clipboard.js +6 -12
- package/dist/clipboard.js.map +1 -1
- package/dist/encryption.js +10 -16
- package/dist/encryption.js.map +1 -1
- package/dist/eventlogs.d.ts +34 -0
- package/dist/eventlogs.d.ts.map +1 -0
- package/dist/eventlogs.js +125 -0
- package/dist/eventlogs.js.map +1 -0
- package/dist/filesystem.js +17 -23
- package/dist/filesystem.js.map +1 -1
- package/dist/firewall.js +6 -9
- package/dist/firewall.js.map +1 -1
- package/dist/index.d.ts +38 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +51 -37
- package/dist/index.js.map +1 -1
- package/dist/localization.d.ts +22 -0
- package/dist/localization.d.ts.map +1 -0
- package/dist/localization.js +102 -0
- package/dist/localization.js.map +1 -0
- package/dist/msconfig.d.ts +32 -0
- package/dist/msconfig.d.ts.map +1 -0
- package/dist/msconfig.js +192 -0
- package/dist/msconfig.js.map +1 -0
- package/dist/network.js +17 -23
- package/dist/network.js.map +1 -1
- package/dist/notification.js +17 -23
- package/dist/notification.js.map +1 -1
- package/dist/power.d.ts +2 -2
- package/dist/power.d.ts.map +1 -1
- package/dist/power.js +12 -15
- package/dist/power.js.map +1 -1
- package/dist/regedit.js +2 -38
- package/dist/regedit.js.map +1 -1
- package/dist/scheduler.d.ts +39 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +116 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/screen.d.ts +223 -0
- package/dist/screen.d.ts.map +1 -1
- package/dist/screen.js +936 -7
- package/dist/screen.js.map +1 -1
- package/dist/secpol.d.ts +22 -0
- package/dist/secpol.d.ts.map +1 -0
- package/dist/secpol.js +88 -0
- package/dist/secpol.js.map +1 -0
- package/dist/services.js +24 -60
- package/dist/services.js.map +1 -1
- package/dist/systeminfo.js +15 -21
- package/dist/systeminfo.js.map +1 -1
- package/dist/taskmgr.js +8 -11
- package/dist/taskmgr.js.map +1 -1
- package/dist/taskscheduler.d.ts +58 -0
- package/dist/taskscheduler.d.ts.map +1 -0
- package/dist/taskscheduler.js +332 -0
- package/dist/taskscheduler.js.map +1 -0
- package/dist/uac.js +7 -10
- package/dist/uac.js.map +1 -1
- package/dist/users.js +3 -6
- package/dist/users.js.map +1 -1
- package/dist/windowsupdate.d.ts +26 -0
- package/dist/windowsupdate.d.ts.map +1 -0
- package/dist/windowsupdate.js +120 -0
- package/dist/windowsupdate.js.map +1 -0
- package/package.json +11 -2
- package/README.md +0 -142
|
@@ -0,0 +1,1153 @@
|
|
|
1
|
+
import { exec, execSync } from "child_process";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import util from "util";
|
|
5
|
+
const execAsync = util.promisify(exec);
|
|
6
|
+
class Sync {
|
|
7
|
+
static getLocale(serial) {
|
|
8
|
+
try {
|
|
9
|
+
const adb = this.getAdbPath();
|
|
10
|
+
const lang = execSync(`"${adb}" -s ${serial} shell getprop persist.sys.locale`, { encoding: "utf8" }).trim();
|
|
11
|
+
if (!lang.includes("-"))
|
|
12
|
+
return null;
|
|
13
|
+
const [language, country] = lang.split("-");
|
|
14
|
+
return { language, country };
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
static clearAppData(serial, packageName) {
|
|
21
|
+
try {
|
|
22
|
+
const adb = this.getAdbPath();
|
|
23
|
+
const cmd = `"${adb}" -s ${serial} shell pm clear ${packageName}`;
|
|
24
|
+
const output = execSync(cmd, { encoding: "utf8" });
|
|
25
|
+
const success = /Success/i.test(output);
|
|
26
|
+
return { success, command: cmd, output: output.trim() };
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return { success: false, command: "clearAppData", error: error.message };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
static getUptime(serial) {
|
|
33
|
+
try {
|
|
34
|
+
const adb = this.getAdbPath();
|
|
35
|
+
const output = execSync(`"${adb}" -s ${serial} shell uptime`, {
|
|
36
|
+
encoding: "utf8",
|
|
37
|
+
});
|
|
38
|
+
return output.trim();
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
static isRooted(serial) {
|
|
45
|
+
try {
|
|
46
|
+
const adb = this.getAdbPath();
|
|
47
|
+
const output = execSync(`"${adb}" -s ${serial} shell which su`, {
|
|
48
|
+
encoding: "utf8",
|
|
49
|
+
});
|
|
50
|
+
return output.trim().length > 0;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
static getCpuUsage(serial) {
|
|
57
|
+
try {
|
|
58
|
+
const adb = this.getAdbPath();
|
|
59
|
+
const output = execSync(`"${adb}" -s ${serial} shell top -n 1 -b`, {
|
|
60
|
+
encoding: "utf8",
|
|
61
|
+
});
|
|
62
|
+
const cpuMatch = output.match(/CPU usage:\s+(.*)%/i);
|
|
63
|
+
return cpuMatch ? cpuMatch[1].trim() + "%" : null;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
static getTopApp(serial) {
|
|
70
|
+
try {
|
|
71
|
+
const adb = this.getAdbPath();
|
|
72
|
+
const output = execSync(`"${adb}" -s ${serial} shell dumpsys window windows | grep -E 'mCurrentFocus'`, { encoding: "utf8" });
|
|
73
|
+
const match = output.match(/Window\{.*\s([^\s\/]+)\/([^\s}]+)\}/);
|
|
74
|
+
if (!match)
|
|
75
|
+
return null;
|
|
76
|
+
return { package: match[1], activity: match[2] };
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
static killProcess(serial, pid) {
|
|
83
|
+
try {
|
|
84
|
+
const adb = this.getAdbPath();
|
|
85
|
+
const cmd = `"${adb}" -s ${serial} shell kill ${pid}`;
|
|
86
|
+
execSync(cmd);
|
|
87
|
+
return { success: true, command: cmd };
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
return { success: false, command: "kill", error: error.message };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
static getProcesses(serial) {
|
|
94
|
+
try {
|
|
95
|
+
const adb = this.getAdbPath();
|
|
96
|
+
const cmd = `"${adb}" -s ${serial} shell ps -A`;
|
|
97
|
+
const output = execSync(cmd, { encoding: "utf8" });
|
|
98
|
+
const lines = output.trim().split("\n").slice(1);
|
|
99
|
+
return lines.map((line) => {
|
|
100
|
+
const parts = line.trim().split(/\s+/);
|
|
101
|
+
return {
|
|
102
|
+
user: parts[0],
|
|
103
|
+
pid: Number(parts[1]),
|
|
104
|
+
name: parts.slice(-1)[0],
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
static getNetworkInfo(serial) {
|
|
113
|
+
try {
|
|
114
|
+
const adb = this.getAdbPath();
|
|
115
|
+
const cmd = `"${adb}" -s ${serial} shell ip addr show wlan0`;
|
|
116
|
+
const output = execSync(cmd, { encoding: "utf8" });
|
|
117
|
+
const info = {};
|
|
118
|
+
const ipMatch = output.match(/inet\s+(\d+\.\d+\.\d+\.\d+)/);
|
|
119
|
+
if (ipMatch)
|
|
120
|
+
info["ip_address"] = ipMatch[1];
|
|
121
|
+
const macMatch = output.match(/link\/ether\s+([0-9a-f:]+)/i);
|
|
122
|
+
if (macMatch)
|
|
123
|
+
info["mac_address"] = macMatch[1];
|
|
124
|
+
info["interface"] = "wlan0";
|
|
125
|
+
return info;
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
static getStorageInfo(serial) {
|
|
132
|
+
try {
|
|
133
|
+
const adb = this.getAdbPath();
|
|
134
|
+
const cmd = `"${adb}" -s ${serial} shell df -h`;
|
|
135
|
+
const stdout = execSync(cmd, { encoding: "utf8" });
|
|
136
|
+
const lines = stdout.trim().split("\n");
|
|
137
|
+
if (lines.length < 2)
|
|
138
|
+
return null;
|
|
139
|
+
const data = lines.slice(1).map((line) => {
|
|
140
|
+
const parts = line.split(/\s+/);
|
|
141
|
+
return {
|
|
142
|
+
device: parts[0] || "",
|
|
143
|
+
size: parts[1] || "",
|
|
144
|
+
used: parts[2] || "",
|
|
145
|
+
available: parts[3] || "",
|
|
146
|
+
use: parts[4] || "",
|
|
147
|
+
mount: parts[5] || "",
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
return data.length ? data : null;
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
static getMemoryInfo(serial) {
|
|
157
|
+
try {
|
|
158
|
+
const adb = this.getAdbPath();
|
|
159
|
+
const cmd = `"${adb}" -s ${serial} shell cat /proc/meminfo`;
|
|
160
|
+
const stdout = execSync(cmd, { encoding: "utf8" });
|
|
161
|
+
const memInfo = {};
|
|
162
|
+
stdout.split("\n").forEach((line) => {
|
|
163
|
+
const parts = line.split(":");
|
|
164
|
+
if (parts.length === 2) {
|
|
165
|
+
memInfo[parts[0].trim()] = parts[1].trim();
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
return Object.keys(memInfo).length ? memInfo : null;
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
static exec(serial, command) {
|
|
175
|
+
try {
|
|
176
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
177
|
+
const __dirname = path.dirname(__filename);
|
|
178
|
+
const adbPath = path.join(__dirname, "dependencies", "adb.exe");
|
|
179
|
+
const cmd = `"${adbPath}" -s ${serial} ${command}`;
|
|
180
|
+
const output = execSync(cmd, { encoding: "utf8" }).toString();
|
|
181
|
+
return { success: true, command: cmd, output: output.trim() };
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
return { success: false, command: command, error: error.message };
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
static setScreenBrightness(serial, level) {
|
|
188
|
+
try {
|
|
189
|
+
const adb = this.getAdbPath();
|
|
190
|
+
const cmd = `"${adb}" -s ${serial} shell settings put system screen_brightness ${level}`;
|
|
191
|
+
execSync(cmd);
|
|
192
|
+
return { success: true, command: cmd };
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
return {
|
|
196
|
+
success: false,
|
|
197
|
+
command: "setScreenBrightness",
|
|
198
|
+
error: error.message,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
static getScreenBrightness(serial) {
|
|
203
|
+
try {
|
|
204
|
+
const adb = this.getAdbPath();
|
|
205
|
+
const output = execSync(`"${adb}" -s ${serial} shell settings get system screen_brightness`, { encoding: "utf8" });
|
|
206
|
+
return Number(output.trim());
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
static getScreenResolution(serial) {
|
|
213
|
+
try {
|
|
214
|
+
const adb = this.getAdbPath();
|
|
215
|
+
const output = execSync(`"${adb}" -s ${serial} shell wm size`, {
|
|
216
|
+
encoding: "utf8",
|
|
217
|
+
})
|
|
218
|
+
.replace("Physical size: ", "")
|
|
219
|
+
.trim();
|
|
220
|
+
const match = output.match(/^(\d+)x(\d+)$/);
|
|
221
|
+
if (!match)
|
|
222
|
+
return null;
|
|
223
|
+
return { width: Number(match[1]), height: Number(match[2]) };
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
static screenshot(serial, remotePath) {
|
|
230
|
+
try {
|
|
231
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
232
|
+
const __dirname = path.dirname(__filename);
|
|
233
|
+
const adbPath = path.join(__dirname, "dependencies", "adb.exe");
|
|
234
|
+
const cmd = `"${adbPath}" -s ${serial} shell screencap -p "${remotePath}"`;
|
|
235
|
+
execSync(cmd, { stdio: "ignore" });
|
|
236
|
+
return { success: true, command: cmd };
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
return { success: false, command: "screenshot", error: error.message };
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
static uninstallPackage(serial, packageName) {
|
|
243
|
+
try {
|
|
244
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
245
|
+
const __dirname = path.dirname(__filename);
|
|
246
|
+
const adbPath = path.join(__dirname, "dependencies", "adb.exe");
|
|
247
|
+
const cmd = `"${adbPath}" -s ${serial} shell pm uninstall "${packageName}"`;
|
|
248
|
+
const output = execSync(cmd, {
|
|
249
|
+
encoding: "utf8",
|
|
250
|
+
stdio: "pipe",
|
|
251
|
+
}).toString();
|
|
252
|
+
const success = /Success/i.test(output);
|
|
253
|
+
return {
|
|
254
|
+
success,
|
|
255
|
+
command: cmd,
|
|
256
|
+
error: success ? undefined : output.trim(),
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
return {
|
|
261
|
+
success: false,
|
|
262
|
+
command: "uninstall",
|
|
263
|
+
error: error.message,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
static getBatteryInfo(serial) {
|
|
268
|
+
try {
|
|
269
|
+
const adb = this.getAdbPath();
|
|
270
|
+
const output = execSync(`"${adb}" -s ${serial} shell dumpsys battery`, {
|
|
271
|
+
encoding: "utf8",
|
|
272
|
+
});
|
|
273
|
+
const info = {};
|
|
274
|
+
output.split("\n").forEach((line) => {
|
|
275
|
+
const match = line.trim().match(/^(\S+):\s*(.+)$/);
|
|
276
|
+
if (match)
|
|
277
|
+
info[match[1]] = match[2];
|
|
278
|
+
});
|
|
279
|
+
return info;
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
static getAdbPath() {
|
|
286
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
287
|
+
const __dirname = path.dirname(__filename);
|
|
288
|
+
return path.join(__dirname, "dependencies", "adb.exe");
|
|
289
|
+
}
|
|
290
|
+
static getPackages(serial, systemOnly = false) {
|
|
291
|
+
try {
|
|
292
|
+
const adb = this.getAdbPath();
|
|
293
|
+
const flag = systemOnly ? "-s" : "";
|
|
294
|
+
const output = execSync(`"${adb}" -s ${serial} shell pm list packages ${flag}`, {
|
|
295
|
+
encoding: "utf8",
|
|
296
|
+
});
|
|
297
|
+
return output
|
|
298
|
+
.split("\n")
|
|
299
|
+
.map((l) => l.replace("package:", "").trim())
|
|
300
|
+
.filter(Boolean);
|
|
301
|
+
}
|
|
302
|
+
catch {
|
|
303
|
+
return [];
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
static pushFile(serial, localPath, remotePath) {
|
|
307
|
+
try {
|
|
308
|
+
const adb = this.getAdbPath();
|
|
309
|
+
const cmd = `"${adb}" -s ${serial} push "${localPath}" "${remotePath}"`;
|
|
310
|
+
execSync(cmd, { stdio: "pipe" });
|
|
311
|
+
return { success: true, command: cmd };
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
return { success: false, command: "push", error: error.message };
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
static pullFile(serial, remotePath, localPath) {
|
|
318
|
+
try {
|
|
319
|
+
const adb = this.getAdbPath();
|
|
320
|
+
const cmd = `"${adb}" -s ${serial} pull "${remotePath}" "${localPath}"`;
|
|
321
|
+
execSync(cmd, { stdio: "pipe" });
|
|
322
|
+
return { success: true, command: cmd };
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
return { success: false, command: "pull", error: error.message };
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
static installApk(serial, apkPath, ...args) {
|
|
329
|
+
try {
|
|
330
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
331
|
+
const __dirname = path.dirname(__filename);
|
|
332
|
+
const adbPath = path.join(__dirname, "dependencies", "adb.exe");
|
|
333
|
+
// Construir el comando con argumentos extra
|
|
334
|
+
const params = args.length ? args.join(" ") : "";
|
|
335
|
+
const cmd = `"${adbPath}" -s ${serial} install ${params} "${apkPath}"`;
|
|
336
|
+
const output = execSync(cmd, { encoding: "utf8", stdio: "pipe" });
|
|
337
|
+
const success = /Success/i.test(output);
|
|
338
|
+
return {
|
|
339
|
+
success,
|
|
340
|
+
command: cmd,
|
|
341
|
+
error: success ? undefined : output.trim(),
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
catch (error) {
|
|
345
|
+
return {
|
|
346
|
+
success: false,
|
|
347
|
+
command: "install",
|
|
348
|
+
error: error.message,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
static getModel(serial) {
|
|
353
|
+
const props = this.getDeviceProperties(serial);
|
|
354
|
+
return props?.["ro.product.model"] || null;
|
|
355
|
+
}
|
|
356
|
+
static getBrand(serial) {
|
|
357
|
+
const props = this.getDeviceProperties(serial);
|
|
358
|
+
return props?.["ro.product.brand"] || null;
|
|
359
|
+
}
|
|
360
|
+
static getAndroidVersion(serial) {
|
|
361
|
+
const props = this.getDeviceProperties(serial);
|
|
362
|
+
return props?.["ro.build.version.release"] || null;
|
|
363
|
+
}
|
|
364
|
+
static getSdkVersion(serial) {
|
|
365
|
+
const props = this.getDeviceProperties(serial);
|
|
366
|
+
return props?.["ro.build.version.sdk"] || null;
|
|
367
|
+
}
|
|
368
|
+
static getDeviceProperties(serial) {
|
|
369
|
+
try {
|
|
370
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
371
|
+
const __dirname = path.dirname(__filename);
|
|
372
|
+
const adbPath = path.join(__dirname, "dependencies", "adb.exe");
|
|
373
|
+
const stdout = execSync(`"${adbPath}" -s ${serial} shell getprop`, {
|
|
374
|
+
encoding: "utf8",
|
|
375
|
+
});
|
|
376
|
+
const props = {};
|
|
377
|
+
stdout.split("\n").forEach((line) => {
|
|
378
|
+
line = line.trim();
|
|
379
|
+
if (!line)
|
|
380
|
+
return;
|
|
381
|
+
const match = line.match(/^\[([^\]]+)\]: \[(.*)\]$/);
|
|
382
|
+
if (match) {
|
|
383
|
+
const key = match[1].trim();
|
|
384
|
+
let value = match[2].trim();
|
|
385
|
+
const lower = value.toLowerCase();
|
|
386
|
+
// Booleanos
|
|
387
|
+
if (["true", "yes", "1"].includes(lower)) {
|
|
388
|
+
value = true;
|
|
389
|
+
}
|
|
390
|
+
else if (["false", "no", "0"].includes(lower)) {
|
|
391
|
+
value = false;
|
|
392
|
+
}
|
|
393
|
+
// Números enteros o flotantes
|
|
394
|
+
else if (!isNaN(Number(value)) && value !== "") {
|
|
395
|
+
value = Number(value);
|
|
396
|
+
}
|
|
397
|
+
// String vacío → null
|
|
398
|
+
else if (value === "") {
|
|
399
|
+
value = null;
|
|
400
|
+
}
|
|
401
|
+
props[key] = value;
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
return Object.keys(props).length ? props : null;
|
|
405
|
+
}
|
|
406
|
+
catch {
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
static power(serial, command, customCommand) {
|
|
411
|
+
try {
|
|
412
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
413
|
+
const __dirname = path.dirname(__filename);
|
|
414
|
+
const adbPath = path.join(__dirname, "dependencies", "adb.exe");
|
|
415
|
+
let cmd = `"${adbPath}" -s ${serial} `;
|
|
416
|
+
const defaultCommands = {
|
|
417
|
+
shutdown: "shell reboot -p",
|
|
418
|
+
reboot: "reboot",
|
|
419
|
+
bootloader: "reboot bootloader",
|
|
420
|
+
fastbootd: "reboot fastboot",
|
|
421
|
+
};
|
|
422
|
+
cmd += customCommand ?? defaultCommands[command] ?? command;
|
|
423
|
+
execSync(cmd, { stdio: "ignore" });
|
|
424
|
+
return { success: true, command: cmd };
|
|
425
|
+
}
|
|
426
|
+
catch (error) {
|
|
427
|
+
return { success: false, command: String(command), error: error.message };
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
static listDevices() {
|
|
431
|
+
try {
|
|
432
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
433
|
+
const __dirname = path.dirname(__filename);
|
|
434
|
+
const adbPath = path.join(__dirname, "dependencies", "adb.exe");
|
|
435
|
+
const output = execSync(`"${adbPath}" devices`, { encoding: "utf8" });
|
|
436
|
+
const lines = output
|
|
437
|
+
.split("\n")
|
|
438
|
+
.map((line) => line.trim())
|
|
439
|
+
.filter((line) => line && !line.startsWith("*"));
|
|
440
|
+
const devices = [];
|
|
441
|
+
for (const line of lines.slice(1)) {
|
|
442
|
+
const [serial, stateRaw] = line.split("\t");
|
|
443
|
+
if (!serial || !stateRaw)
|
|
444
|
+
continue;
|
|
445
|
+
const state = ["device", "offline", "unauthorized"].includes(stateRaw)
|
|
446
|
+
? stateRaw
|
|
447
|
+
: "unknown";
|
|
448
|
+
devices.push({ serial, state });
|
|
449
|
+
}
|
|
450
|
+
return devices;
|
|
451
|
+
}
|
|
452
|
+
catch {
|
|
453
|
+
return [];
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
static enableDeveloperMode(serial) {
|
|
457
|
+
try {
|
|
458
|
+
const adb = this.getAdbPath();
|
|
459
|
+
execSync(`"${adb}" -s ${serial} shell settings put global development_settings_enabled 1`);
|
|
460
|
+
execSync(`"${adb}" -s ${serial} shell settings put global adb_enabled 1`);
|
|
461
|
+
return { success: true };
|
|
462
|
+
}
|
|
463
|
+
catch (error) {
|
|
464
|
+
return { success: false, error: error.message };
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
class Async {
|
|
469
|
+
static async enableDeveloperMode(serial) {
|
|
470
|
+
try {
|
|
471
|
+
const adb = Sync.getAdbPath();
|
|
472
|
+
await execAsync(`"${adb}" -s ${serial} shell settings put global development_settings_enabled 1`);
|
|
473
|
+
await execAsync(`"${adb}" -s ${serial} shell settings put global adb_enabled 1`);
|
|
474
|
+
return { success: true };
|
|
475
|
+
}
|
|
476
|
+
catch (error) {
|
|
477
|
+
return { success: false, error: error.message };
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
static async getLocale(serial) {
|
|
481
|
+
return new Promise((resolve) => {
|
|
482
|
+
try {
|
|
483
|
+
const adb = Sync.getAdbPath();
|
|
484
|
+
const cmd = `"${adb}" -s ${serial} shell getprop persist.sys.locale`;
|
|
485
|
+
exec(cmd, { encoding: "utf8" }, (error, stdout) => {
|
|
486
|
+
if (error || !stdout)
|
|
487
|
+
return resolve(null);
|
|
488
|
+
const lang = stdout.trim();
|
|
489
|
+
if (!lang.includes("-"))
|
|
490
|
+
return resolve(null);
|
|
491
|
+
const [language, country] = lang.split("-");
|
|
492
|
+
resolve({ language, country });
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
catch {
|
|
496
|
+
resolve(null);
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
static async clearAppData(serial, packageName) {
|
|
501
|
+
return new Promise((resolve) => {
|
|
502
|
+
try {
|
|
503
|
+
const adb = Sync.getAdbPath();
|
|
504
|
+
const cmd = `"${adb}" -s ${serial} shell pm clear ${packageName}`;
|
|
505
|
+
exec(cmd, { encoding: "utf8" }, (error, stdout, stderr) => {
|
|
506
|
+
const output = (stdout + stderr).trim();
|
|
507
|
+
const success = /Success/i.test(output);
|
|
508
|
+
if (error) {
|
|
509
|
+
resolve({ success: false, command: cmd, error: error.message });
|
|
510
|
+
}
|
|
511
|
+
else {
|
|
512
|
+
resolve({ success, command: cmd, output });
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
catch (error) {
|
|
517
|
+
resolve({
|
|
518
|
+
success: false,
|
|
519
|
+
command: "clearAppData",
|
|
520
|
+
error: error.message,
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
static async getUptime(serial) {
|
|
526
|
+
return new Promise((resolve) => {
|
|
527
|
+
try {
|
|
528
|
+
const adb = Sync.getAdbPath();
|
|
529
|
+
const cmd = `"${adb}" -s ${serial} shell uptime`;
|
|
530
|
+
exec(cmd, { encoding: "utf8" }, (error, stdout) => {
|
|
531
|
+
if (error || !stdout)
|
|
532
|
+
return resolve(null);
|
|
533
|
+
resolve(stdout.trim());
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
catch {
|
|
537
|
+
resolve(null);
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
static async isRooted(serial) {
|
|
542
|
+
return new Promise((resolve) => {
|
|
543
|
+
try {
|
|
544
|
+
const adb = Sync.getAdbPath();
|
|
545
|
+
const cmd = `"${adb}" -s ${serial} shell which su`;
|
|
546
|
+
exec(cmd, { encoding: "utf8" }, (error, stdout) => {
|
|
547
|
+
if (error || !stdout)
|
|
548
|
+
return resolve(false);
|
|
549
|
+
resolve(stdout.trim().length > 0);
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
catch {
|
|
553
|
+
resolve(false);
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
static async getCpuUsage(serial) {
|
|
558
|
+
return new Promise((resolve) => {
|
|
559
|
+
try {
|
|
560
|
+
const adb = Sync.getAdbPath();
|
|
561
|
+
const cmd = `"${adb}" -s ${serial} shell top -n 1 -b`;
|
|
562
|
+
exec(cmd, { encoding: "utf8" }, (error, stdout) => {
|
|
563
|
+
if (error || !stdout)
|
|
564
|
+
return resolve(null);
|
|
565
|
+
const match = stdout.match(/CPU usage:\s+(.*)%/i);
|
|
566
|
+
resolve(match ? match[1].trim() + "%" : null);
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
catch {
|
|
570
|
+
resolve(null);
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
static async getTopApp(serial) {
|
|
575
|
+
return new Promise((resolve) => {
|
|
576
|
+
try {
|
|
577
|
+
const adb = Sync.getAdbPath();
|
|
578
|
+
const cmd = `"${adb}" -s ${serial} shell dumpsys window windows | grep -E 'mCurrentFocus'`;
|
|
579
|
+
exec(cmd, { encoding: "utf8" }, (error, stdout) => {
|
|
580
|
+
if (error || !stdout)
|
|
581
|
+
return resolve(null);
|
|
582
|
+
const match = stdout.match(/Window\{.*\s([^\s\/]+)\/([^\s}]+)\}/);
|
|
583
|
+
resolve(match ? { package: match[1], activity: match[2] } : null);
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
catch {
|
|
587
|
+
resolve(null);
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
static async killProcess(serial, pid) {
|
|
592
|
+
return new Promise((resolve) => {
|
|
593
|
+
try {
|
|
594
|
+
const adb = Sync.getAdbPath();
|
|
595
|
+
const cmd = `"${adb}" -s ${serial} shell kill ${pid}`;
|
|
596
|
+
exec(cmd, { encoding: "utf8" }, (error) => {
|
|
597
|
+
resolve({ success: !error, command: cmd, error: error?.message });
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
catch (error) {
|
|
601
|
+
resolve({ success: false, command: "kill", error: error.message });
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
static async getProcesses(serial) {
|
|
606
|
+
return new Promise((resolve) => {
|
|
607
|
+
try {
|
|
608
|
+
const adb = Sync.getAdbPath();
|
|
609
|
+
const cmd = `"${adb}" -s ${serial} shell ps -A`;
|
|
610
|
+
exec(cmd, { encoding: "utf8" }, (error, stdout) => {
|
|
611
|
+
if (error || !stdout)
|
|
612
|
+
return resolve(null);
|
|
613
|
+
const lines = stdout.trim().split("\n").slice(1);
|
|
614
|
+
const processes = lines.map((line) => {
|
|
615
|
+
const parts = line.trim().split(/\s+/);
|
|
616
|
+
return {
|
|
617
|
+
user: parts[0],
|
|
618
|
+
pid: Number(parts[1]),
|
|
619
|
+
name: parts.slice(-1)[0],
|
|
620
|
+
};
|
|
621
|
+
});
|
|
622
|
+
resolve(processes.length ? processes : null);
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
catch {
|
|
626
|
+
resolve(null);
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
static async getNetworkInfo(serial) {
|
|
631
|
+
return new Promise((resolve) => {
|
|
632
|
+
try {
|
|
633
|
+
const adb = Sync.getAdbPath();
|
|
634
|
+
const cmd = `"${adb}" -s ${serial} shell ip addr show wlan0`;
|
|
635
|
+
exec(cmd, { encoding: "utf8" }, (error, stdout) => {
|
|
636
|
+
if (error || !stdout)
|
|
637
|
+
return resolve(null);
|
|
638
|
+
const info = {};
|
|
639
|
+
const ipMatch = stdout.match(/inet\s+(\d+\.\d+\.\d+\.\d+)/);
|
|
640
|
+
const macMatch = stdout.match(/link\/ether\s+([0-9a-f:]+)/i);
|
|
641
|
+
if (ipMatch)
|
|
642
|
+
info["ip_address"] = ipMatch[1];
|
|
643
|
+
if (macMatch)
|
|
644
|
+
info["mac_address"] = macMatch[1];
|
|
645
|
+
info["interface"] = "wlan0";
|
|
646
|
+
resolve(info);
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
catch {
|
|
650
|
+
resolve(null);
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
static async getMemoryInfo(serial) {
|
|
655
|
+
return new Promise((resolve) => {
|
|
656
|
+
try {
|
|
657
|
+
const adb = Sync.getAdbPath();
|
|
658
|
+
const cmd = `"${adb}" -s ${serial} shell cat /proc/meminfo`;
|
|
659
|
+
exec(cmd, { encoding: "utf8" }, (error, stdout, stderr) => {
|
|
660
|
+
if (error || (!stdout && !stderr))
|
|
661
|
+
return resolve(null);
|
|
662
|
+
const output = (stdout + stderr).trim();
|
|
663
|
+
if (!output)
|
|
664
|
+
return resolve(null);
|
|
665
|
+
const memInfo = {};
|
|
666
|
+
output.split(/\r?\n/).forEach((line) => {
|
|
667
|
+
const parts = line.split(":");
|
|
668
|
+
if (parts.length === 2)
|
|
669
|
+
memInfo[parts[0].trim()] = parts[1].trim().replace(/\s+/g, " ");
|
|
670
|
+
});
|
|
671
|
+
resolve(Object.keys(memInfo).length ? memInfo : null);
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
catch (err) {
|
|
675
|
+
resolve(null);
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
static async getStorageInfo(serial) {
|
|
680
|
+
return new Promise((resolve) => {
|
|
681
|
+
try {
|
|
682
|
+
const adb = ADB.Sync.getAdbPath(); // uso correcto del path
|
|
683
|
+
const cmd = `"${adb}" -s ${serial} shell df -h`;
|
|
684
|
+
exec(cmd, { encoding: "utf8" }, (error, stdout, stderr) => {
|
|
685
|
+
if (error && !stdout && !stderr)
|
|
686
|
+
return resolve(null);
|
|
687
|
+
const output = (stdout + stderr).trim();
|
|
688
|
+
const lines = output.split("\n");
|
|
689
|
+
if (lines.length < 2)
|
|
690
|
+
return resolve(null);
|
|
691
|
+
const data = lines.slice(1).map((line) => {
|
|
692
|
+
const parts = line.trim().split(/\s+/);
|
|
693
|
+
return {
|
|
694
|
+
device: parts[0] || "",
|
|
695
|
+
size: parts[1] || "",
|
|
696
|
+
used: parts[2] || "",
|
|
697
|
+
available: parts[3] || "",
|
|
698
|
+
use: parts[4] || "",
|
|
699
|
+
mount: parts[5] || "",
|
|
700
|
+
};
|
|
701
|
+
});
|
|
702
|
+
resolve(data.length ? data : null);
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
catch {
|
|
706
|
+
resolve(null);
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
static exec(serial, command) {
|
|
711
|
+
return new Promise((resolve) => {
|
|
712
|
+
try {
|
|
713
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
714
|
+
const __dirname = path.dirname(__filename);
|
|
715
|
+
const adbPath = path.join(__dirname, "dependencies", "adb.exe");
|
|
716
|
+
const cmd = `"${adbPath}" -s ${serial} ${command}`;
|
|
717
|
+
exec(cmd, { encoding: "utf8" }, (error, stdout, stderr) => {
|
|
718
|
+
resolve({
|
|
719
|
+
success: !error,
|
|
720
|
+
command: cmd,
|
|
721
|
+
output: stdout?.trim(),
|
|
722
|
+
error: error ? stderr?.trim() || error.message : undefined,
|
|
723
|
+
});
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
catch (error) {
|
|
727
|
+
resolve({
|
|
728
|
+
success: false,
|
|
729
|
+
command: command,
|
|
730
|
+
error: error.message,
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
static async setScreenBrightness(serial, level) {
|
|
736
|
+
return new Promise((resolve) => {
|
|
737
|
+
try {
|
|
738
|
+
const adb = Sync.getAdbPath();
|
|
739
|
+
const cmd = `"${adb}" -s ${serial} shell settings put system screen_brightness ${level}`;
|
|
740
|
+
exec(cmd, { encoding: "utf8" }, (error) => {
|
|
741
|
+
if (error) {
|
|
742
|
+
resolve({
|
|
743
|
+
success: false,
|
|
744
|
+
command: "setScreenBrightness",
|
|
745
|
+
error: error.message,
|
|
746
|
+
});
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
resolve({ success: true, command: cmd });
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
catch (error) {
|
|
753
|
+
resolve({
|
|
754
|
+
success: false,
|
|
755
|
+
command: "setScreenBrightness",
|
|
756
|
+
error: error.message,
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
static async getScreenBrightness(serial) {
|
|
762
|
+
return new Promise((resolve) => {
|
|
763
|
+
try {
|
|
764
|
+
const adb = Sync.getAdbPath();
|
|
765
|
+
const cmd = `"${adb}" -s ${serial} shell settings get system screen_brightness`;
|
|
766
|
+
exec(cmd, { encoding: "utf8" }, (error, stdout) => {
|
|
767
|
+
if (error || !stdout) {
|
|
768
|
+
resolve(null);
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
resolve(Number(stdout.trim()));
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
catch {
|
|
775
|
+
resolve(null);
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
static async getScreenResolution(serial) {
|
|
780
|
+
return new Promise((resolve) => {
|
|
781
|
+
try {
|
|
782
|
+
const adb = Sync.getAdbPath();
|
|
783
|
+
const cmd = `"${adb}" -s ${serial} shell wm size`;
|
|
784
|
+
exec(cmd, { encoding: "utf8" }, (error, stdout) => {
|
|
785
|
+
if (error || !stdout) {
|
|
786
|
+
resolve(null);
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
const output = stdout.replace("Physical size: ", "").trim();
|
|
790
|
+
const match = output.match(/^(\d+)x(\d+)$/);
|
|
791
|
+
if (!match) {
|
|
792
|
+
resolve(null);
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
resolve({ width: Number(match[1]), height: Number(match[2]) });
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
catch {
|
|
799
|
+
resolve(null);
|
|
800
|
+
}
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
static async screenshot(serial, remotePath) {
|
|
804
|
+
return new Promise((resolve) => {
|
|
805
|
+
try {
|
|
806
|
+
const adb = Sync.getAdbPath();
|
|
807
|
+
const cmd = `"${adb}" -s ${serial} shell screencap -p "${remotePath}"`;
|
|
808
|
+
exec(cmd, { encoding: "utf8" }, (error) => {
|
|
809
|
+
resolve({ success: !error, command: cmd, error: error?.message });
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
catch (error) {
|
|
813
|
+
resolve({
|
|
814
|
+
success: false,
|
|
815
|
+
command: "screenshot",
|
|
816
|
+
error: error.message,
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
static async uninstallPackage(serial, packageName) {
|
|
822
|
+
return new Promise((resolve) => {
|
|
823
|
+
try {
|
|
824
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
825
|
+
const __dirname = path.dirname(__filename);
|
|
826
|
+
const adbPath = path.join(__dirname, "dependencies", "adb.exe");
|
|
827
|
+
const cmd = `"${adbPath}" -s ${serial} shell pm uninstall "${packageName}"`;
|
|
828
|
+
exec(cmd, { encoding: "utf8" }, (error, stdout, stderr) => {
|
|
829
|
+
if (error) {
|
|
830
|
+
resolve({
|
|
831
|
+
success: false,
|
|
832
|
+
command: cmd,
|
|
833
|
+
error: stderr.trim() || error.message,
|
|
834
|
+
});
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
const output = (stdout + stderr).trim();
|
|
838
|
+
const success = /Success/i.test(output);
|
|
839
|
+
resolve({
|
|
840
|
+
success,
|
|
841
|
+
command: cmd,
|
|
842
|
+
error: success ? undefined : output,
|
|
843
|
+
});
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
catch (error) {
|
|
847
|
+
resolve({
|
|
848
|
+
success: false,
|
|
849
|
+
command: "uninstall",
|
|
850
|
+
error: error.message,
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
static async getBatteryInfo(serial) {
|
|
856
|
+
return new Promise((resolve) => {
|
|
857
|
+
try {
|
|
858
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
859
|
+
const __dirname = path.dirname(__filename);
|
|
860
|
+
const adbPath = path.join(__dirname, "dependencies", "adb.exe");
|
|
861
|
+
const cmd = `"${adbPath}" -s ${serial} shell dumpsys battery`;
|
|
862
|
+
exec(cmd, { encoding: "utf8" }, (error, stdout) => {
|
|
863
|
+
if (error || !stdout) {
|
|
864
|
+
resolve(null);
|
|
865
|
+
return;
|
|
866
|
+
}
|
|
867
|
+
const info = {};
|
|
868
|
+
stdout.split("\n").forEach((line) => {
|
|
869
|
+
const parts = line.trim().split(": ");
|
|
870
|
+
if (parts.length === 2) {
|
|
871
|
+
const key = parts[0].trim();
|
|
872
|
+
let value = parts[1].trim();
|
|
873
|
+
const lower = value.toLowerCase();
|
|
874
|
+
if (["true", "yes", "1"].includes(lower))
|
|
875
|
+
value = true;
|
|
876
|
+
else if (["false", "no", "0"].includes(lower))
|
|
877
|
+
value = false;
|
|
878
|
+
else if (!isNaN(Number(value)))
|
|
879
|
+
value = Number(value);
|
|
880
|
+
info[key] = value;
|
|
881
|
+
}
|
|
882
|
+
});
|
|
883
|
+
resolve(Object.keys(info).length ? info : null);
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
catch {
|
|
887
|
+
resolve(null);
|
|
888
|
+
}
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
static async getPackages(serial, systemOnly = false) {
|
|
892
|
+
return new Promise((resolve) => {
|
|
893
|
+
try {
|
|
894
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
895
|
+
const __dirname = path.dirname(__filename);
|
|
896
|
+
const adbPath = path.join(__dirname, "dependencies", "adb.exe");
|
|
897
|
+
const flag = systemOnly ? "-s" : "";
|
|
898
|
+
const cmd = `"${adbPath}" -s ${serial} shell pm list packages ${flag}`;
|
|
899
|
+
exec(cmd, { encoding: "utf8" }, (error, stdout) => {
|
|
900
|
+
if (error || !stdout) {
|
|
901
|
+
resolve([]);
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
const packages = stdout
|
|
905
|
+
.split("\n")
|
|
906
|
+
.map((l) => l.replace("package:", "").trim())
|
|
907
|
+
.filter(Boolean);
|
|
908
|
+
resolve(packages);
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
catch {
|
|
912
|
+
resolve([]);
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
static async pushFile(serial, localPath, remotePath, ...args) {
|
|
917
|
+
return new Promise((resolve) => {
|
|
918
|
+
try {
|
|
919
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
920
|
+
const __dirname = path.dirname(__filename);
|
|
921
|
+
const adbPath = path.join(__dirname, "dependencies", "adb.exe");
|
|
922
|
+
const params = args.length ? args.join(" ") : "";
|
|
923
|
+
const cmd = `"${adbPath}" -s ${serial} push ${params} "${localPath}" "${remotePath}"`;
|
|
924
|
+
exec(cmd, { encoding: "utf8" }, (error, stdout, stderr) => {
|
|
925
|
+
if (error) {
|
|
926
|
+
resolve({
|
|
927
|
+
success: false,
|
|
928
|
+
command: cmd,
|
|
929
|
+
error: stderr.trim() || error.message,
|
|
930
|
+
});
|
|
931
|
+
return;
|
|
932
|
+
}
|
|
933
|
+
const output = (stdout + stderr).trim();
|
|
934
|
+
const success = /[\d\s]+files? pushed/i.test(output) || /100%/i.test(output);
|
|
935
|
+
resolve({
|
|
936
|
+
success,
|
|
937
|
+
command: cmd,
|
|
938
|
+
error: success ? undefined : output,
|
|
939
|
+
});
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
catch (error) {
|
|
943
|
+
resolve({
|
|
944
|
+
success: false,
|
|
945
|
+
command: "push",
|
|
946
|
+
error: error.message,
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
static async pullFile(serial, remotePath, localPath, ...args) {
|
|
952
|
+
return new Promise((resolve) => {
|
|
953
|
+
try {
|
|
954
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
955
|
+
const __dirname = path.dirname(__filename);
|
|
956
|
+
const adbPath = path.join(__dirname, "dependencies", "adb.exe");
|
|
957
|
+
const params = args.length ? args.join(" ") : "";
|
|
958
|
+
const cmd = `"${adbPath}" -s ${serial} pull ${params} "${remotePath}" "${localPath}"`;
|
|
959
|
+
exec(cmd, { encoding: "utf8" }, (error, stdout, stderr) => {
|
|
960
|
+
if (error) {
|
|
961
|
+
resolve({
|
|
962
|
+
success: false,
|
|
963
|
+
command: cmd,
|
|
964
|
+
error: stderr.trim() || error.message,
|
|
965
|
+
});
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
const output = (stdout + stderr).trim();
|
|
969
|
+
const success = /[\d\s]+files? pulled/i.test(output) || /100%/i.test(output);
|
|
970
|
+
resolve({
|
|
971
|
+
success,
|
|
972
|
+
command: cmd,
|
|
973
|
+
error: success ? undefined : output,
|
|
974
|
+
});
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
catch (error) {
|
|
978
|
+
resolve({
|
|
979
|
+
success: false,
|
|
980
|
+
command: "pull",
|
|
981
|
+
error: error.message,
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
static async installApk(serial, apkPath, ...args) {
|
|
987
|
+
return new Promise((resolve) => {
|
|
988
|
+
try {
|
|
989
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
990
|
+
const __dirname = path.dirname(__filename);
|
|
991
|
+
const adbPath = path.join(__dirname, "dependencies", "adb.exe");
|
|
992
|
+
const params = args.length ? args.join(" ") : "";
|
|
993
|
+
const cmd = `"${adbPath}" -s ${serial} install ${params} "${apkPath}"`;
|
|
994
|
+
exec(cmd, { encoding: "utf8" }, (error, stdout, stderr) => {
|
|
995
|
+
if (error) {
|
|
996
|
+
resolve({
|
|
997
|
+
success: false,
|
|
998
|
+
command: cmd,
|
|
999
|
+
error: stderr.trim() || error.message,
|
|
1000
|
+
});
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
const output = (stdout + stderr).trim();
|
|
1004
|
+
const success = /Success/i.test(output);
|
|
1005
|
+
resolve({
|
|
1006
|
+
success,
|
|
1007
|
+
command: cmd,
|
|
1008
|
+
error: success ? undefined : output,
|
|
1009
|
+
});
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
catch (error) {
|
|
1013
|
+
resolve({
|
|
1014
|
+
success: false,
|
|
1015
|
+
command: "install",
|
|
1016
|
+
error: error.message,
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
static async getModel(serial) {
|
|
1022
|
+
const props = await this.getDeviceProperties(serial);
|
|
1023
|
+
return props?.["ro.product.model"] || null;
|
|
1024
|
+
}
|
|
1025
|
+
static async getBrand(serial) {
|
|
1026
|
+
const props = await this.getDeviceProperties(serial);
|
|
1027
|
+
return props?.["ro.product.brand"] || null;
|
|
1028
|
+
}
|
|
1029
|
+
static async getAndroidVersion(serial) {
|
|
1030
|
+
const props = await this.getDeviceProperties(serial);
|
|
1031
|
+
return props?.["ro.build.version.release"] || null;
|
|
1032
|
+
}
|
|
1033
|
+
static async getSdkVersion(serial) {
|
|
1034
|
+
const props = await this.getDeviceProperties(serial);
|
|
1035
|
+
return props?.["ro.build.version.sdk"] || null;
|
|
1036
|
+
}
|
|
1037
|
+
static async getDeviceProperties(serial) {
|
|
1038
|
+
return new Promise((resolve) => {
|
|
1039
|
+
try {
|
|
1040
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
1041
|
+
const __dirname = path.dirname(__filename);
|
|
1042
|
+
const adbPath = path.join(__dirname, "dependencies", "adb.exe");
|
|
1043
|
+
exec(`"${adbPath}" -s ${serial} shell getprop`, { encoding: "utf8" }, (error, stdout) => {
|
|
1044
|
+
if (error) {
|
|
1045
|
+
resolve(null);
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
const props = {};
|
|
1049
|
+
stdout.split("\n").forEach((line) => {
|
|
1050
|
+
line = line.trim();
|
|
1051
|
+
if (!line)
|
|
1052
|
+
return;
|
|
1053
|
+
const match = line.match(/^\[([^\]]+)\]: \[(.*)\]$/);
|
|
1054
|
+
if (match) {
|
|
1055
|
+
const key = match[1].trim();
|
|
1056
|
+
let value = match[2].trim();
|
|
1057
|
+
const lower = value.toLowerCase();
|
|
1058
|
+
// Booleanos
|
|
1059
|
+
if (["true", "yes", "1"].includes(lower)) {
|
|
1060
|
+
value = true;
|
|
1061
|
+
}
|
|
1062
|
+
else if (["false", "no", "0"].includes(lower)) {
|
|
1063
|
+
value = false;
|
|
1064
|
+
}
|
|
1065
|
+
// Números enteros o flotantes
|
|
1066
|
+
else if (!isNaN(Number(value)) && value !== "") {
|
|
1067
|
+
value = Number(value);
|
|
1068
|
+
}
|
|
1069
|
+
// String vacío → null
|
|
1070
|
+
else if (value === "") {
|
|
1071
|
+
value = null;
|
|
1072
|
+
}
|
|
1073
|
+
props[key] = value;
|
|
1074
|
+
}
|
|
1075
|
+
});
|
|
1076
|
+
resolve(Object.keys(props).length ? props : null);
|
|
1077
|
+
});
|
|
1078
|
+
}
|
|
1079
|
+
catch {
|
|
1080
|
+
resolve(null);
|
|
1081
|
+
}
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
static async power(serial, command, customCommand) {
|
|
1085
|
+
return new Promise((resolve) => {
|
|
1086
|
+
try {
|
|
1087
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
1088
|
+
const __dirname = path.dirname(__filename);
|
|
1089
|
+
const adbPath = path.join(__dirname, "dependencies", "adb.exe");
|
|
1090
|
+
let cmd = `"${adbPath}" -s ${serial} `;
|
|
1091
|
+
const defaultCommands = {
|
|
1092
|
+
shutdown: "shell reboot -p",
|
|
1093
|
+
reboot: "reboot",
|
|
1094
|
+
bootloader: "reboot bootloader",
|
|
1095
|
+
fastbootd: "reboot fastboot",
|
|
1096
|
+
};
|
|
1097
|
+
cmd += customCommand ?? defaultCommands[command] ?? command;
|
|
1098
|
+
exec(cmd, { encoding: "utf8" }, (error) => {
|
|
1099
|
+
if (error) {
|
|
1100
|
+
resolve({ success: false, command: cmd, error: error.message });
|
|
1101
|
+
return;
|
|
1102
|
+
}
|
|
1103
|
+
resolve({ success: true, command: cmd });
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
catch (error) {
|
|
1107
|
+
resolve({
|
|
1108
|
+
success: false,
|
|
1109
|
+
command: String(command),
|
|
1110
|
+
error: error.message,
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
static async listDevices() {
|
|
1116
|
+
return new Promise((resolve) => {
|
|
1117
|
+
try {
|
|
1118
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
1119
|
+
const __dirname = path.dirname(__filename);
|
|
1120
|
+
const adbPath = path.join(__dirname, "dependencies", "adb.exe");
|
|
1121
|
+
exec(`"${adbPath}" devices`, { encoding: "utf8" }, (error, stdout) => {
|
|
1122
|
+
if (error) {
|
|
1123
|
+
resolve([]);
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1126
|
+
const lines = stdout
|
|
1127
|
+
.split("\n")
|
|
1128
|
+
.map((line) => line.trim())
|
|
1129
|
+
.filter((line) => line && !line.startsWith("*"));
|
|
1130
|
+
const devices = [];
|
|
1131
|
+
for (const line of lines.slice(1)) {
|
|
1132
|
+
const [serial, stateRaw] = line.split("\t");
|
|
1133
|
+
if (!serial || !stateRaw)
|
|
1134
|
+
continue;
|
|
1135
|
+
const state = ["device", "offline", "unauthorized"].includes(stateRaw)
|
|
1136
|
+
? stateRaw
|
|
1137
|
+
: "unknown";
|
|
1138
|
+
devices.push({ serial, state });
|
|
1139
|
+
}
|
|
1140
|
+
resolve(devices);
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
catch {
|
|
1144
|
+
resolve([]);
|
|
1145
|
+
}
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
export default class ADB {
|
|
1150
|
+
static Sync = Sync;
|
|
1151
|
+
static Async = Async;
|
|
1152
|
+
}
|
|
1153
|
+
//# sourceMappingURL=adb.js.map
|