@yume-chan/android-bin 0.0.0-20240714132542

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.
Files changed (76) hide show
  1. package/CHANGELOG.md +129 -0
  2. package/LICENSE +21 -0
  3. package/README.md +49 -0
  4. package/esm/am.d.ts +17 -0
  5. package/esm/am.d.ts.map +1 -0
  6. package/esm/am.js +42 -0
  7. package/esm/am.js.map +1 -0
  8. package/esm/bu.d.ts +28 -0
  9. package/esm/bu.d.ts.map +1 -0
  10. package/esm/bu.js +53 -0
  11. package/esm/bu.js.map +1 -0
  12. package/esm/bug-report.d.ts +99 -0
  13. package/esm/bug-report.d.ts.map +1 -0
  14. package/esm/bug-report.js +271 -0
  15. package/esm/bug-report.js.map +1 -0
  16. package/esm/cmd.d.ts +25 -0
  17. package/esm/cmd.d.ts.map +1 -0
  18. package/esm/cmd.js +81 -0
  19. package/esm/cmd.js.map +1 -0
  20. package/esm/demo-mode.d.ts +44 -0
  21. package/esm/demo-mode.d.ts.map +1 -0
  22. package/esm/demo-mode.js +179 -0
  23. package/esm/demo-mode.js.map +1 -0
  24. package/esm/dumpsys.d.ts +51 -0
  25. package/esm/dumpsys.d.ts.map +1 -0
  26. package/esm/dumpsys.js +114 -0
  27. package/esm/dumpsys.js.map +1 -0
  28. package/esm/index.d.ts +13 -0
  29. package/esm/index.d.ts.map +1 -0
  30. package/esm/index.js +14 -0
  31. package/esm/index.js.map +1 -0
  32. package/esm/intent.d.ts +11 -0
  33. package/esm/intent.d.ts.map +1 -0
  34. package/esm/intent.js +59 -0
  35. package/esm/intent.js.map +1 -0
  36. package/esm/logcat.d.ts +93 -0
  37. package/esm/logcat.d.ts.map +1 -0
  38. package/esm/logcat.js +300 -0
  39. package/esm/logcat.js.map +1 -0
  40. package/esm/overlay-display.d.ts +38 -0
  41. package/esm/overlay-display.d.ts.map +1 -0
  42. package/esm/overlay-display.js +51 -0
  43. package/esm/overlay-display.js.map +1 -0
  44. package/esm/pm.d.ts +211 -0
  45. package/esm/pm.d.ts.map +1 -0
  46. package/esm/pm.js +382 -0
  47. package/esm/pm.js.map +1 -0
  48. package/esm/settings.d.ts +27 -0
  49. package/esm/settings.d.ts.map +1 -0
  50. package/esm/settings.js +66 -0
  51. package/esm/settings.js.map +1 -0
  52. package/esm/string-format.d.ts +43 -0
  53. package/esm/string-format.d.ts.map +1 -0
  54. package/esm/string-format.js +152 -0
  55. package/esm/string-format.js.map +1 -0
  56. package/esm/utils.d.ts +4 -0
  57. package/esm/utils.d.ts.map +1 -0
  58. package/esm/utils.js +23 -0
  59. package/esm/utils.js.map +1 -0
  60. package/package.json +49 -0
  61. package/src/am.ts +71 -0
  62. package/src/bu.ts +80 -0
  63. package/src/bug-report.ts +348 -0
  64. package/src/cmd.ts +113 -0
  65. package/src/demo-mode.ts +232 -0
  66. package/src/dumpsys.ts +153 -0
  67. package/src/index.ts +14 -0
  68. package/src/intent.ts +73 -0
  69. package/src/logcat.ts +509 -0
  70. package/src/overlay-display.ts +112 -0
  71. package/src/pm.ts +674 -0
  72. package/src/settings.ts +128 -0
  73. package/src/string-format.ts +197 -0
  74. package/src/utils.ts +29 -0
  75. package/tsconfig.build.json +14 -0
  76. package/tsconfig.build.tsbuildinfo +1 -0
