@yume-chan/android-bin 0.0.12 → 0.0.15

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.
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "files": {
3
- "libraries/android-bin/.rush/temp/shrinkwrap-deps.json": "c2eea9e95f7a91089a0529b750286ccd75726818",
3
+ "libraries/android-bin/.rush/temp/shrinkwrap-deps.json": "33b90fa9ac2c165d2c550be4daa30217e725766d",
4
+ "libraries/android-bin/CHANGELOG.json": "9b60c01d989ef7adc1d88dd37e1a775ad5c7fb9a",
5
+ "libraries/android-bin/CHANGELOG.md": "4acf062834c059898923e0b42d694e4412cbe985",
4
6
  "libraries/android-bin/README.md": "96d1e739d73df6dc17920182c1c5799b65652b69",
5
- "libraries/android-bin/package.json": "d520445357198824728876bfd7175f94e923a1a4",
6
- "libraries/android-bin/src/bug-report.ts": "f2cd3131b59f12a06b943e492274a258123ff6e1",
7
+ "libraries/android-bin/package.json": "4810207a9afe430efae52769919481fdabdcf8f6",
8
+ "libraries/android-bin/src/bu.ts": "cd4d6867127ea824c524989626268b26dde3c7de",
9
+ "libraries/android-bin/src/bug-report.ts": "b4d7c78eaa2abb610a88f240872d209d083b70c9",
7
10
  "libraries/android-bin/src/demo-mode.ts": "1ee4a2d1bc238a1600387fc39549241a2a6bb161",
8
- "libraries/android-bin/src/index.ts": "c9c23c664f823e0dc557405cd538ea8ace80cd3e",
11
+ "libraries/android-bin/src/index.ts": "829476e842a0c136d900c623e14a6f341dba5651",
12
+ "libraries/android-bin/src/logcat.ts": "dc0cb6c8cc75891df866c0ef9a941ca1f4f690ba",
9
13
  "libraries/android-bin/src/settings.ts": "a323081296746d78ea07f473680321331ff0d46c",
10
14
  "libraries/android-bin/tsconfig.json": "39805c3201f468dc5a1a584b592970777c655bca"
11
15
  },
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "files": {
3
- "libraries/android-bin/.rush/temp/shrinkwrap-deps.json": "c2eea9e95f7a91089a0529b750286ccd75726818",
3
+ "libraries/android-bin/.rush/temp/shrinkwrap-deps.json": "86fa479db15bdf15272048209ee971fd39dce07f",
4
+ "libraries/android-bin/CHANGELOG.json": "eb6e965fef89ddcbec37a446dc6bfea34ea9a900",
5
+ "libraries/android-bin/CHANGELOG.md": "d285b842dd4a323acabc825cb24265646269f0ea",
4
6
  "libraries/android-bin/README.md": "96d1e739d73df6dc17920182c1c5799b65652b69",
5
- "libraries/android-bin/package.json": "d520445357198824728876bfd7175f94e923a1a4",
6
- "libraries/android-bin/src/bug-report.ts": "f2cd3131b59f12a06b943e492274a258123ff6e1",
7
+ "libraries/android-bin/package.json": "b0e38dd07f64f0bbe3f74d7f3df27a85a4292250",
8
+ "libraries/android-bin/src/bu.ts": "cd4d6867127ea824c524989626268b26dde3c7de",
9
+ "libraries/android-bin/src/bug-report.ts": "b4d7c78eaa2abb610a88f240872d209d083b70c9",
7
10
  "libraries/android-bin/src/demo-mode.ts": "1ee4a2d1bc238a1600387fc39549241a2a6bb161",
8
- "libraries/android-bin/src/index.ts": "c9c23c664f823e0dc557405cd538ea8ace80cd3e",
11
+ "libraries/android-bin/src/index.ts": "829476e842a0c136d900c623e14a6f341dba5651",
12
+ "libraries/android-bin/src/logcat.ts": "dc0cb6c8cc75891df866c0ef9a941ca1f4f690ba",
9
13
  "libraries/android-bin/src/settings.ts": "a323081296746d78ea07f473680321331ff0d46c",
10
14
  "libraries/android-bin/tsconfig.json": "39805c3201f468dc5a1a584b592970777c655bca"
11
15
  },
@@ -1,4 +1,4 @@
1
1
  {
2
- "tslib@2.3.1": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==",
3
- "typescript@4.7.0-dev.20220403": "sha512-1kTFg2+08XMrBmgDDQVNxSmDWcVstTcNT+rt9JC9Z511ewqUYe45IpWSVdS/xSSTei3N5grakAVbSAhZO0HloA=="
2
+ "tslib@2.4.0": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==",
3
+ "typescript@4.7.0-beta": "sha512-m+CNL8lzHyHDxYYDTI+pm5hw5/bufYVGan2bokPyJY/y9C/4W/PCWMtYZ0vV9fLXbEL57elMeoaz9Evxs8UQ+A=="
4
4
  }
