@yume-chan/adb 0.0.15 → 0.0.16

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 (103) hide show
  1. package/CHANGELOG.json +21 -0
  2. package/CHANGELOG.md +11 -1
  3. package/LICENSE +21 -21
  4. package/README.md +247 -247
  5. package/esm/adb.d.ts +7 -0
  6. package/esm/adb.d.ts.map +1 -1
  7. package/esm/adb.js +7 -0
  8. package/esm/adb.js.map +1 -1
  9. package/esm/commands/subprocess/protocols/none.d.ts +1 -0
  10. package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
  11. package/esm/commands/subprocess/protocols/none.js +6 -5
  12. package/esm/commands/subprocess/protocols/none.js.map +1 -1
  13. package/esm/commands/sync/stat.d.ts.map +1 -1
  14. package/esm/commands/sync/stat.js.map +1 -1
  15. package/esm/socket/dispatcher.d.ts +4 -1
  16. package/esm/socket/dispatcher.d.ts.map +1 -1
  17. package/esm/socket/dispatcher.js +11 -8
  18. package/esm/socket/dispatcher.js.map +1 -1
  19. package/esm/socket/socket.d.ts +6 -1
  20. package/esm/socket/socket.d.ts.map +1 -1
  21. package/esm/socket/socket.js +17 -7
  22. package/esm/socket/socket.js.map +1 -1
  23. package/esm/stream/buffered.d.ts +6 -2
  24. package/esm/stream/buffered.d.ts.map +1 -1
  25. package/esm/stream/buffered.js +67 -47
  26. package/esm/stream/buffered.js.map +1 -1
  27. package/esm/stream/detect.js +1 -0
  28. package/esm/stream/detect.js.map +1 -1
  29. package/esm/stream/detect.polyfill.d.ts.map +1 -1
  30. package/esm/stream/detect.polyfill.js +0 -5
  31. package/esm/stream/detect.polyfill.js.map +1 -1
  32. package/esm/stream/transform.d.ts +20 -0
  33. package/esm/stream/transform.d.ts.map +1 -1
  34. package/esm/stream/transform.js +7 -1
  35. package/esm/stream/transform.js.map +1 -1
  36. package/package.json +10 -10
  37. package/src/adb.ts +280 -273
  38. package/src/auth.ts +173 -173
  39. package/src/backend.ts +11 -11
  40. package/src/commands/base.ts +11 -11
  41. package/src/commands/framebuffer.ts +73 -73
  42. package/src/commands/index.ts +8 -8
  43. package/src/commands/install.ts +30 -30
  44. package/src/commands/power.ts +54 -54
  45. package/src/commands/reverse.ts +140 -140
  46. package/src/commands/subprocess/index.ts +139 -139
  47. package/src/commands/subprocess/protocols/none.ts +70 -68
  48. package/src/commands/subprocess/protocols/shell.ts +190 -190
  49. package/src/commands/subprocess/protocols/types.ts +59 -59
  50. package/src/commands/subprocess/utils.ts +20 -20
  51. package/src/commands/sync/index.ts +7 -7
  52. package/src/commands/sync/list.ts +86 -86
  53. package/src/commands/sync/pull.ts +46 -46
  54. package/src/commands/sync/push.ts +41 -41
  55. package/src/commands/sync/request.ts +50 -50
  56. package/src/commands/sync/response.ts +64 -64
  57. package/src/commands/sync/stat.ts +151 -150
  58. package/src/commands/sync/sync.ts +181 -181
  59. package/src/commands/tcpip.ts +21 -21
  60. package/src/crypto.ts +296 -296
  61. package/src/features.ts +9 -9
  62. package/src/index.ts +11 -11
  63. package/src/packet.ts +80 -80
  64. package/src/socket/dispatcher.ts +305 -304
  65. package/src/socket/index.ts +2 -2
  66. package/src/socket/socket.ts +155 -144
  67. package/src/stream/buffered.ts +168 -147
  68. package/src/stream/detect.native.ts +362 -362
  69. package/src/stream/detect.polyfill.ts +22 -28
  70. package/src/stream/detect.ts +7 -5
  71. package/src/stream/index.ts +3 -3
  72. package/src/stream/transform.ts +474 -447
  73. package/src/utils/auto-reset-event.ts +41 -41
  74. package/src/utils/base64.ts +306 -306
  75. package/src/utils/index.ts +3 -3
  76. package/tsconfig.build.json +3 -3
  77. package/tsconfig.build.tsbuildinfo +1 -1
  78. package/tsconfig.test.json +9 -10
  79. package/web-streams-polyfill-4.0.0-beta.2.tgz +0 -0
  80. package/esm/commands/subprocess/legacy.d.ts +0 -35
  81. package/esm/commands/subprocess/legacy.d.ts.map +0 -1
  82. package/esm/commands/subprocess/legacy.js +0 -53
  83. package/esm/commands/subprocess/legacy.js.map +0 -1
  84. package/esm/commands/subprocess/protocol.d.ts +0 -39
  85. package/esm/commands/subprocess/protocol.d.ts.map +0 -1
  86. package/esm/commands/subprocess/protocol.js +0 -157
  87. package/esm/commands/subprocess/protocol.js.map +0 -1
  88. package/esm/commands/subprocess/types.d.ts +0 -50
  89. package/esm/commands/subprocess/types.d.ts.map +0 -1
  90. package/esm/commands/subprocess/types.js +0 -2
  91. package/esm/commands/subprocess/types.js.map +0 -1
  92. package/esm/socket/controller.d.ts +0 -37
  93. package/esm/socket/controller.d.ts.map +0 -1
  94. package/esm/socket/controller.js +0 -66
  95. package/esm/socket/controller.js.map +0 -1
  96. package/esm/stream/detect.bak.d.ts +0 -240
  97. package/esm/stream/detect.bak.d.ts.map +0 -1
  98. package/esm/stream/detect.bak.js +0 -60
  99. package/esm/stream/detect.bak.js.map +0 -1
  100. package/esm/utils/encoding.d.ts +0 -3
  101. package/esm/utils/encoding.d.ts.map +0 -1
  102. package/esm/utils/encoding.js +0 -11
  103. package/esm/utils/encoding.js.map +0 -1
