@yume-chan/android-bin 2.1.0 → 3.0.0-beta.1

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 (96) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -1
  3. package/esm/am.d.ts +20 -15
  4. package/esm/am.d.ts.map +1 -1
  5. package/esm/am.js +60 -13
  6. package/esm/am.js.map +1 -1
  7. package/esm/bu.d.ts +22 -18
  8. package/esm/bu.d.ts.map +1 -1
  9. package/esm/bu.js +10 -4
  10. package/esm/bu.js.map +1 -1
  11. package/esm/bug-report.d.ts +21 -20
  12. package/esm/bug-report.d.ts.map +1 -1
  13. package/esm/bug-report.js +15 -21
  14. package/esm/bug-report.js.map +1 -1
  15. package/esm/cmd/index.d.ts +2 -0
  16. package/esm/cmd/index.d.ts.map +1 -0
  17. package/esm/cmd/index.js +2 -0
  18. package/esm/cmd/index.js.map +1 -0
  19. package/esm/cmd/none.d.ts +5 -0
  20. package/esm/cmd/none.d.ts.map +1 -0
  21. package/esm/cmd/none.js +39 -0
  22. package/esm/cmd/none.js.map +1 -0
  23. package/esm/cmd/service.d.ts +29 -0
  24. package/esm/cmd/service.d.ts.map +1 -0
  25. package/esm/cmd/service.js +24 -0
  26. package/esm/cmd/service.js.map +1 -0
  27. package/esm/cmd/shell.d.ts +5 -0
  28. package/esm/cmd/shell.d.ts.map +1 -0
  29. package/esm/cmd/shell.js +43 -0
  30. package/esm/cmd/shell.js.map +1 -0
  31. package/esm/cmd/utils.d.ts +5 -0
  32. package/esm/cmd/utils.d.ts.map +1 -0
  33. package/esm/cmd/utils.js +24 -0
  34. package/esm/cmd/utils.js.map +1 -0
  35. package/esm/demo-mode.d.ts +3 -4
  36. package/esm/demo-mode.d.ts.map +1 -1
  37. package/esm/demo-mode.js +13 -21
  38. package/esm/demo-mode.js.map +1 -1
  39. package/esm/dumpsys.d.ts +4 -2
  40. package/esm/dumpsys.d.ts.map +1 -1
  41. package/esm/dumpsys.js +13 -10
  42. package/esm/dumpsys.js.map +1 -1
  43. package/esm/index.d.ts +1 -1
  44. package/esm/index.d.ts.map +1 -1
  45. package/esm/index.js +1 -1
  46. package/esm/index.js.map +1 -1
  47. package/esm/intent.d.ts +37 -9
  48. package/esm/intent.d.ts.map +1 -1
  49. package/esm/intent.js +116 -53
  50. package/esm/intent.js.map +1 -1
  51. package/esm/logcat.d.ts +4 -2
  52. package/esm/logcat.d.ts.map +1 -1
  53. package/esm/logcat.js +9 -6
  54. package/esm/logcat.js.map +1 -1
  55. package/esm/overlay-display.d.ts +17 -14
  56. package/esm/overlay-display.d.ts.map +1 -1
  57. package/esm/overlay-display.js +2 -4
  58. package/esm/overlay-display.js.map +1 -1
  59. package/esm/pm.d.ts +131 -168
  60. package/esm/pm.d.ts.map +1 -1
  61. package/esm/pm.js +229 -112
  62. package/esm/pm.js.map +1 -1
  63. package/esm/settings.d.ts +1 -2
  64. package/esm/settings.d.ts.map +1 -1
  65. package/esm/settings.js +9 -9
  66. package/esm/settings.js.map +1 -1
  67. package/esm/utils.d.ts +4 -1
  68. package/esm/utils.d.ts.map +1 -1
  69. package/esm/utils.js +24 -13
  70. package/esm/utils.js.map +1 -1
  71. package/package.json +9 -9
  72. package/src/am.ts +94 -34
  73. package/src/bu.ts +31 -20
  74. package/src/bug-report.ts +42 -42
  75. package/src/cmd/index.ts +1 -0
  76. package/src/cmd/none.ts +62 -0
  77. package/src/cmd/service.ts +54 -0
  78. package/src/cmd/shell.ts +67 -0
  79. package/src/cmd/utils.ts +35 -0
  80. package/src/demo-mode.ts +13 -24
  81. package/src/dumpsys.ts +16 -10
  82. package/src/index.ts +1 -1
  83. package/src/intent.ts +187 -49
  84. package/src/logcat.ts +12 -6
  85. package/src/overlay-display.ts +21 -19
  86. package/src/pm.ts +374 -301
  87. package/src/settings.ts +11 -10
  88. package/src/utils.ts +30 -13
  89. package/tsconfig.build.json +0 -11
  90. package/CHANGELOG.md +0 -181
  91. package/esm/cmd.d.ts +0 -23
  92. package/esm/cmd.d.ts.map +0 -1
  93. package/esm/cmd.js +0 -104
  94. package/esm/cmd.js.map +0 -1
  95. package/src/cmd.ts +0 -166
  96. package/tsconfig.build.tsbuildinfo +0 -1
