From 92bca1c4ecbf5fcaacf05f6a4eee92af506864a5 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Mon, 1 Apr 2024 14:06:59 -0700 Subject: Consume MOVE from different devices one at a time The events received by the spy window may be batched, and batches could be processed out of order. To avoid this confusing behaviour, consume the events one at a time. Fixes: 332314982 Test: TEST=inputflinger_tests; m $TEST && adb sync && adb shell -t /data/nativetest64/$TEST/$TEST --gtest_filter="*MultiDevicePilfer" --gtest_repeat=10000 --gtest_break_on_failure Change-Id: I9a50bea24401fa55b54687ab227bd2ed5c3d43ba --- services/inputflinger/tests/FakeWindows.cpp | 3 +++ services/inputflinger/tests/InputDispatcher_test.cpp | 17 ++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/services/inputflinger/tests/FakeWindows.cpp b/services/inputflinger/tests/FakeWindows.cpp index bfe09bc4af..a6955eca94 100644 --- a/services/inputflinger/tests/FakeWindows.cpp +++ b/services/inputflinger/tests/FakeWindows.cpp @@ -309,6 +309,9 @@ std::unique_ptr FakeWindowHandle::consumeMotionEvent( } std::unique_ptr motionEvent = std::unique_ptr(static_cast(event.release())); + if (motionEvent == nullptr) { + return nullptr; + } EXPECT_THAT(*motionEvent, matcher) << " on " << mName; return motionEvent; } diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index 05db1ef964..62a92352e5 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -12292,22 +12292,25 @@ TEST_F(InputDispatcherPilferPointersTest, MultiDevicePilfer) { AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(touchDeviceId))); // Continue movements from both stylus and touch. Touch and stylus will be delivered to spy + // Instead of sending the two MOVE events for each input device together, and then receiving + // them both, process them one at at time. InputConsumer is always in the batching mode, which + // means that the two MOVE events will be initially put into a batch. Once the events are + // batched, the 'consume' call may result in any of the MOVE events to be sent first (depending + // on the implementation of InputConsumer), which would mean that the order of the received + // events could be different depending on whether there are 1 or 2 events pending in the + // InputChannel at the time the test calls 'consume'. To make assertions simpler here, and to + // avoid this confusing behaviour, send and receive each MOVE event separately. mDispatcher->notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_STYLUS) .deviceId(stylusDeviceId) .pointer(PointerBuilder(0, ToolType::STYLUS).x(51).y(52)) .build()); + spy->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(stylusDeviceId))); mDispatcher->notifyMotion( MotionArgsBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) .pointer(PointerBuilder(0, ToolType::FINGER).x(151).y(52)) .build()); - std::vector> spyEvents; - spyEvents.push_back(spy->consumeMotionEvent(WithMotionAction(ACTION_MOVE))); - spyEvents.push_back(spy->consumeMotionEvent(WithMotionAction(ACTION_MOVE))); - // TODO(b/332314982) : Figure out why these can be out of order - ASSERT_THAT(spyEvents, - UnorderedElementsAre(Pointee(WithDeviceId(stylusDeviceId)), - Pointee(WithDeviceId(touchDeviceId)))); + spy->consumeMotionEvent(AllOf(WithMotionAction(ACTION_MOVE), WithDeviceId(touchDeviceId))); spy->assertNoEvents(); leftWindow->assertNoEvents(); -- cgit v1.2.3-59-g8ed1b