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

Commit adfd4fa3 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Update eventTime to prevent stale events

Generate a new motionevent for each injection to ensure that eventtime
remains up to date.

In the InputDispatcher benchmarks, if the eventTime is not updated, then
the test will be stuck, because dispatcher will just drop all events.
To hit this condition, the benchmark must be ran for a sufficiently long
amount of time so that isStaleEvent returns true.
At that point, the benchmark for injectMotion will be stuck, because all
events are dropped, and we cannot consume anything.

The setDownTime api is unsupportedAppUsage in the Java layer, so we
shouldn't remove it.

Bug: none
Test: flame:/data/benchmarktest64/inputflinger_benchmarks #
./inputflinger_benchmarks --benchmark_min_time=10

Change-Id: I1eb93ca9ddac52562e0da50de355d5cdc584c893
parent a81d409c
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -109,8 +109,14 @@ public:
        uint32_t consumeSeq;
        InputEvent* event;

        std::chrono::time_point start = std::chrono::steady_clock::now();
        status_t result = WOULD_BLOCK;
        while (result == WOULD_BLOCK) {
            std::chrono::duration elapsed = std::chrono::steady_clock::now() - start;
            if (elapsed > 10ms) {
                ALOGE("Waited too long for consumer to produce an event, giving up");
                break;
            }
            result = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq,
                                        &event);
        }
@@ -282,12 +288,9 @@ static void benchmarkInjectMotion(benchmark::State& state) {

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

    MotionEvent event = generateMotionEvent();

    for (auto _ : state) {
        MotionEvent event = generateMotionEvent();
        // Send ACTION_DOWN
        event.setAction(AMOTION_EVENT_ACTION_DOWN);
        event.setDownTime(now());
        dispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID,
                                     INPUT_EVENT_INJECTION_SYNC_NONE, INJECT_EVENT_TIMEOUT,
                                     POLICY_FLAG_FILTERED | POLICY_FLAG_PASS_TO_USER);
+4 −4
Original line number Diff line number Diff line
@@ -252,6 +252,10 @@ static bool haveSameToken(const sp<InputWindowHandle>& first, const sp<InputWind
    return first->getToken() == second->getToken();
}

static bool isStaleEvent(nsecs_t currentTime, const EventEntry& entry) {
    return currentTime - entry.eventTime >= STALE_EVENT_TIMEOUT;
}

// --- InputDispatcherThread ---

class InputDispatcher::InputDispatcherThread : public Thread {
@@ -743,10 +747,6 @@ void InputDispatcher::resetPendingAppSwitchLocked(bool handled) {
#endif
}

bool InputDispatcher::isStaleEvent(nsecs_t currentTime, const EventEntry& entry) {
    return currentTime - entry.eventTime >= STALE_EVENT_TIMEOUT;
}

bool InputDispatcher::haveCommandsLocked() const {
    return !mCommandQueue.empty();
}
+0 −3
Original line number Diff line number Diff line
@@ -168,9 +168,6 @@ private:
    bool isAppSwitchPendingLocked() REQUIRES(mLock);
    void resetPendingAppSwitchLocked(bool handled) REQUIRES(mLock);

    // Stale event latency optimization.
    static bool isStaleEvent(nsecs_t currentTime, const EventEntry& entry);

    // Blocked event latency optimization.  Drops old events when the user intends
    // to transfer focus to a new application.
    EventEntry* mNextUnblockedEvent GUARDED_BY(mLock);