@yume-chan/adb 0.0.9 → 0.0.10

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 (205) hide show
  1. package/CHANGELOG.json +23 -0
  2. package/CHANGELOG.md +16 -0
  3. package/LICENSE +21 -21
  4. package/README.md +227 -257
  5. package/dts/adb.d.ts.map +1 -1
  6. package/dts/auth.d.ts +11 -1
  7. package/dts/auth.d.ts.map +1 -1
  8. package/dts/backend.d.ts +3 -5
  9. package/dts/backend.d.ts.map +1 -1
  10. package/dts/commands/demo-mode.d.ts +3 -3
  11. package/dts/commands/demo-mode.d.ts.map +1 -1
  12. package/dts/commands/reverse.d.ts +2 -2
  13. package/dts/commands/reverse.d.ts.map +1 -1
  14. package/dts/commands/shell/index.d.ts +31 -5
  15. package/dts/commands/shell/index.d.ts.map +1 -1
  16. package/dts/commands/shell/legacy.d.ts +13 -2
  17. package/dts/commands/shell/legacy.d.ts.map +1 -1
  18. package/dts/commands/shell/protocol.d.ts +11 -3
  19. package/dts/commands/shell/protocol.d.ts.map +1 -1
  20. package/dts/commands/shell/types.d.ts +35 -3
  21. package/dts/commands/shell/types.d.ts.map +1 -1
  22. package/dts/commands/sync/request.d.ts +1 -1
  23. package/dts/commands/sync/request.d.ts.map +1 -1
  24. package/dts/commands/sync/response.d.ts +2 -2
  25. package/dts/commands/sync/response.d.ts.map +1 -1
  26. package/dts/commands/sync/sync.d.ts.map +1 -1
  27. package/dts/crypto.d.ts +7 -0
  28. package/dts/crypto.d.ts.map +1 -1
  29. package/dts/packet.d.ts.map +1 -1
  30. package/dts/socket/close-event-emitter.d.ts.map +1 -1
  31. package/dts/socket/controller.d.ts.map +1 -1
  32. package/dts/socket/data-event-emitter.d.ts.map +1 -1
  33. package/dts/socket/dispatcher.d.ts.map +1 -1
  34. package/dts/stream/buffered-stream.d.ts +2 -4
  35. package/dts/stream/buffered-stream.d.ts.map +1 -1
  36. package/dts/utils/encoding.d.ts +3 -0
  37. package/dts/utils/encoding.d.ts.map +1 -0
  38. package/dts/utils/index.d.ts +1 -0
  39. package/dts/utils/index.d.ts.map +1 -1
  40. package/esm/adb.js +3 -2
  41. package/esm/adb.js.map +1 -1
  42. package/esm/auth.js +2 -2
  43. package/esm/auth.js.map +1 -1
  44. package/esm/commands/demo-mode.js +9 -9
  45. package/esm/commands/demo-mode.js.map +1 -1
  46. package/esm/commands/reverse.js +3 -2
  47. package/esm/commands/reverse.js.map +1 -1
  48. package/esm/commands/shell/index.js +28 -18
  49. package/esm/commands/shell/index.js.map +1 -1
  50. package/esm/commands/shell/legacy.js +16 -0
  51. package/esm/commands/shell/legacy.js.map +1 -1
  52. package/esm/commands/shell/protocol.js +36 -9
  53. package/esm/commands/shell/protocol.js.map +1 -1
  54. package/esm/commands/sync/request.js +5 -4
  55. package/esm/commands/sync/request.js.map +1 -1
  56. package/esm/commands/sync/response.js +4 -3
  57. package/esm/commands/sync/response.js.map +1 -1
  58. package/esm/commands/sync/sync.js.map +1 -1
  59. package/esm/crypto.js +7 -2
  60. package/esm/crypto.js.map +1 -1
  61. package/esm/packet.js +12 -14
  62. package/esm/packet.js.map +1 -1
  63. package/esm/socket/close-event-emitter.js.map +1 -1
  64. package/esm/socket/controller.js.map +1 -1
  65. package/esm/socket/data-event-emitter.js.map +1 -1
  66. package/esm/socket/dispatcher.js +7 -7
  67. package/esm/socket/dispatcher.js.map +1 -1
  68. package/esm/stream/buffered-stream.js +0 -6
  69. package/esm/stream/buffered-stream.js.map +1 -1
  70. package/esm/utils/encoding.js +11 -0
  71. package/esm/utils/encoding.js.map +1 -0
  72. package/esm/utils/index.js +1 -0
  73. package/esm/utils/index.js.map +1 -1
  74. package/package.json +44 -51
  75. package/src/adb.ts +243 -242
  76. package/src/auth.ts +166 -156
  77. package/src/backend.ts +20 -24
  78. package/src/commands/base.ts +11 -11
  79. package/src/commands/demo-mode.ts +160 -160
  80. package/src/commands/framebuffer.ts +73 -73
  81. package/src/commands/index.ts +8 -8
  82. package/src/commands/install.ts +21 -21
  83. package/src/commands/reverse.ts +134 -133
  84. package/src/commands/shell/index.ts +87 -68
  85. package/src/commands/shell/legacy.ts +59 -42
  86. package/src/commands/shell/protocol.ts +121 -94
  87. package/src/commands/shell/types.ts +55 -21
  88. package/src/commands/shell/utils.ts +20 -20
  89. package/src/commands/sync/index.ts +7 -7
  90. package/src/commands/sync/list.ts +39 -39
  91. package/src/commands/sync/pull.ts +34 -34
  92. package/src/commands/sync/push.ts +46 -46
  93. package/src/commands/sync/request.ts +49 -48
  94. package/src/commands/sync/response.ts +58 -57
  95. package/src/commands/sync/stat.ts +121 -121
  96. package/src/commands/sync/sync.ts +113 -113
  97. package/src/commands/tcpip.ts +21 -21
  98. package/src/crypto.ts +285 -280
  99. package/src/features.ts +5 -5
  100. package/src/index.ts +10 -10
  101. package/src/packet.ts +84 -89
  102. package/src/socket/close-event-emitter.ts +28 -28
  103. package/src/socket/controller.ts +105 -105
  104. package/src/socket/data-event-emitter.ts +27 -27
  105. package/src/socket/dispatcher.ts +269 -269
  106. package/src/socket/index.ts +6 -6
  107. package/src/socket/logger.ts +12 -12
  108. package/src/socket/socket.ts +28 -28
  109. package/src/stream/buffered-stream.ts +92 -100
  110. package/src/stream/index.ts +2 -2
  111. package/src/stream/stream.ts +50 -50
  112. package/src/utils/auto-reset-event.ts +41 -41
  113. package/src/utils/base64.ts +274 -274
  114. package/src/utils/chunk.ts +70 -70
  115. package/src/utils/encoding.ts +13 -0
  116. package/src/utils/event-queue.ts +145 -145
  117. package/src/utils/index.ts +5 -4
  118. package/cjs/adb.js +0 -205
  119. package/cjs/adb.js.map +0 -1
  120. package/cjs/auth.js +0 -141
  121. package/cjs/auth.js.map +0 -1
  122. package/cjs/backend.js +0 -3
  123. package/cjs/backend.js.map +0 -1
  124. package/cjs/commands/base.js +0 -12
  125. package/cjs/commands/base.js.map +0 -1
  126. package/cjs/commands/demo-mode.js +0 -174
  127. package/cjs/commands/demo-mode.js.map +0 -1
  128. package/cjs/commands/framebuffer.js +0 -66
  129. package/cjs/commands/framebuffer.js.map +0 -1
  130. package/cjs/commands/index.js +0 -12
  131. package/cjs/commands/index.js.map +0 -1
  132. package/cjs/commands/install.js +0 -20
  133. package/cjs/commands/install.js.map +0 -1
  134. package/cjs/commands/reverse.js +0 -105
  135. package/cjs/commands/reverse.js.map +0 -1
  136. package/cjs/commands/shell/index.js +0 -56
  137. package/cjs/commands/shell/index.js.map +0 -1
  138. package/cjs/commands/shell/legacy.js +0 -37
  139. package/cjs/commands/shell/legacy.js.map +0 -1
  140. package/cjs/commands/shell/protocol.js +0 -83
  141. package/cjs/commands/shell/protocol.js.map +0 -1
  142. package/cjs/commands/shell/types.js +0 -3
  143. package/cjs/commands/shell/types.js.map +0 -1
  144. package/cjs/commands/shell/utils.js +0 -23
  145. package/cjs/commands/shell/utils.js.map +0 -1
  146. package/cjs/commands/sync/index.js +0 -11
  147. package/cjs/commands/sync/index.js.map +0 -1
  148. package/cjs/commands/sync/list.js +0 -36
  149. package/cjs/commands/sync/list.js.map +0 -1
  150. package/cjs/commands/sync/pull.js +0 -34
  151. package/cjs/commands/sync/pull.js.map +0 -1
  152. package/cjs/commands/sync/push.js +0 -49
  153. package/cjs/commands/sync/push.js.map +0 -1
  154. package/cjs/commands/sync/request.js +0 -48
  155. package/cjs/commands/sync/request.js.map +0 -1
  156. package/cjs/commands/sync/response.js +0 -53
  157. package/cjs/commands/sync/response.js.map +0 -1
  158. package/cjs/commands/sync/stat.js +0 -109
  159. package/cjs/commands/sync/stat.js.map +0 -1
  160. package/cjs/commands/sync/sync.js +0 -118
  161. package/cjs/commands/sync/sync.js.map +0 -1
  162. package/cjs/commands/tcpip.js +0 -28
  163. package/cjs/commands/tcpip.js.map +0 -1
  164. package/cjs/crypto.js +0 -231
  165. package/cjs/crypto.js.map +0 -1
  166. package/cjs/features.js +0 -10
  167. package/cjs/features.js.map +0 -1
  168. package/cjs/index.js +0 -14
  169. package/cjs/index.js.map +0 -1
  170. package/cjs/packet.js +0 -77
  171. package/cjs/packet.js.map +0 -1
  172. package/cjs/socket/close-event-emitter.js +0 -32
  173. package/cjs/socket/close-event-emitter.js.map +0 -1
  174. package/cjs/socket/controller.js +0 -84
  175. package/cjs/socket/controller.js.map +0 -1
  176. package/cjs/socket/data-event-emitter.js +0 -29
  177. package/cjs/socket/data-event-emitter.js.map +0 -1
  178. package/cjs/socket/dispatcher.js +0 -219
  179. package/cjs/socket/dispatcher.js.map +0 -1
  180. package/cjs/socket/index.js +0 -10
  181. package/cjs/socket/index.js.map +0 -1
  182. package/cjs/socket/logger.js +0 -3
  183. package/cjs/socket/logger.js.map +0 -1
  184. package/cjs/socket/socket.js +0 -24
  185. package/cjs/socket/socket.js.map +0 -1
  186. package/cjs/stream/buffered-stream.js +0 -78
  187. package/cjs/stream/buffered-stream.js.map +0 -1
  188. package/cjs/stream/index.js +0 -6
  189. package/cjs/stream/index.js.map +0 -1
  190. package/cjs/stream/stream.js +0 -45
  191. package/cjs/stream/stream.js.map +0 -1
  192. package/cjs/utils/auto-reset-event.js +0 -37
  193. package/cjs/utils/auto-reset-event.js.map +0 -1
  194. package/cjs/utils/base64.js +0 -210
  195. package/cjs/utils/base64.js.map +0 -1
  196. package/cjs/utils/chunk.js +0 -75
  197. package/cjs/utils/chunk.js.map +0 -1
  198. package/cjs/utils/event-queue.js +0 -108
  199. package/cjs/utils/event-queue.js.map +0 -1
  200. package/cjs/utils/index.js +0 -8
  201. package/cjs/utils/index.js.map +0 -1
  202. package/tsconfig.cjs.json +0 -11
  203. package/tsconfig.esm.json +0 -28
  204. package/tsconfig.esm.tsbuildinfo +0 -1305
  205. package/tsconfig.json +0 -18