package/CHANGELOG.json CHANGED
@@ -1,6 +1,33 @@
1
1
  {
2
2
  "name": "@yume-chan/android-bin",
3
3
  "entries": [
4
+ {
5
+ "version": "0.0.15",
6
+ "tag": "@yume-chan/android-bin_v0.0.15",
7
+ "date": "Mon, 02 May 2022 04:18:01 GMT",
8
+ "comments": {}
9
+ },
10
+ {
11
+ "version": "0.0.14",
12
+ "tag": "@yume-chan/android-bin_v0.0.14",
13
+ "date": "Sat, 30 Apr 2022 14:05:48 GMT",
14
+ "comments": {}
15
+ },
16
+ {
17
+ "version": "0.0.13",
18
+ "tag": "@yume-chan/android-bin_v0.0.13",
19
+ "date": "Thu, 28 Apr 2022 01:23:53 GMT",
20
+ "comments": {
21
+ "none": [
22
+ {
23
+ "comment": "Add support for bugreport/bugreportz"
24
+ },
25
+ {
26
+ "comment": "Add basic support for logcat"
27
+ }
28
+ ]
29
+ }
30
+ },
4
31
  {
5
32
  "version": "0.0.12",
6
33
  "tag": "@yume-chan/android-bin_v0.0.12",
package/CHANGELOG.md CHANGED
@@ -1,6 +1,24 @@
1
1
  # Change Log - @yume-chan/android-bin
2
2
 
3
- This log was last generated on Sun, 03 Apr 2022 11:18:47 GMT and should not be manually modified.
3
+ This log was last generated on Mon, 02 May 2022 04:18:01 GMT and should not be manually modified.
4
+
5
+ ## 0.0.15
6
+ Mon, 02 May 2022 04:18:01 GMT
7
+
8
+ _Version update only_
9
+
10
+ ## 0.0.14
11
+ Sat, 30 Apr 2022 14:05:48 GMT
12
+
13
+ _Version update only_
14
+
15
+ ## 0.0.13
16
+ Thu, 28 Apr 2022 01:23:53 GMT
17
+
18
+ ### Updates
19
+
20
+ - Add support for bugreport/bugreportz
21
+ - Add basic support for logcat
4
22
 
5
23
  ## 0.0.12
6
24
  Sun, 03 Apr 2022 11:18:47 GMT
@@ -1,2 +1,2 @@
1
- Invoking: build-ts-package
1
+ Invoking: build-ts-package --incremental
2
2
 
package/esm/bu.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { AdbCommandBase } from "@yume-chan/adb";
2
+ export interface AdbBackupOptions {
3
+ apps: string[] | 'all' | 'all-including-system';
4
+ apks: boolean;
5
+ obbs: boolean;
6
+ shared: boolean;
7
+ widgets: boolean;
8
+ compress: boolean;
9
+ user: number;
10
+ }
11
+ export declare class AdbBackup extends AdbCommandBase {
12
+ backup(options: AdbBackupOptions): Promise<void>;
13
+ restore(options: AdbBackupOptions): Promise<void>;
14
+ }
15
+ //# sourceMappingURL=bu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bu.d.ts","sourceRoot":"","sources":["../src/bu.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,GAAG,sBAAsB,CAAC;IAChD,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,SAAU,SAAQ,cAAc;IACnC,MAAM,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAGhD,OAAO,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;CAE1D"}
package/esm/bu.js ADDED
@@ -0,0 +1,10 @@
1
+ // cspell: ignore apks
2
+ // cspell: ignore obbs
3
+ import { AdbCommandBase } from "@yume-chan/adb";
4
+ export class AdbBackup extends AdbCommandBase {
5
+ async backup(options) {
6
+ }
7
+ async restore(options) {
8
+ }
9
+ }
10
+ //# sourceMappingURL=bu.js.map
package/esm/bu.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bu.js","sourceRoot":"","sources":["../src/bu.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,sBAAsB;AAEtB,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAYhD,MAAM,OAAO,SAAU,SAAQ,cAAc;IACzC,KAAK,CAAC,MAAM,CAAC,OAAyB;IACtC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAyB;IACvC,CAAC;CACJ"}
@@ -1,7 +1,9 @@
1
1
  import { AdbCommandBase, ReadableStream } from "@yume-chan/adb";
2
- export interface BugReportVersion {
2
+ export interface BugReportZVersion {
3
3
  major: number;
4
4
  minor: number;
5
+ supportProgress: boolean;
6
+ supportStream: boolean;
5
7
  }
6
8
  export declare class BugReportZ extends AdbCommandBase {
7
9
  static VERSION_REGEX: RegExp;
@@ -14,21 +16,22 @@ export declare class BugReportZ extends AdbCommandBase {
14
16
  *
15
17
  * @returns a `BugReportVersion` object, or `undefined` if `bugreportz` is not available.
16
18
  */
17
- version(): Promise<BugReportVersion | undefined>;
18
- supportStream(version: BugReportVersion): boolean;
19
- stream(): ReadableStream<Uint8Array>;
20
- supportProgress(version: BugReportVersion): boolean;
19
+ version(): Promise<BugReportZVersion | undefined>;
20
+ supportProgress(major: number, minor: number): boolean;
21
21
  /**
22
22
  * Create a zipped bugreport file.
23
23
  *
24
- * Compare to `stream`, this method will write the output on device. You can pull it using sync protocol.
24
+ * Compare to `stream`, this method will write the output to a file on device.
25
+ * You can pull it later using sync protocol.
25
26
  *
26
- * @param onProgress Progress callback. Only specify this if `supportsProgress()` returns `true`.
27
+ * @param onProgress Progress callback. Only specify this if `supportsProgress` is `true`.
27
28
  * @returns The path of the bugreport file.
28
29
  */
29
30
  generate(onProgress?: (progress: string, total: string) => void): Promise<string>;
31
+ supportStream(major: number, minor: number): boolean;
32
+ stream(): ReadableStream<Uint8Array>;
30
33
  }
31
34
  export declare class BugReport extends AdbCommandBase {
32
- generate(): ReadableStream<string>;
35
+ generate(): ReadableStream<Uint8Array>;
33
36
  }
34
37
  //# sourceMappingURL=bug-report.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bug-report.d.ts","sourceRoot":"","sources":["../src/bug-report.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAgD,cAAc,EAAuD,MAAM,gBAAgB,CAAC;AAEnK,MAAM,WAAW,gBAAgB;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,UAAW,SAAQ,cAAc;IAC1C,OAAc,aAAa,SAAkB;IAE7C,OAAc,WAAW,SAAgB;IAEzC,OAAc,cAAc,SAAyB;IAErD,OAAc,QAAQ,SAAa;IAEnC,OAAc,UAAU,SAAe;IAEvC;;;;OAIG;IACU,OAAO,IAAI,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAsBtD,aAAa,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO;IAIjD,MAAM,IAAI,cAAc,CAAC,UAAU,CAAC;IAYpC,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO;IAI1D;;;;;;;OAOG;IACU,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;CAmDjG;AAED,qBAAa,SAAU,SAAQ,cAAc;IAClC,QAAQ,IAAI,cAAc,CAAC,MAAM,CAAC;CAY5C"}
1
+ {"version":3,"file":"bug-report.d.ts","sourceRoot":"","sources":["../src/bug-report.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAoE,cAAc,EAAuD,MAAM,gBAAgB,CAAC;AAEvL,MAAM,WAAW,iBAAiB;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IAEd,eAAe,EAAE,OAAO,CAAC;IACzB,aAAa,EAAE,OAAO,CAAC;CAC1B;AAED,qBAAa,UAAW,SAAQ,cAAc;IAC1C,OAAc,aAAa,SAAkB;IAE7C,OAAc,WAAW,SAAgB;IAEzC,OAAc,cAAc,SAAyB;IAErD,OAAc,QAAQ,SAAa;IAEnC,OAAc,UAAU,SAAe;IAEvC;;;;OAIG;IACU,OAAO,IAAI,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC;IA2BvD,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAI7D;;;;;;;;OAQG;IACU,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;IAmDvF,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAIpD,MAAM,IAAI,cAAc,CAAC,UAAU,CAAC;CAoB9C;AAGD,qBAAa,SAAU,SAAQ,cAAc;IAClC,QAAQ,IAAI,cAAc,CAAC,UAAU,CAAC;CAMhD"}
package/esm/bug-report.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // cspell: ignore bugreport
2
2
  // cspell: ignore bugreportz
3
- import { AdbCommandBase, AdbShellSubprocessProtocol, DecodeUtf8Stream, SplitLineStream, WrapReadableStream, WritableStream } from "@yume-chan/adb";
3
+ import { AdbCommandBase, AdbSubprocessShellProtocol, DecodeUtf8Stream, PushReadableStream, SplitLineStream, WrapReadableStream, WritableStream } from "@yume-chan/adb";
4
4
  export class BugReportZ extends AdbCommandBase {
5
5
  static VERSION_REGEX = /(\d+)\.(\d+)/;
6
6
  static BEGIN_REGEX = /BEGIN:(.*)/;
@@ -14,7 +14,7 @@ export class BugReportZ extends AdbCommandBase {
14
14
  */
15
15
  async version() {
16
16
  // bugreportz requires shell protocol
17
- if (!AdbShellSubprocessProtocol.isSupported(this.adb)) {
17
+ if (!AdbSubprocessShellProtocol.isSupported(this.adb)) {
18
18
  return undefined;
19
19
  }
20
20
  const { stderr, exitCode } = await this.adb.subprocess.spawnAndWait(['bugreportz', '-v']);
@@ -25,34 +25,25 @@ export class BugReportZ extends AdbCommandBase {
25
25
  if (!match) {
26
26
  return undefined;
27
27
  }
28
+ const major = parseInt(match[1], 10);
29
+ const minor = parseInt(match[2], 10);
28
30
  return {
29
- major: parseInt(match[1], 10),
30
- minor: parseInt(match[2], 10),
31
+ major,
32
+ minor,
33
+ supportProgress: this.supportProgress(major, minor),
34
+ supportStream: this.supportStream(major, minor),
31
35
  };
32
36
  }
33
- supportStream(version) {
34
- return version.major > 1 || version.minor >= 2;
35
- }
36
- stream() {
37
- return new WrapReadableStream({
38
- start: async () => {
39
- const process = await this.adb.subprocess.spawn(['bugreportz', '-s']);
40
- return {
41
- readable: process.stdout,
42
- state: undefined,
43
- };
44
- },
45
- });
46
- }
47
- supportProgress(version) {
48
- return version.major > 1 || version.minor >= 1;
37
+ supportProgress(major, minor) {
38
+ return major > 1 || minor >= 1;
49
39
  }
50
40
  /**
51
41
  * Create a zipped bugreport file.
52
42
  *
53
- * Compare to `stream`, this method will write the output on device. You can pull it using sync protocol.
43
+ * Compare to `stream`, this method will write the output to a file on device.
44
+ * You can pull it later using sync protocol.
54
45
  *
55
- * @param onProgress Progress callback. Only specify this if `supportsProgress()` returns `true`.
46
+ * @param onProgress Progress callback. Only specify this if `supportsProgress` is `true`.
56
47
  * @returns The path of the bugreport file.
57
48
  */
58
49
  async generate(onProgress) {
@@ -67,7 +58,7 @@ export class BugReportZ extends AdbCommandBase {
67
58
  .pipeThrough(new SplitLineStream())
68
59
  .pipeTo(new WritableStream({
69
60
  write(line) {
70
- // (Not 100% sure) `BEGIN:` and `PROGRESS:` only appear when `-p` is specified.
61
+ // `BEGIN:` and `PROGRESS:` only appear when `-p` is specified.
71
62
  let match = line.match(BugReportZ.PROGRESS_REGEX);
72
63
  if (match) {
73
64
  onProgress?.(match[1], match[2]);
@@ -97,18 +88,36 @@ export class BugReportZ extends AdbCommandBase {
97
88
  // Design choice: we don't automatically pull the file to avoid more dependency on `@yume-chan/adb`
98
89
  return filename;
99
90
  }
91
+ supportStream(major, minor) {
92
+ return major > 1 || minor >= 2;
93
+ }
94
+ stream() {
95
+ return new PushReadableStream(async (controller) => {
96
+ const process = await this.adb.subprocess.spawn(['bugreportz', '-s']);
97
+ process.stdout
98
+ .pipeTo(new WritableStream({
99
+ async write(chunk) {
100
+ await controller.enqueue(chunk);
101
+ },
102
+ }));
103
+ process.stderr
104
+ .pipeThrough(new DecodeUtf8Stream())
105
+ .pipeTo(new WritableStream({
106
+ async write(chunk) {
107
+ controller.error(new Error(chunk));
108
+ }
109
+ }));
110
+ await process.exit;
111
+ controller.close();
112
+ });
113
+ }
100
114
  }
115
+ // https://cs.android.com/android/platform/superproject/+/master:frameworks/native/cmds/bugreport/bugreport.cpp;drc=9b73bf07d73dbab5b792632e1e233edbad77f5fd;bpv=0;bpt=0
101
116
  export class BugReport extends AdbCommandBase {
102
117
  generate() {
103
- return new WrapReadableStream({
104
- start: async () => {
105
- const process = await this.adb.subprocess.spawn(['bugreport']);
106
- return {
107
- readable: process.stdout
108
- .pipeThrough(new DecodeUtf8Stream()),
109
- state: undefined,
110
- };
111
- }
118
+ return new WrapReadableStream(async () => {
119
+ const process = await this.adb.subprocess.spawn(['bugreport']);
120
+ return process.stdout;
112
121
  });
113
122
  }
114
123
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bug-report.js","sourceRoot":"","sources":["../src/bug-report.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,4BAA4B;AAE5B,OAAO,EAAE,cAAc,EAAE,0BAA0B,EAAE,gBAAgB,EAAkB,eAAe,EAAE,kBAAkB,EAAE,cAAc,EAAE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AC,KAAK,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC;YAC/D,OAAO,OAAO,CAAC,MAAM,CAAC;QAC1B,CAAC,CAAC,CAAC;IACP,CAAC;CACJ"}
package/esm/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './bug-report.js';
2
2
  export * from './demo-mode.js';
3
+ export * from './logcat.js';
3
4
  export * from './settings.js';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
package/esm/index.js CHANGED
@@ -1,4 +1,6 @@
1
+ // cspell: ignore logcat
1
2
  export * from './bug-report.js';
2
3
  export * from './demo-mode.js';
4
+ export * from './logcat.js';
3
5
  export * from './settings.js';
4
6
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wBAAwB;AAExB,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,65 @@
1
+ import { AdbCommandBase, ReadableStream } from "@yume-chan/adb";
2
+ import Struct, { StructAsyncDeserializeStream } from "@yume-chan/struct";
3
+ export declare enum LogId {
4
+ All = -1,
5
+ Main = 0,
6
+ Radio = 1,
7
+ Events = 2,
8
+ System = 3,
9
+ Crash = 4,
10
+ Stats = 5,
11
+ Security = 6,
12
+ Kernel = 7
13
+ }
14
+ export declare enum LogPriority {
15
+ Unknown = 0,
16
+ Default = 1,
17
+ Verbose = 2,
18
+ Info = 3,
19
+ Warn = 4,
20
+ Error = 5,
21
+ Fatal = 6,
22
+ Silent = 7
23
+ }
24
+ export interface LogcatOptions {
25
+ pid?: number;
26
+ ids?: LogId[];
27
+ }
28
+ export declare const LoggerEntry: Struct<{
29
+ payloadSize: number;
30
+ headerSize: number;
31
+ pid: number;
32
+ tid: number;
33
+ second: number;
34
+ nanoseconds: number;
35
+ logId: number;
36
+ uid: number;
37
+ }, never, {
38
+ readonly timestamp: bigint;
39
+ }, undefined>;
40
+ export declare type LoggerEntry = typeof LoggerEntry['TDeserializeResult'];
41
+ export interface LogMessage extends LoggerEntry {
42
+ priority: LogPriority;
43
+ payload: Uint8Array;
44
+ }
45
+ export declare function deserializeLogMessage(stream: StructAsyncDeserializeStream): Promise<LogMessage>;
46
+ export interface LogSize {
47
+ id: LogId;
48
+ size: number;
49
+ readable?: number;
50
+ consumed: number;
51
+ maxEntrySize: number;
52
+ maxPayloadSize: number;
53
+ }
54
+ export declare class Logcat extends AdbCommandBase {
55
+ static logIdToName(id: LogId): string;
56
+ static logNameToId(name: string): LogId;
57
+ static joinLogId(ids: LogId[]): string;
58
+ static parseSize(value: number, multiplier: string): number;
59
+ static readonly LOG_SIZE_REGEX_10: RegExp;
60
+ static readonly LOG_SIZE_REGEX_11: RegExp;
61
+ getLogSize(ids?: LogId[]): Promise<LogSize[]>;
62
+ clear(ids?: LogId[]): Promise<void>;
63
+ binary(options?: LogcatOptions): ReadableStream<LogMessage>;
64
+ }
65
+ //# sourceMappingURL=logcat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logcat.d.ts","sourceRoot":"","sources":["../src/logcat.ts"],"names":[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AAK;WAKhC,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,MAAM;WAI/B,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;IAOlE,gBAAuB,iBAAiB,SAAyG;IAIjJ,gBAAuB,iBAAiB,SAA8H;IAEzJ,UAAU,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAyC7C,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE;IAQzB,MAAM,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,cAAc,CAAC,UAAU,CAAC;CA8BrE"}
package/esm/logcat.js ADDED
@@ -0,0 +1,149 @@
1
+ // cspell: ignore logcat
2
+ import { AdbCommandBase, BufferedStream, BufferedStreamEndedError, DecodeUtf8Stream, ReadableStream, SplitLineStream, WritableStream } from "@yume-chan/adb";
3
+ import Struct from "@yume-chan/struct";
4
+ // `adb logcat` is an alias to `adb shell logcat`
5
+ // so instead of adding to core library, it's implemented here
6
+ // https://cs.android.com/android/platform/superproject/+/master:system/logging/liblog/include/android/log.h;l=141;drc=82b5738732161dbaafb2e2f25cce19cd26b9157d
7
+ export var LogId;
8
+ (function (LogId) {
9
+ LogId[LogId["All"] = -1] = "All";
10
+ LogId[LogId["Main"] = 0] = "Main";
11
+ LogId[LogId["Radio"] = 1] = "Radio";
12
+ LogId[LogId["Events"] = 2] = "Events";
13
+ LogId[LogId["System"] = 3] = "System";
14
+ LogId[LogId["Crash"] = 4] = "Crash";
15
+ LogId[LogId["Stats"] = 5] = "Stats";
16
+ LogId[LogId["Security"] = 6] = "Security";
17
+ LogId[LogId["Kernel"] = 7] = "Kernel";
18
+ })(LogId || (LogId = {}));
19
+ export var LogPriority;
20
+ (function (LogPriority) {
21
+ LogPriority[LogPriority["Unknown"] = 0] = "Unknown";
22
+ LogPriority[LogPriority["Default"] = 1] = "Default";
23
+ LogPriority[LogPriority["Verbose"] = 2] = "Verbose";
24
+ LogPriority[LogPriority["Info"] = 3] = "Info";
25
+ LogPriority[LogPriority["Warn"] = 4] = "Warn";
26
+ LogPriority[LogPriority["Error"] = 5] = "Error";
27
+ LogPriority[LogPriority["Fatal"] = 6] = "Fatal";
28
+ LogPriority[LogPriority["Silent"] = 7] = "Silent";
29
+ })(LogPriority || (LogPriority = {}));
30
+ const NANOSECONDS_PER_SECOND = BigInt(1e9);
31
+ // https://cs.android.com/android/platform/superproject/+/master:system/logging/liblog/include/log/log_read.h;l=39;drc=82b5738732161dbaafb2e2f25cce19cd26b9157d
32
+ export const LoggerEntry = new Struct({ littleEndian: true })
33
+ .uint16('payloadSize')
34
+ .uint16('headerSize')
35
+ .int32('pid')
36
+ .uint32('tid')
37
+ .uint32('second')
38
+ .uint32('nanoseconds')
39
+ .uint32('logId')
40
+ .uint32('uid')
41
+ .extra({
42
+ get timestamp() {
43
+ return BigInt(this.second) * NANOSECONDS_PER_SECOND + BigInt(this.nanoseconds);
44
+ },
45
+ });
46
+ export async function deserializeLogMessage(stream) {
47
+ const entry = await LoggerEntry.deserialize(stream);
48
+ await stream.read(entry.headerSize - LoggerEntry.size);
49
+ const priority = (await stream.read(1))[0];
50
+ const payload = await stream.read(entry.payloadSize - 1);
51
+ return { ...entry, priority, payload };
52
+ }
53
+ export class Logcat extends AdbCommandBase {
54
+ static logIdToName(id) {
55
+ return LogId[id];
56
+ }
57
+ static logNameToId(name) {
58
+ const key = name[0].toUpperCase() + name.substring(1);
59
+ return LogId[key];
60
+ }
61
+ static joinLogId(ids) {
62
+ return ids.map(id => Logcat.logIdToName(id)).join(',');
63
+ }
64
+ static parseSize(value, multiplier) {
65
+ const MULTIPLIERS = ['', 'Ki', 'Mi', 'Gi'];
66
+ return value * 1024 ** (MULTIPLIERS.indexOf(multiplier) || 0);
67
+ }
68
+ // TODO: logcat: Support output format before Android 10
69
+ // ref https://android-review.googlesource.com/c/platform/system/core/+/748128
70
+ static LOG_SIZE_REGEX_10 = /(.*): ring buffer is (.*) (.*)B \((.*) (.*)B consumed\), max entry is (.*) B, max payload is (.*) B/;
71
+ // Android 11 added `readable` part
72
+ // ref https://android-review.googlesource.com/c/platform/system/core/+/1390940
73
+ static LOG_SIZE_REGEX_11 = /(.*): ring buffer is (.*) (.*)B \((.*) (.*)B consumed, (.*) (.*)B readable\), max entry is (.*) B, max payload is (.*) B/;
74
+ async getLogSize(ids) {
75
+ const { stdout } = await this.adb.subprocess.spawn([
76
+ 'logcat',
77
+ '-g',
78
+ ...(ids ? ['-b', Logcat.joinLogId(ids)] : [])
79
+ ]);
80
+ const result = [];
81
+ await stdout
82
+ .pipeThrough(new DecodeUtf8Stream())
83
+ .pipeThrough(new SplitLineStream())
84
+ .pipeTo(new WritableStream({
85
+ write(chunk) {
86
+ let match = chunk.match(Logcat.LOG_SIZE_REGEX_11);
87
+ if (match) {
88
+ result.push({
89
+ id: Logcat.logNameToId(match[1]),
90
+ size: Logcat.parseSize(Number.parseInt(match[2], 10), match[3]),
91
+ readable: Logcat.parseSize(Number.parseInt(match[6], 10), match[7]),
92
+ consumed: Logcat.parseSize(Number.parseInt(match[4], 10), match[5]),
93
+ maxEntrySize: parseInt(match[8], 10),
94
+ maxPayloadSize: parseInt(match[9], 10),
95
+ });
96
+ }
97
+ match = chunk.match(Logcat.LOG_SIZE_REGEX_10);
98
+ if (match) {
99
+ result.push({
100
+ id: Logcat.logNameToId(match[1]),
101
+ size: Logcat.parseSize(Number.parseInt(match[2], 10), match[3]),
102
+ consumed: Logcat.parseSize(Number.parseInt(match[4], 10), match[5]),
103
+ maxEntrySize: parseInt(match[6], 10),
104
+ maxPayloadSize: parseInt(match[7], 10),
105
+ });
106
+ }
107
+ },
108
+ }));
109
+ return result;
110
+ }
111
+ async clear(ids) {
112
+ await this.adb.subprocess.spawnAndWait([
113
+ 'logcat',
114
+ '-c',
115
+ ...(ids ? ['-b', Logcat.joinLogId(ids)] : []),
116
+ ]);
117
+ }
118
+ binary(options) {
119
+ let bufferedStream;
120
+ return new ReadableStream({
121
+ start: async () => {
122
+ const { stdout } = await this.adb.subprocess.spawn([
123
+ 'logcat',
124
+ '-B',
125
+ ...(options?.pid ? ['--pid', options.pid.toString()] : []),
126
+ ...(options?.ids ? ['-b', Logcat.joinLogId(options.ids)] : [])
127
+ ]);
128
+ bufferedStream = new BufferedStream(stdout);
129
+ },
130
+ async pull(controller) {
131
+ try {
132
+ const entry = await deserializeLogMessage(bufferedStream);
133
+ controller.enqueue(entry);
134
+ }
135
+ catch (e) {
136
+ if (e instanceof BufferedStreamEndedError) {
137
+ controller.close();
138
+ return;
139
+ }
140
+ throw e;
141
+ }
142
+ },
143
+ cancel() {
144
+ bufferedStream.close();
145
+ },
146
+ });
147
+ }
148
+ }
149
+ //# sourceMappingURL=logcat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logcat.js","sourceRoot":"","sources":["../src/logcat.ts"],"names":[],"mappings":"AAAA,wBAAwB;AAExB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC7J,OAAO,MAAwC,MAAM,mBAAmB,CAAC;AAEzE,iDAAiD;AACjD,8DAA8D;AAE9D,+JAA+J;AAC/J,MAAM,CAAN,IAAY,KAUX;AAVD,WAAY,KAAK;IACb,gCAAQ,CAAA;IACR,iCAAI,CAAA;IACJ,mCAAK,CAAA;IACL,qCAAM,CAAA;IACN,qCAAM,CAAA;IACN,mCAAK,CAAA;IACL,mCAAK,CAAA;IACL,yCAAQ,CAAA;IACR,qCAAM,CAAA;AACV,CAAC,EAVW,KAAK,KAAL,KAAK,QAUhB;AAED,MAAM,CAAN,IAAY,WASX;AATD,WAAY,WAAW;IACnB,mDAAO,CAAA;IACP,mDAAO,CAAA;IACP,mDAAO,CAAA;IACP,6CAAI,CAAA;IACJ,6CAAI,CAAA;IACJ,+CAAK,CAAA;IACL,+CAAK,CAAA;IAC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,CAAC,CAAC,EAAE,CAAC;iBACjE,CAAC,CAAC;gBACH,cAAc,GAAG,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;YAChD,CAAC;YACD,KAAK,CAAC,IAAI,CAAC,UAAU;gBACjB,IAAI;oBACA,MAAM,KAAK,GAAG,MAAM,qBAAqB,CAAC,cAAc,CAAC,CAAC;oBAC1D,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;iBAC7B;gBAAC,OAAO,CAAC,EAAE;oBACR,IAAI,CAAC,YAAY,wBAAwB,EAAE;wBACvC,UAAU,CAAC,KAAK,EAAE,CAAC;wBACnB,OAAO;qBACV;oBAED,MAAM,CAAC,CAAC;iBACX;YACL,CAAC;YACD,MAAM;gBACF,cAAc,CAAC,KAAK,EAAE,CAAC;YAC3B,CAAC;SACJ,CAAC,CAAC;IACP,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yume-chan/android-bin",
3
- "version": "0.0.12",
3
+ "version": "0.0.15",
4
4
  "description": "Wrappers for Android built-in executables.",
5
5
  "keywords": [
6
6
  "adb",
@@ -25,11 +25,12 @@
25
25
  "main": "esm/index.js",
26
26
  "types": "esm/index.d.ts",
27
27
  "devDependencies": {
28
- "typescript": "next",
28
+ "typescript": "4.7.0-beta",
29
29
  "@yume-chan/ts-package-builder": "^1.0.0"
30
30
  },
31
31
  "dependencies": {
32
- "@yume-chan/adb": "^0.0.12",
32
+ "@yume-chan/adb": "^0.0.15",
33
+ "@yume-chan/struct": "^0.0.15",
33
34
  "tslib": "^2.3.1"
34
35
  },
35
36
  "scripts": {
package/src/bu.ts ADDED
@@ -0,0 +1,22 @@
1
+ // cspell: ignore apks
2
+ // cspell: ignore obbs
3
+
4
+ import { AdbCommandBase } from "@yume-chan/adb";
5
+
6
+ export interface AdbBackupOptions {
7
+ apps: string[] | 'all' | 'all-including-system';
8
+ apks: boolean;
9
+ obbs: boolean;
10
+ shared: boolean;
11
+ widgets: boolean;
12
+ compress: boolean;
13
+ user: number;
14
+ }
15
+
16
+ export class AdbBackup extends AdbCommandBase {
17
+ async backup(options: AdbBackupOptions): Promise<void> {
18
+ }
19
+
20
+ async restore(options: AdbBackupOptions): Promise<void> {
21
+ }
22
+ }
package/src/bug-report.ts CHANGED
@@ -1,11 +1,14 @@
1
1
  // cspell: ignore bugreport
2
2
  // cspell: ignore bugreportz
3
3
 
4
- import { AdbCommandBase, AdbShellSubprocessProtocol, DecodeUtf8Stream, ReadableStream, SplitLineStream, WrapReadableStream, WritableStream } from "@yume-chan/adb";
4
+ import { AdbCommandBase, AdbSubprocessShellProtocol, DecodeUtf8Stream, PushReadableStream, ReadableStream, SplitLineStream, WrapReadableStream, WritableStream } from "@yume-chan/adb";
5
5
 
6
- export interface BugReportVersion {
6
+ export interface BugReportZVersion {
7
7
  major: number;
8
8
  minor: number;
9
+
10
+ supportProgress: boolean;
11
+ supportStream: boolean;
9
12
  }
10
13
 
11
14
  export class BugReportZ extends AdbCommandBase {
@@ -24,9 +27,9 @@ export class BugReportZ extends AdbCommandBase {
24
27
  *
25
28
  * @returns a `BugReportVersion` object, or `undefined` if `bugreportz` is not available.
26
29
  */
27
- public async version(): Promise<BugReportVersion | undefined> {
30
+ public async version(): Promise<BugReportZVersion | undefined> {
28
31
  // bugreportz requires shell protocol
29
- if (!AdbShellSubprocessProtocol.isSupported(this.adb)) {
32
+ if (!AdbSubprocessShellProtocol.isSupported(this.adb)) {
30
33
  return undefined;
31
34
  }
32
35
 
@@ -40,38 +43,28 @@ export class BugReportZ extends AdbCommandBase {
40
43
  return undefined;
41
44
  }
42
45
 
46
+ const major = parseInt(match[1]!, 10);
47
+ const minor = parseInt(match[2]!, 10);
43
48
  return {
44
- major: parseInt(match[1]!, 10),
45
- minor: parseInt(match[2]!, 10),
46
- };
47
- }
48
-
49
- public supportStream(version: BugReportVersion): boolean {
50
- return version.major > 1 || version.minor >= 2;
51
- }
49
+ major,
50
+ minor,
52
51
 
53
- public stream(): ReadableStream<Uint8Array> {
54
- return new WrapReadableStream<Uint8Array, ReadableStream<Uint8Array>, undefined>({
55
- start: async () => {
56
- const process = await this.adb.subprocess.spawn(['bugreportz', '-s']);
57
- return {
58
- readable: process.stdout,
59
- state: undefined,
60
- };
61
- },
62
- });
52
+ supportProgress: this.supportProgress(major, minor),
53
+ supportStream: this.supportStream(major, minor),
54
+ };
63
55
  }
64
56
 
65
- public supportProgress(version: BugReportVersion): boolean {
66
- return version.major > 1 || version.minor >= 1;
57
+ public supportProgress(major: number, minor: number): boolean {
58
+ return major > 1 || minor >= 1;
67
59
  }
68
60
 
69
61
  /**
70
62
  * Create a zipped bugreport file.
71
63
  *
72
- * Compare to `stream`, this method will write the output on device. You can pull it using sync protocol.
64
+ * Compare to `stream`, this method will write the output to a file on device.
65
+ * You can pull it later using sync protocol.
73
66
  *
74
- * @param onProgress Progress callback. Only specify this if `supportsProgress()` returns `true`.
67
+ * @param onProgress Progress callback. Only specify this if `supportsProgress` is `true`.
75
68
  * @returns The path of the bugreport file.
76
69
  */
77
70
  public async generate(onProgress?: (progress: string, total: string) => void): Promise<string> {
@@ -88,7 +81,7 @@ export class BugReportZ extends AdbCommandBase {
88
81
  .pipeThrough(new SplitLineStream())
89
82
  .pipeTo(new WritableStream<string>({
90
83
  write(line) {
91
- // (Not 100% sure) `BEGIN:` and `PROGRESS:` only appear when `-p` is specified.
84
+ // `BEGIN:` and `PROGRESS:` only appear when `-p` is specified.
92
85
  let match = line.match(BugReportZ.PROGRESS_REGEX);
93
86
  if (match) {
94
87
  onProgress?.(match[1]!, match[2]!);
@@ -109,7 +102,6 @@ export class BugReportZ extends AdbCommandBase {
109
102
  // Don't report error now
110
103
  // We want to gather all output.
111
104
  error = match[1];
112
-
113
105
  }
114
106
  }
115
107
  }));
@@ -125,19 +117,39 @@ export class BugReportZ extends AdbCommandBase {
125
117
  // Design choice: we don't automatically pull the file to avoid more dependency on `@yume-chan/adb`
126
118
  return filename;
127
119
  }
120
+
121
+ public supportStream(major: number, minor: number): boolean {
122
+ return major > 1 || minor >= 2;
123
+ }
124
+
125
+ public stream(): ReadableStream<Uint8Array> {
126
+ return new PushReadableStream(async (controller) => {
127
+ const process = await this.adb.subprocess.spawn(['bugreportz', '-s']);
128
+ process.stdout
129
+ .pipeTo(new WritableStream({
130
+ async write(chunk) {
131
+ await controller.enqueue(chunk);
132
+ },
133
+ }));
134
+ process.stderr
135
+ .pipeThrough(new DecodeUtf8Stream())
136
+ .pipeTo(new WritableStream({
137
+ async write(chunk) {
138
+ controller.error(new Error(chunk));
139
+ }
140
+ }));
141
+ await process.exit;
142
+ controller.close();
143
+ });
144
+ }
128
145
  }
129
146
 
147
+ // https://cs.android.com/android/platform/superproject/+/master:frameworks/native/cmds/bugreport/bugreport.cpp;drc=9b73bf07d73dbab5b792632e1e233edbad77f5fd;bpv=0;bpt=0
130
148
  export class BugReport extends AdbCommandBase {
131
- public generate(): ReadableStream<string> {
132
- return new WrapReadableStream<string, ReadableStream<string>, undefined>({
133
- start: async () => {
134
- const process = await this.adb.subprocess.spawn(['bugreport']);
135
- return {
136
- readable: process.stdout
137
- .pipeThrough(new DecodeUtf8Stream()),
138
- state: undefined,
139
- };
140
- }
149
+ public generate(): ReadableStream<Uint8Array> {
150
+ return new WrapReadableStream(async () => {
151
+ const process = await this.adb.subprocess.spawn(['bugreport']);
152
+ return process.stdout;
141
153
  });
142
154
  }
143
155
  }
package/src/index.ts CHANGED
@@ -1,3 +1,6 @@
1
+ // cspell: ignore logcat
2
+
1
3
  export * from './bug-report.js';
2
4
  export * from './demo-mode.js';
5
+ export * from './logcat.js';
3
6
  export * from './settings.js';
package/src/logcat.ts ADDED
@@ -0,0 +1,187 @@
1
+ // cspell: ignore logcat
2
+
3
+ import { AdbCommandBase, BufferedStream, BufferedStreamEndedError, DecodeUtf8Stream, ReadableStream, SplitLineStream, WritableStream } from "@yume-chan/adb";
4
+ import Struct, { StructAsyncDeserializeStream } from "@yume-chan/struct";
5
+
6
+ // `adb logcat` is an alias to `adb shell logcat`
7
+ // so instead of adding to core library, it's implemented here
8
+
9
+ // https://cs.android.com/android/platform/superproject/+/master:system/logging/liblog/include/android/log.h;l=141;drc=82b5738732161dbaafb2e2f25cce19cd26b9157d
10
+ export enum LogId {
11
+ All = -1,
12
+ Main,
13
+ Radio,
14
+ Events,
15
+ System,
16
+ Crash,
17
+ Stats,
18
+ Security,
19
+ Kernel,
20
+ }
21
+
22
+ export enum LogPriority {
23
+ Unknown,
24
+ Default,
25
+ Verbose,
26
+ Info,
27
+ Warn,
28
+ Error,
29
+ Fatal,
30
+ Silent,
31
+ }
32
+
33
+ export interface LogcatOptions {
34
+ pid?: number;
35
+ ids?: LogId[];
36
+ }
37
+
38
+ const NANOSECONDS_PER_SECOND = BigInt(1e9);
39
+
40
+ // https://cs.android.com/android/platform/superproject/+/master:system/logging/liblog/include/log/log_read.h;l=39;drc=82b5738732161dbaafb2e2f25cce19cd26b9157d
41
+ export const LoggerEntry =
42
+ new Struct({ littleEndian: true })
43
+ .uint16('payloadSize')
44
+ .uint16('headerSize')
45
+ .int32('pid')
46
+ .uint32('tid')
47
+ .uint32('second')
48
+ .uint32('nanoseconds')
49
+ .uint32('logId')
50
+ .uint32('uid')
51
+ .extra({
52
+ get timestamp() {
53
+ return BigInt(this.second) * NANOSECONDS_PER_SECOND + BigInt(this.nanoseconds);
54
+ },
55
+ });
56
+
57
+ export type LoggerEntry = typeof LoggerEntry['TDeserializeResult'];
58
+
59
+ export interface LogMessage extends LoggerEntry {
60
+ priority: LogPriority;
61
+ payload: Uint8Array;
62
+ }
63
+
64
+ export async function deserializeLogMessage(stream: StructAsyncDeserializeStream): Promise<LogMessage> {
65
+ const entry = await LoggerEntry.deserialize(stream);
66
+ await stream.read(entry.headerSize - LoggerEntry.size);
67
+ const priority = (await stream.read(1))[0] as LogPriority;
68
+ const payload = await stream.read(entry.payloadSize - 1);
69
+ return { ...entry, priority, payload };
70
+ }
71
+
72
+ export interface LogSize {
73
+ id: LogId;
74
+ size: number;
75
+ readable?: number;
76
+ consumed: number;
77
+ maxEntrySize: number;
78
+ maxPayloadSize: number;
79
+ }
80
+
81
+ export class Logcat extends AdbCommandBase {
82
+ public static logIdToName(id: LogId): string {
83
+ return LogId[id]!;
84
+ }
85
+
86
+ public static logNameToId(name: string): LogId {
87
+ const key = name[0]!.toUpperCase() + name.substring(1);
88
+ return (LogId as any)[key];
89
+ }
90
+
91
+ public static joinLogId(ids: LogId[]): string {
92
+ return ids.map(id => Logcat.logIdToName(id)).join(',');
93
+ }
94
+
95
+ public static parseSize(value: number, multiplier: string): number {
96
+ const MULTIPLIERS = ['', 'Ki', 'Mi', 'Gi'];
97
+ return value * 1024 ** (MULTIPLIERS.indexOf(multiplier) || 0);
98
+ }
99
+
100
+ // TODO: logcat: Support output format before Android 10
101
+ // ref https://android-review.googlesource.com/c/platform/system/core/+/748128
102
+ public static readonly LOG_SIZE_REGEX_10 = /(.*): ring buffer is (.*) (.*)B \((.*) (.*)B consumed\), max entry is (.*) B, max payload is (.*) B/;
103
+
104
+ // Android 11 added `readable` part
105
+ // ref https://android-review.googlesource.com/c/platform/system/core/+/1390940
106
+ public static readonly LOG_SIZE_REGEX_11 = /(.*): ring buffer is (.*) (.*)B \((.*) (.*)B consumed, (.*) (.*)B readable\), max entry is (.*) B, max payload is (.*) B/;
107
+
108
+ public async getLogSize(ids?: LogId[]): Promise<LogSize[]> {
109
+ const { stdout } = await this.adb.subprocess.spawn([
110
+ 'logcat',
111
+ '-g',
112
+ ...(ids ? ['-b', Logcat.joinLogId(ids)] : [])
113
+ ]);
114
+
115
+ const result: LogSize[] = [];
116
+ await stdout
117
+ .pipeThrough(new DecodeUtf8Stream())
118
+ .pipeThrough(new SplitLineStream())
119
+ .pipeTo(new WritableStream({
120
+ write(chunk) {
121
+ let match = chunk.match(Logcat.LOG_SIZE_REGEX_11);
122
+ if (match) {
123
+ result.push({
124
+ id: Logcat.logNameToId(match[1]!),
125
+ size: Logcat.parseSize(Number.parseInt(match[2]!, 10), match[3]!),
126
+ readable: Logcat.parseSize(Number.parseInt(match[6]!, 10), match[7]!),
127
+ consumed: Logcat.parseSize(Number.parseInt(match[4]!, 10), match[5]!),
128
+ maxEntrySize: parseInt(match[8]!, 10),
129
+ maxPayloadSize: parseInt(match[9]!, 10),
130
+ });
131
+ }
132
+
133
+ match = chunk.match(Logcat.LOG_SIZE_REGEX_10);
134
+ if (match) {
135
+ result.push({
136
+ id: Logcat.logNameToId(match[1]!),
137
+ size: Logcat.parseSize(Number.parseInt(match[2]!, 10), match[3]!),
138
+ consumed: Logcat.parseSize(Number.parseInt(match[4]!, 10), match[5]!),
139
+ maxEntrySize: parseInt(match[6]!, 10),
140
+ maxPayloadSize: parseInt(match[7]!, 10),
141
+ });
142
+ }
143
+ },
144
+ }));
145
+
146
+ return result;
147
+ }
148
+
149
+ public async clear(ids?: LogId[]) {
150
+ await this.adb.subprocess.spawnAndWait([
151
+ 'logcat',
152
+ '-c',
153
+ ...(ids ? ['-b', Logcat.joinLogId(ids)] : []),
154
+ ]);
155
+ }
156
+
157
+ public binary(options?: LogcatOptions): ReadableStream<LogMessage> {
158
+ let bufferedStream: BufferedStream;
159
+ return new ReadableStream({
160
+ start: async () => {
161
+ const { stdout } = await this.adb.subprocess.spawn([
162
+ 'logcat',
163
+ '-B',
164
+ ...(options?.pid ? ['--pid', options.pid.toString()] : []),
165
+ ...(options?.ids ? ['-b', Logcat.joinLogId(options.ids)] : [])
166
+ ]);
167
+ bufferedStream = new BufferedStream(stdout);
168
+ },
169
+ async pull(controller) {
170
+ try {
171
+ const entry = await deserializeLogMessage(bufferedStream);
172
+ controller.enqueue(entry);
173
+ } catch (e) {
174
+ if (e instanceof BufferedStreamEndedError) {
175
+ controller.close();
176
+ return;
177
+ }
178
+
179
+ throw e;
180
+ }
181
+ },
182
+ cancel() {
183
+ bufferedStream.close();
184
+ },
185
+ });
186
+ }
187
+ }