Skip to content

Commit 071afa0

Browse files
author
Arpit Singh
committed
[20/n Dispatcher refactor] Allow access to all TouchedWindowHandles
In this CL we introduce following methods to allow iterating over all touchedWindowHandles. 1. forAllTouchedWindows 2. forAllTouchedWindowsOnDisplay Bug: 367661487 Bug: 245989146 Test: atest inputflinger_tests Flag: EXEMPT refactor Change-Id: I65b2b48d73e11c068d208339931b919e419e2893
1 parent 144aedb commit 071afa0

2 files changed

Lines changed: 38 additions & 7 deletions

File tree

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4072,13 +4072,17 @@ void InputDispatcher::synthesizeCancelationEventsForAllConnectionsLocked(
40724072
// Generate cancellations for touched windows first. This is to avoid generating cancellations
40734073
// through a non-touched window if there are more than one window for an input channel.
40744074
if (cancelPointers) {
4075-
for (const auto& [displayId, touchState] : mTouchStates.mTouchStatesByDisplay) {
4076-
if (options.displayId.has_value() && options.displayId != displayId) {
4077-
continue;
4078-
}
4079-
for (const auto& touchedWindow : touchState.windows) {
4080-
synthesizeCancelationEventsForWindowLocked(touchedWindow.windowHandle, options);
4081-
}
4075+
if (options.displayId.has_value()) {
4076+
mTouchStates.forAllTouchedWindowsOnDisplay(
4077+
options.displayId.value(), [&](const sp<gui::WindowInfoHandle>& windowHandle) {
4078+
base::ScopedLockAssertion assumeLocked(mLock);
4079+
synthesizeCancelationEventsForWindowLocked(windowHandle, options);
4080+
});
4081+
} else {
4082+
mTouchStates.forAllTouchedWindows([&](const sp<gui::WindowInfoHandle>& windowHandle) {
4083+
base::ScopedLockAssertion assumeLocked(mLock);
4084+
synthesizeCancelationEventsForWindowLocked(windowHandle, options);
4085+
});
40824086
}
40834087
}
40844088
// Follow up by generating cancellations for all windows, because we don't explicitly track
@@ -7475,6 +7479,27 @@ InputDispatcher::DispatcherTouchState::findTouchedWindowHandleAndDisplay(
74757479
return std::nullopt;
74767480
}
74777481

7482+
void InputDispatcher::DispatcherTouchState::forAllTouchedWindows(
7483+
std::function<void(const sp<gui::WindowInfoHandle>&)> f) const {
7484+
for (const auto& [_, state] : mTouchStatesByDisplay) {
7485+
for (const TouchedWindow& window : state.windows) {
7486+
f(window.windowHandle);
7487+
}
7488+
}
7489+
}
7490+
7491+
void InputDispatcher::DispatcherTouchState::forAllTouchedWindowsOnDisplay(
7492+
ui::LogicalDisplayId displayId,
7493+
std::function<void(const sp<gui::WindowInfoHandle>&)> f) const {
7494+
const auto touchStateIt = mTouchStatesByDisplay.find(displayId);
7495+
if (touchStateIt == mTouchStatesByDisplay.end()) {
7496+
return;
7497+
}
7498+
for (const TouchedWindow& window : touchStateIt->second.windows) {
7499+
f(window.windowHandle);
7500+
}
7501+
}
7502+
74787503
std::string InputDispatcher::DispatcherTouchState::dump() const {
74797504
std::string dump;
74807505
if (!mTouchStatesByDisplay.empty()) {

services/inputflinger/dispatcher/InputDispatcher.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,12 @@ class InputDispatcher : public android::InputDispatcherInterface {
396396
std::optional<std::tuple<const sp<gui::WindowInfoHandle>&, ui::LogicalDisplayId>>
397397
findTouchedWindowHandleAndDisplay(const sp<IBinder>& token) const;
398398

399+
void forAllTouchedWindows(std::function<void(const sp<gui::WindowInfoHandle>&)> f) const;
400+
401+
void forAllTouchedWindowsOnDisplay(
402+
ui::LogicalDisplayId displayId,
403+
std::function<void(const sp<gui::WindowInfoHandle>&)> f) const;
404+
399405
std::string dump() const;
400406

401407
// Updates the touchState for display from WindowInfo,

0 commit comments

Comments
 (0)