Skip to content

Commit 9d5f9ce

Browse files
committed
InputDispatcher_test: Consume all moves to prevent events from batching
InputDispatcherTest uses a real input channel, which means if subsequent MOVE events are not consumed, they will be batched together. Currently this applies to windows with split touches, where pointers moving on one split window will generate MOVEs on the other window which the test is not consuming, and thus end up getting batched. Avoid this situation by explicitly consuming all MOVE events in affected tests. Bug: 210460522 Test: atest inputflinger_tests Change-Id: I308c12e2aaf98f630bdac8021f7238e913a49056
1 parent c88b1fa commit 9d5f9ce

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

services/inputflinger/tests/InputDispatcher_test.cpp

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3865,48 +3865,57 @@ TEST_F(InputDispatcherTest, SplitTouchesSendCorrectActionDownTime) {
38653865

38663866
// Touch down on the first window
38673867
mDispatcher->notifyMotion(generateTouchArgs(AMOTION_EVENT_ACTION_DOWN, {{50, 50}}));
3868-
38693868
mDispatcher->waitForIdle();
38703869

3871-
std::unique_ptr<MotionEvent> motionEvent1 = window1->consumeMotionEvent();
3872-
ASSERT_NE(nullptr, motionEvent1);
3870+
const std::unique_ptr<MotionEvent> firstDown =
3871+
window1->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN)));
3872+
ASSERT_EQ(firstDown->getDownTime(), firstDown->getEventTime());
38733873
window2->assertNoEvents();
3874-
nsecs_t downTimeForWindow1 = motionEvent1->getDownTime();
3875-
ASSERT_EQ(motionEvent1->getDownTime(), motionEvent1->getEventTime());
38763874

38773875
// Now touch down on the window with another pointer
38783876
mDispatcher->notifyMotion(generateTouchArgs(POINTER_1_DOWN, {{50, 50}, {150, 50}}));
38793877
mDispatcher->waitForIdle();
3880-
std::unique_ptr<MotionEvent> motionEvent2 = window2->consumeMotionEvent();
3881-
ASSERT_NE(nullptr, motionEvent2);
3882-
nsecs_t downTimeForWindow2 = motionEvent2->getDownTime();
3883-
ASSERT_NE(downTimeForWindow1, downTimeForWindow2);
3884-
ASSERT_EQ(motionEvent2->getDownTime(), motionEvent2->getEventTime());
3878+
3879+
const std::unique_ptr<MotionEvent> secondDown =
3880+
window2->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN)));
3881+
ASSERT_EQ(secondDown->getDownTime(), secondDown->getEventTime());
3882+
ASSERT_NE(firstDown->getDownTime(), secondDown->getDownTime());
3883+
// We currently send MOVE events to all windows receiving a split touch when there is any change
3884+
// in the touch state, even when none of the pointers in the split window actually moved.
3885+
// Document this behavior in the test.
3886+
window1->consumeMotionMove();
38853887

38863888
// Now move the pointer on the second window
38873889
mDispatcher->notifyMotion(generateTouchArgs(AMOTION_EVENT_ACTION_MOVE, {{50, 50}, {151, 51}}));
38883890
mDispatcher->waitForIdle();
3889-
window2->consumeMotionEvent(WithDownTime(downTimeForWindow2));
3891+
3892+
window2->consumeMotionEvent(WithDownTime(secondDown->getDownTime()));
3893+
window1->consumeMotionEvent(WithDownTime(firstDown->getDownTime()));
38903894

38913895
// Now add new touch down on the second window
38923896
mDispatcher->notifyMotion(generateTouchArgs(POINTER_2_DOWN, {{50, 50}, {151, 51}, {150, 50}}));
38933897
mDispatcher->waitForIdle();
3894-
window2->consumeMotionEvent(WithDownTime(downTimeForWindow2));
38953898

3896-
// TODO(b/232530217): do not send the unnecessary MOVE event and delete the next line
3897-
window1->consumeMotionMove();
3898-
window1->assertNoEvents();
3899+
window2->consumeMotionEvent(
3900+
AllOf(WithMotionAction(POINTER_1_DOWN), WithDownTime(secondDown->getDownTime())));
3901+
window1->consumeMotionEvent(WithDownTime(firstDown->getDownTime()));
38993902

39003903
// Now move the pointer on the first window
39013904
mDispatcher->notifyMotion(
39023905
generateTouchArgs(AMOTION_EVENT_ACTION_MOVE, {{51, 51}, {151, 51}, {150, 50}}));
39033906
mDispatcher->waitForIdle();
3904-
window1->consumeMotionEvent(WithDownTime(downTimeForWindow1));
39053907

3908+
window1->consumeMotionEvent(WithDownTime(firstDown->getDownTime()));
3909+
window2->consumeMotionEvent(WithDownTime(secondDown->getDownTime()));
3910+
3911+
// Now add new touch down on the first window
39063912
mDispatcher->notifyMotion(
39073913
generateTouchArgs(POINTER_3_DOWN, {{51, 51}, {151, 51}, {150, 50}, {50, 50}}));
39083914
mDispatcher->waitForIdle();
3909-
window1->consumeMotionEvent(WithDownTime(downTimeForWindow1));
3915+
3916+
window1->consumeMotionEvent(
3917+
AllOf(WithMotionAction(POINTER_1_DOWN), WithDownTime(firstDown->getDownTime())));
3918+
window2->consumeMotionEvent(WithDownTime(secondDown->getDownTime()));
39103919
}
39113920

39123921
TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) {
@@ -10780,6 +10789,7 @@ TEST_F(InputDispatcherDragTests, DragAndDropWhenSplitTouch) {
1078010789
InputEventInjectionSync::WAIT_FOR_RESULT))
1078110790
<< "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
1078210791
mWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT);
10792+
mSecondWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT);
1078310793

1078410794
// Perform drag and drop from first window.
1078510795
ASSERT_TRUE(startDrag(false));

0 commit comments

Comments
 (0)