Skip to content

Commit 293a154

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: I7b0b560483e9f758b08a3e2ebfff548c173e906b
1 parent edcc730 commit 293a154

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),
@@ -3161,8 +3160,8 @@ InputDispatcher::DispatcherWindowInfo::computeTouchOcclusionInfo(
31613160
return info;
31623161
}
31633162

3164-
bool InputDispatcher::isTouchTrustedLocked(
3165-
const DispatcherWindowInfo::TouchOcclusionInfo& occlusionInfo) const {
3163+
bool InputDispatcher::DispatcherWindowInfo::isTouchTrusted(
3164+
const TouchOcclusionInfo& occlusionInfo) const {
31663165
if (occlusionInfo.hasBlockingOcclusion) {
31673166
ALOGW("Untrusted touch due to occlusion by %s/%s", occlusionInfo.obscuringPackage.c_str(),
31683167
occlusionInfo.obscuringUid.toString().c_str());
@@ -5268,8 +5267,9 @@ std::string InputDispatcher::DispatcherWindowInfo::dumpDisplayAndWindowInfo() co
52685267
return dump;
52695268
}
52705269

5271-
bool InputDispatcher::canWindowReceiveMotionLocked(const sp<WindowInfoHandle>& window,
5272-
const MotionEntry& motionEntry) const {
5270+
bool InputDispatcher::canWindowReceiveMotionLocked(
5271+
const sp<android::gui::WindowInfoHandle>& window,
5272+
const android::inputdispatcher::MotionEntry& motionEntry) const {
52735273
const WindowInfo& info = *window->getInfo();
52745274

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

57505750
void InputDispatcher::setMaximumObscuringOpacityForTouch(float opacity) {
5751-
if (opacity < 0 || opacity > 1) {
5752-
LOG_ALWAYS_FATAL("Maximum obscuring opacity for touch should be >= 0 and <= 1");
5753-
return;
5754-
}
5755-
57565751
std::scoped_lock lock(mLock);
5757-
mMaximumObscuringOpacityForTouch = opacity;
5752+
mWindowInfos.setMaximumObscuringOpacityForTouch(opacity);
57585753
}
57595754

57605755
std::tuple<const TouchState*, const TouchedWindow*, ui::LogicalDisplayId>
@@ -7354,4 +7349,11 @@ std::string InputDispatcher::ConnectionManager::dump(nsecs_t currentTime) const
73547349
return dump;
73557350
}
73567351

7352+
void InputDispatcher::DispatcherWindowInfo::setMaximumObscuringOpacityForTouch(float opacity) {
7353+
if (opacity < 0 || opacity > 1) {
7354+
LOG_ALWAYS_FATAL("Maximum obscuring opacity for touch should be >= 0 and <= 1");
7355+
}
7356+
mMaximumObscuringOpacityForTouch = opacity;
7357+
}
7358+
73577359
} // namespace android::inputdispatcher

services/inputflinger/dispatcher/InputDispatcher.h

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

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

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

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

338342
private:
@@ -341,6 +345,7 @@ class InputDispatcher : public android::InputDispatcherInterface {
341345
mWindowHandlesByDisplay;
342346
std::unordered_map<ui::LogicalDisplayId /*displayId*/, android::gui::DisplayInfo>
343347
mDisplayInfos;
348+
float mMaximumObscuringOpacityForTouch{1.0f};
344349
};
345350

346351
DispatcherWindowInfo mWindowInfos GUARDED_BY(mLock);
@@ -442,7 +447,6 @@ class InputDispatcher : public android::InputDispatcherInterface {
442447
bool mDispatchEnabled GUARDED_BY(mLock);
443448
bool mDispatchFrozen GUARDED_BY(mLock);
444449
bool mInputFilterEnabled GUARDED_BY(mLock);
445-
float mMaximumObscuringOpacityForTouch GUARDED_BY(mLock);
446450

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

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

0 commit comments

Comments
 (0)