Feature: Add remote lock screen for Android hosts
Implement the Ctrl+Alt+Del path on Android as a system lock screen. Android has no secure attention sequence, so COMMAND_SCREEN_CTRL_ALT_DEL is mapped in the client to GLOBAL_ACTION_LOCK_SCREEN and the server exposes it as the new MCP tool remote_lock_screen. The Android client resolves ControlService.lockScreen()/canLockScreen() in nativeInit and dispatches the command from the screen sub-connection through the usual attach/detach JNI path. The lock action is posted to the accessibility service handler because performGlobalAction must not run on the receiver thread. Login advertises the new CLIENT_CAP_LOCK_SCREEN bit only when the accessibility service is bound and the API level is 28+, so the server can reject old APKs and Windows/Linux hosts up front instead of reporting a lock that never happened. There is no receipt: a successful call only means the command was delivered, and the tool description tells the caller to confirm with get_screenshot. Server side adds the schema and handler next to remote_clipboard, audits the call, and gates it on client type plus the capability bit. Since it is the only APK-only tool, check_platform_table.py gains a documented exemption from the Windows baseline invariant, and make_tools_json.py learns an APK-only platform set. tools.json is regenerated from the live server and the plan document now counts 62 tools. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
0a0b709e8a
commit
fd1b085279
11 files changed
+264
-14
No files matched your search
@@ -349,7 +349,7 @@ const char* kServerInstructions =
|
||||
u8"要靠无障碍服务 takeScreenshot,Android 11+ 且开启无障碍才行),远程控制全族"
|
||||
u8"(remote_open / remote_close / remote_mouse / remote_keyboard / remote_clipboard,"
|
||||
u8"输入被翻译成触摸手势与 ESC(返回)/ HOME(桌面)/ APPS(任务列表)/ PRINTSCREEN(截屏)"
|
||||
u8"等全局动作,只支持整屏目标;注入依赖"
|
||||
u8"等全局动作,只支持整屏目标;remote_lock_screen 用系统的锁屏动作;注入依赖"
|
||||
u8"无障碍服务、抓屏依赖已授权录屏,两者都没有能力位可查,命令下发成功不代表生效),以及 "
|
||||
u8"host_set_remark / host_set_watch_level 这两个只改服务端本地数据的工具。其余一律不支持"
|
||||
u8"(客户端未实现 SYSTEM 与 SHELL)。\n"
|
||||
@@ -2057,6 +2057,9 @@ Json::Value BuildCopyFilesC2CInputSchema();
|
||||
Json::Value BuildCopyFilesC2COutputSchema();
|
||||
std::string BuildCopyFilesC2C(const Json::Value& id, const Json::Value& args, CMy2015RemoteDlg* parent);
|
||||
std::string BuildRemoteClipboard(const Json::Value& id, const Json::Value& args, CMy2015RemoteDlg* parent);
|
||||
Json::Value BuildRemoteLockScreenInputSchema();
|
||||
Json::Value BuildRemoteLockScreenOutputSchema();
|
||||
std::string BuildRemoteLockScreen(const Json::Value& id, const Json::Value& args, CMy2015RemoteDlg* parent);
|
||||
|
||||
// ===== P7 前置声明(定义见下方「tools/call 分派」前)=====
|
||||
Json::Value BuildKillProcessInputSchema();
|
||||
@@ -2558,6 +2561,14 @@ std::string BuildToolsListResult(const Json::Value& id) {
|
||||
tool["outputSchema"] = BuildRemoteClipboardOutputSchema();
|
||||
tools.append(tool);
|
||||
}
|
||||
{
|
||||
Json::Value tool(Json::objectValue);
|
||||
tool["name"] = "remote_lock_screen";
|
||||
tool["description"] = u8"把远程 Android 主机锁屏。报文是 COMMAND_SCREEN_CTRL_ALT_DEL(客户端的 Ctrl+Alt+Del 命令,目前只有 Android 实现:没有该组合键,客户端映射为系统的 GLOBAL_ACTION_LOCK_SCREEN)。需先 remote_open 建立会话;锁定后锁屏界面会挡住后续注入,要继续操作得先有人解锁(密码/指纹)。没有回执:ok 只代表命令已下发,实际是否锁上取决于系统策略(例如已设置设备管理器策略、部分定制 ROM 可能忽略),请随后用 get_screenshot 确认。只有声明 CLIENT_CAP_LOCK_SCREEN 的新版 APK 支持,老 APK 与 Windows/Linux 主机返回 -32005。";
|
||||
tool["inputSchema"] = BuildRemoteLockScreenInputSchema();
|
||||
tool["outputSchema"] = BuildRemoteLockScreenOutputSchema();
|
||||
tools.append(tool);
|
||||
}
|
||||
{
|
||||
Json::Value tool(Json::objectValue);
|
||||
tool["name"] = "remote_block_input";
|
||||
@@ -6621,6 +6632,99 @@ std::string BuildRemoteClipboard(const Json::Value& id, const Json::Value& args,
|
||||
return BuildResult(id, result);
|
||||
}
|
||||
|
||||
// ===== 锁屏:remote_lock_screen(COMMAND_SCREEN_CTRL_ALT_DEL)=====
|
||||
//
|
||||
// Ctrl+Alt+Del 这个「安全注意序列」在客户端一直没有实现(docs/Mcp_Next_Plan.md),
|
||||
// 服务端也就没有发送入口。Android 把它映射成系统的锁屏(GLOBAL_ACTION_LOCK_SCREEN),
|
||||
// 这是目前唯一有意义的语义:主控在自动化结束后把远端手机锁上,避免停在桌面。
|
||||
// 报文只有 1 字节 [COMMAND_SCREEN_CTRL_ALT_DEL],和 MFC 端其它屏幕命令一样走子连接。
|
||||
// 没有回执:客户端投递到主线程执行 performGlobalAction,成功与否只能看对端屏幕。
|
||||
|
||||
Json::Value BuildRemoteLockScreenInputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value idProp(Json::objectValue);
|
||||
idProp["type"] = "string";
|
||||
idProp["description"] = u8"主机 id,取 list_online_hosts / search_hosts 返回的 id 字段";
|
||||
props["id"] = idProp;
|
||||
Json::Value sid(Json::objectValue);
|
||||
sid["type"] = "string";
|
||||
sid["description"] = u8"remote_open 返回的 session_id";
|
||||
props["session_id"] = sid;
|
||||
Json::Value schema(Json::objectValue);
|
||||
schema["type"] = "object";
|
||||
schema["properties"] = props;
|
||||
Json::Value required(Json::arrayValue);
|
||||
required.append("id");
|
||||
required.append("session_id");
|
||||
schema["required"] = required;
|
||||
return schema;
|
||||
}
|
||||
|
||||
Json::Value BuildRemoteLockScreenOutputSchema() {
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value schema(Json::objectValue);
|
||||
schema["type"] = "object";
|
||||
schema["properties"] = props;
|
||||
return schema;
|
||||
}
|
||||
|
||||
// tools/call:remote_lock_screen(锁屏;成功返回空对象)
|
||||
std::string BuildRemoteLockScreen(const Json::Value& id, const Json::Value& args, CMy2015RemoteDlg* parent) {
|
||||
CMcpServer& mcp = CMcpServer::Instance();
|
||||
mcp.SweepIdleScreenCtrl(kScreenCtrlIdleTimeoutSec);
|
||||
|
||||
uint64_t devId = 0;
|
||||
context* ctx = nullptr;
|
||||
std::string errJson;
|
||||
if (!ResolveScreenCtrlSessionHost(id, args, parent, devId, ctx, errJson))
|
||||
return errJson;
|
||||
|
||||
std::string sessionId = GetStringArg(args, "session_id");
|
||||
if (sessionId.empty())
|
||||
return BuildError(id, -32602, "Missing required parameter: session_id");
|
||||
|
||||
// 目前只有 Android 客户端处理 COMMAND_SCREEN_CTRL_ALT_DEL;Windows/Linux 收到也是丢弃。
|
||||
if (ctx->GetAdditionalData(RES_CLIENT_TYPE) != "APK")
|
||||
return BuildError(id, -32005, "remote_lock_screen is only supported on Android hosts");
|
||||
// 老 APK 没有该分支,包会被静默丢弃;用能力位提前拒绝,别假报成功。
|
||||
if (!ctx->SupportsLockScreen())
|
||||
return BuildError(id, -32005, "Android client is too old for remote_lock_screen: "
|
||||
"the APK has no lock-screen handler, upgrade the client first");
|
||||
|
||||
// 校验 session_id/busy 并置 busy,取屏幕子连接(与注入/剪贴板共用同一子连接串行化)。
|
||||
context* subCtx = nullptr;
|
||||
int screenW = 0, screenH = 0;
|
||||
int r = mcp.BeginScreenCtrlAction(devId, sessionId, subCtx, screenW, screenH);
|
||||
if (r == 2) return BuildError(id, -32003, "Device busy: another injection is in flight for this session");
|
||||
if (r == 1) return BuildError(id, -32002, "Remote control session not found, not ready, or closed: " + sessionId);
|
||||
|
||||
BYTE packet[1] = { (BYTE)COMMAND_SCREEN_CTRL_ALT_DEL };
|
||||
bool ok = subCtx->Send2Client(packet, sizeof(packet)) != FALSE;
|
||||
|
||||
mcp.EndScreenCtrlAction(devId, sessionId);
|
||||
|
||||
if (!ok)
|
||||
return BuildError(id, -32004, "Failed to send lock-screen command");
|
||||
|
||||
if (parent) {
|
||||
std::string audit = "host " + std::to_string(devId) + " remote-lock-screen: session " + sessionId;
|
||||
parent->PostMessageA(WM_SHOWERRORMSG,
|
||||
(WPARAM)new CString(ToAnsi(audit, 936).c_str()),
|
||||
(LPARAM)new CString(_TR("MCP远程控制")));
|
||||
}
|
||||
|
||||
Json::Value result(Json::objectValue);
|
||||
result["structuredContent"] = Json::Value(Json::objectValue);
|
||||
Json::Value content(Json::arrayValue);
|
||||
Json::Value item(Json::objectValue);
|
||||
item["type"] = "text";
|
||||
item["text"] = std::string(u8"ok");
|
||||
content.append(item);
|
||||
result["content"] = content;
|
||||
result["isError"] = false;
|
||||
return BuildResult(id, result);
|
||||
}
|
||||
|
||||
// ===== P10-C:remote_block_input(锁定/解除对端键鼠;零客户端改动)=====
|
||||
//
|
||||
// 报文与 MFC 端 IDM_BLOCK_INPUT 完全一致:[COMMAND_SCREEN_BLOCK_INPUT][0|1](2 字节,
|
||||
@@ -9985,6 +10089,8 @@ const ToolPlatform kToolPlatforms[] = {
|
||||
{ "remote_keyboard", kPlatWin|kPlatLnx|kPlatApk },
|
||||
{ "remote_mouse", kPlatWin|kPlatLnx|kPlatApk },
|
||||
{ "remote_clipboard", kPlatWin|kPlatLnx|kPlatApk },
|
||||
// COMMAND_SCREEN_CTRL_ALT_DEL:只有 Android 客户端实现(映射为系统锁屏)
|
||||
{ "remote_lock_screen", kPlatApk },
|
||||
// macOS 客户端有 PTY 实现(macos/main.mm:753),但服务端刻意不开放
|
||||
// (McpServer.cpp:3652「macOS 本轮不开放」),故实际不可用
|
||||
{ "exec_command", kPlatWin|kPlatLnx },
|
||||
@@ -10355,6 +10461,7 @@ std::string DispatchSingleHostTool(const Json::Value& id, const std::string& too
|
||||
if (toolName == "remote_keyboard") return BuildRemoteKeyboard(id, args, parent);
|
||||
if (toolName == "remote_mouse") return BuildRemoteMouse(id, args, parent);
|
||||
if (toolName == "remote_clipboard") return BuildRemoteClipboard(id, args, parent);
|
||||
if (toolName == "remote_lock_screen") return BuildRemoteLockScreen(id, args, parent);
|
||||
if (toolName == "remote_block_input") return BuildRemoteBlockInput(id, args, parent);
|
||||
if (toolName == "download_file") return BuildDownloadFile(id, args, parent);
|
||||
if (toolName == "upload_file") return BuildUploadFile(id, args, parent);
|
||||
|
||||
Reference in new issue
Block a user