Feature: Report client run logs from the Android client

Before this change the Android client's run log went to logcat only:
Logger's init tried to create a log directory, enable was true, and the
in-memory ring that MCP's get_client_log reads was never fed, so the
tool returned an empty log for APK hosts.

Logger now has an Android branch that skips the directory and file writer
and keeps only the ring, which is always written regardless of enable.
Mprintf carries the source file and line as on Windows/Linux, and both
android_log (Mprintf) and a new android_log_tag (platform LOGI/LOGE,
LOGI_SH/LOGE_SH) print to logcat and append to the ring.

A new ClientLogThread opens a sub-connection on COMMAND_QUERY_LOG and
lets ClientLogHandler send TOKEN_REPORT_LOG plus the full ring as the
first packet. It has to be a sub-connection: the server takes the first
packet and calls CancelIO, which would drop the main connection. The
server side allows get_client_log on kPlatApk and decodes the payload as
UTF-8 like the other POSIX clients.

Verified on the emulator against a local debug server: get_client_log
returned 21 UTF-8 lines including [file:line] Mprintf output, LOGI
lines, and the ClientLogThread handshake.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-11 12:57:12 +01:00
1 parent 51747dc0ea
commit d365a4f948
5 files changed
+99 -14

No files matched your search

+7 -5
View File
@@ -343,8 +343,8 @@ const char* kServerInstructions =
u8"exec_command、terminal_open / terminal_exec / terminal_close"
u8"(客户端有 PTY 实现,但服务端本轮未开放)、kill_process;"
u8"文件传输、进程列表、日志可用。\n"
u8"apk(APK):只支持主机列表(list_online_hosts / list_all_hosts)/ 详情 / 搜索 / "
u8"审计日志 / 服务状态 / 会话管理,以及 "
u8"apk(APK):支持主机列表(list_online_hosts / list_all_hosts)/ 详情 / 搜索 / "
u8"审计日志 / 服务状态 / 会话管理、运行日志(get_client_log),以及 "
u8"host_set_remark / host_set_watch_level 这两个只改服务端本地数据的工具。其余一律不支持"
u8"(客户端未实现 SYSTEM 与 SHELL)。\n"
u8"copy_files_c2c 是唯一有方向性的工具:源端 src_id 必须是 win,目标端 dst_id 可以是 "
@@ -4173,9 +4173,10 @@ std::string BuildGetClientLog(const Json::Value& id, const Json::Value& args, CM
// data[0]=token,其后为 Logger 内存 ring buffer 的日志文本(无 '\0' 终止)。
// 客户端在子连接建立时 m_sentIdx=0 返回全量,随后每 3s 推增量;MessageHandle 在
// 取走首条全量后立即 CancelIO 关子链接,增量不再到达,故此处即为完整快照。
// 日志文本为客户端 ANSI(Windows 走 vsnprintf A 版),按 clientType 判定编码。
// 日志文本为客户端 ANSI(Windows 走 vsnprintf A 版),按 clientType 判定编码:
// POSIX 客户端(LNX/MAC/APK)一律 UTF-8,Windows 是 GBK。
CString clientType = ctx->GetAdditionalData(RES_CLIENT_TYPE);
UINT cp = (clientType == "LNX" || clientType == "MAC") ? CP_UTF8 : 936;
UINT cp = (clientType == "LNX" || clientType == "MAC" || clientType == "APK") ? CP_UTF8 : 936;
std::string log;
if (data.size() > 1) {
@@ -9935,7 +9936,8 @@ const ToolPlatform kToolPlatforms[] = {
// ---- win+lnx+mac ---- SYSTEM / LIST_DRIVE / QUERY_LOG / V2 文件传输
{ "list_processes", kPlatWin|kPlatLnx|kPlatMac },
{ "list_files", kPlatWin|kPlatLnx|kPlatMac },
{ "get_client_log", kPlatWin|kPlatLnx|kPlatMac },
// Android 客户端同样实现了 COMMAND_QUERY_LOG → TOKEN_REPORT_LOG 子连接上报
{ "get_client_log", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
{ "download_file", kPlatWin|kPlatLnx|kPlatMac },
{ "upload_file", kPlatWin|kPlatLnx|kPlatMac },
// ---- win+lnx ---- 远程控制全族 + 需 SCREEN_PREVIEW 的截屏 + macOS 未开放项