Track hovering pointers explicitly
Before this CL, hovering window was tracked separately inside
InputDispatcher. This window was getting updated in various places.
Inconsistent motion streams, like HOVER_ENTER->DOWN->UP->HOVER_EXIT were
possible.
In this CL, we track hovering pointers inside TouchedWindow. At all
times, the currently tracked pointer must always be in the touch state.
The hovering pointer is removed when HOVER_EXIT is received.
This CL also establishes the foundation for multi-device, multi-pointer
streams, by storing hovering pointers inside TouchedWindow per-device.
Eventually, we can look into separately creating touched targets from
updating the touch state. This approach is partially used in this CL.
TouchState is used to keep track of where the hovering pointer is
currently. The 'addHoveringWindowsLocked' function returns the
equivalent of InputTargets. Eventually, we can change this to return
InputTargets.
Bug: 211379801
Test: m inputflinger_tests && adb sync data && adb shell -t /data/nativetest64/inputflinger_tests/inputflinger_tests
Change-Id: I047926e53b846c96807aed45fb585e031e5b88b9
diff --git a/services/inputflinger/dispatcher/TouchedWindow.cpp b/services/inputflinger/dispatcher/TouchedWindow.cpp
index af74598..3704edd 100644
--- a/services/inputflinger/dispatcher/TouchedWindow.cpp
+++ b/services/inputflinger/dispatcher/TouchedWindow.cpp
@@ -25,11 +25,49 @@
namespace inputdispatcher {
+bool TouchedWindow::hasHoveringPointers() const {
+ return !mHoveringPointerIdsByDevice.empty();
+}
+
+void TouchedWindow::clearHoveringPointers() {
+ mHoveringPointerIdsByDevice.clear();
+}
+
+bool TouchedWindow::hasHoveringPointer(int32_t deviceId, int32_t pointerId) const {
+ auto it = mHoveringPointerIdsByDevice.find(deviceId);
+ if (it == mHoveringPointerIdsByDevice.end()) {
+ return false;
+ }
+ return it->second.test(pointerId);
+}
+
+void TouchedWindow::addHoveringPointer(int32_t deviceId, int32_t pointerId) {
+ const auto [it, _] = mHoveringPointerIdsByDevice.insert({deviceId, {}});
+ it->second.set(pointerId);
+}
+
+void TouchedWindow::removeHoveringPointer(int32_t deviceId, int32_t pointerId) {
+ const auto it = mHoveringPointerIdsByDevice.find(deviceId);
+ if (it == mHoveringPointerIdsByDevice.end()) {
+ return;
+ }
+ it->second.set(pointerId, false);
+
+ if (it->second.none()) {
+ mHoveringPointerIdsByDevice.erase(deviceId);
+ }
+}
+
std::string TouchedWindow::dump() const {
- return StringPrintf("name='%s', pointerIds=0x%0x, "
- "targetFlags=%s, firstDownTimeInTarget=%s\n",
+ std::string out;
+ std::string hoveringPointers =
+ dumpMap(mHoveringPointerIdsByDevice, constToString, bitsetToString);
+ out += StringPrintf("name='%s', pointerIds=0x%0x, targetFlags=%s, firstDownTimeInTarget=%s, "
+ "mHoveringPointerIdsByDevice=%s\n",
windowHandle->getName().c_str(), pointerIds.value,
- targetFlags.string().c_str(), toString(firstDownTimeInTarget).c_str());
+ targetFlags.string().c_str(), toString(firstDownTimeInTarget).c_str(),
+ hoveringPointers.c_str());
+ return out;
}
} // namespace inputdispatcher