package/src/auth.ts CHANGED
@@ -1,173 +1,173 @@
1
- import { PromiseResolver } from '@yume-chan/async';
2
- import type { Disposable } from '@yume-chan/event';
3
- import type { ValueOrPromise } from '@yume-chan/struct';
4
- import { calculatePublicKey, calculatePublicKeyLength, sign } from './crypto.js';
5
- import { AdbCommand, type AdbPacketData } from './packet.js';
6
- import { calculateBase64EncodedLength, encodeBase64 } from './utils/index.js';
7
-
8
- export type AdbKeyIterable = Iterable<Uint8Array> | AsyncIterable<Uint8Array>;
9
-
10
- export interface AdbCredentialStore {
11
- /**
12
- * Generate and store a RSA private key with modulus length `2048` and public exponent `65537`.
13
- *
14
- * The returned `Uint8Array` is the private key in PKCS #8 format.
15
- */
16
- generateKey(): ValueOrPromise<Uint8Array>;
17
-
18
- /**
19
- * Synchronously or asynchronously iterate through all stored RSA private keys.
20
- *
21
- * Each call to `iterateKeys` must return a different iterator that iterate through all stored keys.
22
- */
23
- iterateKeys(): AdbKeyIterable;
24
- }
25
-
26
- export enum AdbAuthType {
27
- Token = 1,
28
- Signature = 2,
29
- PublicKey = 3,
30
- }
31
-
32
- export interface AdbAuthenticator {
33
- /**
34
- * @param getNextRequest
35
- *
36
- * Call this function to get the next authentication request packet from device.
37
- *
38
- * After calling `getNextRequest`, authenticator can `yield` a packet as response, or `return` to indicate its incapability of handling the request.
39
- *
40
- * After `return`, the `AdbAuthenticatorHandler` will move on to next authenticator and never go back.
41
- *
42
- * Calling `getNextRequest` multiple times without `yield` or `return` will always return the same request.
43
- */
44
- (
45
- credentialStore: AdbCredentialStore,
46
- getNextRequest: () => Promise<AdbPacketData>
47
- ): AsyncIterable<AdbPacketData>;
48
- }
49
-
50
- export const AdbSignatureAuthenticator: AdbAuthenticator = async function* (
51
- credentialStore: AdbCredentialStore,
52
- getNextRequest: () => Promise<AdbPacketData>,
53
- ): AsyncIterable<AdbPacketData> {
54
- for await (const key of credentialStore.iterateKeys()) {
55
- const packet = await getNextRequest();
56
-
57
- if (packet.arg0 !== AdbAuthType.Token) {
58
- return;
59
- }
60
-
61
- const signature = sign(key, packet.payload);
62
- yield {
63
- command: AdbCommand.Auth,
64
- arg0: AdbAuthType.Signature,
65
- arg1: 0,
66
- payload: new Uint8Array(signature),
67
- };
68
- }
69
- };
70
-
71
- export const AdbPublicKeyAuthenticator: AdbAuthenticator = async function* (
72
- credentialStore: AdbCredentialStore,
73
- getNextRequest: () => Promise<AdbPacketData>,
74
- ): AsyncIterable<AdbPacketData> {
75
- const packet = await getNextRequest();
76
-
77
- if (packet.arg0 !== AdbAuthType.Token) {
78
- return;
79
- }
80
-
81
- let privateKey: Uint8Array | undefined;
82
- for await (const key of credentialStore.iterateKeys()) {
83
- privateKey = key;
84
- break;
85
- }
86
-
87
-
88
- if (!privateKey) {
89
- privateKey = await credentialStore.generateKey();
90
- }
91
-
92
- const publicKeyLength = calculatePublicKeyLength();
93
- const [publicKeyBase64Length] = calculateBase64EncodedLength(publicKeyLength);
94
-
95
- // The public key is null terminated,
96
- // So we allocate the buffer with one extra byte.
97
- const publicKeyBuffer = new Uint8Array(publicKeyBase64Length + 1);
98
-
99
- calculatePublicKey(privateKey, publicKeyBuffer);
100
- encodeBase64(
101
- publicKeyBuffer.subarray(0, publicKeyLength),
102
- publicKeyBuffer
103
- );
104
-
105
- yield {
106
- command: AdbCommand.Auth,
107
- arg0: AdbAuthType.PublicKey,
108
- arg1: 0,
109
- payload: publicKeyBuffer,
110
- };
111
- };
112
-
113
- export const ADB_DEFAULT_AUTHENTICATORS: AdbAuthenticator[] = [
114
- AdbSignatureAuthenticator,
115
- AdbPublicKeyAuthenticator,
116
- ];
117
-
118
- export class AdbAuthenticationProcessor implements Disposable {
119
- public readonly authenticators: readonly AdbAuthenticator[];
120
-
121
- private readonly credentialStore: AdbCredentialStore;
122
-
123
- private pendingRequest = new PromiseResolver<AdbPacketData>();
124
-
125
- private iterator: AsyncIterator<AdbPacketData, void, void> | undefined;
126
-
127
- public constructor(
128
- authenticators: readonly AdbAuthenticator[],
129
- credentialStore: AdbCredentialStore
130
- ) {
131
- this.authenticators = authenticators;
132
- this.credentialStore = credentialStore;
133
- }
134
-
135
- private getNextRequest = (): Promise<AdbPacketData> => {
136
- return this.pendingRequest.promise;
137
- };
138
-
139
- private async* invokeAuthenticator(): AsyncGenerator<AdbPacketData, void, void> {
140
- for (const authenticator of this.authenticators) {
141
- for await (const packet of authenticator(this.credentialStore, this.getNextRequest)) {
142
- // If the authenticator yielded a response
143
- // Prepare `nextRequest` for next authentication request
144
- this.pendingRequest = new PromiseResolver();
145
-
146
- // Yield the response to outer layer
147
- yield packet;
148
- }
149
-
150
- // If the authenticator returned,
151
- // Next authenticator will be given the same `pendingRequest`
152
- }
153
- }
154
-
155
- public async process(packet: AdbPacketData): Promise<AdbPacketData> {
156
- if (!this.iterator) {
157
- this.iterator = this.invokeAuthenticator();
158
- }
159
-
160
- this.pendingRequest.resolve(packet);
161
-
162
- const result = await this.iterator.next();
163
- if (result.done) {
164
- throw new Error('No authenticator can handle the request');
165
- }
166
-
167
- return result.value;
168
- }
169
-
170
- public dispose() {
171
- this.iterator?.return?.();
172
- }
173
- }
1
+ import { PromiseResolver } from '@yume-chan/async';
2
+ import type { Disposable } from '@yume-chan/event';
3
+ import type { ValueOrPromise } from '@yume-chan/struct';
4
+ import { calculatePublicKey, calculatePublicKeyLength, sign } from './crypto.js';
5
+ import { AdbCommand, type AdbPacketData } from './packet.js';
6
+ import { calculateBase64EncodedLength, encodeBase64 } from './utils/index.js';
7
+
8
+ export type AdbKeyIterable = Iterable<Uint8Array> | AsyncIterable<Uint8Array>;
9
+
10
+ export interface AdbCredentialStore {
11
+ /**
12
+ * Generate and store a RSA private key with modulus length `2048` and public exponent `65537`.
13
+ *
14
+ * The returned `Uint8Array` is the private key in PKCS #8 format.
15
+ */
16
+ generateKey(): ValueOrPromise<Uint8Array>;
17
+
18
+ /**
19
+ * Synchronously or asynchronously iterate through all stored RSA private keys.
20
+ *
21
+ * Each call to `iterateKeys` must return a different iterator that iterate through all stored keys.
22
+ */
23
+ iterateKeys(): AdbKeyIterable;
24
+ }
25
+
26
+ export enum AdbAuthType {
27
+ Token = 1,
28
+ Signature = 2,
29
+ PublicKey = 3,
30
+ }
31
+
32
+ export interface AdbAuthenticator {
33
+ /**
34
+ * @param getNextRequest
35
+ *
36
+ * Call this function to get the next authentication request packet from device.
37
+ *
38
+ * After calling `getNextRequest`, authenticator can `yield` a packet as response, or `return` to indicate its incapability of handling the request.
39
+ *
40
+ * After `return`, the `AdbAuthenticatorHandler` will move on to next authenticator and never go back.
41
+ *
42
+ * Calling `getNextRequest` multiple times without `yield` or `return` will always return the same request.
43
+ */
44
+ (
45
+ credentialStore: AdbCredentialStore,
46
+ getNextRequest: () => Promise<AdbPacketData>
47
+ ): AsyncIterable<AdbPacketData>;
48
+ }
49
+
50
+ export const AdbSignatureAuthenticator: AdbAuthenticator = async function* (
51
+ credentialStore: AdbCredentialStore,
52
+ getNextRequest: () => Promise<AdbPacketData>,
53
+ ): AsyncIterable<AdbPacketData> {
54
+ for await (const key of credentialStore.iterateKeys()) {
55
+ const packet = await getNextRequest();
56
+
57
+ if (packet.arg0 !== AdbAuthType.Token) {
58
+ return;
59
+ }
60
+
61
+ const signature = sign(key, packet.payload);
62
+ yield {
63
+ command: AdbCommand.Auth,
64
+ arg0: AdbAuthType.Signature,
65
+ arg1: 0,
66
+ payload: new Uint8Array(signature),
67
+ };
68
+ }
69
+ };
70
+
71
+ export const AdbPublicKeyAuthenticator: AdbAuthenticator = async function* (
72
+ credentialStore: AdbCredentialStore,
73
+ getNextRequest: () => Promise<AdbPacketData>,
74
+ ): AsyncIterable<AdbPacketData> {
75
+ const packet = await getNextRequest();
76
+
77
+ if (packet.arg0 !== AdbAuthType.Token) {
78
+ return;
79
+ }
80
+
81
+ let privateKey: Uint8Array | undefined;
82
+ for await (const key of credentialStore.iterateKeys()) {
83
+ privateKey = key;
84
+ break;
85
+ }
86
+
87
+
88
+ if (!privateKey) {
89
+ privateKey = await credentialStore.generateKey();
90
+ }
91
+
92
+ const publicKeyLength = calculatePublicKeyLength();
93
+ const [publicKeyBase64Length] = calculateBase64EncodedLength(publicKeyLength);
94
+
95
+ // The public key is null terminated,
96
+ // So we allocate the buffer with one extra byte.
97
+ const publicKeyBuffer = new Uint8Array(publicKeyBase64Length + 1);
98
+
99
+ calculatePublicKey(privateKey, publicKeyBuffer);
100
+ encodeBase64(
101
+ publicKeyBuffer.subarray(0, publicKeyLength),
102
+ publicKeyBuffer
103
+ );
104
+
105
+ yield {
106
+ command: AdbCommand.Auth,
107
+ arg0: AdbAuthType.PublicKey,
108
+ arg1: 0,
109
+ payload: publicKeyBuffer,
110
+ };
111
+ };
112
+
113
+ export const ADB_DEFAULT_AUTHENTICATORS: AdbAuthenticator[] = [
114
+ AdbSignatureAuthenticator,
115
+ AdbPublicKeyAuthenticator,
116
+ ];
117
+
118
+ export class AdbAuthenticationProcessor implements Disposable {
119
+ public readonly authenticators: readonly AdbAuthenticator[];
120
+
121
+ private readonly credentialStore: AdbCredentialStore;
122
+
123
+ private pendingRequest = new PromiseResolver<AdbPacketData>();
124
+
125
+ private iterator: AsyncIterator<AdbPacketData, void, void> | undefined;
126
+
127
+ public constructor(
128
+ authenticators: readonly AdbAuthenticator[],
129
+ credentialStore: AdbCredentialStore
130
+ ) {
131
+ this.authenticators = authenticators;
132
+ this.credentialStore = credentialStore;
133
+ }
134
+
135
+ private getNextRequest = (): Promise<AdbPacketData> => {
136
+ return this.pendingRequest.promise;
137
+ };
138
+
139
+ private async* invokeAuthenticator(): AsyncGenerator<AdbPacketData, void, void> {
140
+ for (const authenticator of this.authenticators) {
141
+ for await (const packet of authenticator(this.credentialStore, this.getNextRequest)) {
142
+ // If the authenticator yielded a response
143
+ // Prepare `nextRequest` for next authentication request
144
+ this.pendingRequest = new PromiseResolver();
145
+
146
+ // Yield the response to outer layer
147
+ yield packet;
148
+ }
149
+
150
+ // If the authenticator returned,
151
+ // Next authenticator will be given the same `pendingRequest`
152
+ }
153
+ }
154
+
155
+ public async process(packet: AdbPacketData): Promise<AdbPacketData> {
156
+ if (!this.iterator) {
157
+ this.iterator = this.invokeAuthenticator();
158
+ }
159
+
160
+ this.pendingRequest.resolve(packet);
161
+
162
+ const result = await this.iterator.next();
163
+ if (result.done) {
164
+ throw new Error('No authenticator can handle the request');
165
+ }
166
+
167
+ return result.value;
168
+ }
169
+
170
+ public dispose() {
171
+ this.iterator?.return?.();
172
+ }
173
+ }
package/src/backend.ts CHANGED
@@ -1,11 +1,11 @@
1
- import type { ValueOrPromise } from '@yume-chan/struct';
2
- import type { AdbPacketData, AdbPacketInit } from "./packet.js";
3
- import type { ReadableWritablePair } from "./stream/index.js";
4
-
5
- export interface AdbBackend {
6
- readonly serial: string;
7
-
8
- readonly name: string | undefined;
9
-
10
- connect(): ValueOrPromise<ReadableWritablePair<AdbPacketData, AdbPacketInit>>;
11
- }
1
+ import type { ValueOrPromise } from '@yume-chan/struct';
2
+ import type { AdbPacketData, AdbPacketInit } from "./packet.js";
3
+ import type { ReadableWritablePair } from "./stream/index.js";
4
+
5
+ export interface AdbBackend {
6
+ readonly serial: string;
7
+
8
+ readonly name: string | undefined;
9
+
10
+ connect(): ValueOrPromise<ReadableWritablePair<AdbPacketData, AdbPacketInit>>;
11
+ }
@@ -1,11 +1,11 @@
1
- import { AutoDisposable } from '@yume-chan/event';
2
- import type { Adb } from '../adb.js';
3
-
4
- export class AdbCommandBase extends AutoDisposable {
5
- protected adb: Adb;
6
-
7
- public constructor(adb: Adb) {
8
- super();
9
- this.adb = adb;
10
- }
11
- }
1
+ import { AutoDisposable } from '@yume-chan/event';
2
+ import type { Adb } from '../adb.js';
3
+
4
+ export class AdbCommandBase extends AutoDisposable {
5
+ protected adb: Adb;
6
+
7
+ public constructor(adb: Adb) {
8
+ super();
9
+ this.adb = adb;
10
+ }
11
+ }
@@ -1,73 +1,73 @@
1
- import Struct from "@yume-chan/struct";
2
- import type { Adb } from '../adb.js';
3
- import { AdbBufferedStream } from '../stream/index.js';
4
-
5
- const Version =
6
- new Struct({ littleEndian: true })
7
- .uint32('version');
8
-
9
- /*
10
- * ADB uses 8 int32 fields to describe bit depths
11
- * The only combination I have seen is RGBA8888, which is
12
- * red_offset: 0
13
- * red_length: 8
14
- * blue_offset: 16
15
- * blue_length: 8
16
- * green_offset: 8
17
- * green_length: 8
18
- * alpha_offset: 24
19
- * alpha_length: 8
20
- */
21
-
22
- export const AdbFrameBufferV1 =
23
- new Struct({ littleEndian: true })
24
- .uint32('bpp')
25
- .uint32('size')
26
- .uint32('width')
27
- .uint32('height')
28
- .uint32('red_offset')
29
- .uint32('red_length')
30
- .uint32('blue_offset')
31
- .uint32('blue_length')
32
- .uint32('green_offset')
33
- .uint32('green_length')
34
- .uint32('alpha_offset')
35
- .uint32('alpha_length')
36
- .uint8Array('data', { lengthField: 'size' });
37
-
38
- export type AdbFrameBufferV1 = typeof AdbFrameBufferV1['TDeserializeResult'];
39
-
40
- export const AdbFrameBufferV2 =
41
- new Struct({ littleEndian: true })
42
- .uint32('bpp')
43
- .uint32('colorSpace')
44
- .uint32('size')
45
- .uint32('width')
46
- .uint32('height')
47
- .uint32('red_offset')
48
- .uint32('red_length')
49
- .uint32('blue_offset')
50
- .uint32('blue_length')
51
- .uint32('green_offset')
52
- .uint32('green_length')
53
- .uint32('alpha_offset')
54
- .uint32('alpha_length')
55
- .uint8Array('data', { lengthField: 'size' });
56
-
57
- export type AdbFrameBufferV2 = typeof AdbFrameBufferV2['TDeserializeResult'];
58
-
59
- export type AdbFrameBuffer = AdbFrameBufferV1 | AdbFrameBufferV2;
60
-
61
- export async function framebuffer(adb: Adb): Promise<AdbFrameBuffer> {
62
- const socket = await adb.createSocket('framebuffer:');
63
- const stream = new AdbBufferedStream(socket);
64
- const { version } = await Version.deserialize(stream);
65
- switch (version) {
66
- case 1:
67
- return AdbFrameBufferV1.deserialize(stream);
68
- case 2:
69
- return AdbFrameBufferV2.deserialize(stream);
70
- default:
71
- throw new Error('Unknown FrameBuffer version');
72
- }
73
- }
1
+ import Struct from "@yume-chan/struct";
2
+ import type { Adb } from '../adb.js';
3
+ import { AdbBufferedStream } from '../stream/index.js';
4
+
5
+ const Version =
6
+ new Struct({ littleEndian: true })
7
+ .uint32('version');
8
+
9
+ /*
10
+ * ADB uses 8 int32 fields to describe bit depths
11
+ * The only combination I have seen is RGBA8888, which is
12
+ * red_offset: 0
13
+ * red_length: 8
14
+ * blue_offset: 16
15
+ * blue_length: 8
16
+ * green_offset: 8
17
+ * green_length: 8
18
+ * alpha_offset: 24
19
+ * alpha_length: 8
20
+ */
21
+
22
+ export const AdbFrameBufferV1 =
23
+ new Struct({ littleEndian: true })
24
+ .uint32('bpp')
25
+ .uint32('size')
26
+ .uint32('width')
27
+ .uint32('height')
28
+ .uint32('red_offset')
29
+ .uint32('red_length')
30
+ .uint32('blue_offset')
31
+ .uint32('blue_length')
32
+ .uint32('green_offset')
33
+ .uint32('green_length')
34
+ .uint32('alpha_offset')
35
+ .uint32('alpha_length')
36
+ .uint8Array('data', { lengthField: 'size' });
37
+
38
+ export type AdbFrameBufferV1 = typeof AdbFrameBufferV1['TDeserializeResult'];
39
+
40
+ export const AdbFrameBufferV2 =
41
+ new Struct({ littleEndian: true })
42
+ .uint32('bpp')
43
+ .uint32('colorSpace')
44
+ .uint32('size')
45
+ .uint32('width')
46
+ .uint32('height')
47
+ .uint32('red_offset')
48
+ .uint32('red_length')
49
+ .uint32('blue_offset')
50
+ .uint32('blue_length')
51
+ .uint32('green_offset')
52
+ .uint32('green_length')
53
+ .uint32('alpha_offset')
54
+ .uint32('alpha_length')
55
+ .uint8Array('data', { lengthField: 'size' });
56
+
57
+ export type AdbFrameBufferV2 = typeof AdbFrameBufferV2['TDeserializeResult'];
58
+
59
+ export type AdbFrameBuffer = AdbFrameBufferV1 | AdbFrameBufferV2;
60
+
61
+ export async function framebuffer(adb: Adb): Promise<AdbFrameBuffer> {
62
+ const socket = await adb.createSocket('framebuffer:');
63
+ const stream = new AdbBufferedStream(socket);
64
+ const { version } = await Version.deserialize(stream);
65
+ switch (version) {
66
+ case 1:
67
+ return AdbFrameBufferV1.deserialize(stream);
68
+ case 2:
69
+ return AdbFrameBufferV2.deserialize(stream);
70
+ default:
71
+ throw new Error('Unknown FrameBuffer version');
72
+ }
73
+ }
@@ -1,8 +1,8 @@
1
- export * from './base.js';
2
- export * from './framebuffer.js';
3
- export * from './install.js';
4
- export * from './power.js';
5
- export * from './reverse.js';
6
- export * from './subprocess/index.js';
7
- export * from './sync/index.js';
8
- export * from './tcpip.js';
1
+ export * from './base.js';
2
+ export * from './framebuffer.js';
3
+ export * from './install.js';
4
+ export * from './power.js';
5
+ export * from './reverse.js';
6
+ export * from './subprocess/index.js';
7
+ export * from './sync/index.js';
8
+ export * from './tcpip.js';
@@ -1,30 +1,30 @@
1
- import type { Adb } from "../adb.js";
2
- import { WrapWritableStream, WritableStream } from "../stream/index.js";
3
- import { escapeArg } from "./subprocess/index.js";
4
- import type { AdbSync } from "./sync/index.js";
5
-
6
- export function install(
7
- adb: Adb,
8
- ): WritableStream<Uint8Array> {
9
- const filename = `/data/local/tmp/${Math.random().toString().substring(2)}.apk`;
10
-
11
- let sync!: AdbSync;
12
- return new WrapWritableStream<Uint8Array>({
13
- async start() {
14
- // TODO: install: support other install apk methods (streaming, etc.)
15
-
16
- // Upload apk file to tmp folder
17
- sync = await adb.sync();
18
- return sync.write(filename, undefined, undefined);
19
- },
20
- async close() {
21
- sync.dispose();
22
-
23
- // Invoke `pm install` to install it
24
- await adb.subprocess.spawnAndWaitLegacy(['pm', 'install', escapeArg(filename)]);
25
-
26
- // Remove the temp file
27
- await adb.rm(filename);
28
- }
29
- });
30
- }
1
+ import type { Adb } from "../adb.js";
2
+ import { WrapWritableStream, WritableStream } from "../stream/index.js";
3
+ import { escapeArg } from "./subprocess/index.js";
4
+ import type { AdbSync } from "./sync/index.js";
5
+
6
+ export function install(
7
+ adb: Adb,
8
+ ): WritableStream<Uint8Array> {
9
+ const filename = `/data/local/tmp/${Math.random().toString().substring(2)}.apk`;
10
+
11
+ let sync!: AdbSync;
12
+ return new WrapWritableStream<Uint8Array>({
13
+ async start() {
14
+ // TODO: install: support other install apk methods (streaming, etc.)
15
+
16
+ // Upload apk file to tmp folder
17
+ sync = await adb.sync();
18
+ return sync.write(filename, undefined, undefined);
19
+ },
20
+ async close() {
21
+ sync.dispose();
22
+
23
+ // Invoke `pm install` to install it
24
+ await adb.subprocess.spawnAndWaitLegacy(['pm', 'install', escapeArg(filename)]);
25
+
26
+ // Remove the temp file
27
+ await adb.rm(filename);
28
+ }
29
+ });
30
+ }