InputDispatcher: Use correct coordinate space when synthesizing down
Input targets for synthesized down events were not created using the
same pipeline as normal dispatching. Due to this, things like window and
display transforms were not being applied to the events. This means the
ACTION_DOWN event did not have the correct coordinates in many cases.
Here, we fix that by attempting to use the same pipeline as normal
dispatching for creating the input target. When it's not possible to do
due to there being no window (e.g. for global monitors), we fall back to
creating the target ourselves.
Bug: 287908447
Test: atest inputflinger_tests
Change-Id: I6987619c91e458249aa7c7be884566e4b21363c4
diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp
index e8b04b3..d532d50 100644
--- a/services/inputflinger/tests/InputDispatcher_test.cpp
+++ b/services/inputflinger/tests/InputDispatcher_test.cpp
@@ -4700,6 +4700,21 @@
AllOf(WithMotionAction(ACTION_CANCEL), WithPointers(expectedMonitorPointers)));
}
+TEST_F(InputDispatcherDisplayProjectionTest, SynthesizeDownWithCorrectCoordinates) {
+ auto [firstWindow, secondWindow] = setupScaledDisplayScenario();
+
+ // Send down to the first window.
+ mDispatcher->notifyMotion(generateMotionArgs(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, {PointF{50, 100}}));
+ firstWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithCoords(100, 400)));
+
+ // The pointer is transferred to the second window, and the second window receives it in the
+ // correct coordinate space.
+ mDispatcher->transferTouchFocus(firstWindow->getToken(), secondWindow->getToken());
+ firstWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_CANCEL), WithCoords(100, 400)));
+ secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithCoords(-100, -400)));
+}
+
/** Ensure consistent behavior of InputDispatcher in all orientations. */
class InputDispatcherDisplayOrientationFixture
: public InputDispatcherDisplayProjectionTest,