Feature: Support input blocking and privacy overlay on Android hosts

remote_block_input rejected anything but Windows because the Android
client had no COMMAND_SCREEN_BLOCK_INPUT handler. This adds the overlay
on the client and the server gating, and wires up COMMAND_SCREEN_BLANK.

Client: the accessibility service hangs a full-screen
TYPE_ACCESSIBILITY_OVERLAY on itself. block=true makes it transparent
and touchable so it swallows physical taps; black=true paints it black.
Both are absolute states, so repeated commands are idempotent, and the
handler clears the overlay when the screen sub-connection dies (Android
has no "released when the calling thread exits" fallback). During a
remote gesture the overlay is flipped to FLAG_NOT_TOUCHABLE, mirroring
Windows' BlockInput(false) wrap; the flag change and the injection must
be separated by a short delay or the gesture is swallowed.

Server: CLIENT_CAP_PRIVACY_OVERLAY distinguishes new APKs from old ones;
Linux/macOS and old APKs still get -32005 up front. Tool masks,
instructions and mcp/tools.json follow the change. COMMAND_SCREEN_BLANK
is implemented but not exposed as a tool: MediaProjection captures the
overlay, so blacking out the screen blinds the operator too and cannot
emulate Windows' WDA_EXCLUDEFROMCAPTURE.

Verified on the Android 15 emulator: blocked taps are swallowed while
remote clicks still land, the block re-arms after each gesture, the
watchdog auto-unblocks at the deadline, a dropped sub-connection clears
the overlay, and a black overlay shows up in both screencap and
get_screenshot. The committed ghost.apk is stale; rebuild before release.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-11 21:58:54 +01:00
1 parent 445bd8bbb9
commit a801a2999a
9 files changed
+306 -24

No files matched your search

+33
View File
@@ -24,6 +24,8 @@ extern uint64_t g_myClientID;
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);
extern void DispatchLockScreen();
// 隐私 overlay(COMMAND_SCREEN_BLANK / COMMAND_SCREEN_BLOCK_INPUT),定义在 main.cpp
extern void DispatchPrivacyOverlay(bool black, bool block);
// Linux/macOS 共用的 BITMAPINFOHEADER 布局(与 Windows 完全一致)
#pragma pack(push, 1)
@@ -64,6 +66,14 @@ public:
}
~AndroidScreenHandler() {
// 屏幕子连接断了 overlay 就没人能解除:全屏黑色/不可触摸窗口会把本机用户锁在外面,
// 必须在 handler 销毁时兜底撤掉(服务端侧也有强制解锁 + 关闭会话的路径,但断网时
// 服务端已经发不出任何报文)。
if (m_black.load() || m_block.load()) {
LOGE_SH("screen conn ended with overlay on (black=%d block=%d); clearing",
(int)m_black.load(), (int)m_block.load());
DispatchPrivacyOverlay(false, false);
}
m_running = false;
m_cond.notify_all();
if (m_sendThread.joinable())
@@ -134,6 +144,18 @@ public:
// Ctrl+Alt+Del 在 Android 无对应键,客户端映射为锁屏(GLOBAL_ACTION_LOCK_SCREEN)
DispatchLockScreen();
break;
case COMMAND_SCREEN_BLOCK_INPUT:
// [cmd][0|1]:1=吃掉本机触摸(透明 overlay),0=解除。
// 与 Windows 的 BlockInput 语义对齐:服务端注入的手势照常穿透(Kotlin 侧在
// 手势在飞时临时置 FLAG_NOT_TOUCHABLE,等价于 Windows 的 BlockInput(false) 包裹)。
if (size >= 2) ApplyOverlay(m_black.load(), data[1] != 0);
break;
case COMMAND_SCREEN_BLANK:
// [cmd][0|1]:1=全屏黑,0=恢复。注意 Android 没有「窗口不参与抓屏」的等价物
// (Windows 是 WDA_EXCLUDEFROMCAPTURE),黑色 overlay 会被 MediaProjection
// 一起抓走,主控端看到的画面也会变黑——这是给本机旁观者看的隐私屏,不是隐身。
if (size >= 2) ApplyOverlay(data[1] != 0, m_block.load());
break;
case COMMAND_SCREEN_CONTROL: {
// 服务端通过子连接下发鼠标/键盘控制包(MSG64 固定 48 字节)
// 坐标从 lParam(offset 24)读取,与 Windows/Linux/macOS 客户端一致:
@@ -157,6 +179,15 @@ public:
}
private:
// 服务端下发的是「绝对状态」(black/block 各一个 bool),这里只记客户端当前状态,
// 用于两条收尾路径:另一条命令到来时保持它不变、子连接断开时整体撤掉。
void ApplyOverlay(bool black, bool block) {
m_black.store(black);
m_block.store(block);
LOGI_SH("privacy overlay: black=%d block=%d", (int)black, (int)block);
DispatchPrivacyOverlay(black, block);
}
struct Frame { std::vector<uint8_t> data; bool isKeyframe; };
IOCPClient* m_client;
@@ -165,6 +196,8 @@ private:
std::atomic<bool> m_running;
std::atomic<bool> m_firstSent;
std::atomic<bool> m_skipLogged{false};
std::atomic<bool> m_black{false}; // 隐私 overlay:全屏黑(COMMAND_SCREEN_BLANK)
std::atomic<bool> m_block{false}; // 隐私 overlay:吃掉本机触摸(COMMAND_SCREEN_BLOCK_INPUT)
BmpInfoHeader m_bmpHdr;