package/src/settings.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import type { Adb } from "@yume-chan/adb";
2
- import { AdbServiceBase } from "@yume-chan/adb";
3
2
 
4
- import { CmdNoneProtocolService } from "./cmd.js";
3
+ import { Cmd } from "./cmd/index.js";
5
4
  import type { SingleUser } from "./utils.js";
6
5
 
7
6
  export type SettingsNamespace = "system" | "secure" | "global";
@@ -25,15 +24,14 @@ export interface SettingsPutOptions extends SettingsOptions {
25
24
  }
26
25
 
27
26
  // frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/SettingsService.java
28
- export class Settings extends AdbServiceBase {
27
+ export class Settings {
29
28
  static ServiceName = "settings";
30
29
  static CommandName = "settings";
31
30
 
32
- #cmd: CmdNoneProtocolService;
31
+ readonly #cmd: Cmd.NoneProtocolService;
33
32
 
34
33
  constructor(adb: Adb) {
35
- super(adb);
36
- this.#cmd = new CmdNoneProtocolService(adb, Settings.CommandName);
34
+ this.#cmd = Cmd.createNoneProtocol(adb, Settings.CommandName);
37
35
  }
38
36
 
39
37
  base(
@@ -42,16 +40,19 @@ export class Settings extends AdbServiceBase {
42
40
  options: SettingsOptions | undefined,
43
41
  ...args: string[]
44
42
  ): Promise<string> {
45
- let command = [Settings.ServiceName];
43
+ const command = [Settings.ServiceName];
46
44
 
47
45
  if (options?.user !== undefined) {
48
46
  command.push("--user", options.user.toString());
49
47
  }
50
48
 
51
49
  command.push(verb, namespace);
52
- command = command.concat(args);
53
50
 
54
- return this.#cmd.spawnWaitText(command);
51
+ for (const arg of args) {
52
+ command.push(arg);
53
+ }
54
+
55
+ return this.#cmd.spawn(command).wait().toString();
55
56
  }
56
57
 
57
58
  async get(
@@ -61,7 +62,7 @@ export class Settings extends AdbServiceBase {
61
62
  ): Promise<string> {
62
63
  const output = await this.base("get", namespace, options, key);
63
64
  // Remove last \n
64
- return output.substring(0, output.length - 1);
65
+ return output.endsWith("\n") ? output.slice(0, -1) : output;
65
66
  }
66
67
 
67
68
  async delete(
package/src/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- export function buildArguments<T>(
1
+ export function buildCommand<T>(
2
2
  commands: readonly string[],
3
3
  options: Partial<T> | undefined,
4
4
  map: Partial<Record<keyof T, string>>,
@@ -6,19 +6,34 @@ export function buildArguments<T>(
6
6
  const args = commands.slice();
7
7
  if (options) {
8
8
  for (const [key, value] of Object.entries(options)) {
9
- if (value) {
10
- const option = map[key as keyof T];
11
- if (option) {
12
- args.push(option);
13
- switch (typeof value) {
14
- case "number":
15
- args.push(value.toString());
16
- break;
17
- case "string":
18
- args.push(value);
19
- break;
9
+ if (value === undefined || value === null) {
10
+ continue;
11
+ }
12
+
13
+ const option = map[key as keyof T];
14
+ // Empty string means positional argument,
15
+ // they must be added at the end,
16
+ // so let the caller handle it.
17
+ if (option === undefined || option === "") {
18
+ continue;
19
+ }
20
+
21
+ switch (typeof value) {
22
+ case "boolean":
23
+ if (value) {
24
+ args.push(option);
20
25
  }
21
- }
26
+ break;
27
+ case "number":
28
+ args.push(option, value.toString());
29
+ break;
30
+ case "string":
31
+ args.push(option, value);
32
+ break;
33
+ default:
34
+ throw new Error(
35
+ `Unsupported type for option ${key}: ${typeof value}`,
36
+ );
22
37
  }
23
38
  }
24
39
  }
@@ -27,3 +42,5 @@ export function buildArguments<T>(
27
42
 
28
43
  export type SingleUser = number | "current";
29
44
  export type SingleUserOrAll = SingleUser | "all";
45
+
46
+ export type Optional<T extends object> = { [K in keyof T]?: T[K] | undefined };
@@ -1,14 +1,3 @@
1
1
  {
2
2
  "extends": "./node_modules/@yume-chan/tsconfig/tsconfig.base.json",
3
- "references": [
4
- {
5
- "path": "../adb/tsconfig.build.json"
6
- },
7
- {
8
- "path": "../stream-extra/tsconfig.build.json"
9
- },
10
- {
11
- "path": "../struct/tsconfig.build.json"
12
- }
13
- ]
14
3
  }
package/CHANGELOG.md DELETED
@@ -1,181 +0,0 @@
1
- # Change Log - @yume-chan/android-bin
2
-
3
- ## 2.1.0
4
-
5
- ### Patch Changes
6
-
7
- - Updated dependencies [40a60ca]
8
- - Updated dependencies [a835eb8]
9
- - Updated dependencies [dbcfd34]
10
- - @yume-chan/stream-extra@2.1.0
11
- - @yume-chan/adb@2.1.0
12
-
13
- ## 2.0.1
14
-
15
- ### Patch Changes
16
-
17
- - Updated dependencies [0bcb9b8]
18
- - @yume-chan/struct@2.0.1
19
- - @yume-chan/adb@2.0.1
20
- - @yume-chan/stream-extra@2.0.1
21
-
22
- ## 2.0.0
23
-
24
- ### Major Changes
25
-
26
- - Redesign subprocess API
27
-
28
- ### Minor Changes
29
-
30
- - 0f29501: Add `PackageManager.prototype.getPackages` method to get apk paths
31
-
32
- ### Patch Changes
33
-
34
- - Updated dependencies
35
- - Updated dependencies [05c01ad]
36
- - Updated dependencies [b79df96]
37
- - @yume-chan/adb@2.0.0
38
- - @yume-chan/struct@2.0.0
39
- - @yume-chan/stream-extra@2.0.0
40
-
41
- ## 1.1.0
42
-
43
- ### Patch Changes
44
-
45
- - Updated dependencies [ab98953]
46
- - @yume-chan/adb@1.1.0
47
-
48
- ## 1.0.1
49
-
50
- ### Patch Changes
51
-
52
- - 53688d3: Use PNPM workspace and Changesets to manage the monorepo.
53
-
54
- Because Changesets doesn't support alpha versions (`0.x.x`), this version is `1.0.0`. Future versions will follow SemVer rules, for example, breaking API changes will introduce a new major version.
55
-
56
- - Updated dependencies [53688d3]
57
- - Updated dependencies [db8466f]
58
- - Updated dependencies [db8466f]
59
- - Updated dependencies [ea5002b]
60
- - Updated dependencies [db8466f]
61
- - @yume-chan/stream-extra@1.0.1
62
- - @yume-chan/struct@1.0.1
63
- - @yume-chan/adb@1.0.1
64
-
65
- This log was last generated on Tue, 18 Jun 2024 02:49:43 GMT and should not be manually modified.
66
-
67
- ## 0.0.24
68
-
69
- Tue, 18 Jun 2024 02:49:43 GMT
70
-
71
- ### Updates
72
-
73
- - Allow streams to accept both `Uint8Array` and `Consumable<Uint8Array>` as inputs
74
- - Add all supported fields to `DumpSys.Battery.Info`
75
-
76
- ## 0.0.23
77
-
78
- Thu, 21 Mar 2024 03:15:10 GMT
79
-
80
- ### Updates
81
-
82
- - Add support for pm install session
83
-
84
- ## 0.0.22
85
-
86
- Wed, 13 Dec 2023 05:57:27 GMT
87
-
88
- ### Updates
89
-
90
- - Add wrapper for `pm uninstall`
91
- - Change `PackageManager#listPackages` to return an async generator
92
- - Add wrapper for `am start`
93
- - Add wrapper for `pm resolve-activity`
94
- - Add `status` and `health` fields to `DumpSys#battery`
95
-
96
- ## 0.0.21
97
-
98
- Fri, 25 Aug 2023 14:05:18 GMT
99
-
100
- ### Updates
101
-
102
- - Add wrapper for `bu`
103
- - Remove the last `\n` from `Settings#get`
104
- - Add wrappers for `dumpsys diskstats` and `dumpsys battery`
105
- - Add wrapper for `pm list packages`
106
- - Rewrite `Settings` to use `Cmd` if available
107
- - Add support to stop `bugreport`
108
- - Merge `bugreport` and `bugreportz` wrappers, providing an `automatic` method to choose the best available bugreport method
109
-
110
- ## 0.0.20
111
-
112
- Mon, 05 Jun 2023 02:51:41 GMT
113
-
114
- _Version update only_
115
-
116
- ## 0.0.19
117
-
118
- Sun, 09 Apr 2023 05:55:33 GMT
119
-
120
- ### Updates
121
-
122
- - Add wrapper for `cmd`, with support for Android Binder Bridge (abb)
123
- - Add `OverlayDisplay` wrapper for managing overlay displays
124
-
125
- ## 0.0.18
126
-
127
- Wed, 25 Jan 2023 21:33:49 GMT
128
-
129
- _Version update only_
130
-
131
- ## 0.0.17
132
-
133
- Tue, 18 Oct 2022 09:32:30 GMT
134
-
135
- ### Updates
136
-
137
- - Update to use new stream util package
138
-
139
- ## 0.0.16
140
-
141
- Sat, 28 May 2022 03:56:37 GMT
142
-
143
- ### Updates
144
-
145
- - Upgrade TypeScript to 4.7.2 to enable Node.js ESM
146
- - Improve performance of `Logcat#binary()` by up to 150%
147
-
148
- ## 0.0.15
149
-
150
- Mon, 02 May 2022 04:18:01 GMT
151
-
152
- _Version update only_
153
-
154
- ## 0.0.14
155
-
156
- Sat, 30 Apr 2022 14:05:48 GMT
157
-
158
- _Version update only_
159
-
160
- ## 0.0.13
161
-
162
- Thu, 28 Apr 2022 01:23:53 GMT
163
-
164
- ### Updates
165
-
166
- - Add support for bugreport/bugreportz
167
- - Add basic support for logcat
168
-
169
- ## 0.0.12
170
-
171
- Sun, 03 Apr 2022 11:18:47 GMT
172
-
173
- _Version update only_
174
-
175
- ## 0.0.11
176
-
177
- Sun, 03 Apr 2022 10:54:15 GMT
178
-
179
- ### Updates
180
-
181
- - Improve compatibility with Node.js 12 ESM format
package/esm/cmd.d.ts DELETED
@@ -1,23 +0,0 @@
1
- import type { Adb } from "@yume-chan/adb";
2
- import { AdbNoneProtocolSpawner, AdbServiceBase, AdbShellProtocolSpawner } from "@yume-chan/adb";
3
- export declare class CmdNoneProtocolService extends AdbNoneProtocolSpawner {
4
- #private;
5
- get supportsAbbExec(): boolean;
6
- get supportsCmd(): boolean;
7
- get isSupported(): boolean;
8
- constructor(adb: Adb, fallback?: string | Record<string, string> | ((service: string) => string));
9
- }
10
- export declare class CmdShellProtocolService extends AdbShellProtocolSpawner {
11
- #private;
12
- get supportsCmd(): boolean;
13
- get supportsAbb(): boolean;
14
- get isSupported(): boolean;
15
- constructor(adb: Adb, fallback?: string | Record<string, string> | ((service: string) => string));
16
- }
17
- export declare class Cmd extends AdbServiceBase {
18
- #private;
19
- get noneProtocol(): CmdNoneProtocolService | undefined;
20
- get shellProtocol(): CmdShellProtocolService | undefined;
21
- constructor(adb: Adb, fallback?: string | Record<string, string> | ((service: string) => string));
22
- }
23
- //# sourceMappingURL=cmd.d.ts.map
package/esm/cmd.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cmd.d.ts","sourceRoot":"","sources":["../src/cmd.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAA2B,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAGH,sBAAsB,EACtB,cAAc,EAEd,uBAAuB,EAC1B,MAAM,gBAAgB,CAAC;AAExB,qBAAa,sBAAuB,SAAQ,sBAAsB;;IAE9D,IAAI,eAAe,IAAI,OAAO,CAE7B;IAGD,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED,IAAI,WAAW,YAEd;gBAGG,GAAG,EAAE,GAAG,EACR,QAAQ,CAAC,EACH,MAAM,GACN,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACtB,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;CAiC1C;AAED,qBAAa,uBAAwB,SAAQ,uBAAuB;;IAIhE,IAAI,WAAW,IAAI,OAAO,CAEzB;IAGD,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED,IAAI,WAAW,YAKd;gBAGG,GAAG,EAAE,GAAG,EACR,QAAQ,CAAC,EACH,MAAM,GACN,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACtB,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;CAsC1C;AAED,qBAAa,GAAI,SAAQ,cAAc;;IAEnC,IAAI,YAAY,uCAEf;IAGD,IAAI,aAAa,wCAEhB;gBAGG,GAAG,EAAE,GAAG,EACR,QAAQ,CAAC,EACH,MAAM,GACN,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACtB,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;CAmB1C"}
package/esm/cmd.js DELETED
@@ -1,104 +0,0 @@
1
- import { AdbFeature, AdbNoneProtocolProcessImpl, AdbNoneProtocolSpawner, AdbServiceBase, AdbShellProtocolProcessImpl, AdbShellProtocolSpawner, } from "@yume-chan/adb";
2
- export class CmdNoneProtocolService extends AdbNoneProtocolSpawner {
3
- #supportsAbbExec;
4
- get supportsAbbExec() {
5
- return this.#supportsAbbExec;
6
- }
7
- #supportsCmd;
8
- get supportsCmd() {
9
- return this.#supportsCmd;
10
- }
11
- get isSupported() {
12
- return this.#supportsAbbExec || this.#supportsCmd;
13
- }
14
- constructor(adb, fallback) {
15
- super(async (command) => {
16
- if (this.#supportsAbbExec) {
17
- return new AdbNoneProtocolProcessImpl(await adb.createSocket(`abb_exec:${command.join("\0")}\0`));
18
- }
19
- if (this.#supportsCmd) {
20
- return adb.subprocess.noneProtocol.spawn(`cmd ${command.join(" ")}`);
21
- }
22
- if (typeof fallback === "function") {
23
- fallback = fallback(command[0]);
24
- }
25
- else if (typeof fallback === "object") {
26
- fallback = fallback[command[0]];
27
- }
28
- if (!fallback) {
29
- throw new Error("Unsupported");
30
- }
31
- const fallbackCommand = command.slice();
32
- fallbackCommand[0] = fallback;
33
- return adb.subprocess.noneProtocol.spawn(fallbackCommand);
34
- });
35
- this.#supportsCmd = adb.canUseFeature(AdbFeature.Cmd);
36
- this.#supportsAbbExec = adb.canUseFeature(AdbFeature.AbbExec);
37
- }
38
- }
39
- export class CmdShellProtocolService extends AdbShellProtocolSpawner {
40
- #adb;
41
- #supportsCmd;
42
- get supportsCmd() {
43
- return this.#supportsCmd;
44
- }
45
- #supportsAbb;
46
- get supportsAbb() {
47
- return this.#supportsAbb;
48
- }
49
- get isSupported() {
50
- return (this.#supportsAbb ||
51
- (this.#supportsCmd && !!this.#adb.subprocess.shellProtocol));
52
- }
53
- constructor(adb, fallback) {
54
- super(async (command) => {
55
- if (this.#supportsAbb) {
56
- return new AdbShellProtocolProcessImpl(await this.#adb.createSocket(`abb:${command.join("\0")}\0`));
57
- }
58
- if (!adb.subprocess.shellProtocol) {
59
- throw new Error("Unsupported");
60
- }
61
- if (this.#supportsCmd) {
62
- return adb.subprocess.shellProtocol.spawn(`cmd ${command.join(" ")}`);
63
- }
64
- if (typeof fallback === "function") {
65
- fallback = fallback(command[0]);
66
- }
67
- else if (typeof fallback === "object") {
68
- fallback = fallback[command[0]];
69
- }
70
- if (!fallback) {
71
- throw new Error("Unsupported");
72
- }
73
- const fallbackCommand = command.slice();
74
- fallbackCommand[0] = fallback;
75
- return adb.subprocess.shellProtocol.spawn(fallbackCommand);
76
- });
77
- this.#adb = adb;
78
- this.#supportsCmd = adb.canUseFeature(AdbFeature.Cmd);
79
- this.#supportsAbb = adb.canUseFeature(AdbFeature.Abb);
80
- }
81
- }
82
- export class Cmd extends AdbServiceBase {
83
- #noneProtocol;
84
- get noneProtocol() {
85
- return this.#noneProtocol;
86
- }
87
- #shellProtocol;
88
- get shellProtocol() {
89
- return this.#shellProtocol;
90
- }
91
- constructor(adb, fallback) {
92
- super(adb);
93
- if (adb.canUseFeature(AdbFeature.AbbExec) ||
94
- adb.canUseFeature(AdbFeature.Cmd)) {
95
- this.#noneProtocol = new CmdNoneProtocolService(adb, fallback);
96
- }
97
- if (adb.canUseFeature(AdbFeature.Abb) ||
98
- (adb.canUseFeature(AdbFeature.Cmd) &&
99
- adb.canUseFeature(AdbFeature.ShellV2))) {
100
- this.#shellProtocol = new CmdShellProtocolService(adb, fallback);
101
- }
102
- }
103
- }
104
- //# sourceMappingURL=cmd.js.map
package/esm/cmd.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cmd.js","sourceRoot":"","sources":["../src/cmd.ts"],"names":[],"mappings":"AACA,OAAO,EACH,UAAU,EACV,0BAA0B,EAC1B,sBAAsB,EACtB,cAAc,EACd,2BAA2B,EAC3B,uBAAuB,GAC1B,MAAM,gBAAgB,CAAC;AAExB,MAAM,OAAO,sBAAuB,SAAQ,sBAAsB;IAC9D,gBAAgB,CAAU;IAC1B,IAAI,eAAe;QACf,OAAO,IAAI,CAAC,gBAAgB,CAAC;IACjC,CAAC;IAED,YAAY,CAAU;IACtB,IAAI,WAAW;QACX,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED,IAAI,WAAW;QACX,OAAO,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAC,YAAY,CAAC;IACtD,CAAC;IAED,YACI,GAAQ,E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CAAC,CAAC;QACrE,CAAC;IACL,CAAC;CACJ"}
package/src/cmd.ts DELETED
@@ -1,166 +0,0 @@
1
- import type { Adb, AdbShellProtocolProcess } from "@yume-chan/adb";
2
- import {
3
- AdbFeature,
4
- AdbNoneProtocolProcessImpl,
5
- AdbNoneProtocolSpawner,
6
- AdbServiceBase,
7
- AdbShellProtocolProcessImpl,
8
- AdbShellProtocolSpawner,
9
- } from "@yume-chan/adb";
10
-
11
- export class CmdNoneProtocolService extends AdbNoneProtocolSpawner {
12
- #supportsAbbExec: boolean;
13
- get supportsAbbExec(): boolean {
14
- return this.#supportsAbbExec;
15
- }
16
-
17
- #supportsCmd: boolean;
18
- get supportsCmd(): boolean {
19
- return this.#supportsCmd;
20
- }
21
-
22
- get isSupported() {
23
- return this.#supportsAbbExec || this.#supportsCmd;
24
- }
25
-
26
- constructor(
27
- adb: Adb,
28
- fallback?:
29
- | string
30
- | Record<string, string>
31
- | ((service: string) => string),
32
- ) {
33
- super(async (command) => {
34
- if (this.#supportsAbbExec) {
35
- return new AdbNoneProtocolProcessImpl(
36
- await adb.createSocket(`abb_exec:${command.join("\0")}\0`),
37
- );
38
- }
39
-
40
- if (this.#supportsCmd) {
41
- return adb.subprocess.noneProtocol.spawn(
42
- `cmd ${command.join(" ")}`,
43
- );
44
- }
45
-
46
- if (typeof fallback === "function") {
47
- fallback = fallback(command[0]!);
48
- } else if (typeof fallback === "object") {
49
- fallback = fallback[command[0]!];
50
- }
51
-
52
- if (!fallback) {
53
- throw new Error("Unsupported");
54
- }
55
-
56
- const fallbackCommand = command.slice();
57
- fallbackCommand[0] = fallback;
58
- return adb.subprocess.noneProtocol.spawn(fallbackCommand);
59
- });
60
-
61
- this.#supportsCmd = adb.canUseFeature(AdbFeature.Cmd);
62
- this.#supportsAbbExec = adb.canUseFeature(AdbFeature.AbbExec);
63
- }
64
- }
65
-
66
- export class CmdShellProtocolService extends AdbShellProtocolSpawner {
67
- #adb: Adb;
68
-
69
- #supportsCmd: boolean;
70
- get supportsCmd(): boolean {
71
- return this.#supportsCmd;
72
- }
73
-
74
- #supportsAbb: boolean;
75
- get supportsAbb(): boolean {
76
- return this.#supportsAbb;
77
- }
78
-
79
- get isSupported() {
80
- return (
81
- this.#supportsAbb ||
82
- (this.#supportsCmd && !!this.#adb.subprocess.shellProtocol)
83
- );
84
- }
85
-
86
- constructor(
87
- adb: Adb,
88
- fallback?:
89
- | string
90
- | Record<string, string>
91
- | ((service: string) => string),
92
- ) {
93
- super(async (command): Promise<AdbShellProtocolProcess> => {
94
- if (this.#supportsAbb) {
95
- return new AdbShellProtocolProcessImpl(
96
- await this.#adb.createSocket(`abb:${command.join("\0")}\0`),
97
- );
98
- }
99
-
100
- if (!adb.subprocess.shellProtocol) {
101
- throw new Error("Unsupported");
102
- }
103
-
104
- if (this.#supportsCmd) {
105
- return adb.subprocess.shellProtocol.spawn(
106
- `cmd ${command.join(" ")}`,
107
- );
108
- }
109
-
110
- if (typeof fallback === "function") {
111
- fallback = fallback(command[0]!);
112
- } else if (typeof fallback === "object") {
113
- fallback = fallback[command[0]!];
114
- }
115
-
116
- if (!fallback) {
117
- throw new Error("Unsupported");
118
- }
119
-
120
- const fallbackCommand = command.slice();
121
- fallbackCommand[0] = fallback;
122
- return adb.subprocess.shellProtocol.spawn(fallbackCommand);
123
- });
124
-
125
- this.#adb = adb;
126
- this.#supportsCmd = adb.canUseFeature(AdbFeature.Cmd);
127
- this.#supportsAbb = adb.canUseFeature(AdbFeature.Abb);
128
- }
129
- }
130
-
131
- export class Cmd extends AdbServiceBase {
132
- #noneProtocol: CmdNoneProtocolService | undefined;
133
- get noneProtocol() {
134
- return this.#noneProtocol;
135
- }
136
-
137
- #shellProtocol: CmdShellProtocolService | undefined;
138
- get shellProtocol() {
139
- return this.#shellProtocol;
140
- }
141
-
142
- constructor(
143
- adb: Adb,
144
- fallback?:
145
- | string
146
- | Record<string, string>
147
- | ((service: string) => string),
148
- ) {
149
- super(adb);
150
-
151
- if (
152
- adb.canUseFeature(AdbFeature.AbbExec) ||
153
- adb.canUseFeature(AdbFeature.Cmd)
154
- ) {
155
- this.#noneProtocol = new CmdNoneProtocolService(adb, fallback);
156
- }
157
-
158
- if (
159
- adb.canUseFeature(AdbFeature.Abb) ||
160
- (adb.canUseFeature(AdbFeature.Cmd) &&
161
- adb.canUseFeature(AdbFeature.ShellV2))
162
- ) {
163
- this.#shellProtocol = new CmdShellProtocolService(adb, fallback);
164
- }
165
- }
166
- }