InputDispatcher: Remove transform for non-pointer events
MotionEvents that are not pointer events should not have a window
transform associated with them because they don't correspond to
on-screen locations.
Bug: 182325974
Test: manual, verify pointer capture in freeform and multi-window modes
Change-Id: I774bbdfacffa68a42e72e3ca52ec4b474560ff34
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 19f8694..6d9190c 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -332,10 +332,11 @@
int32_t inputTargetFlags) {
if (eventEntry->type == EventEntry::Type::MOTION) {
const MotionEntry& motionEntry = static_cast<const MotionEntry&>(*eventEntry);
- if (motionEntry.source & AINPUT_SOURCE_CLASS_JOYSTICK) {
+ if ((motionEntry.source & AINPUT_SOURCE_CLASS_POINTER) == 0) {
const ui::Transform identityTransform;
- // Use identity transform for joystick events events because they don't depend on
- // the window info
+ // Use identity transform for events that are not pointer events because their axes
+ // values do not represent on-screen coordinates, so they should not have any window
+ // transformations applied to them.
return std::make_unique<DispatchEntry>(eventEntry, inputTargetFlags, identityTransform,
1.0f /*globalScaleFactor*/);
}
diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp
index 51f6f5d..5cdcfaf 100644
--- a/services/inputflinger/tests/InputDispatcher_test.cpp
+++ b/services/inputflinger/tests/InputDispatcher_test.cpp
@@ -2183,7 +2183,7 @@
EXPECT_EQ(motionArgs.buttonState, verifiedMotion.buttonState);
}
-TEST_F(InputDispatcherTest, NonPointerMotionEvent_JoystickNotTransformed) {
+TEST_F(InputDispatcherTest, NonPointerMotionEvent_NotTransformed) {
std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
sp<FakeWindowHandle> window =
new FakeWindowHandle(application, mDispatcher, "Test window", ADISPLAY_ID_DEFAULT);
@@ -2203,28 +2203,41 @@
// Second, we consume focus event if it is right or wrong according to onFocusChangedLocked.
window->consumeFocusEvent(true);
- NotifyMotionArgs motionArgs = generateMotionArgs(AMOTION_EVENT_ACTION_MOVE,
- AINPUT_SOURCE_JOYSTICK, ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&motionArgs);
+ constexpr const std::array nonPointerSources = {AINPUT_SOURCE_TRACKBALL,
+ AINPUT_SOURCE_MOUSE_RELATIVE,
+ AINPUT_SOURCE_JOYSTICK};
+ for (const int source : nonPointerSources) {
+ // Notify motion with a non-pointer source.
+ NotifyMotionArgs motionArgs =
+ generateMotionArgs(AMOTION_EVENT_ACTION_MOVE, source, ADISPLAY_ID_DEFAULT);
+ mDispatcher->notifyMotion(&motionArgs);
- // Third, we consume motion event.
- InputEvent* event = window->consume();
- ASSERT_NE(event, nullptr);
- ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType())
- << name.c_str() << "expected " << inputEventTypeToString(AINPUT_EVENT_TYPE_MOTION)
- << " event, got " << inputEventTypeToString(event->getType()) << " event";
+ InputEvent* event = window->consume();
+ ASSERT_NE(event, nullptr);
+ ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType())
+ << name.c_str() << "expected " << inputEventTypeToString(AINPUT_EVENT_TYPE_MOTION)
+ << " event, got " << inputEventTypeToString(event->getType()) << " event";
- const MotionEvent& motionEvent = static_cast<const MotionEvent&>(*event);
- EXPECT_EQ(AINPUT_EVENT_TYPE_MOTION, motionEvent.getAction());
+ const MotionEvent& motionEvent = static_cast<const MotionEvent&>(*event);
+ EXPECT_EQ(AMOTION_EVENT_ACTION_MOVE, motionEvent.getAction());
+ EXPECT_EQ(motionArgs.pointerCount, motionEvent.getPointerCount());
- float expectedX = motionArgs.pointerCoords[0].getX();
- float expectedY = motionArgs.pointerCoords[0].getY();
+ float expectedX = motionArgs.pointerCoords[0].getX();
+ float expectedY = motionArgs.pointerCoords[0].getY();
- // Finally we test if the axis values from the final motion event are not transformed
- EXPECT_EQ(expectedX, motionEvent.getX(0)) << "expected " << expectedX << " for x coord of "
- << name.c_str() << ", got " << motionEvent.getX(0);
- EXPECT_EQ(expectedY, motionEvent.getY(0)) << "expected " << expectedY << " for y coord of "
- << name.c_str() << ", got " << motionEvent.getY(0);
+ // Ensure the axis values from the final motion event are not transformed.
+ EXPECT_EQ(expectedX, motionEvent.getX(0))
+ << "expected " << expectedX << " for x coord of " << name.c_str() << ", got "
+ << motionEvent.getX(0);
+ EXPECT_EQ(expectedY, motionEvent.getY(0))
+ << "expected " << expectedY << " for y coord of " << name.c_str() << ", got "
+ << motionEvent.getY(0);
+ // Ensure the raw and transformed axis values for the motion event are the same.
+ EXPECT_EQ(motionEvent.getRawX(0), motionEvent.getX(0))
+ << "expected raw and transformed X-axis values to be equal";
+ EXPECT_EQ(motionEvent.getRawY(0), motionEvent.getY(0))
+ << "expected raw and transformed Y-axis values to be equal";
+ }
}
/**