@@ -1,160 +1,160 @@
1
- import { AdbCommandBase } from './base';
2
-
3
- export enum AdbDemoModeWifiSignalStrength {
4
- Hidden = 'null',
5
- Level0 = '0',
6
- Level1 = '1',
7
- Level2 = '2',
8
- Level3 = '3',
9
- Level4 = '4',
10
- }
11
-
12
- // https://cs.android.com/android/platform/superproject/+/master:frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java;l=1073
13
- export const AdbDemoModeMobileDataTypes = ['1x', '3g', '4g', '4g+', '5g', '5ge', '5g+',
14
- 'e', 'g', 'h', 'h+', 'lte', 'lte+', 'dis', 'not', 'null'] as const;
15
-
16
- export type AdbDemoModeMobileDataType = (typeof AdbDemoModeMobileDataTypes)[number];
17
-
18
- // https://cs.android.com/android/platform/superproject/+/master:frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java;l=3136
19
- export const AdbDemoModeStatusBarModes = ['opaque', 'translucent', 'semi-transparent', 'transparent', 'warning'] as const;
20
-
21
- export type AdbDemoModeStatusBarMode = (typeof AdbDemoModeStatusBarModes)[number];
22
-
23
- export class AdbDemoMode extends AdbCommandBase {
24
- public static readonly AllowedSettingKey = 'sysui_demo_allowed';
25
-
26
- // Demo Mode actually doesn't have a setting indicates its enablement
27
- // However Developer Mode menu uses this key
28
- // So we can only try our best to guess if it's enabled
29
- public static readonly EnabledSettingKey = 'sysui_tuner_demo_on';
30
-
31
- public async getAllowed(): Promise<boolean> {
32
- const result = await this.adb.childProcess.exec('settings', 'get', 'global', AdbDemoMode.AllowedSettingKey);
33
- return result.trim() === '1';
34
- }
35
-
36
- public async setAllowed(value: boolean): Promise<void> {
37
- if (value) {
38
- await this.adb.childProcess.exec('settings', 'put', 'global', AdbDemoMode.AllowedSettingKey, '1');
39
- } else {
40
- await this.setEnabled(false);
41
- await this.adb.childProcess.exec('settings', 'delete', 'global', AdbDemoMode.AllowedSettingKey);
42
- }
43
- }
44
-
45
- public async getEnabled(): Promise<boolean> {
46
- const result = await this.adb.childProcess.exec('settings', 'get', 'global', AdbDemoMode.EnabledSettingKey);
47
- return result.trim() === '1';
48
- }
49
-
50
- public async setEnabled(value: boolean): Promise<void> {
51
- if (value) {
52
- await this.adb.childProcess.exec('settings', 'put', 'global', AdbDemoMode.EnabledSettingKey, '1');
53
- } else {
54
- await this.adb.childProcess.exec('settings', 'delete', 'global', AdbDemoMode.EnabledSettingKey);
55
- await this.broadcast('exit');
56
- }
57
- }
58
-
59
- public async broadcast(command: string, extra?: Record<string, string>): Promise<void> {
60
- await this.adb.childProcess.exec(
61
- 'am',
62
- 'broadcast',
63
- '-a',
64
- 'com.android.systemui.demo',
65
- '-e',
66
- 'command',
67
- command,
68
- ...(extra ? Object.entries(extra).flatMap(([key, value]) => ['-e', key, value]) : []),
69
- );
70
- }
71
-
72
- public async setBatteryLevel(level: number): Promise<void> {
73
- await this.broadcast('battery', { level: level.toString() });
74
- }
75
-
76
- public async setBatteryCharging(value: boolean): Promise<void> {
77
- await this.broadcast('battery', { plugged: value.toString() });
78
- }
79
-
80
- public async setPowerSaveMode(value: boolean): Promise<void> {
81
- await this.broadcast('battery', { powersave: value.toString() });
82
- }
83
-
84
- public async setAirplaneMode(show: boolean): Promise<void> {
85
- await this.broadcast('network', { airplane: show ? 'show' : 'hide' });
86
- }
87
-
88
- public async setWifiSignalStrength(value: AdbDemoModeWifiSignalStrength): Promise<void> {
89
- await this.broadcast('network', { wifi: 'show', level: value });
90
- }
91
-
92
- public async setMobileDataType(value: AdbDemoModeMobileDataType): Promise<void> {
93
- for (let i = 0; i < 2; i += 1) {
94
- await this.broadcast('network', {
95
- mobile: 'show',
96
- sims: '1',
97
- nosim: 'hide',
98
- slot: '0',
99
- datatype: value,
100
- fully: 'true',
101
- roam: 'false',
102
- level: '4',
103
- inflate: 'false',
104
- activity: 'in',
105
- carriernetworkchange: 'hide',
106
- });
107
- }
108
- }
109
-
110
- public async setMobileSignalStrength(value: AdbDemoModeWifiSignalStrength): Promise<void> {
111
- await this.broadcast('network', { mobile: 'show', level: value });
112
- }
113
-
114
- public async setNoSimCardIcon(show: boolean): Promise<void> {
115
- await this.broadcast('network', { nosim: show ? 'show' : 'hide' });
116
- }
117
-
118
- public async setStatusBarMode(mode: AdbDemoModeStatusBarMode): Promise<void> {
119
- await this.broadcast('bars', { mode });
120
- }
121
-
122
- public async setVibrateModeEnabled(value: boolean): Promise<void> {
123
- // https://cs.android.com/android/platform/superproject/+/master:frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/DemoStatusIcons.java;l=103
124
- await this.broadcast('status', { volume: value ? 'vibrate' : 'hide' });
125
- }
126
-
127
- public async setBluetoothConnected(value: boolean): Promise<void> {
128
- // https://cs.android.com/android/platform/superproject/+/master:frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/DemoStatusIcons.java;l=114
129
- await this.broadcast('status', { bluetooth: value ? 'connected' : 'hide' });
130
- }
131
-
132
- public async setLocatingIcon(show: boolean): Promise<void> {
133
- await this.broadcast('status', { location: show ? 'show' : 'hide' });
134
- }
135
-
136
- public async setAlarmIcon(show: boolean): Promise<void> {
137
- await this.broadcast('status', { alarm: show ? 'show' : 'hide' });
138
- }
139
-
140
- public async setSyncingIcon(show: boolean): Promise<void> {
141
- await this.broadcast('status', { sync: show ? 'show' : 'hide' });
142
- }
143
-
144
- public async setMuteIcon(show: boolean): Promise<void> {
145
- await this.broadcast('status', { mute: show ? 'show' : 'hide' });
146
- }
147
-
148
- public async setSpeakerPhoneIcon(show: boolean): Promise<void> {
149
- await this.broadcast('status', { speakerphone: show ? 'show' : 'hide' });
150
- }
151
-
152
- public async setNotificationsVisibility(show: boolean): Promise<void> {
153
- // https://cs.android.com/android/platform/superproject/+/master:frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java;l=3131
154
- await this.broadcast('notifications', { visible: show.toString() });
155
- }
156
-
157
- public async setTime(hour: number, minute: number): Promise<void> {
158
- await this.broadcast('clock', { hhmm: `${hour.toString().padStart(2, '0')}${minute.toString().padStart(2, '0')}` });
159
- }
160
- }
1
+ import { AdbCommandBase } from './base';
2
+
3
+ export enum AdbDemoModeSignalStrength {
4
+ Hidden = 'null',
5
+ Level0 = '0',
6
+ Level1 = '1',
7
+ Level2 = '2',
8
+ Level3 = '3',
9
+ Level4 = '4',
10
+ }
11
+
12
+ // https://cs.android.com/android/platform/superproject/+/master:frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java;l=1073
13
+ export const AdbDemoModeMobileDataTypes = ['1x', '3g', '4g', '4g+', '5g', '5ge', '5g+',
14
+ 'e', 'g', 'h', 'h+', 'lte', 'lte+', 'dis', 'not', 'null'] as const;
15
+
16
+ export type AdbDemoModeMobileDataType = (typeof AdbDemoModeMobileDataTypes)[number];
17
+
18
+ // https://cs.android.com/android/platform/superproject/+/master:frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java;l=3136
19
+ export const AdbDemoModeStatusBarModes = ['opaque', 'translucent', 'semi-transparent', 'transparent', 'warning'] as const;
20
+
21
+ export type AdbDemoModeStatusBarMode = (typeof AdbDemoModeStatusBarModes)[number];
22
+
23
+ export class AdbDemoMode extends AdbCommandBase {
24
+ public static readonly AllowedSettingKey = 'sysui_demo_allowed';
25
+
26
+ // Demo Mode actually doesn't have a setting indicates its enablement
27
+ // However Developer Mode menu uses this key
28
+ // So we can only try our best to guess if it's enabled
29
+ public static readonly EnabledSettingKey = 'sysui_tuner_demo_on';
30
+
31
+ public async getAllowed(): Promise<boolean> {
32
+ const result = await this.adb.childProcess.exec('settings', 'get', 'global', AdbDemoMode.AllowedSettingKey);
33
+ return result.trim() === '1';
34
+ }
35
+
36
+ public async setAllowed(value: boolean): Promise<void> {
37
+ if (value) {
38
+ await this.adb.childProcess.exec('settings', 'put', 'global', AdbDemoMode.AllowedSettingKey, '1');
39
+ } else {
40
+ await this.setEnabled(false);
41
+ await this.adb.childProcess.exec('settings', 'delete', 'global', AdbDemoMode.AllowedSettingKey);
42
+ }
43
+ }
44
+
45
+ public async getEnabled(): Promise<boolean> {
46
+ const result = await this.adb.childProcess.exec('settings', 'get', 'global', AdbDemoMode.EnabledSettingKey);
47
+ return result.trim() === '1';
48
+ }
49
+
50
+ public async setEnabled(value: boolean): Promise<void> {
51
+ if (value) {
52
+ await this.adb.childProcess.exec('settings', 'put', 'global', AdbDemoMode.EnabledSettingKey, '1');
53
+ } else {
54
+ await this.adb.childProcess.exec('settings', 'delete', 'global', AdbDemoMode.EnabledSettingKey);
55
+ await this.broadcast('exit');
56
+ }
57
+ }
58
+
59
+ public async broadcast(command: string, extra?: Record<string, string>): Promise<void> {
60
+ await this.adb.childProcess.exec(
61
+ 'am',
62
+ 'broadcast',
63
+ '-a',
64
+ 'com.android.systemui.demo',
65
+ '-e',
66
+ 'command',
67
+ command,
68
+ ...(extra ? Object.entries(extra).flatMap(([key, value]) => ['-e', key, value]) : []),
69
+ );
70
+ }
71
+
72
+ public async setBatteryLevel(level: number): Promise<void> {
73
+ await this.broadcast('battery', { level: level.toString() });
74
+ }
75
+
76
+ public async setBatteryCharging(value: boolean): Promise<void> {
77
+ await this.broadcast('battery', { plugged: value.toString() });
78
+ }
79
+
80
+ public async setPowerSaveMode(value: boolean): Promise<void> {
81
+ await this.broadcast('battery', { powersave: value.toString() });
82
+ }
83
+
84
+ public async setAirplaneMode(show: boolean): Promise<void> {
85
+ await this.broadcast('network', { airplane: show ? 'show' : 'hide' });
86
+ }
87
+
88
+ public async setWifiSignalStrength(value: AdbDemoModeSignalStrength): Promise<void> {
89
+ await this.broadcast('network', { wifi: 'show', level: value });
90
+ }
91
+
92
+ public async setMobileDataType(value: AdbDemoModeMobileDataType): Promise<void> {
93
+ for (let i = 0; i < 2; i += 1) {
94
+ await this.broadcast('network', {
95
+ mobile: 'show',
96
+ sims: '1',
97
+ nosim: 'hide',
98
+ slot: '0',
99
+ datatype: value,
100
+ fully: 'true',
101
+ roam: 'false',
102
+ level: '4',
103
+ inflate: 'false',
104
+ activity: 'in',
105
+ carriernetworkchange: 'hide',
106
+ });
107
+ }
108
+ }
109
+
110
+ public async setMobileSignalStrength(value: AdbDemoModeSignalStrength): Promise<void> {
111
+ await this.broadcast('network', { mobile: 'show', level: value });
112
+ }
113
+
114
+ public async setNoSimCardIcon(show: boolean): Promise<void> {
115
+ await this.broadcast('network', { nosim: show ? 'show' : 'hide' });
116
+ }
117
+
118
+ public async setStatusBarMode(mode: AdbDemoModeStatusBarMode): Promise<void> {
119
+ await this.broadcast('bars', { mode });
120
+ }
121
+
122
+ public async setVibrateModeEnabled(value: boolean): Promise<void> {
123
+ // https://cs.android.com/android/platform/superproject/+/master:frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/DemoStatusIcons.java;l=103
124
+ await this.broadcast('status', { volume: value ? 'vibrate' : 'hide' });
125
+ }
126
+
127
+ public async setBluetoothConnected(value: boolean): Promise<void> {
128
+ // https://cs.android.com/android/platform/superproject/+/master:frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/DemoStatusIcons.java;l=114
129
+ await this.broadcast('status', { bluetooth: value ? 'connected' : 'hide' });
130
+ }
131
+
132
+ public async setLocatingIcon(show: boolean): Promise<void> {
133
+ await this.broadcast('status', { location: show ? 'show' : 'hide' });
134
+ }
135
+
136
+ public async setAlarmIcon(show: boolean): Promise<void> {
137
+ await this.broadcast('status', { alarm: show ? 'show' : 'hide' });
138
+ }
139
+
140
+ public async setSyncingIcon(show: boolean): Promise<void> {
141
+ await this.broadcast('status', { sync: show ? 'show' : 'hide' });
142
+ }
143
+
144
+ public async setMuteIcon(show: boolean): Promise<void> {
145
+ await this.broadcast('status', { mute: show ? 'show' : 'hide' });
146
+ }
147
+
148
+ public async setSpeakerPhoneIcon(show: boolean): Promise<void> {
149
+ await this.broadcast('status', { speakerphone: show ? 'show' : 'hide' });
150
+ }
151
+
152
+ public async setNotificationsVisibility(show: boolean): Promise<void> {
153
+ // https://cs.android.com/android/platform/superproject/+/master:frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java;l=3131
154
+ await this.broadcast('notifications', { visible: show.toString() });
155
+ }
156
+
157
+ public async setTime(hour: number, minute: number): Promise<void> {
158
+ await this.broadcast('clock', { hhmm: `${hour.toString().padStart(2, '0')}${minute.toString().padStart(2, '0')}` });
159
+ }
160
+ }
@@ -1,73 +1,73 @@
1
- import Struct from "@yume-chan/struct";
2
- import { Adb } from '../adb';
3
- import { AdbBufferedStream } from '../stream';
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
- .uint8ClampedArray('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
- .uint8ClampedArray('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 { Adb } from '../adb';
3
+ import { AdbBufferedStream } from '../stream';
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
+ .uint8ClampedArray('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
+ .uint8ClampedArray('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';
2
- export * from './demo-mode';
3
- export * from './framebuffer';
4
- export * from './install';
5
- export * from './reverse';
6
- export * from './shell';
7
- export * from './sync';
8
- export * from './tcpip';
1
+ export * from './base';
2
+ export * from './demo-mode';
3
+ export * from './framebuffer';
4
+ export * from './install';
5
+ export * from './reverse';
6
+ export * from './shell';
7
+ export * from './sync';
8
+ export * from './tcpip';
@@ -1,21 +1,21 @@
1
- import { Adb } from "../adb";
2
- import { escapeArg } from "./shell";
3
-
4
- export async function install(
5
- adb: Adb,
6
- apk: ArrayLike<number> | ArrayBufferLike | AsyncIterable<ArrayBuffer>,
7
- onProgress?: (uploaded: number) => void,
8
- ): Promise<void> {
9
- const filename = `/data/local/tmp/${Math.random().toString().substr(2)}.apk`;
10
-
11
- // Upload apk file to tmp folder
12
- const sync = await adb.sync();
13
- await sync.write(filename, apk, undefined, undefined, onProgress);
14
- sync.dispose();
15
-
16
- // Invoke `pm install` to install it
17
- await adb.childProcess.exec('pm', 'install', escapeArg(filename));
18
-
19
- // Remove the temp file
20
- await adb.rm(filename);
21
- }
1
+ import { Adb } from "../adb";
2
+ import { escapeArg } from "./shell";
3
+
4
+ export async function install(
5
+ adb: Adb,
6
+ apk: ArrayLike<number> | ArrayBufferLike | AsyncIterable<ArrayBuffer>,
7
+ onProgress?: (uploaded: number) => void,
8
+ ): Promise<void> {
9
+ const filename = `/data/local/tmp/${Math.random().toString().substr(2)}.apk`;
10
+
11
+ // Upload apk file to tmp folder
12
+ const sync = await adb.sync();
13
+ await sync.write(filename, apk, undefined, undefined, onProgress);
14
+ sync.dispose();
15
+
16
+ // Invoke `pm install` to install it
17
+ await adb.childProcess.exec('pm', 'install', escapeArg(filename));
18
+
19
+ // Remove the temp file
20
+ await adb.rm(filename);
21
+ }