Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 81e2bb96 authored by chaviw's avatar chaviw
Browse files

Consume batches in dispatcher tests

We are currently calling consume with consumeBatches=false. But that
means we don't want to consume any batched events. As a result, when
events are simply stored internally in inputconsumer, they are not
returned to callers of consume(..).

We never had tests that included MOVE events, and since DOWN events are
never batched, we did not encounter this case.

Now that we are adding a MOVE test, we need to ensure batches are
consumed as well.

Bug: none
Test: atest inputflinger_tests

Change-Id: Ieb13e1bb43bbf96f7f9352a283387ffdb11ba54a
parent eb1cdc5b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -301,8 +301,8 @@ status_t InputChannel::sendMessage(const InputMessage* msg) {
    if (nWrite < 0) {
        int error = errno;
#if DEBUG_CHANNEL_MESSAGES
        ALOGD("channel '%s' ~ error sending message of type %d, errno=%d", mName.c_str(),
                msg->header.type, error);
        ALOGD("channel '%s' ~ error sending message of type %d, %s", mName.c_str(),
              msg->header.type, strerror(error));
#endif
        if (error == EAGAIN || error == EWOULDBLOCK) {
            return WOULD_BLOCK;
+27 −1
Original line number Diff line number Diff line
@@ -418,7 +418,7 @@ public:
        std::chrono::time_point start = std::chrono::steady_clock::now();
        status_t status = WOULD_BLOCK;
        while (status == WOULD_BLOCK) {
            status = mConsumer->consume(&mEventFactory, false /*consumeBatches*/, -1, &consumeSeq,
            status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq,
                                        &event);
            std::chrono::duration elapsed = std::chrono::steady_clock::now() - start;
            if (elapsed > 100ms) {
@@ -932,6 +932,32 @@ TEST_F(InputDispatcherTest, GestureMonitor_CanPilferAfterWindowIsRemovedMidStrea
    monitor->consumeMotionUp(ADISPLAY_ID_DEFAULT);
}

TEST_F(InputDispatcherTest, TestMoveEvent) {
    sp<FakeApplicationHandle> application = new FakeApplicationHandle();
    sp<FakeWindowHandle> window =
            new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT);

    mDispatcher->setInputWindows({window}, ADISPLAY_ID_DEFAULT);

    NotifyMotionArgs motionArgs =
            generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
                               ADISPLAY_ID_DEFAULT);

    mDispatcher->notifyMotion(&motionArgs);
    // Window should receive motion down event.
    window->consumeMotionDown(ADISPLAY_ID_DEFAULT);

    motionArgs.action = AMOTION_EVENT_ACTION_MOVE;
    motionArgs.sequenceNum += 1;
    motionArgs.eventTime = systemTime(SYSTEM_TIME_MONOTONIC);
    motionArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X,
                                             motionArgs.pointerCoords[0].getX() - 10);

    mDispatcher->notifyMotion(&motionArgs);
    window->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_MOVE, ADISPLAY_ID_DEFAULT,
                         0 /*expectedFlags*/);
}

/* Test InputDispatcher for MultiDisplay */
class InputDispatcherFocusOnTwoDisplaysTest : public InputDispatcherTest {
public: