来自于一个网友在技术交流群中问题,我正好之前开发过程中也遇到了类似的问题,写个文章记录一下。
InputDispatcher: Untrusted touch due to occlusion by com.xx.xx/10074 (obscuring opacity = 1.00, maximum allowed = 0.80)
InputDispatcher: Dropping untrusted touch event due to com.xx.xx/10074
大佬们,请教个问题哈,测试时发现launcher上有个app,点击按钮没反应,然后捞了下日志,发现有输出上述这2行日志。
请问下大佬们,这2行日志是干啥的呢?
保护你的手机操作的安全,避免你误点了某个功能,怎么理解这件事?
举个例子,假如悬浮窗口B设置成了可穿透的触摸模式,就是touch事件可以穿透到应用A,那用户在不清楚状况的情况下,以为点击了紫色的“取消"按钮,最后生效的是绿色的“付款“”按钮那不是很危险吗?
图中就应该屏蔽点击取消的触摸事件,阻止应用A使用这次触摸事件
此变更会影响选择让触摸操作穿透其窗口的应用,例如使用 [FLAG_NOT_TOUCHABLE
]标志,但不限于以下示例:
SYSTEM_ALERT_WINDOW
权限并使用 FLAG_NOT_TOUCHABLE
标志的叠加层,例如使用 TYPE_APPLICATION_OVERLAY
的窗口。FLAG_NOT_TOUCHABLE
标志的 activity 窗口。这个很好理解,以为都是你app内部的事,不用担心有什么不安全的,除非app自己想搞事情
无障碍窗口 输入法 (IME) 窗口 Google 助理窗口
注意:类型为 TYPE_APPLICATION_OVERLAY 的窗口不受信任。
这个也好理解,毕竟都是系统内部的窗口
不会造成用户的误解
与3.3理由一样
这个网友遇到的错误就是obscuring opacity = 1.00, maximum allowed = 0.80
,不透明度1.00,怎么能允许被穿透呢,所以这个应用写的就是不符合规范。
只有让用户可以有足够的透明度知道自己点击的是后面那个窗口,那才是受信任的触摸。
可以通过adb日志查看
Untrusted touch due to occlusion by PACKAGE_NAME
如需允许不受信任的触摸操作,请在终端窗口中运行以下 ADB 命令
# A specific app
adb shell am compat disable BLOCK_UNTRUSTED_TOUCHES com.example.app
# All apps
# If you'd still like to see a Logcat message warning when a touch would be
# blocked, use 1 instead of 0.
adb shell settings put global block_untrusted_touches 0
如需将行为还原为默认设置(不受信任的触摸操作被屏蔽),请运行以下命令:
# A specific app
adb shell am compat reset BLOCK_UNTRUSTED_TOUCHES com.example.app
# All apps
adb shell settings put global block_untrusted_touches 2
这里注意block_untrusted_touches为2是打开功能,1是关闭这个功能,但是还有日志输出,0是彻底关闭这个功能,没有日志输出。
具体的代码实现在findTouchedWindowTargetsLocked的逻辑中,会调用computeTouchOcclusionInfoLocked算出TouchOcclusionInfo,然后再调用isTouchTrustedLocked确认是否是信任的触摸事件,有兴趣的可以看看实现细节。
InputEventInjectionResult InputDispatcher::findTouchedWindowTargetsLocked(
nsecs_t currentTime, const MotionEntry& entry, std::vector<InputTarget>& inputTargets,
nsecs_t* nextWakeupTime, bool* outConflictingPointerActions) {
...
for (const sp<WindowInfoHandle>& windowHandle : newTouchedWindows) {
// Drop events that can't be trusted due to occlusion
if (mBlockUntrustedTouchesMode != BlockUntrustedTouchesMode::DISABLED) {
TouchOcclusionInfo occlusionInfo =
computeTouchOcclusionInfoLocked(windowHandle, x, y);
if (!isTouchTrustedLocked(occlusionInfo)) {
if (DEBUG_TOUCH_OCCLUSION) {
ALOGD("Stack of obscuring windows during untrusted touch (%d, %d):", x, y);
for (const auto& log : occlusionInfo.debugInfo) {
ALOGD("%s", log.c_str());
}
}
sendUntrustedTouchCommandLocked(occlusionInfo.obscuringPackage);
if (mBlockUntrustedTouchesMode == BlockUntrustedTouchesMode::BLOCK) {
ALOGW("Dropping untrusted touch event due to %s/%d",
occlusionInfo.obscuringPackage.c_str(), occlusionInfo.obscuringUid);
continue;
}
}
}
}
}
bool InputDispatcher::isTouchTrustedLocked(const TouchOcclusionInfo& occlusionInfo) const {
if (occlusionInfo.hasBlockingOcclusion) {
ALOGW("Untrusted touch due to occlusion by %s/%d", occlusionInfo.obscuringPackage.c_str(),
occlusionInfo.obscuringUid);
return false;
}
if (occlusionInfo.obscuringOpacity > mMaximumObscuringOpacityForTouch) {
ALOGW("Untrusted touch due to occlusion by %s/%d (obscuring opacity = "
"%.2f, maximum allowed = %.2f)",
occlusionInfo.obscuringPackage.c_str(), occlusionInfo.obscuringUid,
occlusionInfo.obscuringOpacity, mMaximumObscuringOpacityForTouch);
return false;
}
return true;
}
https://developer.android.google.cn/about/versions/12/behavior-changes-all#untrusted-touch-events
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有