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

Commit 82e413ed authored by Arpit Singh's avatar Arpit Singh
Browse files

Record last keypress timestamp on physical keyboard while typing

Added method to record keypress timestamp while typing. This will be
used by touchpad to trigger additional palm rejection logic.

Bug: 301055381
Test: atest KeyboardInputMapperUnitTest
Change-Id: I4bbfe4c5fefc687a4901e46c9d4c6f832ec1a245
parent 5791961d
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -1046,6 +1046,14 @@ bool InputReader::ContextImpl::isPreventingTouchpadTaps() {
    return mReader->mPreventingTouchpadTaps;
}

void InputReader::ContextImpl::setLastKeyDownTimestamp(nsecs_t when) {
    mReader->mLastKeyDownTimestamp = when;
}

nsecs_t InputReader::ContextImpl::getLastKeyDownTimestamp() {
    return mReader->mLastKeyDownTimestamp;
}

void InputReader::ContextImpl::disableVirtualKeysUntil(nsecs_t time) {
    // lock is already held by the input loop
    mReader->disableVirtualKeysUntilLocked(time);
+6 −0
Original line number Diff line number Diff line
@@ -158,6 +158,9 @@ protected:
        void setPreventingTouchpadTaps(bool prevent) REQUIRES(mReader->mLock)
                REQUIRES(mLock) override;
        bool isPreventingTouchpadTaps() REQUIRES(mReader->mLock) REQUIRES(mLock) override;
        void setLastKeyDownTimestamp(nsecs_t when) REQUIRES(mReader->mLock)
                REQUIRES(mLock) override;
        nsecs_t getLastKeyDownTimestamp() REQUIRES(mReader->mLock) REQUIRES(mLock) override;
    } mContext;

    friend class ContextImpl;
@@ -198,6 +201,9 @@ private:
    // true if tap-to-click on touchpad currently disabled
    bool mPreventingTouchpadTaps GUARDED_BY(mLock){false};

    // records timestamp of the last key press on the physical keyboard
    nsecs_t mLastKeyDownTimestamp GUARDED_BY(mLock){0};

    // low-level input event decoding and device management
    [[nodiscard]] std::list<NotifyArgs> processEventsLocked(const RawEvent* rawEvents, size_t count)
            REQUIRES(mLock);
+3 −0
Original line number Diff line number Diff line
@@ -65,6 +65,9 @@ public:

    virtual void setPreventingTouchpadTaps(bool prevent) = 0;
    virtual bool isPreventingTouchpadTaps() = 0;

    virtual void setLastKeyDownTimestamp(nsecs_t when) = 0;
    virtual nsecs_t getLastKeyDownTimestamp() = 0;
};

} // namespace android
+3 −2
Original line number Diff line number Diff line
@@ -270,7 +270,7 @@ std::list<NotifyArgs> KeyboardInputMapper::processKey(nsecs_t when, nsecs_t read
            keyDown.flags = flags;
            mKeyDowns.push_back(keyDown);
        }
        onKeyDownProcessed();
        onKeyDownProcessed(downTime);
    } else {
        // Remove key down.
        if (keyDownIndex) {
@@ -448,8 +448,9 @@ std::list<NotifyArgs> KeyboardInputMapper::cancelAllDownKeys(nsecs_t when) {
    return out;
}

void KeyboardInputMapper::onKeyDownProcessed() {
void KeyboardInputMapper::onKeyDownProcessed(nsecs_t downTime) {
    InputReaderContext& context = *getContext();
    context.setLastKeyDownTimestamp(downTime);
    if (context.isPreventingTouchpadTaps()) {
        // avoid pinging java service unnecessarily, just fade pointer again if it became visible
        context.fadePointer();
+1 −1
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ private:
    void updateLedStateForModifier(LedState& ledState, int32_t led, int32_t modifier, bool reset);
    std::optional<DisplayViewport> findViewport(const InputReaderConfiguration& readerConfig);
    [[nodiscard]] std::list<NotifyArgs> cancelAllDownKeys(nsecs_t when);
    void onKeyDownProcessed();
    void onKeyDownProcessed(nsecs_t downTime);
};

} // namespace android
Loading