[11/n Dispatcher refactor] Move isTouchTrusted to WindowInfo
This CL moves isTouchTrusted to WindowInfo subclass along with
setMaximumObscuringOpacityForTouch.
Bug: 367661487
Bug: 245989146
Test: atest inputflinger_tests
Flag: EXEMPT refactor
Change-Id: I9f2f1821e4bf22c3177ca4bb9fd3370976e8e2d6
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index d4f067b..266e691 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -954,7 +954,6 @@
mDispatchEnabled(false),
mDispatchFrozen(false),
mInputFilterEnabled(false),
- mMaximumObscuringOpacityForTouch(1.0f),
mFocusedDisplayId(ui::LogicalDisplayId::DEFAULT),
mWindowTokenWithPointerCapture(nullptr),
mAwaitedApplicationDisplayId(ui::LogicalDisplayId::INVALID),
@@ -3164,8 +3163,8 @@
return info;
}
-bool InputDispatcher::isTouchTrustedLocked(
- const DispatcherWindowInfo::TouchOcclusionInfo& occlusionInfo) const {
+bool InputDispatcher::DispatcherWindowInfo::isTouchTrusted(
+ const TouchOcclusionInfo& occlusionInfo) const {
if (occlusionInfo.hasBlockingOcclusion) {
ALOGW("Untrusted touch due to occlusion by %s/%s", occlusionInfo.obscuringPackage.c_str(),
occlusionInfo.obscuringUid.toString().c_str());
@@ -5271,8 +5270,9 @@
return dump;
}
-bool InputDispatcher::canWindowReceiveMotionLocked(const sp<WindowInfoHandle>& window,
- const MotionEntry& motionEntry) const {
+bool InputDispatcher::canWindowReceiveMotionLocked(
+ const sp<android::gui::WindowInfoHandle>& window,
+ const android::inputdispatcher::MotionEntry& motionEntry) const {
const WindowInfo& info = *window->getInfo();
// Skip spy window targets that are not valid for targeted injection.
@@ -5307,7 +5307,7 @@
const auto [x, y] = resolveTouchedPosition(motionEntry);
DispatcherWindowInfo::TouchOcclusionInfo occlusionInfo =
mWindowInfos.computeTouchOcclusionInfo(window, x, y);
- if (!isTouchTrustedLocked(occlusionInfo)) {
+ if (!mWindowInfos.isTouchTrusted(occlusionInfo)) {
if (DEBUG_TOUCH_OCCLUSION) {
ALOGD("Stack of obscuring windows during untrusted touch (%.1f, %.1f):", x, y);
for (const auto& log : occlusionInfo.debugInfo) {
@@ -5751,13 +5751,8 @@
}
void InputDispatcher::setMaximumObscuringOpacityForTouch(float opacity) {
- if (opacity < 0 || opacity > 1) {
- LOG_ALWAYS_FATAL("Maximum obscuring opacity for touch should be >= 0 and <= 1");
- return;
- }
-
std::scoped_lock lock(mLock);
- mMaximumObscuringOpacityForTouch = opacity;
+ mWindowInfos.setMaximumObscuringOpacityForTouch(opacity);
}
std::tuple<const TouchState*, const TouchedWindow*, ui::LogicalDisplayId>
@@ -7362,4 +7357,11 @@
return dump;
}
+void InputDispatcher::DispatcherWindowInfo::setMaximumObscuringOpacityForTouch(float opacity) {
+ if (opacity < 0 || opacity > 1) {
+ LOG_ALWAYS_FATAL("Maximum obscuring opacity for touch should be >= 0 and <= 1");
+ }
+ mMaximumObscuringOpacityForTouch = opacity;
+}
+
} // namespace android::inputdispatcher
diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h
index 92cbad4..13fec2a 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.h
+++ b/services/inputflinger/dispatcher/InputDispatcher.h
@@ -290,6 +290,8 @@
void removeDisplay(ui::LogicalDisplayId displayId);
+ void setMaximumObscuringOpacityForTouch(float opacity);
+
// Get a reference to window handles by display, return an empty vector if not found.
const std::vector<sp<android::gui::WindowInfoHandle>>& getWindowHandlesForDisplay(
ui::LogicalDisplayId displayId) const;
@@ -334,6 +336,8 @@
sp<android::gui::WindowInfoHandle> findWallpaperWindowBelow(
const sp<android::gui::WindowInfoHandle>& windowHandle) const;
+ bool isTouchTrusted(const TouchOcclusionInfo& occlusionInfo) const;
+
std::string dumpDisplayAndWindowInfo() const;
private:
@@ -342,6 +346,7 @@
mWindowHandlesByDisplay;
std::unordered_map<ui::LogicalDisplayId /*displayId*/, android::gui::DisplayInfo>
mDisplayInfos;
+ float mMaximumObscuringOpacityForTouch{1.0f};
};
DispatcherWindowInfo mWindowInfos GUARDED_BY(mLock);
@@ -443,7 +448,6 @@
bool mDispatchEnabled GUARDED_BY(mLock);
bool mDispatchFrozen GUARDED_BY(mLock);
bool mInputFilterEnabled GUARDED_BY(mLock);
- float mMaximumObscuringOpacityForTouch GUARDED_BY(mLock);
// This map is not really needed, but it helps a lot with debugging (dumpsys input).
// In the java layer, touch mode states are spread across multiple DisplayContent objects,
@@ -646,8 +650,6 @@
void addDragEventLocked(const MotionEntry& entry) REQUIRES(mLock);
void finishDragAndDrop(ui::LogicalDisplayId displayId, float x, float y) REQUIRES(mLock);
- bool isTouchTrustedLocked(const DispatcherWindowInfo::TouchOcclusionInfo& occlusionInfo) const
- REQUIRES(mLock);
std::string getApplicationWindowLabel(const InputApplicationHandle* applicationHandle,
const sp<android::gui::WindowInfoHandle>& windowHandle);