TouchedWindow: store tool type in addition to pointer id
Before this CL, we only stored the touching pointer id's inside
TouchWindow. However, it is also necessary to know which of the touching
pointers are touch vs stylus. This would allow us in a later CL to
determine whether the stylus is currently down anywhere on screen.
In this CL, instead of storing just the pointer ids, store
PointerProperties in a vector. This includes the pointer id and the
tooltype.
There should be no behaviour change in this CL.
Bug: 316225294
Test: TEST=inputflinger_tests; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST
Change-Id: I7fb2bbd46e7da7e085679ee16da3a53773931875
diff --git a/include/input/Input.h b/include/input/Input.h
index 1c4ea6b..7b253a5 100644
--- a/include/input/Input.h
+++ b/include/input/Input.h
@@ -515,6 +515,8 @@
PointerProperties& operator=(const PointerProperties&) = default;
};
+std::ostream& operator<<(std::ostream& out, const PointerProperties& properties);
+
// TODO(b/211379801) : Use a strong type from ftl/mixins.h instead
using DeviceId = int32_t;
diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp
index bd5b67b..8eaff00 100644
--- a/libs/input/Input.cpp
+++ b/libs/input/Input.cpp
@@ -379,6 +379,11 @@
return out;
}
+std::ostream& operator<<(std::ostream& out, const PointerProperties& properties) {
+ out << "Pointer(id=" << properties.id << ", " << ftl::enum_string(properties.toolType) << ")";
+ return out;
+}
+
// --- PointerCoords ---
float PointerCoords::getAxisValue(int32_t axis) const {
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 00ffddd..d6ff4b5 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -253,6 +253,14 @@
}
}
+std::bitset<MAX_POINTER_ID + 1> getPointerIds(const std::vector<PointerProperties>& pointers) {
+ std::bitset<MAX_POINTER_ID + 1> pointerIds;
+ for (const PointerProperties& pointer : pointers) {
+ pointerIds.set(pointer.id);
+ }
+ return pointerIds;
+}
+
std::string dumpRegion(const Region& region) {
if (region.isEmpty()) {
return "<empty>";
@@ -631,15 +639,15 @@
}
// We should consider all hovering pointers here. But for now, just use the first one
- const int32_t pointerId = entry.pointerProperties[0].id;
+ const PointerProperties& pointer = entry.pointerProperties[0];
std::set<sp<WindowInfoHandle>> oldWindows;
if (oldState != nullptr) {
- oldWindows = oldState->getWindowsWithHoveringPointer(entry.deviceId, pointerId);
+ oldWindows = oldState->getWindowsWithHoveringPointer(entry.deviceId, pointer.id);
}
std::set<sp<WindowInfoHandle>> newWindows =
- newTouchState.getWindowsWithHoveringPointer(entry.deviceId, pointerId);
+ newTouchState.getWindowsWithHoveringPointer(entry.deviceId, pointer.id);
// If the pointer is no longer in the new window set, send HOVER_EXIT.
for (const sp<WindowInfoHandle>& oldWindow : oldWindows) {
@@ -673,7 +681,7 @@
}
touchedWindow.dispatchMode = InputTarget::DispatchMode::AS_IS;
}
- touchedWindow.addHoveringPointer(entry.deviceId, pointerId);
+ touchedWindow.addHoveringPointer(entry.deviceId, pointer);
if (canReceiveForegroundTouches(*newWindow->getInfo())) {
touchedWindow.targetFlags |= InputTarget::Flags::FOREGROUND;
}
@@ -2320,7 +2328,7 @@
/* Case 1: New splittable pointer going down, or need target for hover or scroll. */
const auto [x, y] = resolveTouchedPosition(entry);
const int32_t pointerIndex = MotionEvent::getActionIndex(action);
- const int32_t pointerId = entry.pointerProperties[pointerIndex].id;
+ const PointerProperties& pointer = entry.pointerProperties[pointerIndex];
// Outside targets should be added upon first dispatched DOWN event. That means, this should
// be a pointer that would generate ACTION_DOWN, *and* touch should not already be down.
const bool isStylus = isPointerFromStylus(entry, pointerIndex);
@@ -2328,7 +2336,7 @@
findTouchedWindowAtLocked(displayId, x, y, isStylus);
if (isDown) {
- targets += findOutsideTargetsLocked(displayId, newTouchedWindowHandle, pointerId);
+ targets += findOutsideTargetsLocked(displayId, newTouchedWindowHandle, pointer.id);
}
// Handle the case where we did not find a window.
if (newTouchedWindowHandle == nullptr) {
@@ -2386,7 +2394,7 @@
if (isHoverAction) {
// The "windowHandle" is the target of this hovering pointer.
- tempTouchState.addHoveringPointerToWindow(windowHandle, entry.deviceId, pointerId);
+ tempTouchState.addHoveringPointerToWindow(windowHandle, entry.deviceId, pointer);
}
// Set target flags.
@@ -2409,12 +2417,10 @@
// Update the temporary touch state.
if (!isHoverAction) {
- std::bitset<MAX_POINTER_ID + 1> pointerIds;
- pointerIds.set(pointerId);
const bool isDownOrPointerDown = maskedAction == AMOTION_EVENT_ACTION_DOWN ||
maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN;
tempTouchState.addOrUpdateWindow(windowHandle, InputTarget::DispatchMode::AS_IS,
- targetFlags, entry.deviceId, pointerIds,
+ targetFlags, entry.deviceId, {pointer},
isDownOrPointerDown
? std::make_optional(entry.eventTime)
: std::nullopt);
@@ -2437,7 +2443,7 @@
}
tempTouchState.addOrUpdateWindow(wallpaper,
InputTarget::DispatchMode::AS_IS,
- wallpaperFlags, entry.deviceId, pointerIds,
+ wallpaperFlags, entry.deviceId, {pointer},
entry.eventTime);
}
}
@@ -2448,12 +2454,12 @@
// make it pilfering. This will prevent other non-spy windows from getting this pointer,
// which is a specific behaviour that we want.
for (TouchedWindow& touchedWindow : tempTouchState.windows) {
- if (touchedWindow.hasTouchingPointer(entry.deviceId, pointerId) &&
+ if (touchedWindow.hasTouchingPointer(entry.deviceId, pointer.id) &&
touchedWindow.hasPilferingPointers(entry.deviceId)) {
// This window is already pilfering some pointers, and this new pointer is also
// going to it. Therefore, take over this pointer and don't give it to anyone
// else.
- touchedWindow.addPilferingPointer(entry.deviceId, pointerId);
+ touchedWindow.addPilferingPointer(entry.deviceId, pointer.id);
}
}
@@ -2522,8 +2528,8 @@
// Make a slippery exit from the old window.
std::bitset<MAX_POINTER_ID + 1> pointerIds;
- const int32_t pointerId = entry.pointerProperties[0].id;
- pointerIds.set(pointerId);
+ const PointerProperties& pointer = entry.pointerProperties[0];
+ pointerIds.set(pointer.id);
const TouchedWindow& touchedWindow =
tempTouchState.getTouchedWindow(oldTouchedWindowHandle);
@@ -2553,13 +2559,13 @@
tempTouchState.addOrUpdateWindow(newTouchedWindowHandle,
InputTarget::DispatchMode::SLIPPERY_ENTER,
- targetFlags, entry.deviceId, pointerIds,
+ targetFlags, entry.deviceId, {pointer},
entry.eventTime);
// Check if the wallpaper window should deliver the corresponding event.
slipWallpaperTouch(targetFlags, oldTouchedWindowHandle, newTouchedWindowHandle,
- tempTouchState, entry.deviceId, pointerId, targets);
- tempTouchState.removeTouchingPointerFromWindow(entry.deviceId, pointerId,
+ tempTouchState, entry.deviceId, pointer, targets);
+ tempTouchState.removeTouchingPointerFromWindow(entry.deviceId, pointer.id,
oldTouchedWindowHandle);
}
}
@@ -2568,14 +2574,12 @@
if (!isSplit && maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN) {
// If no split, we suppose all touched windows should receive pointer down.
const int32_t pointerIndex = MotionEvent::getActionIndex(action);
- for (size_t i = 0; i < tempTouchState.windows.size(); i++) {
- TouchedWindow& touchedWindow = tempTouchState.windows[i];
+ std::vector<PointerProperties> touchingPointers{entry.pointerProperties[pointerIndex]};
+ for (TouchedWindow& touchedWindow : tempTouchState.windows) {
// Ignore drag window for it should just track one pointer.
if (mDragState && mDragState->dragWindow == touchedWindow.windowHandle) {
continue;
}
- std::bitset<MAX_POINTER_ID + 1> touchingPointers;
- touchingPointers.set(entry.pointerProperties[pointerIndex].id);
touchedWindow.addTouchingPointers(entry.deviceId, touchingPointers);
}
}
@@ -2646,13 +2650,13 @@
// Output targets from the touch state.
for (const TouchedWindow& touchedWindow : tempTouchState.windows) {
- std::bitset<MAX_POINTER_ID + 1> touchingPointers =
+ std::vector<PointerProperties> touchingPointers =
touchedWindow.getTouchingPointers(entry.deviceId);
- if (touchingPointers.none()) {
+ if (touchingPointers.empty()) {
continue;
}
addPointerWindowTargetLocked(touchedWindow.windowHandle, touchedWindow.dispatchMode,
- touchedWindow.targetFlags, touchingPointers,
+ touchedWindow.targetFlags, getPointerIds(touchingPointers),
touchedWindow.getDownTimeInTarget(entry.deviceId), targets);
}
@@ -5481,7 +5485,7 @@
// Erase old window.
ftl::Flags<InputTarget::Flags> oldTargetFlags = touchedWindow->targetFlags;
- std::bitset<MAX_POINTER_ID + 1> pointerIds = touchedWindow->getTouchingPointers(deviceId);
+ std::vector<PointerProperties> pointers = touchedWindow->getTouchingPointers(deviceId);
sp<WindowInfoHandle> fromWindowHandle = touchedWindow->windowHandle;
state->removeWindowByToken(fromToken);
@@ -5493,17 +5497,17 @@
newTargetFlags |= InputTarget::Flags::FOREGROUND;
}
state->addOrUpdateWindow(toWindowHandle, InputTarget::DispatchMode::AS_IS, newTargetFlags,
- deviceId, pointerIds, downTimeInTarget);
+ deviceId, pointers, downTimeInTarget);
// Store the dragging window.
if (isDragDrop) {
- if (pointerIds.count() != 1) {
+ if (pointers.size() != 1) {
ALOGW("The drag and drop cannot be started when there is no pointer or more than 1"
" pointer on the window.");
return false;
}
// Track the pointer id for drag window and generate the drag state.
- const size_t id = firstMarkedBit(pointerIds);
+ const size_t id = pointers.begin()->id;
mDragState = std::make_unique<DragState>(toWindowHandle, id);
}
@@ -5520,7 +5524,7 @@
// Check if the wallpaper window should deliver the corresponding event.
transferWallpaperTouch(oldTargetFlags, newTargetFlags, fromWindowHandle, toWindowHandle,
- *state, deviceId, pointerIds);
+ *state, deviceId, pointers);
}
} // release lock
@@ -5997,8 +6001,10 @@
"input channel stole pointer stream");
options.deviceId = deviceId;
options.displayId = displayId;
- std::bitset<MAX_POINTER_ID + 1> pointerIds = window.getTouchingPointers(deviceId);
+ std::vector<PointerProperties> pointers = window.getTouchingPointers(deviceId);
+ std::bitset<MAX_POINTER_ID + 1> pointerIds = getPointerIds(pointers);
options.pointerIds = pointerIds;
+
std::string canceledWindows;
for (const TouchedWindow& w : state.windows) {
const std::shared_ptr<InputChannel> channel =
@@ -6794,10 +6800,10 @@
void InputDispatcher::slipWallpaperTouch(ftl::Flags<InputTarget::Flags> targetFlags,
const sp<WindowInfoHandle>& oldWindowHandle,
const sp<WindowInfoHandle>& newWindowHandle,
- TouchState& state, int32_t deviceId, int32_t pointerId,
+ TouchState& state, int32_t deviceId,
+ const PointerProperties& pointerProperties,
std::vector<InputTarget>& targets) const {
- std::bitset<MAX_POINTER_ID + 1> pointerIds;
- pointerIds.set(pointerId);
+ std::vector<PointerProperties> pointers{pointerProperties};
const bool oldHasWallpaper = oldWindowHandle->getInfo()->inputConfig.test(
gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER);
const bool newHasWallpaper = targetFlags.test(InputTarget::Flags::FOREGROUND) &&
@@ -6814,16 +6820,16 @@
if (oldWallpaper != nullptr) {
const TouchedWindow& oldTouchedWindow = state.getTouchedWindow(oldWallpaper);
addPointerWindowTargetLocked(oldWallpaper, InputTarget::DispatchMode::SLIPPERY_EXIT,
- oldTouchedWindow.targetFlags, pointerIds,
+ oldTouchedWindow.targetFlags, getPointerIds(pointers),
oldTouchedWindow.getDownTimeInTarget(deviceId), targets);
- state.removeTouchingPointerFromWindow(deviceId, pointerId, oldWallpaper);
+ state.removeTouchingPointerFromWindow(deviceId, pointerProperties.id, oldWallpaper);
}
if (newWallpaper != nullptr) {
state.addOrUpdateWindow(newWallpaper, InputTarget::DispatchMode::SLIPPERY_ENTER,
InputTarget::Flags::WINDOW_IS_OBSCURED |
InputTarget::Flags::WINDOW_IS_PARTIALLY_OBSCURED,
- deviceId, pointerIds);
+ deviceId, pointers);
}
}
@@ -6832,7 +6838,7 @@
const sp<WindowInfoHandle> fromWindowHandle,
const sp<WindowInfoHandle> toWindowHandle,
TouchState& state, int32_t deviceId,
- std::bitset<MAX_POINTER_ID + 1> pointerIds) {
+ const std::vector<PointerProperties>& pointers) {
const bool oldHasWallpaper = oldTargetFlags.test(InputTarget::Flags::FOREGROUND) &&
fromWindowHandle->getInfo()->inputConfig.test(
gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER);
@@ -6861,7 +6867,7 @@
wallpaperFlags |= InputTarget::Flags::WINDOW_IS_OBSCURED |
InputTarget::Flags::WINDOW_IS_PARTIALLY_OBSCURED;
state.addOrUpdateWindow(newWallpaper, InputTarget::DispatchMode::AS_IS, wallpaperFlags,
- deviceId, pointerIds, downTimeInTarget);
+ deviceId, pointers, downTimeInTarget);
std::shared_ptr<Connection> wallpaperConnection =
getConnectionLocked(newWallpaper->getToken());
if (wallpaperConnection != nullptr) {
diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h
index 3f99b2d..010dbb2 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.h
+++ b/services/inputflinger/dispatcher/InputDispatcher.h
@@ -690,14 +690,15 @@
void slipWallpaperTouch(ftl::Flags<InputTarget::Flags> targetFlags,
const sp<android::gui::WindowInfoHandle>& oldWindowHandle,
const sp<android::gui::WindowInfoHandle>& newWindowHandle,
- TouchState& state, int32_t deviceId, int32_t pointerId,
+ TouchState& state, int32_t deviceId,
+ const PointerProperties& pointerProperties,
std::vector<InputTarget>& targets) const REQUIRES(mLock);
void transferWallpaperTouch(ftl::Flags<InputTarget::Flags> oldTargetFlags,
ftl::Flags<InputTarget::Flags> newTargetFlags,
const sp<android::gui::WindowInfoHandle> fromWindowHandle,
const sp<android::gui::WindowInfoHandle> toWindowHandle,
TouchState& state, int32_t deviceId,
- std::bitset<MAX_POINTER_ID + 1> pointerIds) REQUIRES(mLock);
+ const std::vector<PointerProperties>& pointers) REQUIRES(mLock);
sp<android::gui::WindowInfoHandle> findWallpaperWindowBelow(
const sp<android::gui::WindowInfoHandle>& windowHandle) const REQUIRES(mLock);
diff --git a/services/inputflinger/dispatcher/TouchState.cpp b/services/inputflinger/dispatcher/TouchState.cpp
index e8d8c18..cc7616a 100644
--- a/services/inputflinger/dispatcher/TouchState.cpp
+++ b/services/inputflinger/dispatcher/TouchState.cpp
@@ -73,9 +73,9 @@
void TouchState::addOrUpdateWindow(const sp<WindowInfoHandle>& windowHandle,
InputTarget::DispatchMode dispatchMode,
ftl::Flags<InputTarget::Flags> targetFlags, DeviceId deviceId,
- std::bitset<MAX_POINTER_ID + 1> touchingPointerIds,
+ const std::vector<PointerProperties>& touchingPointers,
std::optional<nsecs_t> firstDownTimeInTarget) {
- if (touchingPointerIds.none()) {
+ if (touchingPointers.empty()) {
LOG(FATAL) << __func__ << "No pointers specified for " << windowHandle->getName();
return;
}
@@ -91,7 +91,7 @@
// For cases like hover enter/exit or DISPATCH_AS_OUTSIDE a touch window might not have
// downTime set initially. Need to update existing window when a pointer is down for the
// window.
- touchedWindow.addTouchingPointers(deviceId, touchingPointerIds);
+ touchedWindow.addTouchingPointers(deviceId, touchingPointers);
if (firstDownTimeInTarget) {
touchedWindow.trySetDownTimeInTarget(deviceId, *firstDownTimeInTarget);
}
@@ -102,7 +102,7 @@
touchedWindow.windowHandle = windowHandle;
touchedWindow.dispatchMode = dispatchMode;
touchedWindow.targetFlags = targetFlags;
- touchedWindow.addTouchingPointers(deviceId, touchingPointerIds);
+ touchedWindow.addTouchingPointers(deviceId, touchingPointers);
if (firstDownTimeInTarget) {
touchedWindow.trySetDownTimeInTarget(deviceId, *firstDownTimeInTarget);
}
@@ -110,17 +110,17 @@
}
void TouchState::addHoveringPointerToWindow(const sp<WindowInfoHandle>& windowHandle,
- DeviceId deviceId, int32_t hoveringPointerId) {
+ DeviceId deviceId, const PointerProperties& pointer) {
for (TouchedWindow& touchedWindow : windows) {
if (touchedWindow.windowHandle == windowHandle) {
- touchedWindow.addHoveringPointer(deviceId, hoveringPointerId);
+ touchedWindow.addHoveringPointer(deviceId, pointer);
return;
}
}
TouchedWindow touchedWindow;
touchedWindow.windowHandle = windowHandle;
- touchedWindow.addHoveringPointer(deviceId, hoveringPointerId);
+ touchedWindow.addHoveringPointer(deviceId, pointer);
windows.push_back(touchedWindow);
}
diff --git a/services/inputflinger/dispatcher/TouchState.h b/services/inputflinger/dispatcher/TouchState.h
index e0a84e8..932c3fb 100644
--- a/services/inputflinger/dispatcher/TouchState.h
+++ b/services/inputflinger/dispatcher/TouchState.h
@@ -46,11 +46,11 @@
void addOrUpdateWindow(const sp<android::gui::WindowInfoHandle>& windowHandle,
InputTarget::DispatchMode dispatchMode,
ftl::Flags<InputTarget::Flags> targetFlags, DeviceId deviceId,
- std::bitset<MAX_POINTER_ID + 1> touchingPointerIds,
+ const std::vector<PointerProperties>& touchingPointers,
std::optional<nsecs_t> firstDownTimeInTarget = std::nullopt);
void addHoveringPointerToWindow(const sp<android::gui::WindowInfoHandle>& windowHandle,
- DeviceId deviceId, int32_t hoveringPointerId);
- void removeHoveringPointer(DeviceId deviceId, int32_t hoveringPointerId);
+ DeviceId deviceId, const PointerProperties& pointer);
+ void removeHoveringPointer(DeviceId deviceId, int32_t pointerId);
void clearHoveringPointers(DeviceId deviceId);
void removeAllPointersForDevice(DeviceId deviceId);
diff --git a/services/inputflinger/dispatcher/TouchedWindow.cpp b/services/inputflinger/dispatcher/TouchedWindow.cpp
index cd0500c..5914808 100644
--- a/services/inputflinger/dispatcher/TouchedWindow.cpp
+++ b/services/inputflinger/dispatcher/TouchedWindow.cpp
@@ -26,9 +26,20 @@
namespace inputdispatcher {
+namespace {
+
+bool hasPointerId(const std::vector<PointerProperties>& pointers, int32_t pointerId) {
+ return std::find_if(pointers.begin(), pointers.end(),
+ [&pointerId](const PointerProperties& properties) {
+ return properties.id == pointerId;
+ }) != pointers.end();
+}
+
+} // namespace
+
bool TouchedWindow::hasHoveringPointers() const {
for (const auto& [_, state] : mDeviceStates) {
- if (state.hoveringPointerIds.any()) {
+ if (!state.hoveringPointers.empty()) {
return true;
}
}
@@ -42,7 +53,7 @@
}
const DeviceState& state = stateIt->second;
- return state.hoveringPointerIds.any();
+ return !state.hoveringPointers.empty();
}
void TouchedWindow::clearHoveringPointers(DeviceId deviceId) {
@@ -51,7 +62,7 @@
return;
}
DeviceState& state = stateIt->second;
- state.hoveringPointerIds.reset();
+ state.hoveringPointers.clear();
if (!state.hasPointers()) {
mDeviceStates.erase(stateIt);
}
@@ -63,22 +74,40 @@
return false;
}
const DeviceState& state = stateIt->second;
-
- return state.hoveringPointerIds.test(pointerId);
+ return hasPointerId(state.hoveringPointers, pointerId);
}
-void TouchedWindow::addHoveringPointer(DeviceId deviceId, int32_t pointerId) {
- mDeviceStates[deviceId].hoveringPointerIds.set(pointerId);
+void TouchedWindow::addHoveringPointer(DeviceId deviceId, const PointerProperties& pointer) {
+ std::vector<PointerProperties>& hoveringPointers = mDeviceStates[deviceId].hoveringPointers;
+ const size_t initialSize = hoveringPointers.size();
+ std::erase_if(hoveringPointers, [&pointer](const PointerProperties& properties) {
+ return properties.id == pointer.id;
+ });
+ if (hoveringPointers.size() != initialSize) {
+ LOG(ERROR) << __func__ << ": " << pointer << ", device " << deviceId << " was in " << *this;
+ }
+ hoveringPointers.push_back(pointer);
}
void TouchedWindow::addTouchingPointers(DeviceId deviceId,
- std::bitset<MAX_POINTER_ID + 1> pointers) {
- mDeviceStates[deviceId].touchingPointerIds |= pointers;
+ const std::vector<PointerProperties>& pointers) {
+ std::vector<PointerProperties>& touchingPointers = mDeviceStates[deviceId].touchingPointers;
+ const size_t initialSize = touchingPointers.size();
+ for (const PointerProperties& pointer : pointers) {
+ std::erase_if(touchingPointers, [&pointer](const PointerProperties& properties) {
+ return properties.id == pointer.id;
+ });
+ }
+ if (touchingPointers.size() != initialSize) {
+ LOG(ERROR) << __func__ << ": " << dumpVector(pointers, streamableToString) << ", device "
+ << deviceId << " already in " << *this;
+ }
+ touchingPointers.insert(touchingPointers.end(), pointers.begin(), pointers.end());
}
bool TouchedWindow::hasTouchingPointers() const {
for (const auto& [_, state] : mDeviceStates) {
- if (state.touchingPointerIds.any()) {
+ if (!state.touchingPointers.empty()) {
return true;
}
}
@@ -86,21 +115,25 @@
}
bool TouchedWindow::hasTouchingPointers(DeviceId deviceId) const {
- return getTouchingPointers(deviceId).any();
+ return !getTouchingPointers(deviceId).empty();
}
bool TouchedWindow::hasTouchingPointer(DeviceId deviceId, int32_t pointerId) const {
- return getTouchingPointers(deviceId).test(pointerId);
+ const auto stateIt = mDeviceStates.find(deviceId);
+ if (stateIt == mDeviceStates.end()) {
+ return false;
+ }
+ const DeviceState& state = stateIt->second;
+ return hasPointerId(state.touchingPointers, pointerId);
}
-std::bitset<MAX_POINTER_ID + 1> TouchedWindow::getTouchingPointers(DeviceId deviceId) const {
+std::vector<PointerProperties> TouchedWindow::getTouchingPointers(DeviceId deviceId) const {
const auto stateIt = mDeviceStates.find(deviceId);
if (stateIt == mDeviceStates.end()) {
return {};
}
const DeviceState& state = stateIt->second;
-
- return state.touchingPointerIds;
+ return state.touchingPointers;
}
void TouchedWindow::removeTouchingPointer(DeviceId deviceId, int32_t pointerId) {
@@ -118,7 +151,10 @@
}
DeviceState& state = stateIt->second;
- state.touchingPointerIds &= ~pointers;
+ std::erase_if(state.touchingPointers, [&pointers](const PointerProperties& properties) {
+ return pointers.test(properties.id);
+ });
+
state.pilferingPointerIds &= ~pointers;
if (!state.hasPointers()) {
@@ -129,7 +165,7 @@
std::set<DeviceId> TouchedWindow::getTouchingDeviceIds() const {
std::set<DeviceId> deviceIds;
for (const auto& [deviceId, deviceState] : mDeviceStates) {
- if (deviceState.touchingPointerIds.any()) {
+ if (!deviceState.touchingPointers.empty()) {
deviceIds.insert(deviceId);
}
}
@@ -198,7 +234,7 @@
}
DeviceState& state = stateIt->second;
- state.touchingPointerIds.reset();
+ state.touchingPointers.clear();
state.pilferingPointerIds.reset();
state.downTimeInTarget.reset();
@@ -214,7 +250,9 @@
}
DeviceState& state = stateIt->second;
- state.hoveringPointerIds.set(pointerId, false);
+ std::erase_if(state.hoveringPointers, [&pointerId](const PointerProperties& properties) {
+ return properties.id == pointerId;
+ });
if (!state.hasPointers()) {
mDeviceStates.erase(stateIt);
@@ -228,7 +266,7 @@
}
DeviceState& state = stateIt->second;
- state.hoveringPointerIds.reset();
+ state.hoveringPointers.clear();
if (!state.hasPointers()) {
mDeviceStates.erase(stateIt);
@@ -236,11 +274,11 @@
}
std::string TouchedWindow::deviceStateToString(const TouchedWindow::DeviceState& state) {
- return StringPrintf("[touchingPointerIds=%s, "
- "downTimeInTarget=%s, hoveringPointerIds=%s, pilferingPointerIds=%s]",
- bitsetToString(state.touchingPointerIds).c_str(),
+ return StringPrintf("[touchingPointers=%s, "
+ "downTimeInTarget=%s, hoveringPointers=%s, pilferingPointerIds=%s]",
+ dumpVector(state.touchingPointers, streamableToString).c_str(),
toString(state.downTimeInTarget).c_str(),
- bitsetToString(state.hoveringPointerIds).c_str(),
+ dumpVector(state.hoveringPointers, streamableToString).c_str(),
bitsetToString(state.pilferingPointerIds).c_str());
}
diff --git a/services/inputflinger/dispatcher/TouchedWindow.h b/services/inputflinger/dispatcher/TouchedWindow.h
index c604353..2e68d3e 100644
--- a/services/inputflinger/dispatcher/TouchedWindow.h
+++ b/services/inputflinger/dispatcher/TouchedWindow.h
@@ -38,15 +38,15 @@
bool hasHoveringPointers() const;
bool hasHoveringPointers(DeviceId deviceId) const;
bool hasHoveringPointer(DeviceId deviceId, int32_t pointerId) const;
- void addHoveringPointer(DeviceId deviceId, int32_t pointerId);
+ void addHoveringPointer(DeviceId deviceId, const PointerProperties& pointer);
void removeHoveringPointer(DeviceId deviceId, int32_t pointerId);
// Touching
bool hasTouchingPointer(DeviceId deviceId, int32_t pointerId) const;
bool hasTouchingPointers() const;
bool hasTouchingPointers(DeviceId deviceId) const;
- std::bitset<MAX_POINTER_ID + 1> getTouchingPointers(DeviceId deviceId) const;
- void addTouchingPointers(DeviceId deviceId, std::bitset<MAX_POINTER_ID + 1> pointers);
+ std::vector<PointerProperties> getTouchingPointers(DeviceId deviceId) const;
+ void addTouchingPointers(DeviceId deviceId, const std::vector<PointerProperties>& pointers);
void removeTouchingPointer(DeviceId deviceId, int32_t pointerId);
void removeTouchingPointers(DeviceId deviceId, std::bitset<MAX_POINTER_ID + 1> pointers);
std::set<DeviceId> getTouchingDeviceIds() const;
@@ -69,16 +69,16 @@
private:
struct DeviceState {
- std::bitset<MAX_POINTER_ID + 1> touchingPointerIds;
+ std::vector<PointerProperties> touchingPointers;
// The pointer ids of the pointers that this window is currently pilfering, by device
std::bitset<MAX_POINTER_ID + 1> pilferingPointerIds;
// Time at which the first action down occurred on this window, for each device
// NOTE: This is not initialized in case of HOVER entry/exit and DISPATCH_AS_OUTSIDE
// scenario.
std::optional<nsecs_t> downTimeInTarget;
- std::bitset<MAX_POINTER_ID + 1> hoveringPointerIds;
+ std::vector<PointerProperties> hoveringPointers;
- bool hasPointers() const { return touchingPointerIds.any() || hoveringPointerIds.any(); };
+ bool hasPointers() const { return !touchingPointers.empty() || !hoveringPointers.empty(); };
};
std::map<DeviceId, DeviceState> mDeviceStates;
diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp
index 9394995..9eb322e 100644
--- a/services/inputflinger/tests/InputDispatcher_test.cpp
+++ b/services/inputflinger/tests/InputDispatcher_test.cpp
@@ -9692,7 +9692,7 @@
// Receives cancel for first pointer after next pointer down
mSpyWindow->consumeMotionEvent(WithMotionAction(ACTION_CANCEL));
- mSpyWindow->consumeMotionEvent(WithMotionAction(ACTION_DOWN));
+ mSpyWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithPointerIds({1})));
mDragWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE));
mSpyWindow->assertNoEvents();
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index e0a3e94..6816818 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -2894,9 +2894,9 @@
mapper.assertConfigureWasCalled();
mapper.assertResetWasNotCalled();
- RawEvent event{.deviceId = EVENTHUB_ID,
+ RawEvent event{.when = ARBITRARY_TIME,
.readTime = ARBITRARY_TIME,
- .when = ARBITRARY_TIME,
+ .deviceId = EVENTHUB_ID,
.type = EV_SYN,
.code = SYN_REPORT,
.value = 0};
diff --git a/services/inputflinger/tests/TestEventMatchers.h b/services/inputflinger/tests/TestEventMatchers.h
index 66fdaa4..8ba497a 100644
--- a/services/inputflinger/tests/TestEventMatchers.h
+++ b/services/inputflinger/tests/TestEventMatchers.h
@@ -464,6 +464,53 @@
return WithPointersMatcher(pointers);
}
+/// Pointer ids matcher
+class WithPointerIdsMatcher {
+public:
+ using is_gtest_matcher = void;
+ explicit WithPointerIdsMatcher(std::set<int32_t> pointerIds) : mPointerIds(pointerIds) {}
+
+ bool MatchAndExplain(const MotionEvent& event, std::ostream* os) const {
+ std::set<int32_t> actualPointerIds;
+ for (size_t pointerIndex = 0; pointerIndex < event.getPointerCount(); pointerIndex++) {
+ const PointerProperties* properties = event.getPointerProperties(pointerIndex);
+ actualPointerIds.insert(properties->id);
+ }
+
+ if (mPointerIds != actualPointerIds) {
+ *os << "expected pointer ids " << dumpSet(mPointerIds) << ", but got "
+ << dumpSet(actualPointerIds);
+ return false;
+ }
+ return true;
+ }
+
+ bool MatchAndExplain(const NotifyMotionArgs& event, std::ostream* os) const {
+ std::set<int32_t> actualPointerIds;
+ for (const PointerProperties& properties : event.pointerProperties) {
+ actualPointerIds.insert(properties.id);
+ }
+
+ if (mPointerIds != actualPointerIds) {
+ *os << "expected pointer ids " << dumpSet(mPointerIds) << ", but got "
+ << dumpSet(actualPointerIds);
+ return false;
+ }
+ return true;
+ }
+
+ void DescribeTo(std::ostream* os) const { *os << "with pointer ids " << dumpSet(mPointerIds); }
+
+ void DescribeNegationTo(std::ostream* os) const { *os << "wrong pointer ids"; }
+
+private:
+ const std::set<int32_t> mPointerIds;
+};
+
+inline WithPointerIdsMatcher WithPointerIds(const std::set<int32_t /*id*/>& pointerIds) {
+ return WithPointerIdsMatcher(pointerIds);
+}
+
/// Key code
class WithKeyCodeMatcher {
public: