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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (450) 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 +11 -10
  63. package/esm/server/client.d.ts.map +1 -1
  64. package/esm/server/client.js +82 -98
  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 +36 -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 +11 -15
  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 +50 -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 +7 -7
  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 +112 -104
  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 +85 -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 +13 -17
  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 +113 -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/CHANGELOG.md +0 -257
  331. package/esm/commands/base.d.ts +0 -8
  332. package/esm/commands/base.d.ts.map +0 -1
  333. package/esm/commands/base.js +0 -12
  334. package/esm/commands/base.js.map +0 -1
  335. package/esm/commands/framebuffer.d.ts.map +0 -1
  336. package/esm/commands/framebuffer.js.map +0 -1
  337. package/esm/commands/index.d.ts.map +0 -1
  338. package/esm/commands/index.js.map +0 -1
  339. package/esm/commands/power.d.ts.map +0 -1
  340. package/esm/commands/power.js.map +0 -1
  341. package/esm/commands/reverse.d.ts +0 -48
  342. package/esm/commands/reverse.d.ts.map +0 -1
  343. package/esm/commands/reverse.js.map +0 -1
  344. package/esm/commands/subprocess/index.d.ts.map +0 -1
  345. package/esm/commands/subprocess/index.js.map +0 -1
  346. package/esm/commands/subprocess/none/process.d.ts.map +0 -1
  347. package/esm/commands/subprocess/none/process.js.map +0 -1
  348. package/esm/commands/subprocess/none/pty.d.ts.map +0 -1
  349. package/esm/commands/subprocess/none/pty.js.map +0 -1
  350. package/esm/commands/subprocess/none/service.d.ts +0 -10
  351. package/esm/commands/subprocess/none/service.d.ts.map +0 -1
  352. package/esm/commands/subprocess/none/service.js +0 -34
  353. package/esm/commands/subprocess/none/service.js.map +0 -1
  354. package/esm/commands/subprocess/none/spawner.d.ts +0 -19
  355. package/esm/commands/subprocess/none/spawner.d.ts.map +0 -1
  356. package/esm/commands/subprocess/none/spawner.js +0 -26
  357. package/esm/commands/subprocess/none/spawner.js.map +0 -1
  358. package/esm/commands/subprocess/pty.d.ts.map +0 -1
  359. package/esm/commands/subprocess/service.d.ts.map +0 -1
  360. package/esm/commands/subprocess/service.js.map +0 -1
  361. package/esm/commands/subprocess/shell/index.d.ts +0 -6
  362. package/esm/commands/subprocess/shell/index.d.ts.map +0 -1
  363. package/esm/commands/subprocess/shell/index.js +0 -6
  364. package/esm/commands/subprocess/shell/index.js.map +0 -1
  365. package/esm/commands/subprocess/shell/process.d.ts.map +0 -1
  366. package/esm/commands/subprocess/shell/process.js.map +0 -1
  367. package/esm/commands/subprocess/shell/pty.d.ts.map +0 -1
  368. package/esm/commands/subprocess/shell/pty.js.map +0 -1
  369. package/esm/commands/subprocess/shell/service.d.ts +0 -14
  370. package/esm/commands/subprocess/shell/service.d.ts.map +0 -1
  371. package/esm/commands/subprocess/shell/service.js +0 -41
  372. package/esm/commands/subprocess/shell/service.js.map +0 -1
  373. package/esm/commands/subprocess/shell/shared.d.ts +0 -19
  374. package/esm/commands/subprocess/shell/shared.d.ts.map +0 -1
  375. package/esm/commands/subprocess/shell/shared.js.map +0 -1
  376. package/esm/commands/subprocess/shell/spawner.d.ts.map +0 -1
  377. package/esm/commands/subprocess/shell/spawner.js +0 -38
  378. package/esm/commands/subprocess/shell/spawner.js.map +0 -1
  379. package/esm/commands/subprocess/utils.d.ts +0 -3
  380. package/esm/commands/subprocess/utils.d.ts.map +0 -1
  381. package/esm/commands/subprocess/utils.js +0 -56
  382. package/esm/commands/subprocess/utils.js.map +0 -1
  383. package/esm/commands/sync/index.d.ts +0 -9
  384. package/esm/commands/sync/index.d.ts.map +0 -1
  385. package/esm/commands/sync/index.js +0 -9
  386. package/esm/commands/sync/index.js.map +0 -1
  387. package/esm/commands/sync/list.d.ts.map +0 -1
  388. package/esm/commands/sync/list.js +0 -64
  389. package/esm/commands/sync/list.js.map +0 -1
  390. package/esm/commands/sync/pull.d.ts +0 -12
  391. package/esm/commands/sync/pull.d.ts.map +0 -1
  392. package/esm/commands/sync/pull.js +0 -33
  393. package/esm/commands/sync/pull.js.map +0 -1
  394. package/esm/commands/sync/push.d.ts +0 -61
  395. package/esm/commands/sync/push.d.ts.map +0 -1
  396. package/esm/commands/sync/push.js +0 -83
  397. package/esm/commands/sync/push.js.map +0 -1
  398. package/esm/commands/sync/request.d.ts +0 -24
  399. package/esm/commands/sync/request.d.ts.map +0 -1
  400. package/esm/commands/sync/request.js +0 -32
  401. package/esm/commands/sync/request.js.map +0 -1
  402. package/esm/commands/sync/response.d.ts +0 -28
  403. package/esm/commands/sync/response.d.ts.map +0 -1
  404. package/esm/commands/sync/response.js +0 -81
  405. package/esm/commands/sync/response.js.map +0 -1
  406. package/esm/commands/sync/socket.d.ts +0 -22
  407. package/esm/commands/sync/socket.d.ts.map +0 -1
  408. package/esm/commands/sync/socket.js +0 -78
  409. package/esm/commands/sync/socket.js.map +0 -1
  410. package/esm/commands/sync/stat.d.ts.map +0 -1
  411. package/esm/commands/sync/stat.js +0 -121
  412. package/esm/commands/sync/stat.js.map +0 -1
  413. package/esm/commands/sync/sync.d.ts +0 -82
  414. package/esm/commands/sync/sync.d.ts.map +0 -1
  415. package/esm/commands/sync/sync.js +0 -138
  416. package/esm/commands/sync/sync.js.map +0 -1
  417. package/esm/commands/tcpip.d.ts.map +0 -1
  418. package/esm/commands/tcpip.js.map +0 -1
  419. package/esm/daemon/auth.d.ts +0 -54
  420. package/esm/daemon/auth.d.ts.map +0 -1
  421. package/esm/daemon/auth.js +0 -104
  422. package/esm/daemon/auth.js.map +0 -1
  423. package/esm/server/stream.d.ts.map +0 -1
  424. package/esm/server/stream.js.map +0 -1
  425. package/src/commands/base.ts +0 -15
  426. package/src/commands/subprocess/none/service.ts +0 -45
  427. package/src/commands/subprocess/none/spawner.ts +0 -68
  428. package/src/commands/subprocess/shell/service.ts +0 -58
  429. package/src/commands/subprocess/shell/spawner.ts +0 -90
  430. package/src/commands/subprocess/utils.ts +0 -61
  431. package/src/commands/sync/index.ts +0 -8
  432. package/src/commands/sync/list.ts +0 -99
  433. package/src/commands/sync/pull.ts +0 -55
  434. package/src/commands/sync/push.ts +0 -172
  435. package/src/commands/sync/request.ts +0 -53
  436. package/src/commands/sync/response.ts +0 -105
  437. package/src/commands/sync/socket.ts +0 -109
  438. package/src/commands/sync/stat.ts +0 -177
  439. package/src/commands/sync/sync.ts +0 -175
  440. package/src/daemon/auth.ts +0 -203
  441. package/tsconfig.build.tsbuildinfo +0 -1
  442. /package/esm/{commands → service}/framebuffer.d.ts +0 -0
  443. /package/esm/{commands → service}/framebuffer.js +0 -0
  444. /package/esm/{commands → service}/subprocess/none/index.d.ts +0 -0
  445. /package/esm/{commands → service}/subprocess/none/index.js +0 -0
  446. /package/esm/{commands → service}/subprocess/none/process.js +0 -0
  447. /package/esm/{commands → service}/subprocess/pty.js +0 -0
  448. /package/esm/{commands → service}/subprocess/service.d.ts +0 -0
  449. /package/src/{commands → service}/framebuffer.ts +0 -0
  450. /package/src/{commands → service}/subprocess/none/index.ts +0 -0
