@yume-chan/adb 2.6.2 → 3.0.0-beta.0

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 (451) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/esm/adb.d.ts +18 -15
  4. package/esm/adb.d.ts.map +1 -1
  5. package/esm/adb.js +18 -11
  6. package/esm/adb.js.map +1 -1
  7. package/esm/banner.d.ts +1 -1
  8. package/esm/banner.d.ts.map +1 -1
  9. package/esm/banner.js.map +1 -1
  10. package/esm/daemon/auth/authenticator.d.ts +28 -0
  11. package/esm/daemon/auth/authenticator.d.ts.map +1 -0
  12. package/esm/daemon/auth/authenticator.js +108 -0
  13. package/esm/daemon/auth/authenticator.js.map +1 -0
  14. package/esm/daemon/auth/index.d.ts +5 -0
  15. package/esm/daemon/auth/index.d.ts.map +1 -0
  16. package/esm/daemon/auth/index.js +5 -0
  17. package/esm/daemon/auth/index.js.map +1 -0
  18. package/esm/daemon/auth/packet-processor.d.ts +42 -0
  19. package/esm/daemon/auth/packet-processor.d.ts.map +1 -0
  20. package/esm/daemon/auth/packet-processor.js +129 -0
  21. package/esm/daemon/auth/packet-processor.js.map +1 -0
  22. package/esm/daemon/auth/public-key.d.ts +8 -0
  23. package/esm/daemon/auth/public-key.d.ts.map +1 -0
  24. package/esm/daemon/auth/public-key.js +74 -0
  25. package/esm/daemon/auth/public-key.js.map +1 -0
  26. package/esm/daemon/auth/type.d.ts +5 -0
  27. package/esm/daemon/auth/type.d.ts.map +1 -0
  28. package/esm/daemon/auth/type.js +2 -0
  29. package/esm/daemon/auth/type.js.map +1 -0
  30. package/esm/daemon/crypto.d.ts +6 -5
  31. package/esm/daemon/crypto.d.ts.map +1 -1
  32. package/esm/daemon/crypto.js +23 -72
  33. package/esm/daemon/crypto.js.map +1 -1
  34. package/esm/daemon/dispatcher.d.ts +3 -3
  35. package/esm/daemon/dispatcher.d.ts.map +1 -1
  36. package/esm/daemon/dispatcher.js +11 -4
  37. package/esm/daemon/dispatcher.js.map +1 -1
  38. package/esm/daemon/index.d.ts +1 -1
  39. package/esm/daemon/index.d.ts.map +1 -1
  40. package/esm/daemon/index.js +1 -1
  41. package/esm/daemon/index.js.map +1 -1
  42. package/esm/daemon/socket.d.ts +3 -3
  43. package/esm/daemon/socket.d.ts.map +1 -1
  44. package/esm/daemon/transport.d.ts +13 -65
  45. package/esm/daemon/transport.d.ts.map +1 -1
  46. package/esm/daemon/transport.js +18 -140
  47. package/esm/daemon/transport.js.map +1 -1
  48. package/esm/device-observer.d.ts +2 -3
  49. package/esm/device-observer.d.ts.map +1 -1
  50. package/esm/features-value.d.ts +40 -0
  51. package/esm/features-value.d.ts.map +1 -0
  52. package/esm/features-value.js +46 -0
  53. package/esm/features-value.js.map +1 -0
  54. package/esm/features.d.ts +4 -12
  55. package/esm/features.d.ts.map +1 -1
  56. package/esm/features.js +27 -13
  57. package/esm/features.js.map +1 -1
  58. package/esm/index.d.ts +1 -1
  59. package/esm/index.d.ts.map +1 -1
  60. package/esm/index.js +1 -1
  61. package/esm/index.js.map +1 -1
  62. package/esm/server/client.d.ts +7 -7
  63. package/esm/server/client.d.ts.map +1 -1
  64. package/esm/server/client.js +69 -86
  65. package/esm/server/client.js.map +1 -1
  66. package/esm/server/commands/wireless.js +1 -1
  67. package/esm/server/commands/wireless.js.map +1 -1
  68. package/esm/server/{stream.d.ts → data-connection.d.ts} +5 -5
  69. package/esm/server/data-connection.d.ts.map +1 -0
  70. package/esm/server/{stream.js → data-connection.js} +4 -4
  71. package/esm/server/data-connection.js.map +1 -0
  72. package/esm/server/index.d.ts +1 -1
  73. package/esm/server/index.d.ts.map +1 -1
  74. package/esm/server/index.js +1 -1
  75. package/esm/server/index.js.map +1 -1
  76. package/esm/server/observer.d.ts.map +1 -1
  77. package/esm/server/observer.js +14 -13
  78. package/esm/server/observer.js.map +1 -1
  79. package/esm/server/transport.d.ts +4 -6
  80. package/esm/server/transport.d.ts.map +1 -1
  81. package/esm/server/transport.js +9 -24
  82. package/esm/server/transport.js.map +1 -1
  83. package/esm/service/framebuffer.d.ts.map +1 -0
  84. package/esm/service/framebuffer.js.map +1 -0
  85. package/esm/{commands → service}/index.d.ts +1 -2
  86. package/esm/service/index.d.ts.map +1 -0
  87. package/esm/{commands → service}/index.js +1 -2
  88. package/esm/service/index.js.map +1 -0
  89. package/esm/{commands → service}/power.d.ts +4 -2
  90. package/esm/service/power.d.ts.map +1 -0
  91. package/esm/{commands → service}/power.js +11 -5
  92. package/esm/service/power.js.map +1 -0
  93. package/esm/service/reverse/error.d.ts +14 -0
  94. package/esm/service/reverse/error.d.ts.map +1 -0
  95. package/esm/service/reverse/error.js +21 -0
  96. package/esm/service/reverse/error.js.map +1 -0
  97. package/esm/service/reverse/index.d.ts +3 -0
  98. package/esm/service/reverse/index.d.ts.map +1 -0
  99. package/esm/service/reverse/index.js +4 -0
  100. package/esm/service/reverse/index.js.map +1 -0
  101. package/esm/service/reverse/response.d.ts +2 -0
  102. package/esm/service/reverse/response.d.ts.map +1 -0
  103. package/esm/service/reverse/response.js +30 -0
  104. package/esm/service/reverse/response.js.map +1 -0
  105. package/esm/service/reverse/service.d.ts +59 -0
  106. package/esm/service/reverse/service.d.ts.map +1 -0
  107. package/esm/{commands/reverse.js → service/reverse/service.js} +16 -45
  108. package/esm/service/reverse/service.js.map +1 -0
  109. package/esm/{commands → service}/subprocess/index.d.ts +1 -0
  110. package/esm/service/subprocess/index.d.ts.map +1 -0
  111. package/esm/{commands → service}/subprocess/index.js +1 -0
  112. package/esm/service/subprocess/index.js.map +1 -0
  113. package/esm/service/subprocess/none/index.d.ts.map +1 -0
  114. package/esm/service/subprocess/none/index.js.map +1 -0
  115. package/esm/{commands → service}/subprocess/none/process.d.ts +2 -2
  116. package/esm/service/subprocess/none/process.d.ts.map +1 -0
  117. package/esm/service/subprocess/none/process.js.map +1 -0
  118. package/esm/{commands → service}/subprocess/none/pty.d.ts +4 -4
  119. package/esm/service/subprocess/none/pty.d.ts.map +1 -0
  120. package/esm/{commands → service}/subprocess/none/pty.js +1 -1
  121. package/esm/service/subprocess/none/pty.js.map +1 -0
  122. package/esm/service/subprocess/none/service.d.ts +10 -0
  123. package/esm/service/subprocess/none/service.d.ts.map +1 -0
  124. package/esm/service/subprocess/none/service.js +44 -0
  125. package/esm/service/subprocess/none/service.js.map +1 -0
  126. package/esm/service/subprocess/none/spawner.d.ts +15 -0
  127. package/esm/service/subprocess/none/spawner.d.ts.map +1 -0
  128. package/esm/service/subprocess/none/spawner.js +31 -0
  129. package/esm/service/subprocess/none/spawner.js.map +1 -0
  130. package/esm/{commands → service}/subprocess/pty.d.ts +1 -1
  131. package/esm/service/subprocess/pty.d.ts.map +1 -0
  132. package/esm/{commands → service}/subprocess/pty.js.map +1 -1
  133. package/esm/service/subprocess/service.d.ts.map +1 -0
  134. package/esm/{commands → service}/subprocess/service.js +1 -1
  135. package/esm/service/subprocess/service.js.map +1 -0
  136. package/esm/service/subprocess/shell/index.d.ts +5 -0
  137. package/esm/{commands/subprocess/none → service/subprocess/shell}/index.d.ts.map +1 -1
  138. package/esm/service/subprocess/shell/index.js +6 -0
  139. package/esm/{commands/subprocess/none → service/subprocess/shell}/index.js.map +1 -1
  140. package/esm/{commands → service}/subprocess/shell/process.d.ts +2 -2
  141. package/esm/service/subprocess/shell/process.d.ts.map +1 -0
  142. package/esm/{commands → service}/subprocess/shell/process.js +4 -6
  143. package/esm/service/subprocess/shell/process.js.map +1 -0
  144. package/esm/{commands → service}/subprocess/shell/pty.d.ts +4 -4
  145. package/esm/service/subprocess/shell/pty.d.ts.map +1 -0
  146. package/esm/{commands → service}/subprocess/shell/pty.js +11 -9
  147. package/esm/service/subprocess/shell/pty.js.map +1 -0
  148. package/esm/service/subprocess/shell/service.d.ts +34 -0
  149. package/esm/service/subprocess/shell/service.d.ts.map +1 -0
  150. package/esm/service/subprocess/shell/service.js +52 -0
  151. package/esm/service/subprocess/shell/service.js.map +1 -0
  152. package/esm/service/subprocess/shell/shared.d.ts +2 -0
  153. package/esm/service/subprocess/shell/shared.d.ts.map +1 -0
  154. package/esm/{commands → service}/subprocess/shell/shared.js +2 -0
  155. package/esm/service/subprocess/shell/shared.js.map +1 -0
  156. package/esm/{commands → service}/subprocess/shell/spawner.d.ts +3 -7
  157. package/esm/service/subprocess/shell/spawner.d.ts.map +1 -0
  158. package/esm/service/subprocess/shell/spawner.js +45 -0
  159. package/esm/service/subprocess/shell/spawner.js.map +1 -0
  160. package/esm/service/subprocess/types.d.ts +14 -0
  161. package/esm/service/subprocess/types.d.ts.map +1 -0
  162. package/esm/service/subprocess/types.js +2 -0
  163. package/esm/service/subprocess/types.js.map +1 -0
  164. package/esm/service/subprocess/utils.d.ts +39 -0
  165. package/esm/service/subprocess/utils.d.ts.map +1 -0
  166. package/esm/service/subprocess/utils.js +142 -0
  167. package/esm/service/subprocess/utils.js.map +1 -0
  168. package/esm/service/sync/android.d.ts +34 -0
  169. package/esm/service/sync/android.d.ts.map +1 -0
  170. package/esm/service/sync/android.js +34 -0
  171. package/esm/service/sync/android.js.map +1 -0
  172. package/esm/service/sync/compression/compression.d.ts +17 -0
  173. package/esm/service/sync/compression/compression.d.ts.map +1 -0
  174. package/esm/service/sync/compression/compression.js +92 -0
  175. package/esm/service/sync/compression/compression.js.map +1 -0
  176. package/esm/service/sync/compression/format-ns.d.ts +5 -0
  177. package/esm/service/sync/compression/format-ns.d.ts.map +1 -0
  178. package/esm/service/sync/compression/format-ns.js +5 -0
  179. package/esm/service/sync/compression/format-ns.js.map +1 -0
  180. package/esm/service/sync/compression/format.d.ts +4 -0
  181. package/esm/service/sync/compression/format.d.ts.map +1 -0
  182. package/esm/service/sync/compression/format.js +3 -0
  183. package/esm/service/sync/compression/format.js.map +1 -0
  184. package/esm/service/sync/compression/index.d.ts +2 -0
  185. package/esm/service/sync/compression/index.d.ts.map +1 -0
  186. package/esm/service/sync/compression/index.js +2 -0
  187. package/esm/service/sync/compression/index.js.map +1 -0
  188. package/esm/service/sync/id/common.d.ts +17 -0
  189. package/esm/service/sync/id/common.d.ts.map +1 -0
  190. package/esm/service/sync/id/common.js +29 -0
  191. package/esm/service/sync/id/common.js.map +1 -0
  192. package/esm/service/sync/id/index.d.ts +4 -0
  193. package/esm/service/sync/id/index.d.ts.map +1 -0
  194. package/esm/service/sync/id/index.js +6 -0
  195. package/esm/service/sync/id/index.js.map +1 -0
  196. package/esm/service/sync/id/request.d.ts +7 -0
  197. package/esm/service/sync/id/request.d.ts.map +1 -0
  198. package/esm/service/sync/id/request.js +9 -0
  199. package/esm/service/sync/id/request.js.map +1 -0
  200. package/esm/service/sync/id/response.d.ts +6 -0
  201. package/esm/service/sync/id/response.d.ts.map +1 -0
  202. package/esm/service/sync/id/response.js +8 -0
  203. package/esm/service/sync/id/response.js.map +1 -0
  204. package/esm/service/sync/index-ns.d.ts +7 -0
  205. package/esm/service/sync/index-ns.d.ts.map +1 -0
  206. package/esm/service/sync/index-ns.js +7 -0
  207. package/esm/service/sync/index-ns.js.map +1 -0
  208. package/esm/service/sync/index.d.ts +3 -0
  209. package/esm/service/sync/index.d.ts.map +1 -0
  210. package/esm/service/sync/index.js +3 -0
  211. package/esm/service/sync/index.js.map +1 -0
  212. package/esm/service/sync/request/index.d.ts +5 -0
  213. package/esm/service/sync/request/index.d.ts.map +1 -0
  214. package/esm/service/sync/request/index.js +5 -0
  215. package/esm/service/sync/request/index.js.map +1 -0
  216. package/esm/{commands/sync → service/sync/request}/list.d.ts +21 -19
  217. package/esm/service/sync/request/list.d.ts.map +1 -0
  218. package/esm/service/sync/request/list.js +77 -0
  219. package/esm/service/sync/request/list.js.map +1 -0
  220. package/esm/service/sync/request/pull.d.ts +12 -0
  221. package/esm/service/sync/request/pull.d.ts.map +1 -0
  222. package/esm/service/sync/request/pull.js +28 -0
  223. package/esm/service/sync/request/pull.js.map +1 -0
  224. package/esm/service/sync/request/push.d.ts +54 -0
  225. package/esm/service/sync/request/push.d.ts.map +1 -0
  226. package/esm/service/sync/request/push.js +95 -0
  227. package/esm/service/sync/request/push.js.map +1 -0
  228. package/esm/{commands/sync → service/sync/request}/stat.d.ts +40 -50
  229. package/esm/service/sync/request/stat.d.ts.map +1 -0
  230. package/esm/service/sync/request/stat.js +89 -0
  231. package/esm/service/sync/request/stat.js.map +1 -0
  232. package/esm/service/sync/service.d.ts +123 -0
  233. package/esm/service/sync/service.d.ts.map +1 -0
  234. package/esm/service/sync/service.js +170 -0
  235. package/esm/service/sync/service.js.map +1 -0
  236. package/esm/service/sync/socket-pool.d.ts +11 -0
  237. package/esm/service/sync/socket-pool.d.ts.map +1 -0
  238. package/esm/service/sync/socket-pool.js +80 -0
  239. package/esm/service/sync/socket-pool.js.map +1 -0
  240. package/esm/service/sync/socket.d.ts +40 -0
  241. package/esm/service/sync/socket.d.ts.map +1 -0
  242. package/esm/service/sync/socket.js +153 -0
  243. package/esm/service/sync/socket.js.map +1 -0
  244. package/esm/{commands → service}/tcpip.d.ts +4 -2
  245. package/esm/service/tcpip.d.ts.map +1 -0
  246. package/esm/{commands → service}/tcpip.js +10 -7
  247. package/esm/service/tcpip.js.map +1 -0
  248. package/esm/utils/array-buffer.d.ts.map +1 -1
  249. package/esm/utils/array-buffer.js +2 -3
  250. package/esm/utils/array-buffer.js.map +1 -1
  251. package/esm/utils/base64.d.ts.map +1 -1
  252. package/esm/utils/base64.js +22 -10
  253. package/esm/utils/base64.js.map +1 -1
  254. package/esm/utils/index.d.ts +1 -0
  255. package/esm/utils/index.d.ts.map +1 -1
  256. package/esm/utils/index.js +1 -0
  257. package/esm/utils/index.js.map +1 -1
  258. package/esm/utils/md5.d.ts +8 -0
  259. package/esm/utils/md5.d.ts.map +1 -0
  260. package/esm/utils/md5.js +149 -0
  261. package/esm/utils/md5.js.map +1 -0
  262. package/package.json +9 -9
  263. package/src/adb.ts +44 -35
  264. package/src/banner.ts +2 -1
  265. package/src/daemon/auth/authenticator.ts +186 -0
  266. package/src/daemon/auth/index.ts +4 -0
  267. package/src/daemon/auth/packet-processor.ts +212 -0
  268. package/src/daemon/auth/public-key.ts +112 -0
  269. package/src/daemon/auth/type.ts +5 -0
  270. package/src/daemon/crypto.ts +36 -101
  271. package/src/daemon/dispatcher.ts +15 -8
  272. package/src/daemon/index.ts +1 -1
  273. package/src/daemon/socket.ts +3 -3
  274. package/src/daemon/transport.ts +35 -253
  275. package/src/device-observer.ts +3 -3
  276. package/src/features-value.ts +47 -0
  277. package/src/features.ts +31 -14
  278. package/src/index.ts +1 -1
  279. package/src/server/client.ts +94 -93
  280. package/src/server/commands/wireless.ts +1 -1
  281. package/src/server/{stream.ts → data-connection.ts} +4 -4
  282. package/src/server/index.ts +1 -1
  283. package/src/server/observer.ts +21 -19
  284. package/src/server/transport.ts +13 -34
  285. package/src/{commands → service}/index.ts +1 -2
  286. package/src/{commands → service}/power.ts +14 -5
  287. package/src/service/reverse/error.ts +35 -0
  288. package/src/service/reverse/index.ts +3 -0
  289. package/src/service/reverse/response.ts +38 -0
  290. package/src/{commands/reverse.ts → service/reverse/service.ts} +32 -72
  291. package/src/{commands → service}/subprocess/index.ts +1 -0
  292. package/src/{commands → service}/subprocess/none/process.ts +3 -3
  293. package/src/{commands → service}/subprocess/none/pty.ts +5 -5
  294. package/src/service/subprocess/none/service.ts +57 -0
  295. package/src/service/subprocess/none/spawner.ts +81 -0
  296. package/src/{commands → service}/subprocess/pty.ts +1 -1
  297. package/src/{commands → service}/subprocess/service.ts +1 -1
  298. package/src/{commands → service}/subprocess/shell/index.ts +1 -1
  299. package/src/{commands → service}/subprocess/shell/process.ts +6 -7
  300. package/src/{commands → service}/subprocess/shell/pty.ts +15 -13
  301. package/src/service/subprocess/shell/service.ts +75 -0
  302. package/src/{commands → service}/subprocess/shell/shared.ts +5 -0
  303. package/src/service/subprocess/shell/spawner.ts +109 -0
  304. package/src/service/subprocess/types.ts +19 -0
  305. package/src/service/subprocess/utils.ts +166 -0
  306. package/src/service/sync/android.ts +43 -0
  307. package/src/service/sync/compression/compression.ts +126 -0
  308. package/src/service/sync/compression/format-ns.ts +4 -0
  309. package/src/service/sync/compression/format.ts +5 -0
  310. package/src/service/sync/compression/index.ts +1 -0
  311. package/src/service/sync/id/common.ts +33 -0
  312. package/src/service/sync/id/index.ts +7 -0
  313. package/src/service/sync/id/request.ts +12 -0
  314. package/src/service/sync/id/response.ts +11 -0
  315. package/src/service/sync/index-ns.ts +6 -0
  316. package/src/service/sync/index.ts +2 -0
  317. package/src/service/sync/request/index.ts +4 -0
  318. package/src/service/sync/request/list.ts +110 -0
  319. package/src/service/sync/request/pull.ts +49 -0
  320. package/src/service/sync/request/push.ts +184 -0
  321. package/src/service/sync/request/stat.ts +127 -0
  322. package/src/service/sync/service.ts +255 -0
  323. package/src/service/sync/socket-pool.ts +97 -0
  324. package/src/service/sync/socket.ts +201 -0
  325. package/src/{commands → service}/tcpip.ts +13 -7
  326. package/src/utils/array-buffer.ts +2 -3
  327. package/src/utils/base64.ts +24 -10
  328. package/src/utils/index.ts +1 -0
  329. package/src/utils/md5.ts +185 -0
  330. package/yume-chan-adb-3.0.0-beta.0.tgz +0 -0
  331. package/CHANGELOG.md +0 -257
  332. package/esm/commands/base.d.ts +0 -8
  333. package/esm/commands/base.d.ts.map +0 -1
  334. package/esm/commands/base.js +0 -12
  335. package/esm/commands/base.js.map +0 -1
  336. package/esm/commands/framebuffer.d.ts.map +0 -1
  337. package/esm/commands/framebuffer.js.map +0 -1
  338. package/esm/commands/index.d.ts.map +0 -1
  339. package/esm/commands/index.js.map +0 -1
  340. package/esm/commands/power.d.ts.map +0 -1
  341. package/esm/commands/power.js.map +0 -1
  342. package/esm/commands/reverse.d.ts +0 -48
  343. package/esm/commands/reverse.d.ts.map +0 -1
  344. package/esm/commands/reverse.js.map +0 -1
  345. package/esm/commands/subprocess/index.d.ts.map +0 -1
  346. package/esm/commands/subprocess/index.js.map +0 -1
  347. package/esm/commands/subprocess/none/process.d.ts.map +0 -1
  348. package/esm/commands/subprocess/none/process.js.map +0 -1
  349. package/esm/commands/subprocess/none/pty.d.ts.map +0 -1
  350. package/esm/commands/subprocess/none/pty.js.map +0 -1
  351. package/esm/commands/subprocess/none/service.d.ts +0 -10
  352. package/esm/commands/subprocess/none/service.d.ts.map +0 -1
  353. package/esm/commands/subprocess/none/service.js +0 -34
  354. package/esm/commands/subprocess/none/service.js.map +0 -1
  355. package/esm/commands/subprocess/none/spawner.d.ts +0 -19
  356. package/esm/commands/subprocess/none/spawner.d.ts.map +0 -1
  357. package/esm/commands/subprocess/none/spawner.js +0 -26
  358. package/esm/commands/subprocess/none/spawner.js.map +0 -1
  359. package/esm/commands/subprocess/pty.d.ts.map +0 -1
  360. package/esm/commands/subprocess/service.d.ts.map +0 -1
  361. package/esm/commands/subprocess/service.js.map +0 -1
  362. package/esm/commands/subprocess/shell/index.d.ts +0 -6
  363. package/esm/commands/subprocess/shell/index.d.ts.map +0 -1
  364. package/esm/commands/subprocess/shell/index.js +0 -6
  365. package/esm/commands/subprocess/shell/index.js.map +0 -1
  366. package/esm/commands/subprocess/shell/process.d.ts.map +0 -1
  367. package/esm/commands/subprocess/shell/process.js.map +0 -1
  368. package/esm/commands/subprocess/shell/pty.d.ts.map +0 -1
  369. package/esm/commands/subprocess/shell/pty.js.map +0 -1
  370. package/esm/commands/subprocess/shell/service.d.ts +0 -14
  371. package/esm/commands/subprocess/shell/service.d.ts.map +0 -1
  372. package/esm/commands/subprocess/shell/service.js +0 -41
  373. package/esm/commands/subprocess/shell/service.js.map +0 -1
  374. package/esm/commands/subprocess/shell/shared.d.ts +0 -19
  375. package/esm/commands/subprocess/shell/shared.d.ts.map +0 -1
  376. package/esm/commands/subprocess/shell/shared.js.map +0 -1
  377. package/esm/commands/subprocess/shell/spawner.d.ts.map +0 -1
  378. package/esm/commands/subprocess/shell/spawner.js +0 -38
  379. package/esm/commands/subprocess/shell/spawner.js.map +0 -1
  380. package/esm/commands/subprocess/utils.d.ts +0 -3
  381. package/esm/commands/subprocess/utils.d.ts.map +0 -1
  382. package/esm/commands/subprocess/utils.js +0 -56
  383. package/esm/commands/subprocess/utils.js.map +0 -1
  384. package/esm/commands/sync/index.d.ts +0 -9
  385. package/esm/commands/sync/index.d.ts.map +0 -1
  386. package/esm/commands/sync/index.js +0 -9
  387. package/esm/commands/sync/index.js.map +0 -1
  388. package/esm/commands/sync/list.d.ts.map +0 -1
  389. package/esm/commands/sync/list.js +0 -64
  390. package/esm/commands/sync/list.js.map +0 -1
  391. package/esm/commands/sync/pull.d.ts +0 -12
  392. package/esm/commands/sync/pull.d.ts.map +0 -1
  393. package/esm/commands/sync/pull.js +0 -33
  394. package/esm/commands/sync/pull.js.map +0 -1
  395. package/esm/commands/sync/push.d.ts +0 -61
  396. package/esm/commands/sync/push.d.ts.map +0 -1
  397. package/esm/commands/sync/push.js +0 -83
  398. package/esm/commands/sync/push.js.map +0 -1
  399. package/esm/commands/sync/request.d.ts +0 -24
  400. package/esm/commands/sync/request.d.ts.map +0 -1
  401. package/esm/commands/sync/request.js +0 -32
  402. package/esm/commands/sync/request.js.map +0 -1
  403. package/esm/commands/sync/response.d.ts +0 -28
  404. package/esm/commands/sync/response.d.ts.map +0 -1
  405. package/esm/commands/sync/response.js +0 -81
  406. package/esm/commands/sync/response.js.map +0 -1
  407. package/esm/commands/sync/socket.d.ts +0 -22
  408. package/esm/commands/sync/socket.d.ts.map +0 -1
  409. package/esm/commands/sync/socket.js +0 -78
  410. package/esm/commands/sync/socket.js.map +0 -1
  411. package/esm/commands/sync/stat.d.ts.map +0 -1
  412. package/esm/commands/sync/stat.js +0 -121
  413. package/esm/commands/sync/stat.js.map +0 -1
  414. package/esm/commands/sync/sync.d.ts +0 -82
  415. package/esm/commands/sync/sync.d.ts.map +0 -1
  416. package/esm/commands/sync/sync.js +0 -138
  417. package/esm/commands/sync/sync.js.map +0 -1
  418. package/esm/commands/tcpip.d.ts.map +0 -1
  419. package/esm/commands/tcpip.js.map +0 -1
  420. package/esm/daemon/auth.d.ts +0 -54
  421. package/esm/daemon/auth.d.ts.map +0 -1
  422. package/esm/daemon/auth.js +0 -104
  423. package/esm/daemon/auth.js.map +0 -1
  424. package/esm/server/stream.d.ts.map +0 -1
  425. package/esm/server/stream.js.map +0 -1
  426. package/src/commands/base.ts +0 -15
  427. package/src/commands/subprocess/none/service.ts +0 -45
  428. package/src/commands/subprocess/none/spawner.ts +0 -68
  429. package/src/commands/subprocess/shell/service.ts +0 -58
  430. package/src/commands/subprocess/shell/spawner.ts +0 -90
  431. package/src/commands/subprocess/utils.ts +0 -61
  432. package/src/commands/sync/index.ts +0 -8
  433. package/src/commands/sync/list.ts +0 -99
  434. package/src/commands/sync/pull.ts +0 -55
  435. package/src/commands/sync/push.ts +0 -172
  436. package/src/commands/sync/request.ts +0 -53
  437. package/src/commands/sync/response.ts +0 -105
  438. package/src/commands/sync/socket.ts +0 -109
  439. package/src/commands/sync/stat.ts +0 -177
  440. package/src/commands/sync/sync.ts +0 -175
  441. package/src/daemon/auth.ts +0 -203
  442. package/tsconfig.build.tsbuildinfo +0 -1
  443. /package/esm/{commands → service}/framebuffer.d.ts +0 -0
  444. /package/esm/{commands → service}/framebuffer.js +0 -0
  445. /package/esm/{commands → service}/subprocess/none/index.d.ts +0 -0
  446. /package/esm/{commands → service}/subprocess/none/index.js +0 -0
  447. /package/esm/{commands → service}/subprocess/none/process.js +0 -0
  448. /package/esm/{commands → service}/subprocess/pty.js +0 -0
  449. /package/esm/{commands → service}/subprocess/service.d.ts +0 -0
  450. /package/src/{commands → service}/framebuffer.ts +0 -0
  451. /package/src/{commands → service}/subprocess/none/index.ts +0 -0
