Send cancel events to the correct display when mirroring
When a display is mirrored, such as when screen recording is enabled,
there will be clones of the input windows on the mirrored display that
are on the mirror display.
When there is a stream of input going to the channel through one of
those windows and that stream should be canceled, the generated cancel
event should be sent to the correct window on the correct display.
Bug: 299074463
Test: atest inputflinger_tests
Change-Id: I7b9eab69c9e9086750cf9fe8a10998a12c30d084
diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp
index 2f63b2a..ff3eff1 100644
--- a/services/inputflinger/tests/InputDispatcher_test.cpp
+++ b/services/inputflinger/tests/InputDispatcher_test.cpp
@@ -4699,6 +4699,36 @@
firstWindow->assertNoEvents();
}
+TEST_F(InputDispatcherDisplayProjectionTest,
+ SynthesizeHoverCancelationWithCorrectCoordinatesWhenMirrored) {
+ auto [firstWindow, secondWindow] = setupScaledDisplayScenario();
+
+ const std::array<float, 9> matrix = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 0.0, 0.0, 1.0};
+ ui::Transform secondDisplayTransform;
+ secondDisplayTransform.set(matrix);
+ addDisplayInfo(SECOND_DISPLAY_ID, secondDisplayTransform);
+
+ sp<FakeWindowHandle> secondWindowClone = secondWindow->clone(SECOND_DISPLAY_ID);
+ secondWindowClone->setWindowTransform(1.1, 2.2, 3.3, 4.4);
+ addWindow(secondWindowClone);
+
+ // Send hover enter to second window
+ mDispatcher->notifyMotion(generateMotionArgs(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS,
+ ADISPLAY_ID_DEFAULT, {PointF{150, 220}}));
+ secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_ENTER),
+ WithCoords(100, 80), WithRawCoords(300, 880),
+ WithDisplayId(ADISPLAY_ID_DEFAULT)));
+
+ mDispatcher->cancelCurrentTouch();
+
+ // Ensure the cancelation happens with the correct displayId and the correct coordinates.
+ secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_HOVER_EXIT), WithCoords(100, 80),
+ WithRawCoords(300, 880),
+ WithDisplayId(ADISPLAY_ID_DEFAULT)));
+ secondWindow->assertNoEvents();
+ firstWindow->assertNoEvents();
+}
+
/** Ensure consistent behavior of InputDispatcher in all orientations. */
class InputDispatcherDisplayOrientationFixture
: public InputDispatcherDisplayProjectionTest,