dshgo-vmbridge 0.0.0-stage → 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 xqe-bkflda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,235 @@
1
- # Temporary Holding Version
1
+ # dshgo-vmbridge
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **DSH 手机端插件** · 让 AI 直接操控 **AndVM** 里的 Android 虚拟机:看屏幕、点按钮、敲键盘、跑 root shell、装 APK、截图。
4
+
5
+ > 这是一个 [DSH Go](https://github.com/xqe-bkflda) 手机 App 的本地插件(不是 Cordis 插件,不是桌面端插件)。
6
+
7
+ 手机本身没 root,靠 **AndVM**(基于 Android 官方 AVF 的免 root 虚拟机)开一台有 Magisk root 的 Android 12。
8
+ 插件跑在 DSH 的 proot 环境里,通过 `adb` 驱动那台虚拟机,把这些能力注册成 AI 可以直接调用的工具。
9
+
10
+ ```
11
+ [AI 模型]
12
+ ↓ 调用 vm_* 工具
13
+ [local-vmbridge 插件] ← 跑在 DSH Go 的 proot Ubuntu 里
14
+ ↓ adb (127.0.0.1:5037 fork-server)
15
+ [127.0.0.1:<AndVM 调试端口>] ← 每次重启 AndVM 都会变
16
+ ↓
17
+ [AndVM 里的 Android 12 虚拟机] ← 有 Magisk root
18
+ ├── Shot.apk(无障碍截图,虚拟机里必须装)
19
+ └── 被 AI 操作的各种 App
20
+ ```
21
+
22
+ ![Shot 在 AndVM 虚拟机里截出来的画面](screenshot.png)
23
+
24
+ *<sub>上面这张就是插件通过 `vm_screenshot` 拿到的图:AndVM 里的 Android 12 抽屉页,720×1600</sub>*
25
+
26
+ ---
27
+
28
+ ## 前置条件(两个都必须有)
29
+
30
+ ### 1. AndVM 虚拟机
31
+
32
+ - 装 [AndVM](https://andvm.cn)(包名 `com.lerist.andvm`),在里面创建并启动一台虚拟机
33
+ - 虚拟机里打开 **配置 → 调试 → 启用 ADB**
34
+ - 调试页会显示「**本机地址 127.0.0.1:NNNNN**」,记下这个端口 —— **每次重启虚拟机都会变**
35
+
36
+ > 没有 AndVM 就没法用:插件只负责驱动,不提供虚拟机。
37
+
38
+ ### 2. Shot.apk(虚拟机里必装)
39
+
40
+ **为什么需要它**:AndVM 虚拟机里 `gralloc mapper` 没注册(`/vendor/etc/vintf/manifest.xml` 是空的只读挂载,改不了),
41
+ 导致 `screencap` 无论 shell 还是 root 都直接 `gralloc-mapper is missing` + `Aborted`,产出 0 字节文件。
42
+ `/dev/graphics/`、`/dev/fb*` 都不存在,`LD_PRELOAD` 换 libc++ 会被 linkage namespace 拒绝。
43
+
44
+ 唯一可行的路子是应用内 `AccessibilityService.takeScreenshot()`(API 30+),它不走 gralloc mapper。
45
+ 所以写了一个 17KB 的 Shot App 专门干这件事。
46
+
47
+ **安装**(二选一):
48
+
49
+ ```bash
50
+ # 方式 A:让插件自己装(推荐)
51
+ vm_shot_setup(reinstall=true)
52
+ # 它会:push Shot.apk → pm install -r -g → 启用无障碍 → 自检截一张
53
+
54
+ # 方式 B:手动
55
+ adb -s 127.0.0.1:<端口> install -r -g Shot.apk
56
+ adb -s 127.0.0.1:<端口> shell "su -c 'settings put secure enabled_accessibility_services com.dsh.shot/com.dsh.shot.ShotService; settings put secure accessibility_enabled 1'"
57
+ ```
58
+
59
+ 装完去虚拟机 **设置 → 无障碍 → Shot** 确认是「已开启」状态。
60
+
61
+ > `Shot.apk` 就在仓库根目录,插件目录里也带了一份。
62
+
63
+ ---
64
+
65
+ ## 安装插件
66
+
67
+ ```bash
68
+ # 1. 放到 dsh-go 的插件目录
69
+ cp -r dshgo-vmbridge "$DSH_HOME/dsh-go/plugins/local-vmbridge"
70
+
71
+ # 2. 装进 DSH profile
72
+ dsh plugin --profile web add "$DSH_HOME/dsh-go/plugins/local-vmbridge"
73
+
74
+ # 3. 重启引擎(App → 设置 → 引擎 → 重启)
75
+ ```
76
+
77
+ 也可以直接把本目录软链到 `$DSH_HOME/dsh-go/plugins/local-vmbridge` 再执行第 2 步。
78
+
79
+ 装好后会话里会出现「**虚拟机桥**」面板,也可以在功能页找到。
80
+
81
+ ---
82
+
83
+ ## 第一次用
84
+
85
+ ```
86
+ 1. vm_connect_adb(port=40777) # 填 AndVM 调试页的端口,填数字就行
87
+ 2. vm_status() # 确认 state=device、root=true
88
+ 3. vm_shot_setup() # 装/修截图 App,自检一次出图
89
+ 4. vm_screen() # 看虚拟机当前屏幕(带编号的元素列表)
90
+ ```
91
+
92
+ `vm_connect_adb` 三种填法都行:
93
+
94
+ | 参数 | 例子 | 说明 |
95
+ |---|---|---|
96
+ | `port` | `40777` | 最省事,自动补 `127.0.0.1:` |
97
+ | `addr` | `127.0.0.1:40777` | 完整地址 |
98
+ | `scan` | `true` | 自动扫 32768–60999 找在听的 adb(约 60–90 秒) |
99
+
100
+ 端口变了懒得去抄的时候用 `scan`。
101
+
102
+ ---
103
+
104
+ ## 工具清单(22 个)
105
+
106
+ ### 连接
107
+ | 工具 | 说明 |
108
+ |---|---|
109
+ | `vm_status` | 当前端口、device/offline/unauthorized、guest 系统版本、su root 有没有 |
110
+ | `vm_connect_adb` | 填 adb 地址并连上(`addr` / `host`+`port` / `scan`) |
111
+
112
+ ### 观察
113
+ | 工具 | 说明 |
114
+ |---|---|
115
+ | `vm_screen` | **主观察工具**。带编号的元素列表,`[3] 设置 可点 @494,334`,编号只在本屏有效 |
116
+ | `vm_ui` | 原始 UI 节点(要结构化数据时用) |
117
+ | `vm_screenshot` | 截一张存到本机,返回宽高和字节数 |
118
+ | `vm_shots` | 连拍几张(看动画/加载) |
119
+ | `vm_current` | 当前前台 App / Activity |
120
+ | `vm_activity` | Activity 栈顶 |
121
+
122
+ ### 操作
123
+ | 工具 | 说明 |
124
+ |---|---|
125
+ | `vm_tap` | 点。给 `id`(`vm_screen` 的编号)或 `x`/`y` |
126
+ | `vm_click` | 按文字点,找可点父节点 |
127
+ | `vm_swipe` | 直滑或折线(`points=[[x,y],…]`) |
128
+ | `vm_key` | 系统键:back / home / recents / notifications / enter |
129
+ | `vm_text` | 往聚焦输入框打字 |
130
+
131
+ > `vm_tap` / `vm_click` / `vm_swipe` / `vm_key` / `vm_text` 执行完都会**自动重读屏幕**,返回新的 `screen`,不用再调一次 `vm_screen`。
132
+
133
+ ### App 管理
134
+ | 工具 | 说明 |
135
+ |---|---|
136
+ | `vm_apps` | 列已装应用(可按关键字过滤) |
137
+ | `vm_start` | 启动 App |
138
+ | `vm_install_apk` | 装本机 APK(分块推 → `pm install -r -g -d` → 差集反查包名) |
139
+ | `vm_uninstall_apk` | 卸(可 `--user 0` 退让) |
140
+ | `vm_apk_info` | 路径、大小、版本、安装时间 |
141
+
142
+ ### Shell / 文件
143
+ | 工具 | 说明 |
144
+ |---|---|
145
+ | `vm_shell` | 跑命令。默认 `su -c`,su 不通自动退回普通 shell |
146
+ | `vm_file_push` | 推到虚拟机(>1MB 自动分块) |
147
+ | `vm_file_pull` | 从虚拟机拉回来 |
148
+
149
+ ### 截图 App
150
+ | 工具 | 说明 |
151
+ |---|---|
152
+ | `vm_shot_setup` | 装/修 Shot:装 APK、启用无障碍、自检一次出图 |
153
+
154
+ ---
155
+
156
+ ## 典型用法
157
+
158
+ ```
159
+ 你:看下虚拟机现在是什么界面
160
+ AI:vm_screen()
161
+ → 屏幕 720x1600 com.android.launcher3/.QuickstepLauncher(via accessibility)
162
+ [1] 搜索 可点 @360,164
163
+ [2] 设置 可点 @494,334
164
+ ...
165
+
166
+ 你:打开设置,把 WLAN 关掉
167
+ AI:vm_tap(id=2) → 设置页打开,附带新屏幕
168
+ vm_click(text="网络和互联网")
169
+ vm_screen() → 看到 WLAN 那一行是 [5]
170
+ vm_tap(id=5)
171
+ vm_click(text="关闭")
172
+ ```
173
+
174
+ ---
175
+
176
+ ## 排障
177
+
178
+ | 症状 | 原因 / 处理 |
179
+ |---|---|
180
+ | `连不上 127.0.0.1:NNNNN` | AndVM 重启后端口变了。去调试页抄新端口,或 `vm_connect_adb(scan=true)` |
181
+ | `unauthorized` | 虚拟机画面里点「允许 USB 调试」,勾「一律允许」 |
182
+ | `offline` | 把 AndVM 的「启用 ADB」关掉再开;端口可能变 |
183
+ | `root: false` | Magisk 没授权。虚拟机里 Magisk → 超级用户 → 给「Shell」授权 |
184
+ | `截图失败:无障碍服务没连上` | 跑 `vm_shot_setup(reinstall=true)`;还不行就去 设置→无障碍 手动开 Shot |
185
+ | `等不到截图` | 无障碍被系统回收了(`am force-stop` 会杀掉它)。`vm_shot_setup()` 重新拉起来 |
186
+ | 工具列表里没有 `vm_*` | 插件没加载。`dsh plugin --profile web list` 看有没有 `local-vmbridge`,然后重启引擎 |
187
+
188
+ ### 已知取舍
189
+
190
+ - **截图慢**:无障碍 `takeScreenshot` 一次 3–6 秒,比 `screencap` 慢,但 `screencap` 在这个虚拟机里根本不工作。
191
+ - **截图会带状态栏**:`takeScreenshot` 拿到的是整屏。
192
+ - **无障碍与 `am force-stop` 互斥**:`am force-stop com.dsh.shot` 之后要重新启用无障碍。
193
+ - **只支持 AndVM**:`127.0.0.1:PORT` 这个形态是 AndVM 的 ADB 调试页给出来的。别的模拟器改 `addr` 也许能连,没测过。
194
+
195
+ ---
196
+
197
+ ## 源码结构
198
+
199
+ ```
200
+ dshgo-vmbridge/
201
+ ├── README.md
202
+ ├── screenshot.png # vm_screenshot 的实际输出(示例)
203
+ ├── package.json # dshGo 清单:面板 + 工具
204
+ ├── cordis.patch.yml # cordis 注入声明
205
+ ├── Shot.apk # 虚拟机截图 App(直接装)
206
+ ├── lib/
207
+ │ └── index.js # 插件主文件:22 个工具 + 面板
208
+ └── app/ # Shot App 源码
209
+ ├── AndroidManifest.xml
210
+ ├── build.sh # aarch64 上可用的构建脚本
211
+ ├── res/
212
+ │ ├── values/strings.xml
213
+ │ └── xml/shot_a11y.xml
214
+ └── src/com/dsh/shot/
215
+ ├── Main.java # 极简界面
216
+ ├── ShotReceiver.java # 广播触发入口
217
+ └── ShotService.java # takeScreenshot 出图
218
+ ```
219
+
220
+ ### 在手机上重新编译 Shot.apk
221
+
222
+ ```bash
223
+ cd app && bash build.sh
224
+ # → Shot.apk
225
+ ```
226
+
227
+ `build.sh` 踩过的坑都写在里面了:aarch64 上必须用系统的 `/usr/bin/aapt2`(SDK 里那个是 x86-64),
228
+ `-I` 指 `/usr/share/android-framework-res/framework-res.apk`(不是 `android.jar`),
229
+ `d8` / `apksigner` 用 `java -jar` 跑。
230
+
231
+ ---
232
+
233
+ ## License
234
+
235
+ MIT
package/Shot.apk ADDED
Binary file
@@ -0,0 +1,4 @@
1
+ # id: any unique id; name: must equal "name" in package.json.
2
+ - insert:
3
+ - id: dshgo-vmbridge
4
+ name: dshgo-vmbridge