@@ -0,0 +1,47 @@
1
+ // cspell: ignore Libusb
2
+ // cspell: ignore devraw
3
+ // cspell: ignore Openscreen
4
+ // cspell: ignore devicetracker
5
+
6
+ // The order follows
7
+ // https://cs.android.com/android/platform/superproject/main/+/main:packages/modules/adb/transport.cpp;l=81;drc=2d3e62c2af54a3e8f8803ea10492e63b8dfe709f
8
+
9
+ export const Shell2 = "shell_v2";
10
+ export const Cmd = "cmd";
11
+ export const Stat2 = "stat_v2";
12
+ export const Ls2 = "ls_v2";
13
+ /**
14
+ * server only
15
+ */
16
+ export const Libusb = "libusb";
17
+ /**
18
+ * server only
19
+ */
20
+ export const PushSync = "push_sync";
21
+ export const Apex = "apex";
22
+ export const FixedPushMkdir = "fixed_push_mkdir";
23
+ export const Abb = "abb";
24
+ export const FixedPushSymlinkTimestamp = "fixed_push_symlink_timestamp";
25
+ export const AbbExec = "abb_exec";
26
+ export const RemountShell = "remount_shell";
27
+ export const TrackApp = "track_app";
28
+ export const SendReceive2 = "sendrecv_v2";
29
+ export const SendReceive2Brotli = "sendrecv_v2_brotli";
30
+ export const SendReceive2Lz4 = "sendrecv_v2_lz4";
31
+ export const SendReceive2Zstd = "sendrecv_v2_zstd";
32
+ export const SendReceive2DryRunSend = "sendrecv_v2_dry_run_send";
33
+ export const DelayedAck = "delayed_ack";
34
+ /**
35
+ * server only
36
+ */
37
+ export const OpenscreenMdns = "openscreen_mdns";
38
+ /**
39
+ * server only
40
+ */
41
+ export const DeviceTrackerProtoFormat = "devicetracker_proto_format";
42
+ export const DevRaw = "devraw";
43
+ export const AppInfo = "app_info";
44
+ /**
45
+ * server only
46
+ */
47
+ export const ServerStatus = "server_status";
package/src/features.ts CHANGED
@@ -1,15 +1,32 @@
1
- // The order follows
2
- // https://cs.android.com/android/platform/superproject/+/master:packages/modules/adb/transport.cpp;l=77;drc=6d14d35d0241f6fee145f8e54ffd77252e8d29fd
3
- export const AdbFeature = {
4
- ShellV2: "shell_v2",
5
- Cmd: "cmd",
6
- StatV2: "stat_v2",
7
- ListV2: "ls_v2",
8
- FixedPushMkdir: "fixed_push_mkdir",
9
- Abb: "abb",
10
- AbbExec: "abb_exec",
11
- SendReceiveV2: "sendrecv_v2",
12
- DelayedAck: "delayed_ack",
13
- } as const;
1
+ import * as AdbFeature from "./features-value.js";
14
2
 
