Add debug logs in case of untrusted touches
To help debug those. It's currently turned on to help debug incoming
bugs while in dogfood. I intend to turn off the flag later on.
Test: Perform an untrusted touch, then verify logcat.
Bug: 158002302
Change-Id: Ie335ec079bb2be8cb9d11fba687634686eecef1c
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index d7aea4e..8052084 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -37,6 +37,10 @@
// Log debug messages about input focus tracking.
static constexpr bool DEBUG_FOCUS = false;
+// Log debug messages about touch occlusion
+// STOPSHIP(b/169067926): Set to false
+static constexpr bool DEBUG_TOUCH_OCCLUSION = true;
+
// Log debug messages about the app switch latency optimization.
#define DEBUG_APP_SWITCH 0
@@ -1774,6 +1778,12 @@
TouchOcclusionInfo occlusionInfo =
computeTouchOcclusionInfoLocked(newTouchedWindowHandle, 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());
+ }
+ }
onUntrustedTouchLocked(occlusionInfo.obscuringPackage);
if (mBlockUntrustedTouchesMode == BlockUntrustedTouchesMode::BLOCK) {
ALOGW("Dropping untrusted touch event due to %s/%d",
@@ -2215,7 +2225,8 @@
*/
InputDispatcher::TouchOcclusionInfo InputDispatcher::computeTouchOcclusionInfoLocked(
const sp<InputWindowHandle>& windowHandle, int32_t x, int32_t y) const {
- int32_t displayId = windowHandle->getInfo()->displayId;
+ const InputWindowInfo* windowInfo = windowHandle->getInfo();
+ int32_t displayId = windowInfo->displayId;
const std::vector<sp<InputWindowHandle>>& windowHandles = getWindowHandlesLocked(displayId);
TouchOcclusionInfo info;
info.hasBlockingOcclusion = false;
@@ -2228,8 +2239,11 @@
}
const InputWindowInfo* otherInfo = otherHandle->getInfo();
if (canBeObscuredBy(windowHandle, otherHandle) &&
- windowHandle->getInfo()->ownerUid != otherInfo->ownerUid &&
- otherInfo->frameContainsPoint(x, y)) {
+ windowInfo->ownerUid != otherInfo->ownerUid && otherInfo->frameContainsPoint(x, y)) {
+ if (DEBUG_TOUCH_OCCLUSION) {
+ info.debugInfo.push_back(
+ dumpWindowForTouchOcclusion(otherInfo, /* isTouchedWindow */ false));
+ }
// canBeObscuredBy() has returned true above, which means this window is untrusted, so
// we perform the checks below to see if the touch can be propagated or not based on the
// window's touch occlusion mode
@@ -2255,9 +2269,26 @@
}
}
}
+ if (DEBUG_TOUCH_OCCLUSION) {
+ info.debugInfo.push_back(
+ dumpWindowForTouchOcclusion(windowInfo, /* isTouchedWindow */ true));
+ }
return info;
}
+std::string InputDispatcher::dumpWindowForTouchOcclusion(const InputWindowInfo* info,
+ bool isTouchedWindow) const {
+ return StringPrintf(INDENT2 "* %stype=%s, package=%s/%" PRId32 ", mode=%s, alpha=%.2f, "
+ "frame=[%" PRId32 ",%" PRId32 "][%" PRId32 ",%" PRId32
+ "], window=%s, applicationInfo=%s, flags=%s\n",
+ (isTouchedWindow) ? "[TOUCHED] " : "",
+ NamedEnum::string(info->type).c_str(), info->packageName.c_str(),
+ info->ownerUid, toString(info->touchOcclusionMode).c_str(), info->alpha,
+ info->frameLeft, info->frameTop, info->frameRight, info->frameBottom,
+ info->name.c_str(), info->applicationInfo.name.c_str(),
+ info->flags.string().c_str());
+}
+
bool InputDispatcher::isTouchTrustedLocked(const TouchOcclusionInfo& occlusionInfo) const {
if (occlusionInfo.hasBlockingOcclusion) {
ALOGW("Untrusted touch due to occlusion by %s/%d", occlusionInfo.obscuringPackage.c_str(),
diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h
index 235a8d3..98dea0b 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.h
+++ b/services/inputflinger/dispatcher/InputDispatcher.h
@@ -461,6 +461,7 @@
float obscuringOpacity;
std::string obscuringPackage;
int32_t obscuringUid;
+ std::vector<std::string> debugInfo;
};
TouchOcclusionInfo computeTouchOcclusionInfoLocked(const sp<InputWindowHandle>& windowHandle,
@@ -469,6 +470,7 @@
bool isWindowObscuredAtPointLocked(const sp<InputWindowHandle>& windowHandle, int32_t x,
int32_t y) const REQUIRES(mLock);
bool isWindowObscuredLocked(const sp<InputWindowHandle>& windowHandle) const REQUIRES(mLock);
+ std::string dumpWindowForTouchOcclusion(const InputWindowInfo* info, bool isTouchWindow) const;
std::string getApplicationWindowLabel(
const std::shared_ptr<InputApplicationHandle>& applicationHandle,
const sp<InputWindowHandle>& windowHandle);