package/src/dumpsys.ts ADDED
@@ -0,0 +1,153 @@
1
+ import { AdbCommandBase } from "@yume-chan/adb";
2
+
3
+ const BatteryDumpFields: Record<
4
+ string,
5
+ {
6
+ type: "number" | "boolean" | "string";
7
+ field: keyof DumpSys.Battery.Info;
8
+ }
9
+ > = {
10
+ "AC powered": { type: "boolean", field: "acPowered" },
11
+ "USB powered": { type: "boolean", field: "usbPowered" },
12
+ "Wireless powered": { type: "boolean", field: "wirelessPowered" },
13
+ "Dock powered": { type: "boolean", field: "dockPowered" },
14
+ "Max charging current": {
15
+ type: "number",
16
+ field: "maxChargingCurrent",
17
+ },
18
+ "Max charging voltage": {
19
+ type: "number",
20
+ field: "maxChargingVoltage",
21
+ },
22
+ "Charge counter": { type: "number", field: "chargeCounter" },
23
+ status: { type: "number", field: "status" },
24
+ health: { type: "number", field: "health" },
25
+ present: { type: "boolean", field: "present" },
26
+ level: { type: "number", field: "level" },
27
+ scale: { type: "number", field: "scale" },
28
+ voltage: { type: "number", field: "voltage" },
29
+ temperature: { type: "number", field: "temperature" },
30
+ technology: { type: "string", field: "technology" },
31
+ current: { type: "number", field: "current" },
32
+ };
33
+
34
+ export class DumpSys extends AdbCommandBase {
35
+ async diskStats() {
36
+ const output = await this.adb.subprocess.spawnAndWaitLegacy([
37
+ "dumpsys",
38
+ "diskstats",
39
+ ]);
40
+
41
+ function getSize(name: string) {
42
+ const match = output.match(
43
+ new RegExp(`${name}-Free: (\\d+)K / (\\d+)K`),
44
+ );
45
+ if (!match) {
46
+ return [0, 0];
47
+ }
48
+ return [
49
+ Number.parseInt(match[1]!, 10) * 1024,
50
+ Number.parseInt(match[2]!, 10) * 1024,
51
+ ];
52
+ }
53
+
54
+ const [dataFree, dataTotal] = getSize("Data");
55
+ const [cacheFree, cacheTotal] = getSize("Cache");
56
+ const [systemFree, systemTotal] = getSize("System");
57
+
58
+ return {
59
+ dataFree,
60
+ dataTotal,
61
+ cacheFree,
62
+ cacheTotal,
63
+ systemFree,
64
+ systemTotal,
65
+ };
66
+ }
67
+
68
+ async battery(): Promise<DumpSys.Battery.Info> {
69
+ const output = await this.adb.subprocess.spawnAndWaitLegacy([
70
+ "dumpsys",
71
+ "battery",
72
+ ]);
73
+
74
+ const info: DumpSys.Battery.Info = {
75
+ acPowered: false,
76
+ usbPowered: false,
77
+ wirelessPowered: false,
78
+ dockPowered: false,
79
+ status: DumpSys.Battery.Status.Unknown,
80
+ health: DumpSys.Battery.Health.Unknown,
81
+ };
82
+
83
+ for (const line of output.split("\n")) {
84
+ const parts = line.split(":").map((part) => part.trim());
85
+ if (parts.length !== 2) {
86
+ continue;
87
+ }
88
+
89
+ const field = BatteryDumpFields[parts[0]!];
90
+ if (!field) {
91
+ continue;
92
+ }
93
+
94
+ switch (field.type) {
95
+ case "boolean":
96
+ info[field.field] = (parts[1]!.trim() === "true") as never;
97
+ break;
98
+ case "number":
99
+ info[field.field] = Number.parseInt(
100
+ parts[1]!.trim(),
101
+ 10,
102
+ ) as never;
103
+ break;
104
+ case "string":
105
+ info[field.field] = parts[1]! as never;
106
+ break;
107
+ }
108
+ }
109
+
110
+ return info;
111
+ }
112
+ }
113
+
114
+ export namespace DumpSys {
115
+ export namespace Battery {
116
+ export interface Info {
117
+ acPowered: boolean;
118
+ usbPowered: boolean;
119
+ wirelessPowered: boolean;
120
+ dockPowered: boolean;
121
+ maxChargingCurrent?: number;
122
+ maxChargingVoltage?: number;
123
+ chargeCounter?: number;
124
+ status: Status;
125
+ health: Health;
126
+ present?: boolean;
127
+ level?: number;
128
+ scale?: number;
129
+ voltage?: number;
130
+ temperature?: number;
131
+ technology?: string;
132
+ current?: number;
133
+ }
134
+
135
+ export enum Status {
136
+ Unknown = 1,
137
+ Charging,
138
+ Discharging,
139
+ NotCharging,
140
+ Full,
141
+ }
142
+
143
+ export enum Health {
144
+ Unknown = 1,
145
+ Good,
146
+ Overheat,
147
+ Dead,
148
+ OverVoltage,
149
+ UnspecifiedFailure,
150
+ Cold,
151
+ }
152
+ }
153
+ }
package/src/index.ts ADDED
@@ -0,0 +1,14 @@
1
+ // cspell: ignore logcat
2
+
3
+ export * from "./am.js";
4
+ export * from "./bu.js";
5
+ export * from "./bug-report.js";
6
+ export * from "./cmd.js";
7
+ export * from "./demo-mode.js";
8
+ export * from "./dumpsys.js";
9
+ export * from "./intent.js";
10
+ export * from "./logcat.js";
11
+ export * from "./overlay-display.js";
12
+ export * from "./pm.js";
13
+ export * from "./settings.js";
14
+ export * from "./string-format.js";
package/src/intent.ts ADDED
@@ -0,0 +1,73 @@
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
+ #stringExtras = new Map<string, string>();
9
+
10
+ setAction(action: string): this {
11
+ this.#action = action;
12
+ return this;
13
+ }
14
+
15
+ addCategory(category: string): this {
16
+ this.#categories.push(category);
17
+ return this;
18
+ }
19
+
20
+ setPackage(packageName: string): this {
21
+ this.#packageName = packageName;
22
+ return this;
23
+ }
24
+
25
+ setComponent(component: string): this {
26
+ this.#component = component;
27
+ return this;
28
+ }
29
+
30
+ setData(data: string): this {
31
+ this.#data = data;
32
+ return this;
33
+ }
34
+
35
+ addStringExtra(key: string, value: string): this {
36
+ this.#stringExtras.set(key, value);
37
+ return this;
38
+ }
39
+
40
+ build(): string[] {
41
+ const result: string[] = [];
42
+
43
+ if (this.#action) {
44
+ result.push("-a", this.#action);
45
+ }
46
+
47
+ for (const category of this.#categories) {
48
+ result.push("-c", category);
49
+ }
50
+
51
+ if (this.#packageName) {
52
+ result.push("-p", this.#packageName);
53
+ }
54
+
55
+ if (this.#component) {
56
+ result.push("-n", this.#component);
57
+ }
58
+
59
+ if (this.#data) {
60
+ result.push("-d", this.#data);
61
+ }
62
+
63
+ if (this.#type) {
64
+ result.push("-t", this.#type);
65
+ }
66
+
67
+ for (const [key, value] of this.#stringExtras) {
68
+ result.push("--es", key, value);
69
+ }
70
+
71
+ return result;
72
+ }
73
+ }