15
- export type AdbFeature = (typeof AdbFeature)[keyof typeof AdbFeature];
3
+ // biome-ignore lint/suspicious/noRedeclare: TypeScript declaration merging for enum-like object
4
+ type AdbFeature = (typeof AdbFeature)[keyof typeof AdbFeature];
5
+
6
+ export { AdbFeature };
7
+
8
+ // https://android.googlesource.com/platform/packages/modules/adb/+/79010dc6d5ca7490c493df800d4421730f5466ca/transport.cpp#1252
9
+ // There are some other feature constants, but some of them are only used by ADB server, not devices (daemons).
10
+ export const AdbDeviceFeatures = [
11
+ AdbFeature.Shell2,
12
+ AdbFeature.Cmd,
13
+ AdbFeature.Stat2,
14
+ AdbFeature.Ls2,
15
+ AdbFeature.FixedPushMkdir,
16
+ AdbFeature.Apex,
17
+ AdbFeature.Abb,
18
+ // only tells the client the symlink timestamp issue in `adb push --sync` has been fixed.
19
+ // No special handling required.
20
+ AdbFeature.FixedPushSymlinkTimestamp,
21
+ AdbFeature.AbbExec,
22
+ AdbFeature.RemountShell,
23
+ AdbFeature.TrackApp,
24
+ AdbFeature.SendReceive2,
25
+ AdbFeature.SendReceive2Brotli,
26
+ AdbFeature.SendReceive2Lz4,
27
+ AdbFeature.SendReceive2Zstd,
28
+ AdbFeature.SendReceive2DryRunSend,
29
+ AdbFeature.DevRaw,
30
+ AdbFeature.AppInfo,
31
+ AdbFeature.DelayedAck,
32
+ ] as readonly AdbFeature[];
package/src/index.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export * from "./adb.js";
2
2
  export * from "./banner.js";