@@ -1,7 +1,6 @@
1
1
  // cspell:ignore tport
2
2
 
3
3
  import type { MaybePromiseLike } from "@yume-chan/async";
4
- import { PromiseResolver } from "@yume-chan/async";
5
4
  import type { Event } from "@yume-chan/event";
6
5
  import { getUint64LittleEndian } from "@yume-chan/no-data-view";
7
6
  import type {
@@ -11,7 +10,7 @@ import type {
11
10
  } from "@yume-chan/stream-extra";
12
11
  import { AbortController } from "@yume-chan/stream-extra";
13
12
 
14
- import type { AdbIncomingSocketHandler, AdbSocket, Closeable } from "../adb.js";
13
+ import type { Closeable } from "../adb.js";
15
14
  import { Adb } from "../adb.js";
16
15
  import { AdbBanner } from "../banner.js";
17
16
  import type { DeviceObserver as DeviceObserverBase } from "../device-observer.js";
@@ -25,14 +24,53 @@ import {
25
24
  NetworkError as _NetworkError,
26
25
  UnauthorizedError as _UnauthorizedError,
27
26
  } from "./commands/index.js";
27
+ import { AdbServerDataConnection } from "./data-connection.js";
28
28
  import { AdbServerDeviceObserverOwner } from "./observer.js";
29
- import { AdbServerStream } from "./stream.js";
30
29
  import { AdbServerTransport } from "./transport.js";
31
30
 
31
+ const KeyTransportId = " transport_id:";
32
+ const KeyDevice = " device:";
33
+ const KeyModel = " model:";
34
+ const KeyProduct = " product:";
35
+
36
+ function parseDeviceLineItem<
37
+ T extends string = string,
38
+ Optional extends boolean = false,
39
+ >(
40
+ line: string,
41
+ end: number,
42
+ key: string,
43
+ optional?: Optional,
44
+ ): readonly [start: number, value: Optional extends false ? T : T | undefined] {
45
+ const start = line.lastIndexOf(key, end - 1);
46
+ if (start === -1) {
47
+ if (optional) {
48
+ return [end, undefined as never] as const;
49
+ } else {
50
+ throw new Error(`Invalid device line: ${line}`);
51
+ }
52
+ }
53
+ return [start, line.substring(start + key.length, end) as T] as const;
54
+ }
55
+
32
56
  /**
33
57
  * Client for the ADB Server.
34
58
  */
35
59
  export class AdbServerClient {
60
+ // https://android.googlesource.com/platform/packages/modules/adb/+/9f298fb1f3317371b49439efb20a598b3a881bf3/adb.cpp#144
61
+ static ConnectionState = [
62
+ "offline",
63
+ "bootloader",
64
+ "device",
65
+ "host",
66
+ "recovery",
67
+ "rescue",
68
+ "sideload",
69
+ "unauthorized",
70
+ "authorizing",
71
+ "detached",
72
+ ] as const;
73
+
36
74
  static NetworkError = _NetworkError;
37
75
  static UnauthorizedError = _UnauthorizedError;
38
76
  static AlreadyConnectedError = _AlreadyConnectedError;
@@ -50,37 +88,46 @@ export class AdbServerClient {
50
88
  continue;
51
89
  }
52
90
 
53
- const parts = line.split(" ").filter(Boolean);
54
- const serial = parts[0]!;
55
- const state = parts[1]! as AdbServerClient.ConnectionState;
91
+ // Parse backwards because `serial` might contain spaces.
92
+
93
+ let end = line.length;
94
+ let value: string;
95
+
96
+ // transport_id:123
97
+ // eslint-disable-next-line prefer-const
98
+ [end, value] = parseDeviceLineItem(line, end, KeyTransportId);
99
+ const transportId = BigInt(value);
100
+
101
+ // device:abc (optional)
102
+ let device: string | undefined;
103
+ // eslint-disable-next-line prefer-const
104
+ [end, device] = parseDeviceLineItem(line, end, KeyDevice, true);
105
+
106
+ // model:abc (optional)
107
+ let model: string | undefined;
108
+ // eslint-disable-next-line prefer-const
109
+ [end, model] = parseDeviceLineItem(line, end, KeyModel, true);
110
+
111
+ // product:abc (optional)
112
+ let product: string | undefined;
113
+ // eslint-disable-next-line prefer-const
114
+ [end, product] = parseDeviceLineItem(line, end, KeyProduct, true);
115
+
116
+ let state: AdbServerClient.ConnectionState;
117
+ do {
118
+ // devpath or state
119
+ // devpath doesn't have a fixed pattern
120
+ // (for example, libusb driver gives plain strings like `5-1.4`)
121
+ // so keep parsing until we get a valid state
122
+ [end, state] = parseDeviceLineItem(line, end, " ");
123
+ } while (!AdbServerClient.ConnectionState.includes(state));
124
+
56
125
  if (!includeStates.includes(state)) {
57
126
  continue;
58
127
  }
59
128
 
60
- let product: string | undefined;
61
- let model: string | undefined;
62
- let device: string | undefined;
63
- let transportId: bigint | undefined;
64
- for (let i = 2; i < parts.length; i += 1) {
65
- const [key, value] = parts[i]!.split(":");
66
- switch (key) {
67
- case "product":
68
- product = value;
69
- break;
70
- case "model":
71
- model = value;
72
- break;
73
- case "device":
74
- device = value;
75
- break;
76
- case "transport_id":
77
- transportId = BigInt(value!);
78
- break;
79
- }
80
- }
81
- if (!transportId) {
82
- throw new Error(`No transport id for device ${serial}`);
83
- }
129
+ const serial = line.substring(0, end).trim();
130
+
84
131
  devices.push({
85
132
  serial,
86
133
  state,
@@ -129,24 +176,16 @@ export class AdbServerClient {
129
176
  async createConnection(
130
177
  request: string,
131
178
  options?: AdbServerClient.ServerConnectionOptions,
132
- ): Promise<AdbServerStream> {
179
+ ): Promise<AdbServerDataConnection> {
133
180
  const connection = await this.connector.connect(options);
134
- const stream = new AdbServerStream(connection);
135
-
136
- try {
137
- await stream.writeString(request);
138
- } catch (e) {
139
- await stream.dispose();
140
- throw e;
141
- }
181
+ const dataConnection = new AdbServerDataConnection(connection);
142
182
 
143
183
  try {
144
- // `raceSignal` throws when the signal is aborted,
145
- // so the `catch` block can close the connection.
146
- await raceSignal(() => stream.readOkay(), options?.signal);
147
- return stream;
184
+ await dataConnection.writeString(request);
185
+ await dataConnection.readOkay();
186
+ return dataConnection;
148
187
  } catch (e) {
149
- await stream.dispose();
188
+ await dataConnection.dispose();
150
189
  throw e;
151
190
  }
152
191
  }
@@ -271,13 +310,13 @@ export class AdbServerClient {
271
310
  "host:features",
272
311
  );
273
312
  // Luckily `AdbServerClient.Socket` is compatible with `AdbServerClient.ServerConnection`
274
- const stream = new AdbServerStream(connection);
313
+ const dataConnection = new AdbServerDataConnection(connection);
275
314
  try {
276
- const featuresString = await stream.readString();
315
+ const featuresString = await dataConnection.readString();
277
316
  const features = featuresString.split(",") as AdbFeature[];
278
317
  return { transportId: connection.transportId, features };
279
318
  } finally {
280
- await stream.dispose();
319
+ await dataConnection.dispose();
281
320
  }
282
321
  }
283
322
 
@@ -316,12 +355,7 @@ export class AdbServerClient {
316
355
 
317
356
  try {
318
357
  await connection.writeString(service);
319
- } catch (e) {
320
- await connection.dispose();
321
- throw e;
322
- }
323
358
 
324
- try {
325
359
  if (transportId === undefined) {
326
360
  const array = await connection.readExactly(8);
327
361
  transportId = getUint64LittleEndian(array, 0);
@@ -348,17 +382,14 @@ export class AdbServerClient {
348
382
  throw e;
349
383
  }
350
384
  }
385
+
351
386
  async #waitForUnchecked(
352
387
  device: AdbServerClient.DeviceSelector,
353
388
  state: "device" | "disconnect",
354
389
  options?: AdbServerClient.ServerConnectionOptions,
355
390
  ): Promise<void> {
356
391
  let type: string;
357
- if (!device) {
358
- type = "any";
359
- } else if ("transportId" in device) {
360
- type = "any";
361
- } else if ("serial" in device) {
392
+ if (!device || "transportId" in device || "serial" in device) {
362
393
  type = "any";
363
394
  } else if ("usb" in device) {
364
395
  type = "usb";
@@ -425,12 +456,12 @@ export class AdbServerClient {
425
456
  (device) => device.transportId === transportId,
426
457
  )
427
458
  ) {
428
- observer.stop();
459
+ observer.close();
429
460
  resolve();
430
461
  }
431
462
  });
432
463
  observer.onError((e) => {
433
- observer.stop();
464
+ observer.close();
434
465
  reject(e);
435
466
  });
436
467
  });
@@ -483,37 +514,6 @@ export class AdbServerClient {
483
514
  }
484
515
  }
485
516
 
486
- export async function raceSignal<T>(
487
- callback: () => PromiseLike<T>,
488
- ...signals: (AbortSignal | undefined)[]
489
- ): Promise<T> {
490
- const abortPromise = new PromiseResolver<never>();
491
- function abort(this: AbortSignal) {
492
- abortPromise.reject(this.reason);
493
- }
494
-
495
- try {
496
- for (const signal of signals) {
497
- if (!signal) {
498
- continue;
499
- }
500
- if (signal.aborted) {
501
- throw signal.reason;
502
- }
503
- signal.addEventListener("abort", abort);
504
- }
505
-
506
- return await Promise.race([callback(), abortPromise.promise]);
507
- } finally {
508
- for (const signal of signals) {
509
- if (!signal) {
510
- continue;
511
- }
512
- signal.removeEventListener("abort", abort);
513
- }
514
- }
515
- }
516
-
517
517
  export namespace AdbServerClient {
518
518
  export interface ServerConnectionOptions {
519
519
  unref?: boolean | undefined;
@@ -533,7 +533,7 @@ export namespace AdbServerClient {
533
533
  ): MaybePromiseLike<ServerConnection>;
534
534
 
535
535
  addReverseTunnel(
536
- handler: AdbIncomingSocketHandler,
536
+ handler: Adb.IncomingSocketHandler,
537
537
  address?: string,
538
538
  ): MaybePromiseLike<string>;
539
539
 
@@ -542,7 +542,7 @@ export namespace AdbServerClient {
542
542
  clearReverseTunnels(): MaybePromiseLike<void>;
543
543
  }
544
544
 
545
- export interface Socket extends AdbSocket {
545
+ export interface Socket extends Adb.Socket {
546
546
  transportId: bigint;
547
547
  }
548
548
 
@@ -556,7 +556,8 @@ export namespace AdbServerClient {
556
556
  | { tcp: true }
557
557
  | undefined;
558
558
 
559
- export type ConnectionState = "unauthorized" | "offline" | "device";
559
+ export type ConnectionState =
560
+ (typeof AdbServerClient.ConnectionState)[number];
560
561
 
561
562
  export interface Device {
562
563
  serial: string;
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { hexToNumber, sequenceEqual } from "../../utils/index.js";
4
4
  import type { AdbServerClient } from "../client.js";
5
- import { FAIL } from "../stream.js";
5
+ import { FAIL } from "../data-connection.js";
6
6
 
7
7
  export class NetworkError extends Error {
8
8
  constructor(message: string) {
@@ -19,7 +19,7 @@ import type { AdbServerClient } from "./client.js";
19
19
  const OKAY = encodeUtf8("OKAY");
20
20
  export const FAIL = encodeUtf8("FAIL");
21
21
 
22
- export class AdbServerStream {
22
+ export class AdbServerDataConnection {
23
23
  #connection: AdbServerClient.ServerConnection;
24
24
  #buffered: BufferedReadableStream;
25
25
  #writer: WritableStreamDefaultWriter<Uint8Array>;
@@ -34,7 +34,7 @@ export class AdbServerStream {
34
34
  return this.#buffered.readExactly(length);
35
35
  }
36
36
 
37
- readString = bipedal(function* (this: AdbServerStream, then) {
37
+ readString = bipedal(function* (this: AdbServerDataConnection, then) {
38
38
  const data = yield* then(this.readExactly(4));
39
39
  const length = hexToNumber(data);
40
40
  if (length === 0) {
@@ -93,8 +93,8 @@ export class AdbServerStream {
93
93
  }
94
94
 
95
95
  async dispose() {
96
- void tryCancel(this.#buffered);
97
- void tryClose(this.#writer);
96
+ await tryCancel(this.#buffered);
97
+ await tryClose(this.#writer);
98
98
  await this.#connection.close();
99
99
  }
100
100
  }
@@ -1,4 +1,4 @@
1
1
  export * from "./client.js";
2
+ export * from "./data-connection.js";
2
3
  export * from "./observer.js";
3
- export * from "./stream.js";
4
4
  export * from "./transport.js";
@@ -3,7 +3,7 @@ import { EventEmitter, StickyEventEmitter } from "@yume-chan/event";
3
3
  import { Ref } from "../utils/index.js";
4
4
 
5
5
  import { AdbServerClient } from "./client.js";
6
- import type { AdbServerStream } from "./stream.js";
6
+ import type { AdbServerDataConnection } from "./data-connection.js";
7
7
 
8
8
  export function unorderedRemove<T>(array: T[], index: number) {
9
9
  if (index < 0 || index >= array.length) {
@@ -33,14 +33,14 @@ export class AdbServerDeviceObserverOwner {
33
33
 
34
34
  readonly #client: AdbServerClient;
35
35
 
36
- #stream: Promise<AdbServerStream> | undefined;
36
+ #stream: Promise<AdbServerDataConnection> | undefined;
37
37
  #observers: Observer[] = [];
38
38
 
39
39
  constructor(client: AdbServerClient) {
40
40
  this.#client = client;
41
41
  }
42
42
 
43
- async #receive(stream: AdbServerStream) {
43
+ async #receive(stream: AdbServerDataConnection) {
44
44
  const response = await stream.readString();
45
45
  const next = AdbServerClient.parseDeviceList(response);
46
46
 
@@ -93,7 +93,7 @@ export class AdbServerDeviceObserverOwner {
93
93
  }
94
94
  }
95
95
 
96
- async #receiveLoop(stream: AdbServerStream) {
96
+ async #receiveLoop(stream: AdbServerDataConnection) {
97
97
  try {
98
98
  while (true) {
99
99
  await this.#receive(stream);
@@ -123,10 +123,10 @@ export class AdbServerDeviceObserverOwner {
123
123
  return stream;
124
124
  }
125
125
 
126
- async #handleObserverStop(stream: AdbServerStream) {
126
+ async #handleObserverClose(connection: AdbServerDataConnection) {
127
127
  if (this.#observers.length === 0) {
128
128
  this.#stream = undefined;
129
- await stream.dispose();
129
+ await connection.dispose();
130
130
  }
131
131
  }
132
132
 
@@ -135,7 +135,6 @@ export class AdbServerDeviceObserverOwner {
135
135
  ): Promise<AdbServerClient.DeviceObserver> {
136
136
  options?.signal?.throwIfAborted();
137
137
 
138
- let current: readonly AdbServerClient.Device[] = [];
139
138
  const onDeviceAdd = new EventEmitter<
140
139
  readonly AdbServerClient.Device[]
141
140
  >();
@@ -162,12 +161,9 @@ export class AdbServerDeviceObserverOwner {
162
161
  // So `#handleObserverStop` knows if there is any observer.
163
162
  this.#observers.push(observer);
164
163
 
165
- // Read the filtered `current` value from `onListChange` event
166
- onListChange.event((value) => (current = value));
167
-
168
- let stream: AdbServerStream;
164
+ let stream: AdbServerDataConnection;
169
165
  if (!this.#stream) {
170
- // `#connect` will initialize `onListChange` and `current`
166
+ // `#connect` will initialize `onListChange`
171
167
  this.#stream = this.#connect();
172
168
 
173
169
  try {
@@ -178,25 +174,31 @@ export class AdbServerDeviceObserverOwner {
178
174
  }
179
175
  } else {
180
176
  stream = await this.#stream;
181
- // Initialize `onListChange` and `current` ourselves
177
+ // Initialize `onListChange` ourselves
182
178
  onListChange.fire(filterDeviceStates(this.current, includeStates));
183
179
  }
184
180
 
185
181
  const ref = new Ref(options);
186
182
 
187
- const stop = async () => {
183
+ const close = async () => {
184
+ onDeviceAdd.dispose();
185
+ onDeviceRemove.dispose();
186
+ onListChange.dispose();
187
+ onError.dispose();
188
+
188
189
  unorderedRemove(this.#observers, this.#observers.indexOf(observer));
189
- await this.#handleObserverStop(stream);
190
+ await this.#handleObserverClose(stream);
191
+
190
192
  ref.unref();
191
193
  };
192
194
 
193
195
  if (options?.signal) {
194
196
  if (options.signal.aborted) {
195
- await stop();
197
+ await close();
196
198
  throw options.signal.reason;
197
199
  }
198
200
 
199
- options.signal.addEventListener("abort", () => void stop());
201
+ options.signal.addEventListener("abort", () => void close());
200
202
  }
201
203
 
202
204
  return {
@@ -205,9 +207,9 @@ export class AdbServerDeviceObserverOwner {
205
207
  onListChange: onListChange.event,
206
208
  onError: onError.event,
207
209
  get current() {
208
- return current;
210
+ return onListChange.value;
209
211
  },
210
- stop,
212
+ close,
211
213
  };
212
214
  }
213
215
  }
@@ -1,37 +1,11 @@
1
1
  import { PromiseResolver } from "@yume-chan/async";
2
2
 
3
- import type {
4
- AdbIncomingSocketHandler,
5
- AdbSocket,
6
- AdbTransport,
7
- } from "../adb.js";
3
+ import type { Adb, AdbTransport } from "../adb.js";
8
4
  import type { AdbBanner } from "../banner.js";
9
- import { AdbFeature } from "../features.js";
5
+ import { AdbDeviceFeatures } from "../features.js";
10
6
 
11
7
  import type { AdbServerClient } from "./client.js";
12
8
 
13
- export const ADB_SERVER_DEFAULT_FEATURES = /* #__PURE__ */ (() =>
14
- [
15
- AdbFeature.ShellV2,
16
- AdbFeature.Cmd,
17
- AdbFeature.StatV2,
18
- AdbFeature.ListV2,
19
- AdbFeature.FixedPushMkdir,
20
- "apex",
21
- AdbFeature.Abb,
22
- // only tells the client the symlink timestamp issue in `adb push --sync` has been fixed.
23
- // No special handling required.
24
- "fixed_push_symlink_timestamp",
25
- AdbFeature.AbbExec,
26
- "remount_shell",
27
- "track_app",
28
- AdbFeature.SendReceiveV2,
29
- "sendrecv_v2_brotli",
30
- "sendrecv_v2_lz4",
31
- "sendrecv_v2_zstd",
32
- "sendrecv_v2_dry_run_send",
33
- ] as readonly AdbFeature[])();
34
-
35
9
  export class AdbServerTransport implements AdbTransport {
36
10
  #client: AdbServerClient;
37
11
 
@@ -43,7 +17,7 @@ export class AdbServerTransport implements AdbTransport {
43
17
 
44
18
  readonly banner: AdbBanner;
45
19
 
46
- #sockets: AdbSocket[] = [];
20
+ #sockets: Adb.Socket[] = [];
47
21
 
48
22
  #closed = new PromiseResolver<void>();
49
23
  #disconnected: Promise<void>;
@@ -52,9 +26,14 @@ export class AdbServerTransport implements AdbTransport {
52
26
  }
53
27
 
54
28
  get clientFeatures() {
55
- // No need to get host features (features supported by ADB server)
56
- // Because we create all ADB packets ourselves
57
- return ADB_SERVER_DEFAULT_FEATURES;
29
+ // This list tells the `Adb` instance how to invoke some commands.
30
+ //
31
+ // Because all device commands are created by the `Adb` instance, not ADB server,
32
+ // we don't need to fetch current server's feature list using `host-features` command.
33
+ //
34
+ // And because all server commands are created by the `AdbServerClient` instance, not `Adb`,
35
+ // we don't need to pass server-only features to `Adb` in this list.
36
+ return AdbDeviceFeatures;
58
37
  }
59
38
 
60
39
  // eslint-disable-next-line @typescript-eslint/max-params
@@ -73,7 +52,7 @@ export class AdbServerTransport implements AdbTransport {
73
52
  this.#disconnected = Promise.race([this.#closed.promise, disconnected]);
74
53
  }
75
54
 
76
- async connect(service: string): Promise<AdbSocket> {
55
+ async connect(service: string): Promise<Adb.Socket> {
77
56
  const socket = await this.#client.createDeviceConnection(
78
57
  { transportId: this.transportId },
79
58
  service,
@@ -83,7 +62,7 @@ export class AdbServerTransport implements AdbTransport {
83
62
  }
84
63
 
85
64
  async addReverseTunnel(
86
- handler: AdbIncomingSocketHandler,
65
+ handler: Adb.IncomingSocketHandler,
87
66
  address?: string,
88
67
  ): Promise<string> {
89
68
  return await this.#client.connector.addReverseTunnel(handler, address);
@@ -1,7 +1,6 @@
1
- export * from "./base.js";
2
1
  export * from "./framebuffer.js";
3
2
  export * from "./power.js";
4
- export * from "./reverse.js";
3
+ export * from "./reverse/index.js";
5
4
  export * from "./subprocess/index.js";
6
5
  export * from "./sync/index.js";
7
6
  export * from "./tcpip.js";
@@ -3,11 +3,17 @@
3
3
  // cspell: ignore keyevent
4
4
  // cspell: ignore longpress
5
5
 
6
- import { AdbServiceBase } from "./base.js";
6
+ import type { Adb } from "../adb.js";
7
+
8
+ export class AdbPowerService {
9
+ readonly #adb: Adb;
10
+
11
+ constructor(adb: Adb) {
12
+ this.#adb = adb;
13
+ }
7
14
 
8
- export class AdbPower extends AdbServiceBase {
9
15
  reboot(mode = "") {
10
- return this.adb.createSocketAndWait(`reboot:${mode}`);
16
+ return this.#adb.createSocketAndWait(`reboot:${mode}`);
11
17
  }
12
18
 
13
19
  bootloader() {
@@ -36,7 +42,10 @@ export class AdbPower extends AdbServiceBase {
36
42
  }
37
43
 
38
44
  powerOff(): Promise<string> {
39
- return this.adb.subprocess.noneProtocol.spawnWaitText(["reboot", "-p"]);
45
+ return this.#adb.subprocess.noneProtocol
46
+ .spawn(["reboot", "-p"])
47
+ .wait()
48
+ .toString();
40
49
  }
41
50
 
42
51
  powerButton(longPress = false): Promise<string> {
@@ -46,7 +55,7 @@ export class AdbPower extends AdbServiceBase {
46
55
  }
47
56
  args.push("POWER");
48
57
 
49
- return this.adb.subprocess.noneProtocol.spawnWaitText(args);
58
+ return this.#adb.subprocess.noneProtocol.spawn(args).wait().toString();
50
59
  }
51
60
 
52
61
  /**
@@ -0,0 +1,35 @@
1
+ const AdbReverseErrorBrand = Symbol.for("AdbReverseError.brand");
2
+
3
+ export class AdbReverseError extends Error {
4
+ [AdbReverseErrorBrand] = true;
5
+
6
+ static override [Symbol.hasInstance](value: unknown) {
7
+ return !!(value as AdbReverseNotSupportedError | undefined)?.[
8
+ AdbReverseErrorBrand
9
+ ];
10
+ }
11
+
12
+ constructor(message: string) {
13
+ super(message);
14
+ }
15
+ }
16
+
17
+ const AdbReverseNotSupportedErrorBrand = Symbol.for(
18
+ "AdbReverseNotSupportedError.brand",
19
+ );
20
+
21
+ export class AdbReverseNotSupportedError extends AdbReverseError {
22
+ [AdbReverseNotSupportedErrorBrand] = true;
23
+
24
+ static override [Symbol.hasInstance](value: unknown) {
25
+ return !!(value as AdbReverseNotSupportedError | undefined)?.[
26
+ AdbReverseNotSupportedErrorBrand
27
+ ];
28
+ }
29
+
30
+ constructor() {
31
+ super(
32
+ "ADB reverse tunnel is not supported on this device when connected wirelessly.",
33
+ );
34
+ }
35
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./error.js";
2
+ export * from "./service.js";
3
+ // `response.ts` is internal
@@ -0,0 +1,38 @@
1
+ import { extend, string, struct } from "@yume-chan/struct";
2
+
3
+ import { AdbReverseError, AdbReverseNotSupportedError } from "./error.js";
4
+
5
+ /** @internal exported for tests */
6
+ export const AdbReverseStringResponse = struct(
7
+ {
8
+ length: string(4),
9
+ content: string({
10
+ field: "length",
11
+ convert(value: string) {
12
+ return Number.parseInt(value, 16);
13
+ },
14
+ back(value) {
15
+ return value.toString(16).padStart(4, "0");
16
+ },
17
+ }),
18
+ },
19
+ { littleEndian: true },
20
+ );
21
+
22
+ /** @internal exported for tests */
23
+ export const AdbReverseErrorResponse = extend(
24
+ AdbReverseStringResponse,
25
+ {},
26
+ {
27
+ postDeserialize(value) {
28
+ // https://issuetracker.google.com/issues/37066218
29
+ // ADB on Android <9 can't create reverse tunnels when connected wirelessly (ADB over Wi-Fi),
30
+ // and returns this confusing "more than one device/emulator" error.
31
+ if (value.content === "more than one device/emulator") {
32
+ throw new AdbReverseNotSupportedError();
33
+ } else {
34
+ throw new AdbReverseError(value.content);
35
+ }
36
+ },
37
+ },
38
+ );