InputDispatcher: Ensure pointer down is generated for touched window
A precondition for synthesizing pointer down events is that the touch
state must already be updated to reflect the new gesture going into the
window.
When generating the down event, it should be associated with the correct
touched window, not just any window with the same token. This CL fixes
the a bug where the down event would be synthesized for the top-most
clone window that matches the token, rather than the touched window.
Bug: 210460522
Test: atest inputflinger_tests
Change-Id: I3bedc2c2c8e0f18dc8814d519ba7cf9449e10211
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index aeab1f8..3e999c7 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -4192,7 +4192,12 @@
connection->getInputChannelName().c_str(), downEvents.size());
}
- sp<WindowInfoHandle> windowHandle = getWindowHandleLocked(connection->getToken());
+ const auto [_, touchedWindowState, displayId] =
+ findTouchStateWindowAndDisplayLocked(connection->getToken());
+ if (touchedWindowState == nullptr) {
+ LOG(FATAL) << __func__ << ": Touch state is out of sync: No touched window for token";
+ }
+ const auto& windowHandle = touchedWindowState->windowHandle;
const bool wasEmpty = connection->outboundQueue.empty();
for (std::unique_ptr<EventEntry>& downEventEntry : downEvents) {