Skip to content

Commit 60448cf

Browse files
author
Arpit Singh
committed
[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
1 parent 365ec0b commit 60448cf

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,6 @@ InputDispatcher::InputDispatcher(InputDispatcherPolicyInterface& policy,
954954
mDispatchEnabled(false),
955955
mDispatchFrozen(false),
956956
mInputFilterEnabled(false),
957-
mMaximumObscuringOpacityForTouch(1.0f),
958957
mFocusedDisplayId(ui::LogicalDisplayId::DEFAULT),
959958
mWindowTokenWithPointerCapture(nullptr),
960959
mAwaitedApplicationDisplayId(ui::LogicalDisplayId::INVALID),
@@ -3164,8 +3163,8 @@ InputDispatcher::DispatcherWindowInfo::computeTouchOcclusionInfo(
31643163
return info;
31653164
}
31663165

3167-
bool InputDispatcher::isTouchTrustedLocked(
3168-
const DispatcherWindowInfo::TouchOcclusionInfo& occlusionInfo) const {
3166+
bool InputDispatcher::DispatcherWindowInfo::isTouchTrusted(
3167+
const TouchOcclusionInfo& occlusionInfo) const {
31693168
if (occlusionInfo.hasBlockingOcclusion) {
31703169
ALOGW("Untrusted touch due to occlusion by %s/%s", occlusionInfo.obscuringPackage.c_str(),
31713170
occlusionInfo.obscuringUid.toString().c_str());
@@ -5271,8 +5270,9 @@ std::string InputDispatcher::DispatcherWindowInfo::dumpDisplayAndWindowInfo() co
52715270
return dump;
52725271
}
52735272

5274-
bool InputDispatcher::canWindowReceiveMotionLocked(const sp<WindowInfoHandle>& window,
5275-
const MotionEntry& motionEntry) const {
5273+
bool InputDispatcher::canWindowReceiveMotionLocked(
5274+
const sp<android::gui::WindowInfoHandle>& window,
5275+
const android::inputdispatcher::MotionEntry& motionEntry) const {
52765276
const WindowInfo& info = *window->getInfo();
52775277

52785278
// Skip spy window targets that are not valid for targeted injection.
@@ -5307,7 +5307,7 @@ bool InputDispatcher::canWindowReceiveMotionLocked(const sp<WindowInfoHandle>& w
53075307
const auto [x, y] = resolveTouchedPosition(motionEntry);
53085308
DispatcherWindowInfo::TouchOcclusionInfo occlusionInfo =
53095309
mWindowInfos.computeTouchOcclusionInfo(window, x, y);
5310-
if (!isTouchTrustedLocked(occlusionInfo)) {
5310+
if (!mWindowInfos.isTouchTrusted(occlusionInfo)) {
53115311
if (DEBUG_TOUCH_OCCLUSION) {
53125312
ALOGD("Stack of obscuring windows during untrusted touch (%.1f, %.1f):", x, y);
53135313
for (const auto& log : occlusionInfo.debugInfo) {
@@ -5751,13 +5751,8 @@ bool InputDispatcher::recentWindowsAreOwnedByLocked(gui::Pid pid, gui::Uid uid)
57515751
}
57525752

57535753
void InputDispatcher::setMaximumObscuringOpacityForTouch(float opacity) {
5754-
if (opacity < 0 || opacity > 1) {
5755-
LOG_ALWAYS_FATAL("Maximum obscuring opacity for touch should be >= 0 and <= 1");
5756-
return;
5757-
}
5758-
57595754
std::scoped_lock lock(mLock);
5760-
mMaximumObscuringOpacityForTouch = opacity;
5755+
mWindowInfos.setMaximumObscuringOpacityForTouch(opacity);
57615756
}
57625757

57635758
std::tuple<const TouchState*, const TouchedWindow*, ui::LogicalDisplayId>
@@ -7362,4 +7357,11 @@ std::string InputDispatcher::ConnectionManager::dump(nsecs_t currentTime) const
73627357
return dump;
73637358
}
73647359

7360+
void InputDispatcher::DispatcherWindowInfo::setMaximumObscuringOpacityForTouch(float opacity) {
7361+
if (opacity < 0 || opacity > 1) {
7362+
LOG_ALWAYS_FATAL("Maximum obscuring opacity for touch should be >= 0 and <= 1");
7363+
}
7364+
mMaximumObscuringOpacityForTouch = opacity;
7365+
}
7366+
73657367
} // namespace android::inputdispatcher

services/inputflinger/dispatcher/InputDispatcher.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ class InputDispatcher : public android::InputDispatcherInterface {
290290

291291
void removeDisplay(ui::LogicalDisplayId displayId);
292292

293+
void setMaximumObscuringOpacityForTouch(float opacity);
294+
293295
// Get a reference to window handles by display, return an empty vector if not found.
294296
const std::vector<sp<android::gui::WindowInfoHandle>>& getWindowHandlesForDisplay(
295297
ui::LogicalDisplayId displayId) const;
@@ -334,6 +336,8 @@ class InputDispatcher : public android::InputDispatcherInterface {
334336
sp<android::gui::WindowInfoHandle> findWallpaperWindowBelow(
335337
const sp<android::gui::WindowInfoHandle>& windowHandle) const;
336338

339+
bool isTouchTrusted(const TouchOcclusionInfo& occlusionInfo) const;
340+
337341
std::string dumpDisplayAndWindowInfo() const;
338342

339343
private:
@@ -342,6 +346,7 @@ class InputDispatcher : public android::InputDispatcherInterface {
342346
mWindowHandlesByDisplay;
343347
std::unordered_map<ui::LogicalDisplayId /*displayId*/, android::gui::DisplayInfo>
344348
mDisplayInfos;
349+
float mMaximumObscuringOpacityForTouch{1.0f};
345350
};
346351

347352
DispatcherWindowInfo mWindowInfos GUARDED_BY(mLock);
@@ -443,7 +448,6 @@ class InputDispatcher : public android::InputDispatcherInterface {
443448
bool mDispatchEnabled GUARDED_BY(mLock);
444449
bool mDispatchFrozen GUARDED_BY(mLock);
445450
bool mInputFilterEnabled GUARDED_BY(mLock);
446-
float mMaximumObscuringOpacityForTouch GUARDED_BY(mLock);
447451

448452
// This map is not really needed, but it helps a lot with debugging (dumpsys input).
449453
// In the java layer, touch mode states are spread across multiple DisplayContent objects,
@@ -646,8 +650,6 @@ class InputDispatcher : public android::InputDispatcherInterface {
646650
void addDragEventLocked(const MotionEntry& entry) REQUIRES(mLock);
647651
void finishDragAndDrop(ui::LogicalDisplayId displayId, float x, float y) REQUIRES(mLock);
648652

649-
bool isTouchTrustedLocked(const DispatcherWindowInfo::TouchOcclusionInfo& occlusionInfo) const
650-
REQUIRES(mLock);
651653
std::string getApplicationWindowLabel(const InputApplicationHandle* applicationHandle,
652654
const sp<android::gui::WindowInfoHandle>& windowHandle);
653655

0 commit comments

Comments
 (0)