Only send events to windows with pointers
Due to the recent refactor, some of the windows with only hovering
pointers are getting persisted inside TouchState. This is the case for
the hovering pointers from mouse, for example. Mouse usually never
leaves the screen, so it's always inside some window.
However, we are still currently iterating over TouchedWindows inside
the TouchState in order to determine which targets should receive the
current entry.
That means that the windows that are hovered over will always be there,
which is not something that we want. It would cause the events to go
to windows that are not directly getting touched.
To avoid this, make sure that the pointers are indeed supposed to be
going to the current window. In a future refactor, we will store the pointers
per-device, as well.
The added test reproduces a condition where we crash due to mismatching
downtimes.
There are few issues that it exposes.
1) We currently use hover events for setting the downtime of a window,
which we shouldn't do.
2) If a window is not receiving the events from the current device, it
shouldn't be in the dispatching list. So we should not be sending the
events there to begin with.
Bug: 266455987
Test: m inputflinger_tests && $ANDROID_HOST_OUT/nativetest64/inputflinger_tests/inputflinger_tests --gtest_filter="*HoverFromLeftToRightAndTap*"
Change-Id: Ic0d2a1ed6d053e18077bc7216b1ce02e88017b4a
diff --git a/services/inputflinger/dispatcher/TouchState.cpp b/services/inputflinger/dispatcher/TouchState.cpp
index e9c6ad5..c257ee5 100644
--- a/services/inputflinger/dispatcher/TouchState.cpp
+++ b/services/inputflinger/dispatcher/TouchState.cpp
@@ -63,7 +63,7 @@
void TouchState::addOrUpdateWindow(const sp<WindowInfoHandle>& windowHandle,
ftl::Flags<InputTarget::Flags> targetFlags, BitSet32 pointerIds,
- std::optional<nsecs_t> eventTime) {
+ std::optional<nsecs_t> firstDownTimeInTarget) {
for (TouchedWindow& touchedWindow : windows) {
// We do not compare windows by token here because two windows that share the same token
// may have a different transform
@@ -77,7 +77,7 @@
// the window.
touchedWindow.pointerIds.value |= pointerIds.value;
if (!touchedWindow.firstDownTimeInTarget.has_value()) {
- touchedWindow.firstDownTimeInTarget = eventTime;
+ touchedWindow.firstDownTimeInTarget = firstDownTimeInTarget;
}
return;
}
@@ -86,7 +86,7 @@
touchedWindow.windowHandle = windowHandle;
touchedWindow.targetFlags = targetFlags;
touchedWindow.pointerIds = pointerIds;
- touchedWindow.firstDownTimeInTarget = eventTime;
+ touchedWindow.firstDownTimeInTarget = firstDownTimeInTarget;
windows.push_back(touchedWindow);
}