diff --git a/android/app/src/main/cpp/ScreenHandler.h b/android/app/src/main/cpp/ScreenHandler.h index a7b7c5f..e1b856d 100644 --- a/android/app/src/main/cpp/ScreenHandler.h +++ b/android/app/src/main/cpp/ScreenHandler.h @@ -22,6 +22,7 @@ extern uint64_t g_myClientID; // 定义在 main.cpp,供子连接的 OnReceive 调用 extern void DispatchControlEvent(uint32_t msgVal, uint64_t wParam, int32_t ptX, int32_t ptY); +extern void DispatchClipboardText(const uint8_t* data, size_t size); // Linux/macOS 共用的 BITMAPINFOHEADER 布局(与 Windows 完全一致) #pragma pack(push, 1) @@ -123,6 +124,11 @@ public: case CMD_QUALITY_LEVEL: if (size >= 2) LOGI_SH("QualityLevel=%d", (int)(int8_t)data[1]); break; + case COMMAND_SCREEN_SET_CLIPBOARD: + // 服务端写剪贴板: [cmd:1][GBK text:N](与 Windows CF_TEXT 同编码;人类剪贴板 + // 同步会带 '\0' 结尾,MCP 路径不带,Kotlin 侧统一去掉尾随 NUL) + if (size > 1) DispatchClipboardText(data + 1, (size_t)size - 1); + break; case COMMAND_SCREEN_CONTROL: { // 服务端通过子连接下发鼠标/键盘控制包(MSG64 固定 48 字节) // 坐标从 lParam(offset 24)读取,与 Windows/Linux/macOS 客户端一致: diff --git a/android/app/src/main/cpp/main.cpp b/android/app/src/main/cpp/main.cpp index 35b9afa..c46f59a 100644 --- a/android/app/src/main/cpp/main.cpp +++ b/android/app/src/main/cpp/main.cpp @@ -242,6 +242,7 @@ static jmethodID g_forceFirstFrameMid = nullptr; static jmethodID g_statusMid = nullptr; // CaptureService.onNativeStatus(String) static jmethodID g_nativeExitMid = nullptr; // CaptureService.onNativeExit() — 服务端主动断开时停止服务 static jmethodID g_updateReceivedMid = nullptr; // CaptureService.onUpdateReceived(String) — 升级 APK 已落盘 +static jmethodID g_clipboardMid = nullptr; // CaptureService.onClipboardText([B)V — 远程剪贴板 // ScreenShot(无障碍 takeScreenshot 抓屏,MCP get_screenshot 用) static jclass g_shotClass = nullptr; static jmethodID g_shotCanMid = nullptr; // ScreenShot.canCapture()Z @@ -282,6 +283,52 @@ void DispatchControlEvent(uint32_t msgVal, uint64_t wParam, int32_t ptX, int32_t if (attached) g_jvm->DetachCurrentThread(); } +// 远程剪贴板:服务端下发 [COMMAND_SCREEN_SET_CLIPBOARD][GBK text],字节原样交给 +// CaptureService.onClipboardText(Kotlin 侧按 GBK 解码后写系统剪贴板)。 +// 与 DispatchControlEvent 同一套 attach/detach 套路,供屏幕子连接 OnReceive 调用。 +void DispatchClipboardText(const uint8_t* data, size_t size) +{ + if (!g_jvm || !g_captureClass || !g_clipboardMid) { + LOGE("CLIPBOARD: JNI not ready (cls=%p method=%p)", g_captureClass, g_clipboardMid); + return; + } + JNIEnv* jenv = nullptr; + bool attached = false; + jint st = g_jvm->GetEnv((void**)&jenv, JNI_VERSION_1_6); + if (st == JNI_EDETACHED) { + if (g_jvm->AttachCurrentThread(&jenv, nullptr) != JNI_OK || !jenv) return; + attached = true; + } else if (st != JNI_OK || !jenv) { + return; + } + // 服务端已把剪贴板文本限制在 256 KB,这里再兜一层 1 MiB:超出直接丢, + // 不截断(半截文本写进剪贴板比不写更危险) + const size_t kMaxClipboardBytes = 1u << 20; + if (size > kMaxClipboardBytes) { + LOGE("CLIPBOARD: payload %zu bytes exceeds %zu, dropped", size, kMaxClipboardBytes); + if (attached) g_jvm->DetachCurrentThread(); + return; + } + jbyteArray arr = jenv->NewByteArray((jsize)size); + if (!arr) { + if (jenv->ExceptionOccurred()) jenv->ExceptionClear(); + if (attached) g_jvm->DetachCurrentThread(); + LOGE("CLIPBOARD: NewByteArray(%zu) failed", size); + return; + } + jenv->SetByteArrayRegion(arr, 0, (jsize)size, (const jbyte*)data); + if (!jenv->ExceptionCheck()) { + jenv->CallStaticVoidMethod(g_captureClass, g_clipboardMid, arr); + if (jenv->ExceptionCheck()) jenv->ExceptionClear(); + LOGI("CLIPBOARD: dispatched %zu bytes", size); + } else { + jenv->ExceptionClear(); + LOGE("CLIPBOARD: SetByteArrayRegion failed"); + } + jenv->DeleteLocalRef(arr); + if (attached) g_jvm->DetachCurrentThread(); +} + static std::string GetActiveWindowFromJava() { if (!g_jvm || !g_ctrlClass || !g_getActiveWindowMid) return "Android"; @@ -1369,6 +1416,9 @@ Java_com_yama_client_YamaBridge_nativeInit( g_updateReceivedMid = env->GetStaticMethodID(g_captureClass, "onUpdateReceived", "(Ljava/lang/String;)V"); if (env->ExceptionCheck()) { env->ExceptionClear(); g_updateReceivedMid = nullptr; } if (!g_updateReceivedMid) LOGE("CaptureService.onUpdateReceived not found"); + g_clipboardMid = env->GetStaticMethodID(g_captureClass, "onClipboardText", "([B)V"); + if (env->ExceptionCheck()) { env->ExceptionClear(); g_clipboardMid = nullptr; } + if (!g_clipboardMid) LOGE("CaptureService.onClipboardText not found"); UseAndroidLog(PostStatus); } else { LOGE("CaptureService class not found"); diff --git a/android/app/src/main/java/com/yama/client/CaptureService.kt b/android/app/src/main/java/com/yama/client/CaptureService.kt index 80c64c4..867aeec 100644 --- a/android/app/src/main/java/com/yama/client/CaptureService.kt +++ b/android/app/src/main/java/com/yama/client/CaptureService.kt @@ -4,6 +4,9 @@ import android.app.Notification import android.app.NotificationChannel import android.app.NotificationManager import android.app.Service +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context import android.content.Intent import android.hardware.display.DisplayManager import android.hardware.display.VirtualDisplay @@ -23,6 +26,8 @@ import android.util.Log import android.view.WindowManager import android.widget.Toast +import java.nio.charset.Charset + class CaptureService : Service() { companion object { @@ -59,6 +64,36 @@ class CaptureService : Service() { UpdateInstaller.onApkReceived(ctx, path) } + /** + * 远程剪贴板(COMMAND_SCREEN_SET_CLIPBOARD):服务端按 GBK/ANSI 下发字节(Windows + * CF_TEXT 语义),这里解成字符串写系统剪贴板。写入不要求应用在前台(Android 10+ + * 只限制「读」剪贴板),所以主控能往后台的客户端塞文本;粘到目标输入框由用户在 + * 远端的输入框里用 VK_V(本客户端映射为 ACTION_PASTE)完成。 + */ + @JvmStatic + fun onClipboardText(bytes: ByteArray) { + val ctx = instance ?: appContext + if (ctx == null) { + Log.w(TAG, "onClipboardText: no context, ${bytes.size} bytes dropped") + return + } + val cm = ctx.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager + if (cm == null) { + Log.e(TAG, "onClipboardText: no ClipboardManager") + return + } + // 人类剪贴板同步(ScreenSpyDlg / HideScreenSpyDlg)发的是带 '\0' 结尾的 CF_TEXT, + // MCP 路径不带;统一在这里去掉尾随 NUL,否则粘进输入框会多一个不可见字符 + val text = String(bytes, Charset.forName("GBK")).trimEnd('\u0000') + try { + cm.setPrimaryClip(ClipData.newPlainText("YAMA", text)) + Log.i(TAG, "onClipboardText: ${bytes.size} bytes, ${text.length} chars") + } catch (e: Throwable) { + // Android 10+ 极少见地会在某些受限场景抛 SecurityException;记日志不崩 JNI 线程 + Log.e(TAG, "onClipboardText: setPrimaryClip failed: $e") + } + } + @JvmStatic fun onNativeExit() { val svc = instance ?: return diff --git a/android/app/src/main/java/com/yama/client/ControlService.kt b/android/app/src/main/java/com/yama/client/ControlService.kt index 6ab92f1..d5eeffa 100644 --- a/android/app/src/main/java/com/yama/client/ControlService.kt +++ b/android/app/src/main/java/com/yama/client/ControlService.kt @@ -436,9 +436,48 @@ class ControlService : AccessibilityService() { 0x24 -> performGlobalAction(GLOBAL_ACTION_HOME) // VK_HOME 0x5D -> performGlobalAction(GLOBAL_ACTION_RECENTS) // VK_APPS 0x2C -> performGlobalAction(GLOBAL_ACTION_TAKE_SCREENSHOT) // PrtSc + 0x56 -> pasteIntoFocused() // VK_V → 粘贴 } } + // 远程剪贴板的粘贴动作。Android 没有 Ctrl+V 组合键,而且本客户端不注入文本, + // 所以把 VK_V 映射成输入框的 ACTION_PASTE:由目标应用自己读剪贴板, + // 不受 Android 10+「后台应用不能读剪贴板」的限制。 + @Suppress("DEPRECATION") + private fun pasteIntoFocused() { + val root = rootInActiveWindow ?: run { + Log.w(TAG, "paste: no active window") + return + } + // 焦点链:输入焦点 → 无障碍焦点 → 整棵树里第一个可编辑节点。部分应用只置 + // FOCUS_ACCESSIBILITY;也不拿 isEditable 当门槛(WebView / 自绘输入框常常不置位 + // 但照样响应 ACTION_PASTE),真正的判据是 performAction 的返回值。 + val target = root.findFocus(AccessibilityNodeInfo.FOCUS_INPUT) + ?: root.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY) + ?: findFirstEditable(root) + if (target == null) { + Log.w(TAG, "paste: no focused or editable node") + } else { + if (!target.performAction(AccessibilityNodeInfo.ACTION_PASTE)) + Log.w(TAG, "paste: ACTION_PASTE rejected by ${target.packageName}") + target.recycle() + } + root.recycle() + } + + // 找不到焦点时的兜底:返回整棵树里第一个可见的可编辑节点(调用方负责 recycle) + @Suppress("DEPRECATION") + private fun findFirstEditable(node: AccessibilityNodeInfo): AccessibilityNodeInfo? { + if (node.isEditable && node.isVisibleToUser) return AccessibilityNodeInfo.obtain(node) + for (i in 0 until node.childCount) { + val child = node.getChild(i) ?: continue + val hit = findFirstEditable(child) + child.recycle() + if (hit != null) return hit + } + return null + } + private fun dispatchTap(x: Float, y: Float) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return val path = Path().apply { moveTo(x, y); lineTo(x + 1f, y) } diff --git a/common/commands.h b/common/commands.h index 300a88a..1dbaf69 100644 --- a/common/commands.h +++ b/common/commands.h @@ -144,6 +144,7 @@ inline int isValid_10s() #define CLIENT_CAP_WINDOW_INFO 0x0100 // 支持 COMMAND_MCP_WINDOW_INFO(带矩形/前后台/最小化状态的窗口列表)与窗口激活(CMD_WINDOW_ACTIVATE_FLAG) #define CLIENT_CAP_SCREEN_REGION 0x0200 // 支持 COMMAND_SCREEN_PREVIEW_REQ 扩展(区域/窗口/显示器原生分辨率截图) #define CLIENT_CAP_APK_UPDATE 0x0400 // 支持接收 COMMAND_UPDATE 下发的 APK 并走系统安装器(仅 Android) +#define CLIENT_CAP_SCREEN_CLIPBOARD 0x0800 // 屏幕子连接处理 COMMAND_SCREEN_SET_CLIPBOARD,并把 VK_V 映射成 ACTION_PASTE(仅新版 Android) #define TALK_DLG_MAXLEN 1024 // 最大输入字符长度 @@ -1300,6 +1301,9 @@ typedef struct LOGIN_INFOR { // 收到服务端下发的 APK 后写盘并拉起系统安装器。老 APK 没有这个分支, // 服务端据此提示「先手动装一次新版」,而不是发一个对方会静默丢弃的包。 caps |= CLIENT_CAP_APK_UPDATE; + // 屏幕子连接写剪贴板(COMMAND_SCREEN_SET_CLIPBOARD)+ VK_V → ACTION_PASTE。 + // 更老的 APK 两个分支都没有,收到包只会丢弃,服务端据此提前拒绝而不是假报 ok。 + caps |= CLIENT_CAP_SCREEN_CLIPBOARD; #endif return caps; } diff --git a/mcp/tools.json b/mcp/tools.json index 1bd1ec4..907084d 100644 --- a/mcp/tools.json +++ b/mcp/tools.json @@ -456,7 +456,7 @@ "type": "boolean" }, "remoteControl": { - "description": "能否建立远程控制会话(remote_open/remote_mouse/remote_keyboard 的前提);还要求服务端 Web 远程服务已启动(WebSvrPort>0)", + "description": "能否建立远程控制会话(remote_open/remote_mouse/remote_keyboard 的前提);Android 客户端只支持整屏目标,且需要已授权录屏与无障碍服务;还要求服务端 Web 远程服务已启动(WebSvrPort>0)", "type": "boolean" }, "screenPreview": { @@ -1171,69 +1171,68 @@ ], "impl": "mfc", "inputSchema": { - "type": "object", "properties": { "id": { - "type": "string", - "description": "主机 id,取 list_online_hosts / search_hosts 返回的 id 字段" + "description": "主机 id,取 list_online_hosts / search_hosts 返回的 id 字段", + "type": "string" } }, "required": [ "id" - ] + ], + "type": "object" }, "outputSchema": { - "type": "object", "properties": { "window": { - "type": [ - "object", - "null" - ], "properties": { - "hwnd": { - "type": "integer" - }, - "pid": { - "type": "integer" - }, - "left": { - "type": "integer" - }, - "top": { - "type": "integer" - }, - "right": { - "type": "integer" - }, "bottom": { "type": "integer" }, - "width": { - "type": "integer" - }, "height": { "type": "integer" }, - "zOrder": { + "hwnd": { "type": "integer" }, - "title": { - "type": "string" + "isForeground": { + "type": "boolean" }, - "visible": { + "left": { + "type": "integer" + }, + "maximized": { "type": "boolean" }, "minimized": { "type": "boolean" }, - "maximized": { + "pid": { + "type": "integer" + }, + "right": { + "type": "integer" + }, + "title": { + "type": "string" + }, + "top": { + "type": "integer" + }, + "visible": { "type": "boolean" }, - "isForeground": { - "type": "boolean" + "width": { + "type": "integer" + }, + "zOrder": { + "type": "integer" } - } + }, + "type": [ + "object", + "null" + ] }, "windowCount": { "type": "integer" @@ -1242,7 +1241,8 @@ "required": [ "window", "windowCount" - ] + ], + "type": "object" } }, { @@ -2327,12 +2327,13 @@ }, { "name": "remote_open", - "description": "在指定在线 Windows 或 Linux 主机上建立远程控制会话(隐藏屏幕子连接)并返回 session_id、抓屏帧尺寸(screen_w/screen_h)与目标(target)。默认推整屏/整虚拟桌面(可能等比缩放);可用 window_hwnd 只推一个窗口,或用 region 只推一个矩形区域,带宽、延迟和点击精度都更好,此时归一化坐标 0..1 相对该目标帧。后续 remote_mouse/remote_keyboard 用归一化坐标(0..1)注入输入,用毕须 remote_close。Linux 需要 X11/Xorg(或 XWayland)桌面,纯 Wayland 会话无法抓屏/注入;window_hwnd/region 仅支持声明 CLIENT_CAP_WINDOW_INFO 的新 Windows 客户端。Windows 多显示器下整屏目标需要新版客户端(整虚拟桌面抓屏),老客户端会被拒绝;window 目标不依赖虚拟桌面抓屏,不受此限。", + "description": "在指定在线 Windows、Linux 或 Android 主机上建立远程控制会话(隐藏屏幕子连接)并返回 session_id、抓屏帧尺寸(screen_w/screen_h)与目标(target)。默认推整屏/整虚拟桌面(可能等比缩放);可用 window_hwnd 只推一个窗口,或用 region 只推一个矩形区域,带宽、延迟和点击精度都更好,此时归一化坐标 0..1 相对该目标帧。后续 remote_mouse/remote_keyboard 用归一化坐标(0..1)注入输入,用毕须 remote_close。Linux 需要 X11/Xorg(或 XWayland)桌面,纯 Wayland 会话无法抓屏/注入;window_hwnd/region 仅支持声明 CLIENT_CAP_WINDOW_INFO 的新 Windows 客户端。Windows 多显示器下整屏目标需要新版客户端(整虚拟桌面抓屏),老客户端会被拒绝;window 目标不依赖虚拟桌面抓屏,不受此限。Android 主机只支持整屏目标,输入被翻译成触摸手势与全局动作(见 remote_mouse / remote_keyboard);抓屏依赖客户端已授权录屏(MediaProjection),未授权时 remote_open 会一直等不到屏幕子连接,注入还依赖无障碍服务在跑(未开启时命令照样下发但不生效,且没有回执)。", "gate": "remote_control", "write": true, "platforms": [ "win", - "lnx" + "lnx", + "apk" ], "impl": "mfc", "inputSchema": { @@ -2441,7 +2442,8 @@ "write": true, "platforms": [ "win", - "lnx" + "lnx", + "apk" ], "impl": "mfc", "inputSchema": { @@ -2476,12 +2478,13 @@ }, { "name": "remote_keyboard", - "description": "向已建立的远程控制会话注入键盘事件。action 可选 key_down / key_up / key_press / type:前三种需 key(虚拟键名,如 ENTER/TAB/F5/LEFT/CTRL/ALT/SHIFT/WIN,Linux 侧映射为 X11 keysym),type 需 text(仅 ASCII 文本;非 ASCII 请用 remote_clipboard + Ctrl+V)。modifiers 可选(CTRL/ALT/SHIFT/WIN)。可选 expect_hwnd:注入前先确认目标窗口仍在可见列表里(整数或 0x 字符串);配合 require_foreground=true 还要求它已是前台,否则不发注入返回 -32000;同时默认在结果里回报注入后的前台窗口(structuredContent.foreground),用于确认按键真的进了目标窗口。窗口校验仅新 Windows 客户端支持,其他客户端返回 -32005。", + "description": "向已建立的远程控制会话注入键盘事件。action 可选 key_down / key_up / key_press / type:前三种需 key(虚拟键名,如 ENTER/TAB/F5/LEFT/CTRL/ALT/SHIFT/WIN,Linux 侧映射为 X11 keysym),type 需 text(仅 ASCII 文本;非 ASCII 请用 remote_clipboard + Ctrl+V)。modifiers 可选(CTRL/ALT/SHIFT/WIN)。可选 expect_hwnd:注入前先确认目标窗口仍在可见列表里(整数或 0x 字符串);配合 require_foreground=true 还要求它已是前台,否则不发注入返回 -32000;同时默认在结果里回报注入后的前台窗口(structuredContent.foreground),用于确认按键真的进了目标窗口。窗口校验仅新 Windows 客户端支持,其他客户端返回 -32005。Android 主机没有键盘注入:只有 ESC(返回)/HOME(桌面)/APPS(任务列表)/PRINTSCREEN(截屏)这类全局动作、方向键(TV 主机)以及 key=V(粘贴当前剪贴板,需要新版 APK)生效,action=type 对 Android 直接返回 -32005,expect_hwnd 系列参数也返回 -32005;注入需要客户端开启无障碍服务,且没有回执(ok 只代表已下发)。", "gate": "remote_control", "write": true, "platforms": [ "win", - "lnx" + "lnx", + "apk" ], "impl": "mfc", "inputSchema": { @@ -2490,6 +2493,13 @@ "description": "动作:key_down / key_up / key_press / type", "type": "string" }, + "expect_hwnd": { + "description": "可选:注入前先确认目标窗口仍在当前可见窗口列表中(整数或 0x 前缀字符串)。顺带默认回报前台窗口;仅新 Windows 客户端支持(否则 -32005)。", + "type": [ + "integer", + "string" + ] + }, "id": { "description": "主机 id,取 list_online_hosts / search_hosts 返回的 id 字段", "type": "string" @@ -2505,6 +2515,14 @@ }, "type": "array" }, + "report_foreground": { + "description": "可选:注入后回报前台窗口(structuredContent.foreground)。给了 expect_hwnd 时默认 true", + "type": "boolean" + }, + "require_foreground": { + "description": "可选:配合 expect_hwnd,要求该窗口已是前台,否则不发注入并返回 -32000。默认 false", + "type": "boolean" + }, "session_id": { "description": "remote_open 返回的 session_id", "type": "string" @@ -2512,21 +2530,6 @@ "text": { "description": "文本(type 用,仅 ASCII;非 ASCII 请走 remote_clipboard + Ctrl+V)", "type": "string" - }, - "expect_hwnd": { - "type": [ - "integer", - "string" - ], - "description": "可选:注入前先确认目标窗口仍在当前可见窗口列表中(整数或 0x 前缀字符串)。顺带默认回报前台窗口;仅新 Windows 客户端支持(否则 -32005)。" - }, - "require_foreground": { - "type": "boolean", - "description": "可选:配合 expect_hwnd,要求该窗口已是前台,否则不发注入并返回 -32000。默认 false" - }, - "report_foreground": { - "type": "boolean", - "description": "可选:注入后回报前台窗口(structuredContent.foreground)。给了 expect_hwnd 时默认 true" } }, "required": [ @@ -2537,34 +2540,35 @@ "type": "object" }, "outputSchema": { - "type": "object", "properties": { "expectedWindow": { - "type": "object", - "description": "expect_hwnd 时注入前的目标窗口快照" + "description": "expect_hwnd 时注入前的目标窗口快照", + "type": "object" }, "foreground": { + "description": "注入后的前台窗口(report_foreground 时返回;无前台窗口为 null)", "type": [ "object", "null" - ], - "description": "注入后的前台窗口(report_foreground 时返回;无前台窗口为 null)" + ] }, "foregroundError": { - "type": "string", - "description": "前台回报失败的原因(注入本身已成功)" + "description": "前台回报失败的原因(注入本身已成功)", + "type": "string" } - } + }, + "type": "object" } }, { "name": "remote_mouse", - "description": "向已建立的远程控制会话注入鼠标事件。action 可选 move / down / up / click / right_click / middle_click / drag / scroll;坐标 x/y(及 drag 的 x2/y2)为归一化 0..1 浮点,默认相对整屏/整虚拟桌面(remote_open 用 window_hwnd/region 时相对该目标帧)。给 window_hwnd 时改为相对「该窗口与虚拟桌面的交集」(窗口完整可见时即窗口本身;0=左/上边缘,1=右/下边缘),可直接照 get_screenshot mode=window 的图量比例:服务端用该交集与虚拟桌面矩形换算成屏幕坐标,并默认要求该窗口在前台(require_foreground=false 可显式关闭;与 expect_hwnd 同时给出时须指向同一窗口);会话本身已锁定窗口/区域时不要再传 window_hwnd。button 可选 left/middle/right(默认 left);click 的 clicks 可选 1/2/3(默认 1);scroll 的 delta 正=向下滚、负=向上滚。可选 expect_hwnd / require_foreground / report_foreground 与 remote_keyboard 同义(新 Windows 客户端),可用它确认点击确实落在目标窗口。", + "description": "向已建立的远程控制会话注入鼠标事件。action 可选 move / down / up / click / right_click / middle_click / drag / scroll;坐标 x/y(及 drag 的 x2/y2)为归一化 0..1 浮点,默认相对整屏/整虚拟桌面(remote_open 用 window_hwnd/region 时相对该目标帧)。给 window_hwnd 时改为相对「该窗口与虚拟桌面的交集」(窗口完整可见时即窗口本身;0=左/上边缘,1=右/下边缘),可直接照 get_screenshot mode=window 的图量比例:服务端用该交集与虚拟桌面矩形换算成屏幕坐标,并默认要求该窗口在前台(require_foreground=false 可显式关闭;与 expect_hwnd 同时给出时须指向同一窗口);会话本身已锁定窗口/区域时不要再传 window_hwnd。button 可选 left/middle/right(默认 left);click 的 clicks 可选 1/2/3(默认 1);scroll 的 delta 正=向下滚、负=向上滚。可选 expect_hwnd / require_foreground / report_foreground 与 remote_keyboard 同义(新 Windows 客户端),可用它确认点击确实落在目标窗口。Android 主机把事件翻译成触摸:click=点按、right_click=长按、drag=滑动、scroll=上下滑,middle_click 无效果,down/up 单独使用无意义;window_hwnd 系列参数返回 -32005,注入需要客户端开启无障碍服务且没有回执(ok 只代表已下发)。", "gate": "remote_control", "write": true, "platforms": [ "win", - "lnx" + "lnx", + "apk" ], "impl": "mfc", "inputSchema": { @@ -2600,14 +2604,36 @@ "description": "滚动量(仅 scroll;正=向下滚,负=向上滚,与 Web 控制台一致;仅垂直滚轮,忽略 button)", "type": "integer" }, + "expect_hwnd": { + "description": "可选:注入前先确认目标窗口仍在当前可见窗口列表中(整数或 0x 前缀字符串)。顺带默认回报前台窗口;仅新 Windows 客户端支持(否则 -32005)。", + "type": [ + "integer", + "string" + ] + }, "id": { "description": "主机 id,取 list_online_hosts / search_hosts 返回的 id 字段", "type": "string" }, + "report_foreground": { + "description": "可选:注入后回报前台窗口(structuredContent.foreground)。给了 expect_hwnd 时默认 true", + "type": "boolean" + }, + "require_foreground": { + "description": "可选:配合 expect_hwnd,要求该窗口已是前台,否则不发注入并返回 -32000。默认 false", + "type": "boolean" + }, "session_id": { "description": "remote_open 返回的 session_id", "type": "string" }, + "window_hwnd": { + "description": "可选:以该窗口为坐标基准(整数或 0x 前缀字符串)。给定后 x/y(及 drag 的 x2/y2)变为相对「窗口与虚拟桌面的交集」的归一化坐标(窗口完整可见时即窗口本身),服务端用该交集与虚拟桌面矩形换算成屏幕坐标,可直接用 get_screenshot mode=window 图上的比例点。默认要求该窗口是前台(可用 require_foreground=false 显式关闭;与 expect_hwnd 同时给出时须指向同一窗口);窗口不存在/最小化/完全移出虚拟桌面时报错。仅新 Windows 客户端支持(窗口信息 RPC 需带虚拟桌面矩形),否则 -32005。会话本身已只推窗口/区域(remote_open 的 window_hwnd/region)时不要再传:坐标本来就相对目标帧。", + "type": [ + "integer", + "string" + ] + }, "x": { "description": "归一化 X 坐标(0=屏幕最左,1=最右);给了 window_hwnd 时改为相对「窗口与虚拟桌面的交集」(窗口完整可见时即窗口),0=左边缘,1=右边缘", "type": "number" @@ -2623,28 +2649,6 @@ "y2": { "description": "拖拽终点 Y(仅 drag;坐标基准与 y 相同)", "type": "number" - }, - "expect_hwnd": { - "type": [ - "integer", - "string" - ], - "description": "可选:注入前先确认目标窗口仍在当前可见窗口列表中(整数或 0x 前缀字符串)。顺带默认回报前台窗口;仅新 Windows 客户端支持(否则 -32005)。" - }, - "require_foreground": { - "type": "boolean", - "description": "可选:配合 expect_hwnd,要求该窗口已是前台,否则不发注入并返回 -32000。默认 false" - }, - "report_foreground": { - "type": "boolean", - "description": "可选:注入后回报前台窗口(structuredContent.foreground)。给了 expect_hwnd 时默认 true" - }, - "window_hwnd": { - "type": [ - "integer", - "string" - ], - "description": "可选:以该窗口为坐标基准(整数或 0x 前缀字符串)。给定后 x/y(及 drag 的 x2/y2)变为相对「窗口与虚拟桌面的交集」的归一化坐标(窗口完整可见时即窗口本身),服务端用该交集与虚拟桌面矩形换算成屏幕坐标,可直接用 get_screenshot mode=window 图上的比例点。默认要求该窗口是前台(可用 require_foreground=false 显式关闭;与 expect_hwnd 同时给出时须指向同一窗口);窗口不存在/最小化/完全移出虚拟桌面时报错。仅新 Windows 客户端支持(窗口信息 RPC 需带虚拟桌面矩形),否则 -32005。会话本身已只推窗口/区域(remote_open 的 window_hwnd/region)时不要再传:坐标本来就相对目标帧。" } }, "required": [ @@ -2657,42 +2661,43 @@ "type": "object" }, "outputSchema": { - "type": "object", "properties": { + "coordinateWindow": { + "description": "window_hwnd 时命中的窗口原始快照(left/top/right/bottom/width/height,未裁剪);实际归一化基准是 resolved.basis(窗口与虚拟桌面的交集)", + "type": "object" + }, "expectedWindow": { - "type": "object", - "description": "expect_hwnd 时注入前的目标窗口快照" + "description": "expect_hwnd 时注入前的目标窗口快照", + "type": "object" }, "foreground": { + "description": "注入后的前台窗口(report_foreground 时返回;无前台窗口为 null)", "type": [ "object", "null" - ], - "description": "注入后的前台窗口(report_foreground 时返回;无前台窗口为 null)" + ] }, "foregroundError": { - "type": "string", - "description": "前台回报失败的原因(注入本身已成功)" - }, - "coordinateWindow": { - "type": "object", - "description": "window_hwnd 时命中的窗口原始快照(left/top/right/bottom/width/height,未裁剪);实际归一化基准是 resolved.basis(窗口与虚拟桌面的交集)" + "description": "前台回报失败的原因(注入本身已成功)", + "type": "string" }, "resolved": { - "type": "object", - "description": "window_hwnd 时换算后的发送帧归一化坐标(frame_x/frame_y,drag 另有 frame_x2/frame_y2);basis 为实际坐标基准矩形 left/top/right/bottom(窗口与虚拟桌面的交集,与 get_screenshot mode=window 的源矩形一致)" + "description": "window_hwnd 时换算后的发送帧归一化坐标(frame_x/frame_y,drag 另有 frame_x2/frame_y2);basis 为实际坐标基准矩形 left/top/right/bottom(窗口与虚拟桌面的交集,与 get_screenshot mode=window 的源矩形一致)", + "type": "object" } - } + }, + "type": "object" } }, { "name": "remote_clipboard", - "description": "把文本写入远程主机的剪贴板(服务端按 GBK/ANSI 下发,Linux 客户端自动转回 UTF-8;非 GBK 字符如 emoji 会丢失)。仅设置剪贴板,粘贴需随后用 remote_keyboard 注入 Ctrl+V;Linux 需要 X11 桌面与 xclip/xsel。", + "description": "把文本写入远程主机的剪贴板(服务端按 GBK/ANSI 下发,Linux 客户端自动转回 UTF-8,Android 客户端按 GBK 解码;非 GBK 字符如 emoji 会丢失)。仅设置剪贴板,粘贴需随后用 remote_keyboard 注入 Ctrl+V;Linux 需要 X11 桌面与 xclip/xsel,Android 用 remote_keyboard 的 key=V(粘贴到当前焦点输入框,需要新版 APK;粘贴依赖无障碍服务)。", "gate": "remote_control", "write": true, "platforms": [ "win", - "lnx" + "lnx", + "apk" ], "impl": "mfc", "inputSchema": { @@ -3122,24 +3127,24 @@ "description": "命令已下发(不代表窗口已按预期变化);action=activate 时为前台复核结果", "type": "boolean" }, + "state": { + "description": "action=activate 时的复核状态:foreground / background / missing / unknown", + "type": "string" + }, + "truncated": { + "description": "为 true 时表示复核用的可见窗口列表被 96 条单次上限截断,未找到目标不代表窗口不存在(此时 state=unknown)", + "type": "boolean" + }, + "verifyError": { + "description": "action=activate 且前台复核请求失败时的错误说明", + "type": "string" + }, "window": { "description": "dry_run 时的目标窗口;action=activate 时为复核到的窗口快照(hwnd/title/pid/rect/flags 等),复核未找到为 null", "type": [ "object", "null" ] - }, - "state": { - "type": "string", - "description": "action=activate 时的复核状态:foreground / background / missing / unknown" - }, - "verifyError": { - "type": "string", - "description": "action=activate 且前台复核请求失败时的错误说明" - }, - "truncated": { - "description": "为 true 时表示复核用的可见窗口列表被 96 条单次上限截断,未找到目标不代表窗口不存在(此时 state=unknown)", - "type": "boolean" } }, "type": "object" @@ -4138,9 +4143,17 @@ "description": "未过滤的条目总数", "type": "integer" }, + "truncated": { + "description": "为 true 时表示客户端的可见窗口多于单次返回上限(96 条),列表不完整", + "type": "boolean" + }, "windows": { "items": { "properties": { + "bottom": { + "description": "窗口矩形下边界(屏幕坐标,不含边界);height = bottom - top", + "type": "integer" + }, "canSee": { "description": "客户端是否可抓取该窗口画面", "type": "boolean" @@ -4152,59 +4165,51 @@ "description": "窗口句柄(十进制;也可用作 host_control_window / operate_window 的 hwnd)", "type": "integer" }, + "isForeground": { + "description": "是否为当前前台窗口(全表最多一个 true)", + "type": "boolean" + }, + "left": { + "description": "窗口矩形左边界(屏幕坐标,可能为负,多显示器时常见)", + "type": "integer" + }, + "maximized": { + "description": "是否最大化", + "type": "boolean" + }, + "minimized": { + "description": "是否最小化", + "type": "boolean" + }, "pid": { "type": "integer" }, + "right": { + "description": "窗口矩形右边界(屏幕坐标,不含边界);width = right - left", + "type": "integer" + }, "title": { "type": "string" }, + "top": { + "description": "窗口矩形上边界(屏幕坐标)", + "type": "integer" + }, + "visible": { + "description": "是否可见;当前列表只含可见窗口,故恒为 true", + "type": "boolean" + }, "width": { "type": "integer" }, - "left": { - "type": "integer", - "description": "窗口矩形左边界(屏幕坐标,可能为负,多显示器时常见)" - }, - "top": { - "type": "integer", - "description": "窗口矩形上边界(屏幕坐标)" - }, - "right": { - "type": "integer", - "description": "窗口矩形右边界(屏幕坐标,不含边界);width = right - left" - }, - "bottom": { - "type": "integer", - "description": "窗口矩形下边界(屏幕坐标,不含边界);height = bottom - top" - }, - "visible": { - "type": "boolean", - "description": "是否可见;当前列表只含可见窗口,故恒为 true" - }, - "minimized": { - "type": "boolean", - "description": "是否最小化" - }, - "maximized": { - "type": "boolean", - "description": "是否最大化" - }, - "isForeground": { - "type": "boolean", - "description": "是否为当前前台窗口(全表最多一个 true)" - }, "zOrder": { - "type": "integer", - "description": "z 序,0 = 最顶层;数值越小越靠前" + "description": "z 序,0 = 最顶层;数值越小越靠前", + "type": "integer" } }, "type": "object" }, "type": "array" - }, - "truncated": { - "description": "为 true 时表示客户端的可见窗口多于单次返回上限(96 条),列表不完整", - "type": "boolean" } }, "required": [ diff --git a/server/2015Remote/McpServer.cpp b/server/2015Remote/McpServer.cpp index 87b1a2e..097add2 100644 --- a/server/2015Remote/McpServer.cpp +++ b/server/2015Remote/McpServer.cpp @@ -329,8 +329,8 @@ const char* kServerInstructions = u8"5) 客户端平台差异\n" u8"工具能否执行取决于目标主机的平台,这与服务端开关无关,两者是叠加关系。调用前用 " u8"list_online_hosts / get_host_detail 的 capabilities.platform 确认,宁可先查一次,不要先试后错。\n" - u8"支持面从宽到窄依次是 win > lnx > mac ≈ apk:Windows 是唯一全量支持的平台,Linux 次之," - u8"macOS 与 Android 只覆盖一部分。拿不准时按这个顺序假设。\n" + u8"支持面从宽到窄依次是 win > lnx > apk ≈ mac:Windows 是唯一全量支持的平台,Linux 次之," + u8"Android 与 macOS 只覆盖一部分(Android 偏远程控制与截屏,macOS 偏文件与进程)。拿不准时按这个顺序假设。\n" u8"win(EXE / DLL / MEXE / SC / MDLL):全部工具可用。\n" u8"lnx(LNX):不支持服务、注册表、键日志、文件搜索/删除/移动/建目录、" u8"窗口列表(list_windows)与窗口信息(get_foreground_window)、网络连接列表与断开" @@ -346,7 +346,11 @@ const char* kServerInstructions = u8"apk(APK):支持主机列表(list_online_hosts / list_all_hosts)/ 详情 / 搜索 / " u8"审计日志 / 服务状态 / 会话管理、运行日志(get_client_log)、活动历史" u8"(get_activity_history,前台应用停留记录)、截屏(get_screenshot,只支持 mode=screen," - u8"要靠无障碍服务 takeScreenshot,Android 11+ 且开启无障碍才行),以及 " + u8"要靠无障碍服务 takeScreenshot,Android 11+ 且开启无障碍才行),远程控制全族" + u8"(remote_open / remote_close / remote_mouse / remote_keyboard / remote_clipboard," + u8"输入被翻译成触摸手势与 ESC(返回)/ HOME(桌面)/ APPS(任务列表)/ PRINTSCREEN(截屏)" + u8"等全局动作,只支持整屏目标;注入依赖" + u8"无障碍服务、抓屏依赖已授权录屏,两者都没有能力位可查,命令下发成功不代表生效),以及 " u8"host_set_remark / host_set_watch_level 这两个只改服务端本地数据的工具。其余一律不支持" u8"(客户端未实现 SYSTEM 与 SHELL)。\n" u8"copy_files_c2c 是唯一有方向性的工具:源端 src_id 必须是 win,目标端 dst_id 可以是 " @@ -1037,6 +1041,7 @@ Json::Value BuildHostDetailOutputSchema() { u8"仅声明 CLIENT_CAP_SCREEN_REGION 的新 Windows 客户端为 true"); capProps["remoteControl"] = boolProp( u8"能否建立远程控制会话(remote_open/remote_mouse/remote_keyboard 的前提);" + u8"Android 客户端只支持整屏目标,且需要已授权录屏与无障碍服务;" u8"还要求服务端 Web 远程服务已启动(WebSvrPort>0)"); capProps["fileTransferV2"] = boolProp(u8"是否支持 V2 文件传输(download_file / upload_file 的前提)"); capProps["c2cPaths"] = boolProp(u8"能否按路径清单接收另一台主机的文件(copy_files_c2c 源端的前提)"); @@ -2509,13 +2514,14 @@ std::string BuildToolsListResult(const Json::Value& id) { } // 15) remote_open / remote_close / remote_keyboard / remote_mouse / remote_clipboard - // (P5:MCP 远程控制,Windows/Linux;Linux 需 X11 桌面,Wayland 纯会话不支持) + // (P5:MCP 远程控制,Windows/Linux/Android;Linux 需 X11 桌面,Wayland 纯会话不支持; + // Android 注入翻译成触摸手势与全局动作,只支持整屏目标) // 安全门:McpRemoteControl=1 且 McpReadonly=0;全程审计 + idle 回收) if (CMcpServer::Instance().IsRemoteControlEnabled() && !CMcpServer::Instance().IsReadonly()) { { Json::Value tool(Json::objectValue); tool["name"] = "remote_open"; - tool["description"] = u8"在指定在线 Windows 或 Linux 主机上建立远程控制会话(隐藏屏幕子连接)并返回 session_id、抓屏帧尺寸(screen_w/screen_h)与目标(target)。默认推整屏/整虚拟桌面(可能等比缩放);可用 window_hwnd 只推一个窗口,或用 region 只推一个矩形区域,带宽、延迟和点击精度都更好,此时归一化坐标 0..1 相对该目标帧。后续 remote_mouse/remote_keyboard 用归一化坐标(0..1)注入输入,用毕须 remote_close。Linux 需要 X11/Xorg(或 XWayland)桌面,纯 Wayland 会话无法抓屏/注入;window_hwnd/region 仅支持声明 CLIENT_CAP_WINDOW_INFO 的新 Windows 客户端。Windows 多显示器下整屏目标需要新版客户端(整虚拟桌面抓屏),老客户端会被拒绝;window 目标不依赖虚拟桌面抓屏,不受此限。"; + tool["description"] = u8"在指定在线 Windows、Linux 或 Android 主机上建立远程控制会话(隐藏屏幕子连接)并返回 session_id、抓屏帧尺寸(screen_w/screen_h)与目标(target)。默认推整屏/整虚拟桌面(可能等比缩放);可用 window_hwnd 只推一个窗口,或用 region 只推一个矩形区域,带宽、延迟和点击精度都更好,此时归一化坐标 0..1 相对该目标帧。后续 remote_mouse/remote_keyboard 用归一化坐标(0..1)注入输入,用毕须 remote_close。Linux 需要 X11/Xorg(或 XWayland)桌面,纯 Wayland 会话无法抓屏/注入;window_hwnd/region 仅支持声明 CLIENT_CAP_WINDOW_INFO 的新 Windows 客户端。Windows 多显示器下整屏目标需要新版客户端(整虚拟桌面抓屏),老客户端会被拒绝;window 目标不依赖虚拟桌面抓屏,不受此限。Android 主机只支持整屏目标,输入被翻译成触摸手势与全局动作(见 remote_mouse / remote_keyboard);抓屏依赖客户端已授权录屏(MediaProjection),未授权时 remote_open 会一直等不到屏幕子连接,注入还依赖无障碍服务在跑(未开启时命令照样下发但不生效,且没有回执)。"; tool["inputSchema"] = BuildRemoteOpenInputSchema(); tool["outputSchema"] = BuildRemoteOpenOutputSchema(); tools.append(tool); @@ -2531,7 +2537,7 @@ std::string BuildToolsListResult(const Json::Value& id) { { Json::Value tool(Json::objectValue); tool["name"] = "remote_keyboard"; - tool["description"] = u8"向已建立的远程控制会话注入键盘事件。action 可选 key_down / key_up / key_press / type:前三种需 key(虚拟键名,如 ENTER/TAB/F5/LEFT/CTRL/ALT/SHIFT/WIN,Linux 侧映射为 X11 keysym),type 需 text(仅 ASCII 文本;非 ASCII 请用 remote_clipboard + Ctrl+V)。modifiers 可选(CTRL/ALT/SHIFT/WIN)。可选 expect_hwnd:注入前先确认目标窗口仍在可见列表里(整数或 0x 字符串);配合 require_foreground=true 还要求它已是前台,否则不发注入返回 -32000;同时默认在结果里回报注入后的前台窗口(structuredContent.foreground),用于确认按键真的进了目标窗口。窗口校验仅新 Windows 客户端支持,其他客户端返回 -32005。"; + tool["description"] = u8"向已建立的远程控制会话注入键盘事件。action 可选 key_down / key_up / key_press / type:前三种需 key(虚拟键名,如 ENTER/TAB/F5/LEFT/CTRL/ALT/SHIFT/WIN,Linux 侧映射为 X11 keysym),type 需 text(仅 ASCII 文本;非 ASCII 请用 remote_clipboard + Ctrl+V)。modifiers 可选(CTRL/ALT/SHIFT/WIN)。可选 expect_hwnd:注入前先确认目标窗口仍在可见列表里(整数或 0x 字符串);配合 require_foreground=true 还要求它已是前台,否则不发注入返回 -32000;同时默认在结果里回报注入后的前台窗口(structuredContent.foreground),用于确认按键真的进了目标窗口。窗口校验仅新 Windows 客户端支持,其他客户端返回 -32005。Android 主机没有键盘注入:只有 ESC(返回)/HOME(桌面)/APPS(任务列表)/PRINTSCREEN(截屏)这类全局动作、方向键(TV 主机)以及 key=V(粘贴当前剪贴板,需要新版 APK)生效,action=type 对 Android 直接返回 -32005,expect_hwnd 系列参数也返回 -32005;注入需要客户端开启无障碍服务,且没有回执(ok 只代表已下发)。"; tool["inputSchema"] = BuildRemoteKeyboardInputSchema(); tool["outputSchema"] = BuildRemoteKeyboardOutputSchema(); tools.append(tool); @@ -2539,7 +2545,7 @@ std::string BuildToolsListResult(const Json::Value& id) { { Json::Value tool(Json::objectValue); tool["name"] = "remote_mouse"; - tool["description"] = u8"向已建立的远程控制会话注入鼠标事件。action 可选 move / down / up / click / right_click / middle_click / drag / scroll;坐标 x/y(及 drag 的 x2/y2)为归一化 0..1 浮点,默认相对整屏/整虚拟桌面(remote_open 用 window_hwnd/region 时相对该目标帧)。给 window_hwnd 时改为相对「该窗口与虚拟桌面的交集」(窗口完整可见时即窗口本身;0=左/上边缘,1=右/下边缘),可直接照 get_screenshot mode=window 的图量比例:服务端用该交集与虚拟桌面矩形换算成屏幕坐标,并默认要求该窗口在前台(require_foreground=false 可显式关闭;与 expect_hwnd 同时给出时须指向同一窗口);会话本身已锁定窗口/区域时不要再传 window_hwnd。button 可选 left/middle/right(默认 left);click 的 clicks 可选 1/2/3(默认 1);scroll 的 delta 正=向下滚、负=向上滚。可选 expect_hwnd / require_foreground / report_foreground 与 remote_keyboard 同义(新 Windows 客户端),可用它确认点击确实落在目标窗口。"; + tool["description"] = u8"向已建立的远程控制会话注入鼠标事件。action 可选 move / down / up / click / right_click / middle_click / drag / scroll;坐标 x/y(及 drag 的 x2/y2)为归一化 0..1 浮点,默认相对整屏/整虚拟桌面(remote_open 用 window_hwnd/region 时相对该目标帧)。给 window_hwnd 时改为相对「该窗口与虚拟桌面的交集」(窗口完整可见时即窗口本身;0=左/上边缘,1=右/下边缘),可直接照 get_screenshot mode=window 的图量比例:服务端用该交集与虚拟桌面矩形换算成屏幕坐标,并默认要求该窗口在前台(require_foreground=false 可显式关闭;与 expect_hwnd 同时给出时须指向同一窗口);会话本身已锁定窗口/区域时不要再传 window_hwnd。button 可选 left/middle/right(默认 left);click 的 clicks 可选 1/2/3(默认 1);scroll 的 delta 正=向下滚、负=向上滚。可选 expect_hwnd / require_foreground / report_foreground 与 remote_keyboard 同义(新 Windows 客户端),可用它确认点击确实落在目标窗口。Android 主机把事件翻译成触摸:click=点按、right_click=长按、drag=滑动、scroll=上下滑,middle_click 无效果,down/up 单独使用无意义;window_hwnd 系列参数返回 -32005,注入需要客户端开启无障碍服务且没有回执(ok 只代表已下发)。"; tool["inputSchema"] = BuildRemoteMouseInputSchema(); tool["outputSchema"] = BuildRemoteMouseOutputSchema(); tools.append(tool); @@ -2547,7 +2553,7 @@ std::string BuildToolsListResult(const Json::Value& id) { { Json::Value tool(Json::objectValue); tool["name"] = "remote_clipboard"; - tool["description"] = u8"把文本写入远程主机的剪贴板(服务端按 GBK/ANSI 下发,Linux 客户端自动转回 UTF-8;非 GBK 字符如 emoji 会丢失)。仅设置剪贴板,粘贴需随后用 remote_keyboard 注入 Ctrl+V;Linux 需要 X11 桌面与 xclip/xsel。"; + tool["description"] = u8"把文本写入远程主机的剪贴板(服务端按 GBK/ANSI 下发,Linux 客户端自动转回 UTF-8,Android 客户端按 GBK 解码;非 GBK 字符如 emoji 会丢失)。仅设置剪贴板,粘贴需随后用 remote_keyboard 注入 Ctrl+V;Linux 需要 X11 桌面与 xclip/xsel,Android 用 remote_keyboard 的 key=V(粘贴到当前焦点输入框,需要新版 APK;粘贴依赖无障碍服务)。"; tool["inputSchema"] = BuildRemoteClipboardInputSchema(); tool["outputSchema"] = BuildRemoteClipboardOutputSchema(); tools.append(tool); @@ -2924,11 +2930,12 @@ void AppendHostTechnicalDetail(CMy2015RemoteDlg* parent, uint64_t devId, Json::V caps["screenPreview"] = ctx->SupportsScreenPreview(); // screenRegion → get_screenshot 的 region/window/monitor 模式(SupportsScreenCapture) caps["screenRegion"] = ctx->SupportsScreenCapture(); - // 远程控制只实现于 Windows / Linux;多显示器还要求观察与注入同源: - // Windows 需声明整虚拟桌面抓屏能力,Linux 的 root 抓屏/注入天然一致。 + // 远程控制:Windows / Linux / Android 客户端都实现了注入(Android 把事件翻译成触摸 + // 手势与全局动作);多显示器还要求观察与注入同源:Windows 需声明整虚拟桌面抓屏能力, + // Linux 的 root 抓屏/注入天然一致,Android 抓屏与注入都用整屏坐标。 // monitorCount=0(老客户端没报格式)无法判定,与 remote_open 一样按放行处理。 bool virtDesktopOk = monitorCount <= 1 || !IsWindowsClient(ctx) || ctx->SupportsVirtualDesktop(); - caps["remoteControl"] = (IsWindowsClient(ctx) || clientType == "LNX") && virtDesktopOk; + caps["remoteControl"] = (IsWindowsClient(ctx) || clientType == "LNX" || clientType == "APK") && virtDesktopOk; caps["fileTransferV2"] = ctx->SupportsFileV2(); caps["c2cPaths"] = ctx->SupportsC2CPaths(); caps["registry"] = IsWindowsClient(ctx); @@ -5056,7 +5063,7 @@ static bool ResolveScreenCtrlSessionHost(const Json::Value& id, const Json::Valu CString clientType = ctx->GetAdditionalData(RES_CLIENT_TYPE); if (clientType == "MAC") { - errJson = BuildError(id, -32005, "Remote control is only supported on Windows and Linux hosts"); + errJson = BuildError(id, -32005, "Remote control is only supported on Windows, Linux and Android hosts"); return false; } return true; @@ -5911,6 +5918,11 @@ std::string BuildRemoteKeyboard(const Json::Value& id, const Json::Value& args, // 组装注入批次(按发送顺序) std::vector batch; if (action == "type") { + // Android 没有文本注入:type 发的是物理键事件,字符 'v' 会变成 VK_V(本客户端 + // 映射为「粘贴」),其余字符无动作。整条拒绝,别让调用方以为文本被敲进去了。 + if (ctx->GetAdditionalData(RES_CLIENT_TYPE) == "APK") + return BuildError(id, -32005, "Android clients cannot type text; " + "use remote_clipboard + key=V, or the global-action keys (ESC/HOME/APPS/PRINTSCREEN)"); if (text.empty()) return BuildError(id, -32602, "Missing required parameter: text"); if (!IsAscii(text)) @@ -5924,6 +5936,10 @@ std::string BuildRemoteKeyboard(const Json::Value& id, const Json::Value& args, int keyVk = MapKeyNameToVk(keyName); if (keyVk == 0) return BuildError(id, -32602, "Unknown key: " + keyName); + // key=V 的粘贴映射只有新版 APK 才有;老 APK 收到 VK_V 不会动作 + if (keyVk == 'V' && ctx->GetAdditionalData(RES_CLIENT_TYPE) == "APK" && !ctx->SupportsScreenClipboard()) + return BuildError(id, -32005, "Android client is too old for key=V paste: the APK has no paste mapping, " + "upgrade the client first"); bool doDown = (action != "key_up"); bool doUp = (action != "key_down"); if (doDown) { @@ -6548,6 +6564,12 @@ std::string BuildRemoteClipboard(const Json::Value& id, const Json::Value& args, if (sessionId.empty()) return BuildError(id, -32602, "Missing required parameter: session_id"); + // 老 APK 的屏幕子连接没有 COMMAND_SCREEN_SET_CLIPBOARD 分支,包会被静默丢弃; + // 用它声明的能力位提前拒绝,避免调用方把「已下发」当成「已写入」。 + if (ctx->GetAdditionalData(RES_CLIENT_TYPE) == "APK" && !ctx->SupportsScreenClipboard()) + return BuildError(id, -32005, "Android client is too old for remote_clipboard: " + "the APK has no clipboard handler, upgrade the client first"); + std::string text = GetStringArg(args, "text"); if (text.empty()) return BuildError(id, -32602, "Missing required parameter: text"); @@ -9951,16 +9973,18 @@ const ToolPlatform kToolPlatforms[] = { { "get_client_log", kPlatWin|kPlatLnx|kPlatMac|kPlatApk }, { "download_file", kPlatWin|kPlatLnx|kPlatMac }, { "upload_file", kPlatWin|kPlatLnx|kPlatMac }, - // ---- win+lnx ---- 远程控制全族 + 需 SCREEN_PREVIEW 的截屏 + macOS 未开放项 + // ---- win+lnx(+apk) ---- 远程控制全族 + 需 SCREEN_PREVIEW 的截屏 + macOS 未开放项 // Android 用无障碍 takeScreenshot(API 30+,需开无障碍服务),只支持 mode=screen { "get_screenshot", kPlatWin|kPlatLnx|kPlatApk }, // 窗口信息 RPC 只在 Windows 客户端实现(CLIENT_CAP_WINDOW_INFO) { "get_foreground_window", kPlatWin }, - { "remote_open", kPlatWin|kPlatLnx }, - { "remote_close", kPlatWin|kPlatLnx }, - { "remote_keyboard", kPlatWin|kPlatLnx }, - { "remote_mouse", kPlatWin|kPlatLnx }, - { "remote_clipboard", kPlatWin|kPlatLnx }, + // Android 客户端把注入翻译成触摸手势 / 全局动作(android/.../ControlService.kt), + // 剪贴板走 CaptureService.onClipboardText;window_hwnd/region 目标仍只有 Windows 支持 + { "remote_open", kPlatWin|kPlatLnx|kPlatApk }, + { "remote_close", kPlatWin|kPlatLnx|kPlatApk }, + { "remote_keyboard", kPlatWin|kPlatLnx|kPlatApk }, + { "remote_mouse", kPlatWin|kPlatLnx|kPlatApk }, + { "remote_clipboard", kPlatWin|kPlatLnx|kPlatApk }, // macOS 客户端有 PTY 实现(macos/main.mm:753),但服务端刻意不开放 // (McpServer.cpp:3652「macOS 本轮不开放」),故实际不可用 { "exec_command", kPlatWin|kPlatLnx }, diff --git a/server/2015Remote/context.h b/server/2015Remote/context.h index e2dbe00..94deef2 100644 --- a/server/2015Remote/context.h +++ b/server/2015Remote/context.h @@ -131,6 +131,14 @@ public: return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_SCREEN_REGION) != 0; } + // 检查客户端是否支持屏幕子连接写剪贴板(COMMAND_SCREEN_SET_CLIPBOARD)与 VK_V 粘贴。 + // 只有新版 Android 声明;更老的 APK 收到剪贴板包会静默丢弃。 + bool SupportsScreenClipboard() const { + CString caps = GetClientData(ONLINELIST_CAPABILITIES); + if (caps.IsEmpty()) return false; + return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_SCREEN_CLIPBOARD) != 0; + } + // 检查客户端是否支持远程协议切换(COMMAND_SET_PROTO)。老客户端没有这个命令, // 收到也会走 default 丢弃,服务端据此把「协议切换」菜单置灰。 bool SupportsProtoSwitch() const { diff --git a/tools/mcp_tools/make_tools_json.py b/tools/mcp_tools/make_tools_json.py index 518564d..d1ac6fb 100644 --- a/tools/mcp_tools/make_tools_json.py +++ b/tools/mcp_tools/make_tools_json.py @@ -168,12 +168,13 @@ PLATFORMS = { "download_file": _TRIO, "upload_file": _TRIO, - # 远程控制:注释明确只实现于 Windows / Linux - "remote_open": _WL, - "remote_close": _WL, - "remote_keyboard": _WL, - "remote_mouse": _WL, - "remote_clipboard": _WL, + # 远程控制:Windows / Linux 全功能;Android 只支持整屏目标,输入翻译成触摸与全局动作 + # (remote_open/close/keyboard/mouse/clipboard),remote_block_input 仍仅 Windows + "remote_open": _WLA, + "remote_close": _WLA, + "remote_keyboard": _WLA, + "remote_mouse": _WLA, + "remote_clipboard": _WLA, # 需要 CLIENT_CAP_SCREEN_PREVIEW:Windows 恒有,Linux 仅在探测到 X11 桌面时声明, # Android 仅在无障碍服务在跑时声明(takeScreenshot,只支持 mode=screen)