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

Commit 94ab7133 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Update eventTime to prevent stale events"

parents 3b39539d adfd4fa3
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);