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");
|
||||
}
|
||||
|
||||
@@ -7,14 +7,18 @@ import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.graphics.Color
|
||||
import android.graphics.Path
|
||||
import android.graphics.PixelFormat
|
||||
import android.graphics.PointF
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.SystemClock
|
||||
import android.util.Log
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.view.accessibility.AccessibilityEvent
|
||||
import android.view.accessibility.AccessibilityNodeInfo
|
||||
|
||||
@@ -33,6 +37,10 @@ class ControlService : AccessibilityService() {
|
||||
companion object {
|
||||
const val TAG = "YAMA_CTRL"
|
||||
|
||||
// 锁定时注入手势前的放行等待(毫秒):见 sendGesture 的说明。100ms 是实测能
|
||||
// 稳稳让 WMS 应用完 FLAG_NOT_TOUCHABLE 的最小值量级(官方没有回调可等)。
|
||||
private const val OVERLAY_BYPASS_DELAY_MS = 100
|
||||
|
||||
// ── Service instance ─────────────────────────────────────────────
|
||||
@Volatile var instance: ControlService? = null
|
||||
|
||||
@@ -101,6 +109,33 @@ class ControlService : AccessibilityService() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录前探测(C++ 侧据此决定是否声明 CLIENT_CAP_PRIVACY_OVERLAY):隐私 overlay
|
||||
* 用 TYPE_ACCESSIBILITY_OVERLAY 挂在无障碍服务上,服务没在跑就挂不了(我们不申请
|
||||
* SYSTEM_ALERT_WINDOW),API 22 以下没有这个窗口类型。缺任一条都如实不声明。
|
||||
*/
|
||||
@JvmStatic
|
||||
fun canOverlay(): Boolean =
|
||||
instance != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1
|
||||
|
||||
/**
|
||||
* 服务端 COMMAND_SCREEN_BLANK / COMMAND_SCREEN_BLOCK_INPUT 的处理入口。
|
||||
* black=true → 全屏不透明黑(COMMAND_SCREEN_BLANK)
|
||||
* block=true → 透明但吃掉本机触摸(COMMAND_SCREEN_BLOCK_INPUT)
|
||||
* 两个参数都是**绝对状态**不是开关:重复下发幂等,都传 false 就是撤掉 overlay。
|
||||
* 注意 Android 上黑色 overlay 同样会被 MediaProjection 抓到,主控端的画面也会
|
||||
* 变黑——黑屏是给本机旁观的真人看的,不是「主控隐身」。
|
||||
* 调用方是屏幕子连接 OnReceive 线程,WindowManager 的操作必须在主线程。
|
||||
*/
|
||||
@JvmStatic
|
||||
fun setPrivacyOverlay(black: Boolean, block: Boolean) {
|
||||
val svc = instance ?: run {
|
||||
Log.w(TAG, "setPrivacyOverlay: accessibility service inactive, command dropped")
|
||||
return
|
||||
}
|
||||
svc.handler.post { svc.applyPrivacyOverlay(black, block) }
|
||||
}
|
||||
|
||||
// ── Screen geometry (set by CaptureService) ──────────────────────
|
||||
// Server sends coords in encoding space [0, encW) × [0, encH).
|
||||
// We map them to physical screen space before dispatching.
|
||||
@@ -167,6 +202,17 @@ class ControlService : AccessibilityService() {
|
||||
private var tvTouchMoved = false
|
||||
private val TV_TAP_THRESHOLD = 15f // encoding pixels — below this = tap, above = drag
|
||||
|
||||
// ── Privacy overlay(COMMAND_SCREEN_BLANK / COMMAND_SCREEN_BLOCK_INPUT)──
|
||||
// 两种用途共用一个挂在本服务上的 View(TYPE_ACCESSIBILITY_OVERLAY):
|
||||
// 黑屏 → 不透明黑;输入锁 → 透明。两者都要吃掉触摸,因为黑屏之下让真人
|
||||
// 盲点等于让他对着看不见的界面乱按。
|
||||
private var overlayView: View? = null
|
||||
private var overlayParams: WindowManager.LayoutParams? = null
|
||||
private var overlayBlack = false
|
||||
private var overlayConsuming = false
|
||||
// 注入手势期间的临时放行计数(见 sendGesture):>0 时 overlay 置 FLAG_NOT_TOUCHABLE
|
||||
private var overlayBypass = 0
|
||||
|
||||
// ── Left-button drag accumulator ─────────────────────────────────────
|
||||
private var lbuttonDown = false
|
||||
private var gestureStart = 0L
|
||||
@@ -200,10 +246,123 @@ class ControlService : AccessibilityService() {
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
runCatching { unregisterReceiver(screenReceiver) }
|
||||
// 服务被关掉(用户关闭无障碍)时 overlay 必须一起撤掉,否则会留下一个
|
||||
// 没人能解除的全屏黑色/不可触摸窗口把用户锁在外面。
|
||||
removeOverlay()
|
||||
instance = null
|
||||
Log.i(TAG, "ControlService destroyed")
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────
|
||||
// Privacy overlay(主线程)
|
||||
|
||||
private fun applyPrivacyOverlay(black: Boolean, block: Boolean) {
|
||||
overlayBlack = black
|
||||
overlayConsuming = black || block
|
||||
if (!overlayConsuming) {
|
||||
removeOverlay()
|
||||
Log.i(TAG, "privacy overlay: off")
|
||||
return
|
||||
}
|
||||
val v = overlayView ?: createOverlay() ?: return
|
||||
v.setBackgroundColor(if (black) Color.BLACK else Color.TRANSPARENT)
|
||||
syncOverlayTouchability()
|
||||
Log.i(TAG, "privacy overlay: black=$black block=$block")
|
||||
}
|
||||
|
||||
private fun createOverlay(): View? {
|
||||
val wm = getSystemService(Context.WINDOW_SERVICE) as? WindowManager ?: return null
|
||||
val v = View(this)
|
||||
val lp = WindowManager.LayoutParams(
|
||||
WindowManager.LayoutParams.MATCH_PARENT,
|
||||
WindowManager.LayoutParams.MATCH_PARENT,
|
||||
WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY,
|
||||
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or
|
||||
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN or
|
||||
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or
|
||||
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
|
||||
PixelFormat.TRANSLUCENT)
|
||||
lp.gravity = Gravity.TOP or Gravity.START
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
||||
lp.layoutInDisplayCutoutMode =
|
||||
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
||||
v.setBackgroundColor(if (overlayBlack) Color.BLACK else Color.TRANSPARENT)
|
||||
// 吃掉触摸:不给下面的应用(是否可触摸由 FLAG_NOT_TOUCHABLE 控制)
|
||||
v.setOnTouchListener { _, _ -> true }
|
||||
return try {
|
||||
wm.addView(v, lp)
|
||||
overlayView = v
|
||||
overlayParams = lp
|
||||
Log.i(TAG, "privacy overlay added")
|
||||
v
|
||||
} catch (t: Throwable) {
|
||||
Log.e(TAG, "privacy overlay addView failed: ${t.message}")
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeOverlay() {
|
||||
val v = overlayView ?: return
|
||||
val wm = getSystemService(Context.WINDOW_SERVICE) as? WindowManager
|
||||
runCatching { wm?.removeView(v) }
|
||||
overlayView = null
|
||||
overlayParams = null
|
||||
overlayBlack = false
|
||||
overlayConsuming = false
|
||||
overlayBypass = 0
|
||||
Log.i(TAG, "privacy overlay removed")
|
||||
}
|
||||
|
||||
// 触摸能否穿透由 overlay 上的 FLAG_NOT_TOUCHABLE 决定:
|
||||
// 正常锁定 → 可触摸(吃掉);有注入手势在飞 → 临时不可触摸(放行给下面的应用)。
|
||||
private fun syncOverlayTouchability() {
|
||||
val v = overlayView ?: return
|
||||
val lp = overlayParams ?: return
|
||||
val wm = getSystemService(Context.WINDOW_SERVICE) as? WindowManager ?: return
|
||||
val touchable = overlayConsuming && overlayBypass == 0
|
||||
val flag = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
|
||||
val flags = if (touchable) (lp.flags and flag.inv()) else (lp.flags or flag)
|
||||
if (flags == lp.flags) return
|
||||
lp.flags = flags
|
||||
runCatching { wm.updateViewLayout(v, lp) }
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入手势。锁定键鼠时 overlay 会把本服务自己注入的手势也吃掉——Windows 客户端
|
||||
* 的做法是 ProcessCommand 前后临时 BlockInput(false) 再恢复(client/ScreenManager.cpp
|
||||
* 的 COMMAND_SCREEN_CONTROL 分支),这里等价:手势开始前放行 overlay,结束回调里恢复。
|
||||
* 代价与 Windows 相同:手势在飞的那几十~几百毫秒里,真人触摸可以穿透。
|
||||
*
|
||||
* 放行后必须隔一小段时间再注入:改窗口属性(updateViewLayout)和注入触摸是两条
|
||||
* 异步路径,同一条消息里先改属性再 dispatchGesture,事件几乎必然仍打在被吞的
|
||||
* 那个窗口上(实测必现「Tap ok 但点了没反应」)。
|
||||
*/
|
||||
private fun sendGesture(gesture: GestureDescription,
|
||||
callback: GestureResultCallback? = null): Boolean {
|
||||
if (overlayView == null) return dispatchGesture(gesture, callback, null)
|
||||
overlayBypass++
|
||||
syncOverlayTouchability()
|
||||
handler.postDelayed({
|
||||
val restore = object : GestureResultCallback() {
|
||||
override fun onCompleted(g: GestureDescription?) { releaseBypass(); callback?.onCompleted(g) }
|
||||
override fun onCancelled(g: GestureDescription?) { releaseBypass(); callback?.onCancelled(g) }
|
||||
}
|
||||
val ok = try {
|
||||
dispatchGesture(gesture, restore, null)
|
||||
} catch (t: Throwable) {
|
||||
Log.e(TAG, "dispatchGesture threw: ${t.message}")
|
||||
false
|
||||
}
|
||||
if (!ok) releaseBypass() // 没派出去就不会有回调,立刻恢复,别把 overlay 留在放行状态
|
||||
}, OVERLAY_BYPASS_DELAY_MS.toLong())
|
||||
return true
|
||||
}
|
||||
|
||||
private fun releaseBypass() {
|
||||
if (overlayBypass > 0) overlayBypass--
|
||||
syncOverlayTouchability()
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────
|
||||
// Event routing (runs on main thread)
|
||||
|
||||
@@ -293,14 +452,14 @@ class ControlService : AccessibilityService() {
|
||||
.addStroke(GestureDescription.StrokeDescription(p, 0L, 80L))
|
||||
.addStroke(GestureDescription.StrokeDescription(p, 200L, 80L))
|
||||
.build()
|
||||
dispatchGesture(gesture, null, null)
|
||||
sendGesture(gesture)
|
||||
}
|
||||
|
||||
// ── Right-click → long press (600 ms) ────────────────────────
|
||||
WM_RBUTTONDOWN -> {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return
|
||||
val stroke = GestureDescription.StrokeDescription(singlePointPath(x, y), 0L, 600L)
|
||||
dispatchGesture(GestureDescription.Builder().addStroke(stroke).build(), null, null)
|
||||
sendGesture(GestureDescription.Builder().addStroke(stroke).build())
|
||||
}
|
||||
|
||||
// ── Scroll wheel → vertical swipe ─────────────────────────────
|
||||
@@ -312,7 +471,7 @@ class ControlService : AccessibilityService() {
|
||||
val dy = if (delta > 0) 400f else -400f
|
||||
val path = Path().apply { moveTo(x, y); lineTo(x, y + dy) }
|
||||
val stroke = GestureDescription.StrokeDescription(path, 0L, 300L)
|
||||
dispatchGesture(GestureDescription.Builder().addStroke(stroke).build(), null, null)
|
||||
sendGesture(GestureDescription.Builder().addStroke(stroke).build())
|
||||
CaptureService.requestIdr()
|
||||
}
|
||||
|
||||
@@ -336,13 +495,12 @@ class ControlService : AccessibilityService() {
|
||||
// Minimum 50 ms so Android registers the gesture; use actual elapsed for drags.
|
||||
val duration = maxOf(points.last().first, 50L)
|
||||
val stroke = GestureDescription.StrokeDescription(path, 0L, duration)
|
||||
val ok = dispatchGesture(
|
||||
val ok = sendGesture(
|
||||
GestureDescription.Builder().addStroke(stroke).build(),
|
||||
object : GestureResultCallback() {
|
||||
override fun onCompleted(g: GestureDescription?) { Log.d(TAG, "Gesture ok") }
|
||||
override fun onCancelled(g: GestureDescription?) { Log.w(TAG, "Gesture cancelled") }
|
||||
},
|
||||
null
|
||||
}
|
||||
)
|
||||
if (!ok) Log.e(TAG, "dispatchGesture returned false (service not ready?)")
|
||||
}
|
||||
@@ -512,11 +670,11 @@ class ControlService : AccessibilityService() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return
|
||||
val path = Path().apply { moveTo(x, y); lineTo(x + 1f, y) }
|
||||
val stroke = GestureDescription.StrokeDescription(path, 0L, 100L)
|
||||
val ok = dispatchGesture(GestureDescription.Builder().addStroke(stroke).build(),
|
||||
val ok = sendGesture(GestureDescription.Builder().addStroke(stroke).build(),
|
||||
object : GestureResultCallback() {
|
||||
override fun onCompleted(g: GestureDescription?) { Log.d(TAG, "Tap ok") }
|
||||
override fun onCancelled(g: GestureDescription?) { Log.w(TAG, "Tap cancelled") }
|
||||
}, null)
|
||||
})
|
||||
if (!ok) Log.e(TAG, "dispatchTap returned false")
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user