Ensure drag-and-drop and pilfering does not work with hovering pointers
There was a bug where TouchedWindow::getTouchingDeviceIds() would return
a list of all "active" devices (hovering or touching) instead of just
touching.
Fix that bug to ensure there is no crash when trying to start
drag-and-drop with a hovering pointer. Add tests to verify.
Bug: 312636191
Test: atest inputflinger_tests
Change-Id: I865582f21fbe34aca9c1274b02d002018bc9c149
diff --git a/services/inputflinger/dispatcher/TouchedWindow.cpp b/services/inputflinger/dispatcher/TouchedWindow.cpp
index 5367751..cd0500c 100644
--- a/services/inputflinger/dispatcher/TouchedWindow.cpp
+++ b/services/inputflinger/dispatcher/TouchedWindow.cpp
@@ -128,20 +128,14 @@
std::set<DeviceId> TouchedWindow::getTouchingDeviceIds() const {
std::set<DeviceId> deviceIds;
- for (const auto& [deviceId, _] : mDeviceStates) {
- deviceIds.insert(deviceId);
+ for (const auto& [deviceId, deviceState] : mDeviceStates) {
+ if (deviceState.touchingPointerIds.any()) {
+ deviceIds.insert(deviceId);
+ }
}
return deviceIds;
}
-std::set<DeviceId> TouchedWindow::getActiveDeviceIds() const {
- std::set<DeviceId> out;
- for (const auto& [deviceId, _] : mDeviceStates) {
- out.emplace(deviceId);
- }
- return out;
-}
-
bool TouchedWindow::hasPilferingPointers(DeviceId deviceId) const {
const auto stateIt = mDeviceStates.find(deviceId);
if (stateIt == mDeviceStates.end()) {
diff --git a/services/inputflinger/dispatcher/TouchedWindow.h b/services/inputflinger/dispatcher/TouchedWindow.h
index 6d2283e..9a31678 100644
--- a/services/inputflinger/dispatcher/TouchedWindow.h
+++ b/services/inputflinger/dispatcher/TouchedWindow.h
@@ -48,15 +48,7 @@
void addTouchingPointers(DeviceId deviceId, std::bitset<MAX_POINTER_ID + 1> pointers);
void removeTouchingPointer(DeviceId deviceId, int32_t pointerId);
void removeTouchingPointers(DeviceId deviceId, std::bitset<MAX_POINTER_ID + 1> pointers);
- /**
- * Get the currently active touching device id. If there isn't exactly 1 touching device, return
- * nullopt.
- */
std::set<DeviceId> getTouchingDeviceIds() const;
- /**
- * The ids of devices that are currently touching or hovering.
- */
- std::set<DeviceId> getActiveDeviceIds() const;
// Pilfering pointers
bool hasPilferingPointers(DeviceId deviceId) const;