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

Commit 370039c4 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Allow multiple events to be processed in FakeEventHub

Currently, we are only allowing fake event hub to return a single input
event during tests.

That means, tests have to call 'loopOnce' for every event that is
enqueued to fake event hub.

The eventhub interface, however, does not have such a limitation.
EventHubInterface allows up to 'bufferSize' events to be returned at
each 'getEvents' call.

Therefore, adjust FakeEventHub to use this interface in the full
capacity.

Bug: 169866723
Test: atest inputflinger_tests
Change-Id: Icb4dd8fffea9bfef51861ab38ba529a814e7577f
parent 4cd01842
Loading
Loading
Loading
Loading
+8 −9
Original line number Diff line number Diff line
@@ -409,7 +409,7 @@ class FakeEventHub : public EventHubInterface {

    KeyedVector<int32_t, Device*> mDevices;
    std::vector<std::string> mExcludedDevices;
    List<RawEvent> mEvents GUARDED_BY(mLock);
    std::vector<RawEvent> mEvents GUARDED_BY(mLock);
    std::unordered_map<int32_t /*deviceId*/, std::vector<TouchVideoFrame>> mVideoFrames;
    std::vector<int32_t> mVibrators = {0, 1};

@@ -722,16 +722,15 @@ private:
        mExcludedDevices = devices;
    }

    size_t getEvents(int, RawEvent* buffer, size_t) override {
        std::scoped_lock<std::mutex> lock(mLock);
        if (mEvents.empty()) {
            return 0;
        }
    size_t getEvents(int, RawEvent* buffer, size_t bufferSize) override {
        std::scoped_lock lock(mLock);

        const size_t filledSize = std::min(mEvents.size(), bufferSize);
        std::copy(mEvents.begin(), mEvents.begin() + filledSize, buffer);

        *buffer = *mEvents.begin();
        mEvents.erase(mEvents.begin());
        mEvents.erase(mEvents.begin(), mEvents.begin() + filledSize);
        mEventsCondition.notify_all();
        return 1;
        return filledSize;
    }

    std::vector<TouchVideoFrame> getVideoFrames(int32_t deviceId) override {