@yume-chan/android-bin 0.0.21 → 0.0.23
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 +36 -0
- package/CHANGELOG.md +19 -1
- package/README.md +40 -14
- package/esm/am.d.ts +17 -0
- package/esm/am.d.ts.map +1 -0
- package/esm/am.js +42 -0
- package/esm/am.js.map +1 -0
- package/esm/bu.js.map +1 -1
- package/esm/bug-report.js.map +1 -1
- package/esm/cmd.js +4 -4
- package/esm/cmd.js.map +1 -1
- package/esm/demo-mode.js.map +1 -1
- package/esm/dumpsys.d.ts +22 -0
- package/esm/dumpsys.d.ts.map +1 -1
- package/esm/dumpsys.js +34 -1
- package/esm/dumpsys.js.map +1 -1
- package/esm/index.d.ts +3 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +3 -0
- package/esm/index.js.map +1 -1
- package/esm/intent.d.ts +10 -0
- package/esm/intent.d.ts.map +1 -0
- package/esm/intent.js +51 -0
- package/esm/intent.js.map +1 -0
- package/esm/logcat.d.ts.map +1 -1
- package/esm/logcat.js +5 -5
- package/esm/logcat.js.map +1 -1
- package/esm/overlay-display.js.map +1 -1
- package/esm/pm.d.ts +54 -5
- package/esm/pm.d.ts.map +1 -1
- package/esm/pm.js +209 -46
- package/esm/pm.js.map +1 -1
- package/esm/settings.d.ts +2 -1
- package/esm/settings.d.ts.map +1 -1
- package/esm/settings.js.map +1 -1
- package/esm/string-format.d.ts.map +1 -1
- package/esm/string-format.js.map +1 -1
- package/esm/utils.d.ts +4 -0
- package/esm/utils.d.ts.map +1 -0
- package/esm/utils.js +23 -0
- package/esm/utils.js.map +1 -0
- package/package.json +12 -12
- package/src/am.ts +69 -0
- package/src/cmd.ts +4 -4
- package/src/dumpsys.ts +39 -1
- package/src/index.ts +3 -0
- package/src/intent.ts +63 -0
- package/src/logcat.ts +7 -6
- package/src/pm.ts +309 -67
- package/src/settings.ts +2 -1
- package/src/utils.ts +29 -0
- package/tsconfig.build.tsbuildinfo +1 -1
package/esm/utils.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function buildArguments(commands, options, map) {
|
|
2
|
+
const args = commands;
|
|
3
|
+
if (options) {
|
|
4
|
+
for (const [key, value] of Object.entries(options)) {
|
|
5
|
+
if (value) {
|
|
6
|
+
const option = map[key];
|
|
7
|
+
if (option) {
|
|
8
|
+
args.push(option);
|
|
9
|
+
switch (typeof value) {
|
|
10
|
+
case "number":
|
|
11
|
+
args.push(value.toString());
|
|
12
|
+
break;
|
|
13
|
+
case "string":
|
|
14
|
+
args.push(value);
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return args;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=utils.js.map
|
package/esm/utils.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,cAAc,CAC1B,QAAkB,EAClB,OAA+B,EAC/B,GAAqC;IAErC,MAAM,IAAI,GAAG,QAAQ,CAAC;IACtB,IAAI,OAAO,EAAE,CAAC;QACV,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACjD,IAAI,KAAK,EAAE,CAAC;gBACR,MAAM,MAAM,GAAG,GAAG,CAAC,GAAc,CAAC,CAAC;gBACnC,IAAI,MAAM,EAAE,CAAC;oBACT,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;oBAClB,QAAQ,OAAO,KAAK,EAAE,CAAC;wBACnB,KAAK,QAAQ;4BACT,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;4BAC5B,MAAM;wBACV,KAAK,QAAQ;4BACT,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;4BACjB,MAAM;oBACd,CAAC;gBACL,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yume-chan/android-bin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"description": "Wrappers for Android built-in executables.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adb",
|
|
@@ -25,26 +25,26 @@
|
|
|
25
25
|
"main": "esm/index.js",
|
|
26
26
|
"types": "esm/index.d.ts",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@yume-chan/adb": "^0.0.
|
|
29
|
-
"@yume-chan/stream-extra": "^0.0.
|
|
30
|
-
"@yume-chan/struct": "^0.0.
|
|
31
|
-
"tslib": "^2.6.
|
|
28
|
+
"@yume-chan/adb": "^0.0.23",
|
|
29
|
+
"@yume-chan/stream-extra": "^0.0.23",
|
|
30
|
+
"@yume-chan/struct": "^0.0.23",
|
|
31
|
+
"tslib": "^2.6.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@jest/globals": "^
|
|
34
|
+
"@jest/globals": "^30.0.0-alpha.3",
|
|
35
35
|
"@yume-chan/eslint-config": "^1.0.0",
|
|
36
36
|
"@yume-chan/tsconfig": "^1.0.0",
|
|
37
37
|
"cross-env": "^7.0.3",
|
|
38
|
-
"eslint": "^8.
|
|
39
|
-
"jest": "^
|
|
40
|
-
"prettier": "^3.
|
|
41
|
-
"ts-jest": "^29.1.
|
|
42
|
-
"typescript": "^5.
|
|
38
|
+
"eslint": "^8.57.0",
|
|
39
|
+
"jest": "^30.0.0-alpha.3",
|
|
40
|
+
"prettier": "^3.2.5",
|
|
41
|
+
"ts-jest": "^29.1.2",
|
|
42
|
+
"typescript": "^5.4.2"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "tsc -b tsconfig.build.json",
|
|
46
46
|
"build:watch": "tsc -b tsconfig.build.json",
|
|
47
|
-
"test": "cross-env NODE_OPTIONS
|
|
47
|
+
"test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" TS_JEST_DISABLE_VER_CHECKER=true jest --coverage",
|
|
48
48
|
"lint": "eslint src/**/*.ts --fix && prettier src/**/*.ts --write --tab-width 4"
|
|
49
49
|
}
|
|
50
50
|
}
|
package/src/am.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Adb } from "@yume-chan/adb";
|
|
2
|
+
import { AdbCommandBase } from "@yume-chan/adb";
|
|
3
|
+
import { ConcatStringStream, DecodeUtf8Stream } from "@yume-chan/stream-extra";
|
|
4
|
+
|
|
5
|
+
import { Cmd } from "./cmd.js";
|
|
6
|
+
import type { IntentBuilder } from "./intent.js";
|
|
7
|
+
import type { SingleUser } from "./utils.js";
|
|
8
|
+
import { buildArguments } from "./utils.js";
|
|
9
|
+
|
|
10
|
+
export interface ActivityManagerStartActivityOptions {
|
|
11
|
+
displayId?: number;
|
|
12
|
+
windowingMode?: number;
|
|
13
|
+
forceStop?: boolean;
|
|
14
|
+
user?: SingleUser;
|
|
15
|
+
intent: IntentBuilder;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const START_ACTIVITY_OPTIONS_MAP: Partial<
|
|
19
|
+
Record<keyof ActivityManagerStartActivityOptions, string>
|
|
20
|
+
> = {
|
|
21
|
+
displayId: "--display",
|
|
22
|
+
windowingMode: "--windowingMode",
|
|
23
|
+
forceStop: "-S",
|
|
24
|
+
user: "--user",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export class ActivityManager extends AdbCommandBase {
|
|
28
|
+
#cmd: Cmd;
|
|
29
|
+
|
|
30
|
+
constructor(adb: Adb) {
|
|
31
|
+
super(adb);
|
|
32
|
+
this.#cmd = new Cmd(adb);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async #cmdOrSubprocess(args: string[]) {
|
|
36
|
+
if (this.#cmd.supportsCmd) {
|
|
37
|
+
args.shift();
|
|
38
|
+
return await this.#cmd.spawn(false, "activity", ...args);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return this.adb.subprocess.spawn(args);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async startActivity(options: ActivityManagerStartActivityOptions) {
|
|
45
|
+
let args = buildArguments(
|
|
46
|
+
["am", "start-activity", "-W"],
|
|
47
|
+
options,
|
|
48
|
+
START_ACTIVITY_OPTIONS_MAP,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
args = args.concat(options.intent.build());
|
|
52
|
+
|
|
53
|
+
const process = await this.#cmdOrSubprocess(args);
|
|
54
|
+
|
|
55
|
+
const output = await process.stdout
|
|
56
|
+
.pipeThrough(new DecodeUtf8Stream())
|
|
57
|
+
.pipeThrough(new ConcatStringStream())
|
|
58
|
+
.then((output) => output.trim());
|
|
59
|
+
|
|
60
|
+
for (const line of output) {
|
|
61
|
+
if (line.startsWith("Error:")) {
|
|
62
|
+
throw new Error(line.substring("Error:".length).trim());
|
|
63
|
+
}
|
|
64
|
+
if (line === "Complete") {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/cmd.ts
CHANGED
|
@@ -35,10 +35,10 @@ export class Cmd extends AdbCommandBase {
|
|
|
35
35
|
|
|
36
36
|
constructor(adb: Adb) {
|
|
37
37
|
super(adb);
|
|
38
|
-
this.#supportsShellV2 = adb.
|
|
39
|
-
this.#supportsCmd = adb.
|
|
40
|
-
this.#supportsAbb = adb.
|
|
41
|
-
this.#supportsAbbExec = adb.
|
|
38
|
+
this.#supportsShellV2 = adb.canUseFeature(AdbFeature.ShellV2);
|
|
39
|
+
this.#supportsCmd = adb.canUseFeature(AdbFeature.Cmd);
|
|
40
|
+
this.#supportsAbb = adb.canUseFeature(AdbFeature.Abb);
|
|
41
|
+
this.#supportsAbbExec = adb.canUseFeature(AdbFeature.AbbExec);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
async spawn(
|
package/src/dumpsys.ts
CHANGED
|
@@ -47,7 +47,9 @@ export class DumpSys extends AdbCommandBase {
|
|
|
47
47
|
let scale: number | undefined;
|
|
48
48
|
let voltage: number | undefined;
|
|
49
49
|
let current: number | undefined;
|
|
50
|
-
|
|
50
|
+
let status: DumpSys.Battery.Status | undefined;
|
|
51
|
+
let health: DumpSys.Battery.Health | undefined;
|
|
52
|
+
for (const line of output.split("\n")) {
|
|
51
53
|
const parts = line.split(":");
|
|
52
54
|
if (parts.length !== 2) {
|
|
53
55
|
continue;
|
|
@@ -75,6 +77,18 @@ export class DumpSys extends AdbCommandBase {
|
|
|
75
77
|
case "current now":
|
|
76
78
|
current = Number.parseInt(parts[1]!.trim(), 10);
|
|
77
79
|
break;
|
|
80
|
+
case "status":
|
|
81
|
+
status = Number.parseInt(
|
|
82
|
+
parts[1]!.trim(),
|
|
83
|
+
10,
|
|
84
|
+
) as DumpSys.Battery.Status;
|
|
85
|
+
break;
|
|
86
|
+
case "health":
|
|
87
|
+
health = Number.parseInt(
|
|
88
|
+
parts[1]!.trim(),
|
|
89
|
+
10,
|
|
90
|
+
) as DumpSys.Battery.Health;
|
|
91
|
+
break;
|
|
78
92
|
}
|
|
79
93
|
}
|
|
80
94
|
|
|
@@ -86,6 +100,30 @@ export class DumpSys extends AdbCommandBase {
|
|
|
86
100
|
scale,
|
|
87
101
|
voltage,
|
|
88
102
|
current,
|
|
103
|
+
status,
|
|
104
|
+
health,
|
|
89
105
|
};
|
|
90
106
|
}
|
|
91
107
|
}
|
|
108
|
+
|
|
109
|
+
export namespace DumpSys {
|
|
110
|
+
export namespace Battery {
|
|
111
|
+
export enum Status {
|
|
112
|
+
Unknown = 1,
|
|
113
|
+
Charging,
|
|
114
|
+
Discharging,
|
|
115
|
+
NotCharging,
|
|
116
|
+
Full,
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export enum Health {
|
|
120
|
+
Unknown = 1,
|
|
121
|
+
Good,
|
|
122
|
+
Overheat,
|
|
123
|
+
Dead,
|
|
124
|
+
OverVoltage,
|
|
125
|
+
UnspecifiedFailure,
|
|
126
|
+
Cold,
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
// cspell: ignore logcat
|
|
2
2
|
|
|
3
|
+
export * from "./am.js";
|
|
3
4
|
export * from "./bu.js";
|
|
4
5
|
export * from "./bug-report.js";
|
|
5
6
|
export * from "./cmd.js";
|
|
6
7
|
export * from "./demo-mode.js";
|
|
7
8
|
export * from "./dumpsys.js";
|
|
9
|
+
export * from "./intent.js";
|
|
8
10
|
export * from "./logcat.js";
|
|
9
11
|
export * from "./overlay-display.js";
|
|
10
12
|
export * from "./pm.js";
|
|
11
13
|
export * from "./settings.js";
|
|
14
|
+
export * from "./string-format.js";
|
package/src/intent.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export class IntentBuilder {
|
|
2
|
+
#action: string | undefined;
|
|
3
|
+
#categories: string[] = [];
|
|
4
|
+
#packageName: string | undefined;
|
|
5
|
+
#component: string | undefined;
|
|
6
|
+
#data: string | undefined;
|
|
7
|
+
#type: string | undefined;
|
|
8
|
+
|
|
9
|
+
setAction(action: string): this {
|
|
10
|
+
this.#action = action;
|
|
11
|
+
return this;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
addCategory(category: string): this {
|
|
15
|
+
this.#categories.push(category);
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
setPackage(packageName: string): this {
|
|
20
|
+
this.#packageName = packageName;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
setComponent(component: string): this {
|
|
25
|
+
this.#component = component;
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
setData(data: string): this {
|
|
30
|
+
this.#data = data;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
build(): string[] {
|
|
35
|
+
const result: string[] = [];
|
|
36
|
+
|
|
37
|
+
if (this.#action) {
|
|
38
|
+
result.push("-a", this.#action);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
for (const category of this.#categories) {
|
|
42
|
+
result.push("-c", category);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (this.#packageName) {
|
|
46
|
+
result.push("-p", this.#packageName);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (this.#component) {
|
|
50
|
+
result.push("-n", this.#component);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (this.#data) {
|
|
54
|
+
result.push("-d", this.#data);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (this.#type) {
|
|
58
|
+
result.push("-t", this.#type);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/logcat.ts
CHANGED
|
@@ -384,7 +384,7 @@ export interface LogSize {
|
|
|
384
384
|
|
|
385
385
|
export class Logcat extends AdbCommandBase {
|
|
386
386
|
static logIdToName(id: LogId): string {
|
|
387
|
-
return LogId[id]
|
|
387
|
+
return LogId[id];
|
|
388
388
|
}
|
|
389
389
|
|
|
390
390
|
static logNameToId(name: string): LogId {
|
|
@@ -471,11 +471,12 @@ export class Logcat extends AdbCommandBase {
|
|
|
471
471
|
}
|
|
472
472
|
|
|
473
473
|
async clear(ids?: LogId[]) {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
"-
|
|
477
|
-
|
|
478
|
-
|
|
474
|
+
const args = ["logcat", "-c"];
|
|
475
|
+
if (ids && ids.length > 0) {
|
|
476
|
+
args.push("-b", Logcat.joinLogId(ids));
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
await this.adb.subprocess.spawnAndWait(args);
|
|
479
480
|
}
|
|
480
481
|
|
|
481
482
|
binary(options?: LogcatOptions): ReadableStream<AndroidLogEntry> {
|