3
- export * from "./commands/index.js";
4
3
  export * from "./daemon/index.js";
5
4
  export * from "./device-observer.js";
6
5
  export * from "./features.js";
7
6
  export * from "./server/index.js";
7
+ export * from "./service/index.js";
8
8
  export * from "./utils/index.js";
@@ -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);
181
+ const dataConnection = new AdbServerDataConnection(connection);
135
182
 
136
183
  try {
137
- await stream.writeString(request);
184
+ await dataConnection.writeString(request);
185
+ await dataConnection.readOkay();
186
+ return dataConnection;
138
187
  } catch (e) {
139
- await stream.dispose();
140
- throw e;
141
- }
142
-
143
- 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;
148
- } catch (e) {
149
- await stream.dispose();
188
+ await dataConnection.dispose();
150
189
  throw e;
151
190
  }
152
191
  }
@@ -154,8 +193,10 @@ export class AdbServerClient {
154
193
  /**
155
194
  * `adb version`
156
195
  */
157
- async getVersion(): Promise<number> {
158
- const connection = await this.createConnection("host:version");
196
+ async getVersion(
197
+ options?: AdbServerClient.ServerConnectionOptions,
198
+ ): Promise<number> {
199
+ const connection = await this.createConnection("host:version", options);
159
200
  try {
160
201
  const length = hexToNumber(await connection.readExactly(4));
161
202
  const version = hexToNumber(await connection.readExactly(length));
@@ -165,8 +206,11 @@ export class AdbServerClient {
165
206
  }
166
207
  }
167
208
 
168
- async validateVersion(minimalVersion: number) {
169
- const version = await this.getVersion();
209
+ async validateVersion(
210
+ minimalVersion: number,
211
+ options?: AdbServerClient.ServerConnectionOptions,
212
+ ) {
213
+ const version = await this.getVersion(options);
170
214
  if (version < minimalVersion) {
171
215
  throw new Error(
172
216
  `adb server version (${version}) doesn't match this client (${minimalVersion})`,
@@ -271,13 +315,13 @@ export class AdbServerClient {
271
315
  "host:features",
272
316
  );
273
317
  // Luckily `AdbServerClient.Socket` is compatible with `AdbServerClient.ServerConnection`
274
- const stream = new AdbServerStream(connection);
318
+ const dataConnection = new AdbServerDataConnection(connection);
275
319
  try {
276
- const featuresString = await stream.readString();
320
+ const featuresString = await dataConnection.readString();
277
321
  const features = featuresString.split(",") as AdbFeature[];
278
322
  return { transportId: connection.transportId, features };
279
323
  } finally {
280
- await stream.dispose();
324
+ await dataConnection.dispose();
281
325
  }
282
326
  }
283
327
 
@@ -285,43 +329,40 @@ export class AdbServerClient {
285
329
  * Creates a connection that will forward the service to device.
286
330
  * @param device The device selector
287
331
  * @param service The service to forward
332
+ * @param options The server connection options
288
333
  * @returns An `AdbServerClient.Socket` that can be used to communicate with the service
289
334
  */
290
335
  async createDeviceConnection(
291
336
  device: AdbServerClient.DeviceSelector,
292
337
  service: string,
338
+ options?: AdbServerClient.ServerConnectionOptions,
293
339
  ): Promise<AdbServerClient.Socket> {
294
340
  let switchService: string;
295
341
  let transportId: bigint | undefined;
296
342
  if (!device) {
297
- await this.validateVersion(41);
343
+ await this.validateVersion(41, options);
298
344
  switchService = `host:tport:any`;
299
345
  } else if ("transportId" in device) {
300
346
  switchService = `host:transport-id:${device.transportId}`;
301
347
  transportId = device.transportId;
302
348
  } else if ("serial" in device) {
303
- await this.validateVersion(41);
349
+ await this.validateVersion(41, options);
304
350
  switchService = `host:tport:serial:${device.serial}`;
305
351
  } else if ("usb" in device) {
306
- await this.validateVersion(41);
352
+ await this.validateVersion(41, options);
307
353
  switchService = `host:tport:usb`;
308
354
  } else if ("tcp" in device) {
309
- await this.validateVersion(41);
355
+ await this.validateVersion(41, options);
310
356
  switchService = `host:tport:local`;
311
357
  } else {
312
358
  throw new TypeError("Invalid device selector");
313
359
  }
314
360
 
315
- const connection = await this.createConnection(switchService);
361
+ const connection = await this.createConnection(switchService, options);
316
362
 
317
363
  try {
318
364
  await connection.writeString(service);
319
- } catch (e) {
320
- await connection.dispose();
321
- throw e;
322
- }
323
365
 
324
- try {
325
366
  if (transportId === undefined) {
326
367
  const array = await connection.readExactly(8);
327
368
  transportId = getUint64LittleEndian(array, 0);
@@ -348,17 +389,14 @@ export class AdbServerClient {
348
389
  throw e;
349
390
  }
350
391
  }
392
+
351
393
  async #waitForUnchecked(
352
394
  device: AdbServerClient.DeviceSelector,
353
395
  state: "device" | "disconnect",
354
396
  options?: AdbServerClient.ServerConnectionOptions,
355
397
  ): Promise<void> {
356
398
  let type: string;
357
- if (!device) {
358
- type = "any";
359
- } else if ("transportId" in device) {
360
- type = "any";
361
- } else if ("serial" in device) {
399
+ if (!device || "transportId" in device || "serial" in device) {
362
400
  type = "any";
363
401
  } else if ("usb" in device) {
364
402
  type = "usb";
@@ -399,7 +437,7 @@ export class AdbServerClient {
399
437
  options?: AdbServerClient.ServerConnectionOptions,
400
438
  ): Promise<void> {
401
439
  if (state === "disconnect") {
402
- await this.validateVersion(41);
440
+ await this.validateVersion(41, options);
403
441
  }
404
442
 
405
443
  return this.#waitForUnchecked(device, state, options);
@@ -409,7 +447,7 @@ export class AdbServerClient {
409
447
  transportId: bigint,
410
448
  options?: AdbServerClient.ServerConnectionOptions,
411
449
  ): Promise<void> {
412
- const serverVersion = await this.getVersion();
450
+ const serverVersion = await this.getVersion(options);
413
451
  if (serverVersion >= 41) {
414
452
  return this.#waitForUnchecked(
415
453
  { transportId },
@@ -425,12 +463,12 @@ export class AdbServerClient {
425
463
  (device) => device.transportId === transportId,
426
464
  )
427
465
  ) {
428
- observer.stop();
466
+ observer.close();
429
467
  resolve();
430
468
  }
431
469
  });
432
470
  observer.onError((e) => {
433
- observer.stop();
471
+ observer.close();
434
472
  reject(e);
435
473
  });
436
474
  });
@@ -483,37 +521,6 @@ export class AdbServerClient {
483
521
  }
484
522
  }
485
523
 
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
524
  export namespace AdbServerClient {
518
525
  export interface ServerConnectionOptions {
519
526
  unref?: boolean | undefined;
@@ -533,7 +540,7 @@ export namespace AdbServerClient {
533
540
  ): MaybePromiseLike<ServerConnection>;
534
541
 
535
542
  addReverseTunnel(
536
- handler: AdbIncomingSocketHandler,
543
+ handler: Adb.IncomingSocketHandler,
537
544
  address?: string,
538
545
  ): MaybePromiseLike<string>;
539
546
 
@@ -542,7 +549,7 @@ export namespace AdbServerClient {
542
549
  clearReverseTunnels(): MaybePromiseLike<void>;
543
550
  }
544
551
 
545
- export interface Socket extends AdbSocket {
552
+ export interface Socket extends Adb.Socket {
546
553
  transportId: bigint;
547
554
  }
548
555
 
@@ -556,7 +563,8 @@ export namespace AdbServerClient {
556
563
  | { tcp: true }
557
564
  | undefined;
558
565
 
559
- export type ConnectionState = "unauthorized" | "offline" | "device";
566
+ export type ConnectionState =
567
+ (typeof AdbServerClient.ConnectionState)[number];
560
568
 
561
569
  export interface Device {
562
570
  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
  }