InputDispatcher: Add hit test method isPointerInWindow
Before an app can successfully change the pointer icon, we want to
determine whether its windows are actually receiving the pointer.
To do this, we need to be able to do a hit test for a pointer in a
window, so we add a hit test method to InputDispatcher.
Bug: 293587049
Test: atest inputflinger_tests
Change-Id: I8ff103052f8ba58e411b3456f189eab020d49ef1
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 6ad3de0..4a9b67e 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -6948,4 +6948,21 @@
mConfig.keyRepeatDelay = delay.count();
}
+bool InputDispatcher::isPointerInWindow(const sp<android::IBinder>& token, int32_t displayId,
+ DeviceId deviceId, int32_t pointerId) {
+ std::scoped_lock _l(mLock);
+ auto touchStateIt = mTouchStatesByDisplay.find(displayId);
+ if (touchStateIt == mTouchStatesByDisplay.end()) {
+ return false;
+ }
+ for (const TouchedWindow& window : touchStateIt->second.windows) {
+ if (window.windowHandle->getToken() == token &&
+ (window.hasTouchingPointer(deviceId, pointerId) ||
+ window.hasHoveringPointer(deviceId, pointerId))) {
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace android::inputdispatcher