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:
1 parent
445bd8bbb9
commit
a801a2999a
9 files changed
+306
-24
No files matched your search
@@ -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;
|
||||
|
||||
|
||||
@@ -239,6 +239,8 @@ static jmethodID g_getActiveWindowMid = nullptr;
|
||||
static jmethodID g_activityTitleMid = nullptr; // ControlService.currentActivityTitle()
|
||||
static jmethodID g_lockScreenMid = nullptr; // ControlService.lockScreen()V — COMMAND_SCREEN_CTRL_ALT_DEL
|
||||
static jmethodID g_canLockMid = nullptr; // ControlService.canLockScreen()Z — 登录前能力探测
|
||||
static jmethodID g_overlayMid = nullptr; // ControlService.setPrivacyOverlay(ZZ)V — 黑屏 / 锁键鼠
|
||||
static jmethodID g_canOverlayMid = nullptr; // ControlService.canOverlay()Z — 登录前能力探测
|
||||
// CaptureService.requestIdr() / forceFirstFrame() — ScreenSpyThread 子连接建立后触发
|
||||
static jclass g_captureClass = nullptr;
|
||||
static jmethodID g_requestIdrMid = nullptr;
|
||||
@@ -404,6 +406,31 @@ void DispatchLockScreen()
|
||||
if (attached) g_jvm->DetachCurrentThread();
|
||||
}
|
||||
|
||||
// 隐私 overlay:黑屏(COMMAND_SCREEN_BLANK)与锁键鼠(COMMAND_SCREEN_BLOCK_INPUT)
|
||||
// 共用同一个无障碍 overlay,两个参数都是绝对状态(见 ScreenHandler.h 的 ApplyOverlay)。
|
||||
void DispatchPrivacyOverlay(bool black, bool block)
|
||||
{
|
||||
if (!g_jvm || !g_ctrlClass || !g_overlayMid) {
|
||||
LOGE("PRIVACY_OVERLAY: JNI not ready (cls=%p method=%p)", g_ctrlClass, g_overlayMid);
|
||||
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;
|
||||
}
|
||||
jenv->CallStaticVoidMethod(g_ctrlClass, g_overlayMid,
|
||||
black ? JNI_TRUE : JNI_FALSE,
|
||||
block ? JNI_TRUE : JNI_FALSE);
|
||||
if (jenv->ExceptionCheck()) jenv->ExceptionClear();
|
||||
LOGI("PRIVACY_OVERLAY: dispatched black=%d block=%d", (int)black, (int)block);
|
||||
if (attached) g_jvm->DetachCurrentThread();
|
||||
}
|
||||
|
||||
static std::string GetActiveWindowFromJava()
|
||||
{
|
||||
if (!g_jvm || !g_ctrlClass || !g_getActiveWindowMid) return "Android";
|
||||
@@ -961,6 +988,27 @@ static bool LockScreenAvailable()
|
||||
return can == JNI_TRUE;
|
||||
}
|
||||
|
||||
// 登录前探测:无障碍服务在跑且 API 22+(TYPE_ACCESSIBILITY_OVERLAY)才声明
|
||||
// CLIENT_CAP_PRIVACY_OVERLAY,服务端据此放行 Android 的 remote_block_input。
|
||||
// 与 LockScreenAvailable 一样随每次登录刷新:无障碍被关掉重连后撤回。
|
||||
static bool OverlayAvailable()
|
||||
{
|
||||
if (!g_jvm || !g_ctrlClass || !g_canOverlayMid) return false;
|
||||
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 false;
|
||||
attached = true;
|
||||
} else if (st != JNI_OK || !jenv) {
|
||||
return false;
|
||||
}
|
||||
jboolean can = jenv->CallStaticBooleanMethod(g_ctrlClass, g_canOverlayMid);
|
||||
if (jenv->ExceptionCheck()) { jenv->ExceptionClear(); can = JNI_FALSE; }
|
||||
if (attached) g_jvm->DetachCurrentThread();
|
||||
return can == JNI_TRUE;
|
||||
}
|
||||
|
||||
// 抓屏可能耗几十~几百毫秒(系统回调 + 编码),必须离开接收线程;超额请求直接丢弃
|
||||
// (服务端会超时按「预览不可用」降级,与 Linux/Windows 的限流一致)。
|
||||
static void ScreenPreviewThread(ScreenPreviewReq req)
|
||||
@@ -1475,9 +1523,11 @@ static void ConnectionThread(uint64_t gen)
|
||||
// 屏幕预览能力位按运行时状态刷新:无障碍服务在跑才声明(API 30+ 的 takeScreenshot),
|
||||
// 服务端据此放行 get_screenshot;无障碍被关掉后重连会撤回,避免服务端白等抓屏。
|
||||
// 锁屏同理:无障碍服务在跑且 API 28+ 才声明。
|
||||
// 隐私 overlay(黑屏 / 锁键鼠)同理:无障碍服务在跑且 API 22+ 才声明。
|
||||
logInfo.SetCaps(LOGIN_INFOR::DefaultCaps() |
|
||||
(ScreenPreviewAvailable() ? CLIENT_CAP_SCREEN_PREVIEW : 0) |
|
||||
(LockScreenAvailable() ? CLIENT_CAP_LOCK_SCREEN : 0));
|
||||
(LockScreenAvailable() ? CLIENT_CAP_LOCK_SCREEN : 0) |
|
||||
(OverlayAvailable() ? CLIENT_CAP_PRIVACY_OVERLAY : 0));
|
||||
client->SendLoginInfo(logInfo.Speed(clock() - c));
|
||||
g_lastHeartbeatAckMs.store(GetUnixMs(), std::memory_order_relaxed);
|
||||
LOGI("Connected & login sent");
|
||||
@@ -1649,6 +1699,12 @@ Java_com_yama_client_YamaBridge_nativeInit(
|
||||
g_canLockMid = env->GetStaticMethodID(g_ctrlClass, "canLockScreen", "()Z");
|
||||
if (env->ExceptionCheck()) { env->ExceptionClear(); g_canLockMid = nullptr; }
|
||||
if (!g_canLockMid) LOGE("ControlService.canLockScreen not found");
|
||||
g_overlayMid = env->GetStaticMethodID(g_ctrlClass, "setPrivacyOverlay", "(ZZ)V");
|
||||
if (env->ExceptionCheck()) { env->ExceptionClear(); g_overlayMid = nullptr; }
|
||||
if (!g_overlayMid) LOGE("ControlService.setPrivacyOverlay not found");
|
||||
g_canOverlayMid = env->GetStaticMethodID(g_ctrlClass, "canOverlay", "()Z");
|
||||
if (env->ExceptionCheck()) { env->ExceptionClear(); g_canOverlayMid = nullptr; }
|
||||
if (!g_canOverlayMid) LOGE("ControlService.canOverlay not found");
|
||||
} else {
|
||||
LOGE("ControlService class not found");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user