Skip to content

Commit da025e5

Browse files
Arpit SinghAndroid (Google) Code Review
authored andcommitted
Merge changes I7b0b5604,Ie7a00d48,Iccf5b53d into main
* changes: [11/n Dispatcher refactor] Move isTouchTrusted to WindowInfo [10/n Dispatcher refactor] Move obscuring related methods to WindowInfo [9/n Dispatcher refactor] Move computeTouchOcclusionInfo to WindowInfos
2 parents e903151 + 293a154 commit da025e5

2 files changed

Lines changed: 183 additions & 179 deletions

File tree

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,21 @@ InputTarget createInputTarget(const std::shared_ptr<Connection>& connection,
918918
return inputTarget;
919919
}
920920

921+
std::string dumpWindowForTouchOcclusion(const WindowInfo& info, bool isTouchedWindow) {
922+
return StringPrintf(INDENT2 "* %spackage=%s/%s, id=%" PRId32 ", mode=%s, alpha=%.2f, "
923+
"frame=[%" PRId32 ",%" PRId32 "][%" PRId32 ",%" PRId32
924+
"], touchableRegion=%s, window={%s}, inputConfig={%s}, "
925+
"hasToken=%s, applicationInfo.name=%s, applicationInfo.token=%s\n",
926+
isTouchedWindow ? "[TOUCHED] " : "", info.packageName.c_str(),
927+
info.ownerUid.toString().c_str(), info.id,
928+
toString(info.touchOcclusionMode).c_str(), info.alpha, info.frame.left,
929+
info.frame.top, info.frame.right, info.frame.bottom,
930+
dumpRegion(info.touchableRegion).c_str(), info.name.c_str(),
931+
info.inputConfig.string().c_str(), toString(info.token != nullptr),
932+
info.applicationInfo.name.c_str(),
933+
binderToString(info.applicationInfo.token).c_str());
934+
}
935+
921936
} // namespace
922937

