Feature: add file management to the Android client
Android 客户端此前没有文件管理:声明了 CLIENT_CAP_V2 却没有实现,主控的 文件管理对话框和 MCP 的 list_files/download_file/upload_file 对 APK 只会 超时。本次复用 Linux/macOS 已在用的 common/FileManager.h,只补平台差异: - 盘符模型:P=应用私有目录、I=内部存储、S/T/...=SD 卡与 U 盘;V2 上传 通过 FileTransferV2::SetPathMapper 复用同一套映射。 - 文件通道线上是 GBK。NDK 的 iconv 要 API 28,客户端 minSdk 是 21,改走 JNI -> Java Charset(NativeText.kt),严格模式失败原样透传。 - Android 11+ 引导开启「所有文件访问」;未授权时只挂 P: 并回一条提示。 API <=29 用运行时存储权限 + requestLegacyExternalStorage。 - 顺带实现 COMMAND_SEARCH_FILE(深度 32、1 万条),并让 MCP 的 list_files/download_file/upload_file/read_file 对 APK 开闸。 验证:arm64/armeabi 与模拟器 ABI 编译通过;模拟器上用 MCP 完成列盘、 列目录、下载、上传、中文文件名往返,GUI 文件管理器正常显示 P:/I:/S:。 Model: deepseek-flash Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
1 parent
7172ab376d
commit
28c0c9a2a6
9 files changed
+1001
-19
No files matched your search
@@ -386,9 +386,11 @@ const char* kServerInstructions =
|
||||
u8"远程交谈(chat_open / chat_send / chat_wait / chat_close,聊天界面在 App 内,"
|
||||
u8"需要声明 CLIENT_CAP_REMOTE_CHAT 的新版 APK)、远程终端(exec_command / terminal_open / "
|
||||
u8"terminal_exec / terminal_close,PTY 里跑 /system/bin/sh(mksh),命令由 toybox 提供,"
|
||||
u8"需要声明 CLIENT_CAP_TERMINAL 的新版 APK,老 APK 返回 -32005),以及 "
|
||||
u8"host_set_remark / host_set_watch_level 这两个只改服务端本地数据的工具。其余一律不支持"
|
||||
u8"(客户端未实现 SYSTEM 等命令)。\n"
|
||||
u8"需要声明 CLIENT_CAP_TERMINAL 的新版 APK,老 APK 返回 -32005)、文件管理"
|
||||
u8"(list_files / download_file / upload_file / read_file;路径是盘符形式 I:\\、S:\\、P:\\,"
|
||||
u8"I 是内部存储、S 起是 SD 卡/U 盘、P 是应用私有目录;未授予「所有文件访问」时"
|
||||
u8"I/S 下的文件可能读不了,只能正常使用 P:\\),以及 "
|
||||
u8"host_set_remark / host_set_watch_level 这两个只改服务端本地数据的工具。其余一律不支持。\n"
|
||||
u8"copy_files_c2c 是唯一有方向性的工具:源端 src_id 必须是 win,目标端 dst_id 可以是 "
|
||||
u8"win / lnx / mac。Linux 和 macOS 只能当接收方,不能当发送方(反向不支持)。\n"
|
||||
u8"这些不支持的组合多数会立刻返回 -32005;少数要等子连接才暴露的(老客户端不认命令等)"
|
||||
@@ -3167,7 +3169,7 @@ std::string BuildListProcesses(const Json::Value& id, const Json::Value& args, C
|
||||
return BuildError(id, -32001, "Timeout waiting for process list");
|
||||
|
||||
// 进程名/路径编码按 clientType 判定:Windows 走 A 接口(QueryFullProcessImageNameA 等)
|
||||
// =客户端 ANSI(GBK/936),不随 CLIENT_CAP_UTF8 转 UTF-8;LNX/MAC 的 /proc 天然 UTF-8。
|
||||
// =客户端 ANSI(GBK/936),不随 CLIENT_CAP_UTF8 转 UTF-8;LNX/MAC/APK 的 /proc 天然 UTF-8。
|
||||
// 不能用 GetClientEncoding——它按能力位返回 CP_UTF8,会误解 Windows 客户端的 GBK 进程名。
|
||||
CString clientType = ctx->GetAdditionalData(RES_CLIENT_TYPE);
|
||||
UINT cp = (clientType == "LNX" || clientType == "MAC") ? CP_UTF8 : 936;
|
||||
@@ -3687,7 +3689,9 @@ std::string BuildListFiles(const Json::Value& id, const Json::Value& args, CMy20
|
||||
// (客户端 utf8ToGbk 遇到 GBK 无法表示的字符会原样透传 UTF-8),见 DecodeListingName。
|
||||
CString clientType = ctx->GetAdditionalData(RES_CLIENT_TYPE);
|
||||
const bool posixFs = (clientType == "LNX" || clientType == "MAC");
|
||||
const UINT nameCp = posixFs ? CP_UTF8 : 936;
|
||||
// APK 与 POSIX 客户端一样:能转 GBK 的名字发 GBK,转不了的原样发 UTF-8,
|
||||
// 所以这里也要走 DecodeListingName 的「先试 GBK 再当 UTF-8」分支。
|
||||
const UINT nameCp = (posixFs || clientType == "APK") ? CP_UTF8 : 936;
|
||||
|
||||
// Windows 上 "."、"/"、"\\" 是「列盘」的历史写法;POSIX 上 "/" 是真实目录
|
||||
// (根目录),不能当列盘。列盘统一用空 path 下发给 OnDriveList。
|
||||
@@ -9878,7 +9882,7 @@ std::string BuildKillProcess(const Json::Value& id, const Json::Value& args, CMy
|
||||
if (!mcp.WaitPending(devId, data, mcp.ToolTimeoutMs()))
|
||||
return BuildError(id, -32001, "Timeout waiting for process list (dry run)");
|
||||
|
||||
UINT cp = (clientType == "LNX" || clientType == "MAC") ? CP_UTF8 : 936;
|
||||
UINT cp = (clientType == "LNX" || clientType == "MAC" || clientType == "APK") ? CP_UTF8 : 936;
|
||||
Json::Value procs = ParseProcessList(data, cp);
|
||||
|
||||
Json::Value targets(Json::arrayValue);
|
||||
@@ -9939,7 +9943,7 @@ std::string BuildKillProcess(const Json::Value& id, const Json::Value& args, CMy
|
||||
if (!mcp.WaitPendingWrite(devId, data, mcp.ToolTimeoutMs()))
|
||||
return BuildError(id, -32001, "Timeout waiting for process list after kill");
|
||||
|
||||
UINT cp = (clientType == "LNX" || clientType == "MAC") ? CP_UTF8 : 936;
|
||||
UINT cp = (clientType == "LNX" || clientType == "MAC" || clientType == "APK") ? CP_UTF8 : 936;
|
||||
Json::Value procs = ParseProcessList(data, cp);
|
||||
|
||||
Json::Value remaining(Json::arrayValue);
|
||||
@@ -12006,12 +12010,15 @@ const ToolPlatform kToolPlatforms[] = {
|
||||
{ "build_client", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
|
||||
// ---- win+lnx+mac ---- SYSTEM / LIST_DRIVE / QUERY_LOG / V2 文件传输
|
||||
{ "list_processes", kPlatWin|kPlatLnx|kPlatMac },
|
||||
{ "list_files", kPlatWin|kPlatLnx|kPlatMac },
|
||||
// Android 新版实现了 COMMAND_LIST_DRIVE → FileManager 子连接(盘符 I:/S:/P:)。
|
||||
// 老 APK 没有这个实现,却也声明了 CLIENT_CAP_V2,无法按能力位提前区分;
|
||||
// 老包的表现是超时(-32001),升级 APK 即可。
|
||||
{ "list_files", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
|
||||
// Android 客户端同样实现了 COMMAND_QUERY_LOG → TOKEN_REPORT_LOG 子连接上报
|
||||
{ "get_client_log", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
|
||||
{ "download_file", kPlatWin|kPlatLnx|kPlatMac },
|
||||
{ "read_file", kPlatWin|kPlatLnx|kPlatMac },
|
||||
{ "upload_file", kPlatWin|kPlatLnx|kPlatMac },
|
||||
{ "download_file", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
|
||||
{ "read_file", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
|
||||
{ "upload_file", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
|
||||
// ---- win+lnx(+apk) ---- 远程控制全族 + 需 SCREEN_PREVIEW 的截屏 + macOS 未开放项
|
||||
// Android 用无障碍 takeScreenshot(API 30+,需开无障碍服务),只支持 mode=screen
|
||||
// macOS 走 macos/ScreenPreview.mm(CGDisplayCreateImage,声明 CLIENT_CAP_SCREEN_PREVIEW
|
||||
|
||||
Reference in new issue
Block a user