923938
// --- InputDispatcher ---
@@ -933,13 +948,12 @@ InputDispatcher::InputDispatcher(InputDispatcherPolicyInterface& policy,
933948
mLastDropReason(DropReason::NOT_DROPPED),
934949
mIdGenerator(IdGenerator::Source::INPUT_DISPATCHER),
935950
mMinTimeBetweenUserActivityPokes(DEFAULT_USER_ACTIVITY_POKE_INTERVAL),
951+
mConnectionManager(mLooper),
936952
mNextUnblockedEvent(nullptr),
937953
mMonitorDispatchingTimeout(DEFAULT_INPUT_DISPATCHING_TIMEOUT),
938954
mDispatchEnabled(false),
939955
mDispatchFrozen(false),
940956
mInputFilterEnabled(false),
941-
mMaximumObscuringOpacityForTouch(1.0f),
942-
mConnectionManager(mLooper),
943957
mFocusedDisplayId(ui::LogicalDisplayId::DEFAULT),
944958
mWindowTokenWithPointerCapture(nullptr),
945959
mAwaitedApplicationDisplayId(ui::LogicalDisplayId::INVALID),
@@ -2485,9 +2499,9 @@ InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime, const Motio
24852499
if (isSplit) {
24862500
targetFlags |= InputTarget::Flags::SPLIT;
24872501
}
2488-
if (isWindowObscuredAtPointLocked(windowHandle, x, y)) {
2502+
if (mWindowInfos.isWindowObscuredAtPoint(windowHandle, x, y)) {
24892503
targetFlags |= InputTarget::Flags::WINDOW_IS_OBSCURED;
2490-
} else if (isWindowObscuredLocked(windowHandle)) {
2504+
} else if (mWindowInfos.isWindowObscured(windowHandle)) {
24912505
targetFlags |= InputTarget::Flags::WINDOW_IS_PARTIALLY_OBSCURED;
24922506
}
24932507

@@ -2518,7 +2532,8 @@ InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime, const Motio
25182532
if (isDownOrPointerDown && targetFlags.test(InputTarget::Flags::FOREGROUND) &&
25192533
windowHandle->getInfo()->inputConfig.test(
25202534
gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER)) {
2521-
sp<WindowInfoHandle> wallpaper = findWallpaperWindowBelow(windowHandle);
2535+
sp<WindowInfoHandle> wallpaper =
2536+
mWindowInfos.findWallpaperWindowBelow(windowHandle);
25222537
if (wallpaper != nullptr) {
25232538
ftl::Flags<InputTarget::Flags> wallpaperFlags =
25242539
InputTarget::Flags::WINDOW_IS_OBSCURED |
@@ -2630,9 +2645,9 @@ InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime, const Motio
26302645
if (isSplit) {
26312646
targetFlags |= InputTarget::Flags::SPLIT;
26322647
}
2633-
if (isWindowObscuredAtPointLocked(newTouchedWindowHandle, x, y)) {
2648+
if (mWindowInfos.isWindowObscuredAtPoint(newTouchedWindowHandle, x, y)) {
26342649
targetFlags |= InputTarget::Flags::WINDOW_IS_OBSCURED;
2635-
} else if (isWindowObscuredLocked(newTouchedWindowHandle)) {
2650+
} else if (mWindowInfos.isWindowObscured(newTouchedWindowHandle)) {
26362651
targetFlags |= InputTarget::Flags::WINDOW_IS_PARTIALLY_OBSCURED;
26372652
}
26382653

@@ -3085,12 +3100,12 @@ static bool canBeObscuredBy(const sp<WindowInfoHandle>& windowHandle,
30853100
*
30863101
* If neither of those is true, then it means the touch can be allowed.
30873102
*/
3088-
InputDispatcher::TouchOcclusionInfo InputDispatcher::computeTouchOcclusionInfoLocked(
3103+
InputDispatcher::DispatcherWindowInfo::TouchOcclusionInfo
3104+
InputDispatcher::DispatcherWindowInfo::computeTouchOcclusionInfo(
30893105
const sp<WindowInfoHandle>& windowHandle, float x, float y) const {
30903106
const WindowInfo* windowInfo = windowHandle->getInfo();
30913107
ui::LogicalDisplayId displayId = windowInfo->displayId;
3092-
const std::vector<sp<WindowInfoHandle>>& windowHandles =
3093-
mWindowInfos.getWindowHandlesForDisplay(displayId);
3108+
const std::vector<sp<WindowInfoHandle>>& windowHandles = getWindowHandlesForDisplay(displayId);
30943109
TouchOcclusionInfo info;
30953110
info.hasBlockingOcclusion = false;
30963111
info.obscuringOpacity = 0;
@@ -3102,12 +3117,11 @@ InputDispatcher::TouchOcclusionInfo InputDispatcher::computeTouchOcclusionInfoLo
31023117
}
31033118
const WindowInfo* otherInfo = otherHandle->getInfo();
31043119
if (canBeObscuredBy(windowHandle, otherHandle) &&
3105-
windowOccludesTouchAt(*otherInfo, displayId, x, y,
3106-
mWindowInfos.getDisplayTransform(displayId)) &&
3120+
windowOccludesTouchAt(*otherInfo, displayId, x, y, getDisplayTransform(displayId)) &&
31073121
!haveSameApplicationToken(windowInfo, otherInfo)) {
31083122
if (DEBUG_TOUCH_OCCLUSION) {
31093123
info.debugInfo.push_back(
3110-
dumpWindowForTouchOcclusion(otherInfo, /*isTouchedWindow=*/false));
3124+
dumpWindowForTouchOcclusion(*otherInfo, /*isTouchedWindow=*/false));
31113125
}
31123126
// canBeObscuredBy() has returned true above, which means this window is untrusted, so
31133127
// we perform the checks below to see if the touch can be propagated or not based on the
@@ -3135,28 +3149,14 @@ InputDispatcher::TouchOcclusionInfo InputDispatcher::computeTouchOcclusionInfoLo
31353149
}
31363150
}
31373151
if (DEBUG_TOUCH_OCCLUSION) {
3138-
info.debugInfo.push_back(dumpWindowForTouchOcclusion(windowInfo, /*isTouchedWindow=*/true));
3152+
info.debugInfo.push_back(
3153+
dumpWindowForTouchOcclusion(*windowInfo, /*isTouchedWindow=*/true));
31393154
}
31403155
return info;
31413156
}
31423157

3143-
std::string InputDispatcher::dumpWindowForTouchOcclusion(const WindowInfo* info,
3144-
bool isTouchedWindow) const {
3145-
return StringPrintf(INDENT2 "* %spackage=%s/%s, id=%" PRId32 ", mode=%s, alpha=%.2f, "
3146-
"frame=[%" PRId32 ",%" PRId32 "][%" PRId32 ",%" PRId32
3147-
"], touchableRegion=%s, window={%s}, inputConfig={%s}, "
3148-
"hasToken=%s, applicationInfo.name=%s, applicationInfo.token=%s\n",
3149-
isTouchedWindow ? "[TOUCHED] " : "", info->packageName.c_str(),
3150-
info->ownerUid.toString().c_str(), info->id,
3151-
toString(info->touchOcclusionMode).c_str(), info->alpha, info->frame.left,
3152-
info->frame.top, info->frame.right, info->frame.bottom,
3153-
dumpRegion(info->touchableRegion).c_str(), info->name.c_str(),
3154-
info->inputConfig.string().c_str(), toString(info->token != nullptr),
3155-
info->applicationInfo.name.c_str(),
3156-
binderToString(info->applicationInfo.token).c_str());
3157-
}
3158-
3159-
bool InputDispatcher::isTouchTrustedLocked(const TouchOcclusionInfo& occlusionInfo) const {
3158+
bool InputDispatcher::DispatcherWindowInfo::isTouchTrusted(
3159+
const TouchOcclusionInfo& occlusionInfo) const {
31603160
if (occlusionInfo.hasBlockingOcclusion) {
31613161
ALOGW("Untrusted touch due to occlusion by %s/%s", occlusionInfo.obscuringPackage.c_str(),
31623162
occlusionInfo.obscuringUid.toString().c_str());
@@ -3172,29 +3172,27 @@ bool InputDispatcher::isTouchTrustedLocked(const TouchOcclusionInfo& occlusionIn
31723172
return true;
31733173
}
31743174

3175-
bool InputDispatcher::isWindowObscuredAtPointLocked(const sp<WindowInfoHandle>& windowHandle,
3176-
float x, float y) const {
3175+
bool InputDispatcher::DispatcherWindowInfo::isWindowObscuredAtPoint(
3176+
const sp<WindowInfoHandle>& windowHandle, float x, float y) const {
31773177
ui::LogicalDisplayId displayId = windowHandle->getInfo()->displayId;
3178-
const std::vector<sp<WindowInfoHandle>>& windowHandles =
3179-
mWindowInfos.getWindowHandlesForDisplay(displayId);
3178+
const std::vector<sp<WindowInfoHandle>>& windowHandles = getWindowHandlesForDisplay(displayId);
31803179
for (const sp<WindowInfoHandle>& otherHandle : windowHandles) {
31813180
if (windowHandle == otherHandle) {
31823181
break; // All future windows are below us. Exit early.
31833182
}
31843183
const WindowInfo* otherInfo = otherHandle->getInfo();
31853184
if (canBeObscuredBy(windowHandle, otherHandle) &&
3186-
windowOccludesTouchAt(*otherInfo, displayId, x, y,
3187-
mWindowInfos.getDisplayTransform(displayId))) {
3185+
windowOccludesTouchAt(*otherInfo, displayId, x, y, getDisplayTransform(displayId))) {
31883186
return true;
31893187
}
31903188
}
31913189
return false;
31923190
}
31933191

3194-
bool InputDispatcher::isWindowObscuredLocked(const sp<WindowInfoHandle>& windowHandle) const {
3192+
bool InputDispatcher::DispatcherWindowInfo::isWindowObscured(
3193+
const sp<WindowInfoHandle>& windowHandle) const {
31953194
ui::LogicalDisplayId displayId = windowHandle->getInfo()->displayId;
3196-
const std::vector<sp<WindowInfoHandle>>& windowHandles =
3197-
mWindowInfos.getWindowHandlesForDisplay(displayId);
3195+
const std::vector<sp<WindowInfoHandle>>& windowHandles = getWindowHandlesForDisplay(displayId);
31983196
const WindowInfo* windowInfo = windowHandle->getInfo();
31993197
for (const sp<WindowInfoHandle>& otherHandle : windowHandles) {
32003198
if (windowHandle == otherHandle) {
@@ -5264,8 +5262,9 @@ std::string InputDispatcher::DispatcherWindowInfo::dumpDisplayAndWindowInfo() co
52645262
return dump;
52655263
}
52665264

5267-
bool InputDispatcher::canWindowReceiveMotionLocked(const sp<WindowInfoHandle>& window,
5268-
const MotionEntry& motionEntry) const {
5265+
bool InputDispatcher::canWindowReceiveMotionLocked(
5266+
const sp<android::gui::WindowInfoHandle>& window,
5267+
const android::inputdispatcher::MotionEntry& motionEntry) const {
52695268
const WindowInfo& info = *window->getInfo();
52705269

52715270
// Skip spy window targets that are not valid for targeted injection.
@@ -5298,8 +5297,9 @@ bool InputDispatcher::canWindowReceiveMotionLocked(const sp<WindowInfoHandle>& w
52985297

52995298
// Drop events that can't be trusted due to occlusion
53005299
const auto [x, y] = resolveTouchedPosition(motionEntry);
5301-
TouchOcclusionInfo occlusionInfo = computeTouchOcclusionInfoLocked(window, x, y);
5302-
if (!isTouchTrustedLocked(occlusionInfo)) {
5300+
DispatcherWindowInfo::TouchOcclusionInfo occlusionInfo =
5301+
mWindowInfos.computeTouchOcclusionInfo(window, x, y);
5302+
if (!mWindowInfos.isTouchTrusted(occlusionInfo)) {
53035303
if (DEBUG_TOUCH_OCCLUSION) {
53045304
ALOGD("Stack of obscuring windows during untrusted touch (%.1f, %.1f):", x, y);
53055305
for (const auto& log : occlusionInfo.debugInfo) {
@@ -5743,13 +5743,8 @@ bool InputDispatcher::recentWindowsAreOwnedByLocked(gui::Pid pid, gui::Uid uid)
57435743
}
57445744

57455745
void InputDispatcher::setMaximumObscuringOpacityForTouch(float opacity) {
5746-
if (opacity < 0 || opacity > 1) {
5747-
LOG_ALWAYS_FATAL("Maximum obscuring opacity for touch should be >= 0 and <= 1");
5748-
return;
5749-
}
5750-
57515746
std::scoped_lock lock(mLock);
5752-
mMaximumObscuringOpacityForTouch = opacity;
5747+
mWindowInfos.setMaximumObscuringOpacityForTouch(opacity);
57535748
}
57545749

57555750
std::tuple<const TouchState*, const TouchedWindow*, ui::LogicalDisplayId>
@@ -7043,7 +7038,7 @@ bool InputDispatcher::shouldDropInput(
70437038
if (windowHandle->getInfo()->inputConfig.test(WindowInfo::InputConfig::DROP_INPUT) ||
70447039
(windowHandle->getInfo()->inputConfig.test(
70457040
WindowInfo::InputConfig::DROP_INPUT_IF_OBSCURED) &&
7046-
isWindowObscuredLocked(windowHandle))) {
7041+
mWindowInfos.isWindowObscured(windowHandle))) {
70477042
ALOGW("Dropping %s event targeting %s as requested by the input configuration {%s} on "
70487043
"display %s.",
70497044
ftl::enum_string(entry.type).c_str(), windowHandle->getName().c_str(),
@@ -7096,7 +7091,7 @@ void InputDispatcher::slipWallpaperTouch(ftl::Flags<InputTarget::Flags> targetFl
70967091
const sp<WindowInfoHandle> oldWallpaper =
70977092
oldHasWallpaper ? state.getWallpaperWindow(deviceId) : nullptr;
70987093
const sp<WindowInfoHandle> newWallpaper =
7099-
newHasWallpaper ? findWallpaperWindowBelow(newWindowHandle) : nullptr;
7094+
newHasWallpaper ? mWindowInfos.findWallpaperWindowBelow(newWindowHandle) : nullptr;
71007095
if (oldWallpaper == newWallpaper) {
71017096
return;
71027097
}
@@ -7133,7 +7128,7 @@ void InputDispatcher::transferWallpaperTouch(
71337128
const sp<WindowInfoHandle> oldWallpaper =
71347129
oldHasWallpaper ? state.getWallpaperWindow(deviceId) : nullptr;
71357130
const sp<WindowInfoHandle> newWallpaper =
7136-
newHasWallpaper ? findWallpaperWindowBelow(toWindowHandle) : nullptr;
7131+
newHasWallpaper ? mWindowInfos.findWallpaperWindowBelow(toWindowHandle) : nullptr;
71377132
if (oldWallpaper == newWallpaper) {
71387133
return;
71397134
}
@@ -7165,10 +7160,10 @@ void InputDispatcher::transferWallpaperTouch(
71657160
}
71667161
}
71677162

7168-
sp<WindowInfoHandle> InputDispatcher::findWallpaperWindowBelow(
7163+
sp<WindowInfoHandle> InputDispatcher::DispatcherWindowInfo::findWallpaperWindowBelow(
71697164
const sp<WindowInfoHandle>& windowHandle) const {
71707165
const std::vector<sp<WindowInfoHandle>>& windowHandles =
7171-
mWindowInfos.getWindowHandlesForDisplay(windowHandle->getInfo()->displayId);
7166+
getWindowHandlesForDisplay(windowHandle->getInfo()->displayId);
71727167
bool foundWindow = false;
71737168
for (const sp<WindowInfoHandle>& otherHandle : windowHandles) {
71747169
if (!foundWindow && otherHandle != windowHandle) {
@@ -7349,4 +7344,11 @@ std::string InputDispatcher::ConnectionManager::dump(nsecs_t currentTime) const
73497344
return dump;
73507345
}
73517346

7347+
void InputDispatcher::DispatcherWindowInfo::setMaximumObscuringOpacityForTouch(float opacity) {
7348+
if (opacity < 0 || opacity > 1) {
7349+
LOG_ALWAYS_FATAL("Maximum obscuring opacity for touch should be >= 0 and <= 1");
7350+
}
7351+
mMaximumObscuringOpacityForTouch = opacity;
7352+
}
7353+
73527354
} // namespace android::inputdispatcher

0 commit comments

Comments
 (0)