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

Commit c903df12 authored by arthurhung's avatar arthurhung
Browse files

Maintain CapsLock, NumLock and ScrollLock of keyboard

Currently, CapsLock, NumLock and ScrollLock would keep the state in
KeyboardInputMapper. It cause 2 problems:

1. If user reattach the hardware keyboard, the state would be reset.
2. If there are multiple hardware keyboards, we can't make them
consistent.

We need to store them in the global state and notify others if there
is some state changed.

- Store the meta state of CapsLock, NumLock and ScrollLock in InputReader.
- Set NumLock default on.

Bug: 141329037
Test: atest inputflinger_tests
Change-Id: I3ff5e9d25ed76466a86080350f00d39d6db57c8c
parent dcef2dcd
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -481,6 +481,10 @@ size_t InputDevice::getMapperCount() {
    return count;
}

void InputDevice::updateLedState(bool reset) {
    for_each_mapper([reset](InputMapper& mapper) { mapper.updateLedState(reset); });
}

InputDeviceContext::InputDeviceContext(InputDevice& device, int32_t eventHubId)
      : mDevice(device),
        mContext(device.getContext()),
+23 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ InputReader::InputReader(std::shared_ptr<EventHubInterface> eventHub,
        mEventHub(eventHub),
        mPolicy(policy),
        mGlobalMetaState(0),
        mLedMetaState(AMETA_NUM_LOCK_ON),
        mGeneration(1),
        mNextInputDeviceId(END_RESERVED_ID),
        mDisableVirtualKeysTimeout(LLONG_MIN),
@@ -353,6 +354,18 @@ int32_t InputReader::getGlobalMetaStateLocked() {
    return mGlobalMetaState;
}

void InputReader::updateLedMetaStateLocked(int32_t metaState) {
    mLedMetaState = metaState;
    for (auto& devicePair : mDevices) {
        std::shared_ptr<InputDevice>& device = devicePair.second;
        device->updateLedState(false);
    }
}

int32_t InputReader::getLedMetaStateLocked() {
    return mLedMetaState;
}

void InputReader::notifyExternalStylusPresenceChanged() {
    refreshConfigurationLocked(InputReaderConfiguration::CHANGE_EXTERNAL_STYLUS_PRESENCE);
}
@@ -710,6 +723,16 @@ int32_t InputReader::ContextImpl::getGlobalMetaState() {
    return mReader->getGlobalMetaStateLocked();
}

void InputReader::ContextImpl::updateLedMetaState(int32_t metaState) {
    // lock is already held by the input loop
    mReader->updateLedMetaStateLocked(metaState);
}

int32_t InputReader::ContextImpl::getLedMetaState() {
    // lock is already held by the input loop
    return mReader->getLedMetaStateLocked();
}

void InputReader::ContextImpl::disableVirtualKeysUntil(nsecs_t time) {
    // lock is already held by the input loop
    mReader->disableVirtualKeysUntilLocked(time);
+2 −0
Original line number Diff line number Diff line
@@ -98,6 +98,8 @@ public:

    std::optional<int32_t> getAssociatedDisplayId();

    void updateLedState(bool reset);

    size_t getMapperCount();

    // construct and add a mapper to the input device
+37 −34
Original line number Diff line number Diff line
@@ -55,34 +55,32 @@ public:
                const sp<InputListenerInterface>& listener);
    virtual ~InputReader();

    virtual void dump(std::string& dump) override;
    virtual void monitor() override;
    void dump(std::string& dump) override;
    void monitor() override;

    virtual status_t start() override;
    virtual status_t stop() override;
    status_t start() override;
    status_t stop() override;

    virtual void getInputDevices(std::vector<InputDeviceInfo>& outInputDevices) override;
    void getInputDevices(std::vector<InputDeviceInfo>& outInputDevices) override;

    virtual bool isInputDeviceEnabled(int32_t deviceId) override;
    bool isInputDeviceEnabled(int32_t deviceId) override;

    virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask,
                                     int32_t scanCode) override;
    virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
                                    int32_t keyCode) override;
    virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t sw) override;
    int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, int32_t scanCode) override;
    int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, int32_t keyCode) override;
    int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t sw) override;

    virtual void toggleCapsLockState(int32_t deviceId) override;
    void toggleCapsLockState(int32_t deviceId) override;

    virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask, size_t numCodes,
                         const int32_t* keyCodes, uint8_t* outFlags) override;
    bool hasKeys(int32_t deviceId, uint32_t sourceMask, size_t numCodes, const int32_t* keyCodes,
                 uint8_t* outFlags) override;

    virtual void requestRefreshConfiguration(uint32_t changes) override;
    void requestRefreshConfiguration(uint32_t changes) override;

    virtual void vibrate(int32_t deviceId, const std::vector<VibrationElement>& pattern,
                         ssize_t repeat, int32_t token) override;
    virtual void cancelVibrate(int32_t deviceId, int32_t token) override;
    void vibrate(int32_t deviceId, const std::vector<VibrationElement>& pattern, ssize_t repeat,
                 int32_t token) override;
    void cancelVibrate(int32_t deviceId, int32_t token) override;

    virtual bool canDispatchToDisplay(int32_t deviceId, int32_t displayId) override;
    bool canDispatchToDisplay(int32_t deviceId, int32_t displayId) override;

protected:
    // These members are protected so they can be instrumented by test cases.
@@ -100,21 +98,22 @@ protected:
    public:
        explicit ContextImpl(InputReader* reader);

        virtual void updateGlobalMetaState() override;
        virtual int32_t getGlobalMetaState() override;
        virtual void disableVirtualKeysUntil(nsecs_t time) override;
        virtual bool shouldDropVirtualKey(nsecs_t now, int32_t keyCode, int32_t scanCode) override;
        virtual void fadePointer() override;
        virtual std::shared_ptr<PointerControllerInterface> getPointerController(
                int32_t deviceId) override;
        virtual void requestTimeoutAtTime(nsecs_t when) override;
        virtual int32_t bumpGeneration() override;
        virtual void getExternalStylusDevices(std::vector<InputDeviceInfo>& outDevices) override;
        virtual void dispatchExternalStylusState(const StylusState& outState) override;
        virtual InputReaderPolicyInterface* getPolicy() override;
        virtual InputListenerInterface* getListener() override;
        virtual EventHubInterface* getEventHub() override;
        virtual int32_t getNextId() override;
        void updateGlobalMetaState() override;
        int32_t getGlobalMetaState() override;
        void disableVirtualKeysUntil(nsecs_t time) override;
        bool shouldDropVirtualKey(nsecs_t now, int32_t keyCode, int32_t scanCode) override;
        void fadePointer() override;
        std::shared_ptr<PointerControllerInterface> getPointerController(int32_t deviceId) override;
        void requestTimeoutAtTime(nsecs_t when) override;
        int32_t bumpGeneration() override;
        void getExternalStylusDevices(std::vector<InputDeviceInfo>& outDevices) override;
        void dispatchExternalStylusState(const StylusState& outState) override;
        InputReaderPolicyInterface* getPolicy() override;
        InputListenerInterface* getListener() override;
        EventHubInterface* getEventHub() override;
        int32_t getNextId() override;
        void updateLedMetaState(int32_t metaState) override;
        int32_t getLedMetaState() override;
    } mContext;

    friend class ContextImpl;
@@ -157,6 +156,10 @@ private:
    void updateGlobalMetaStateLocked();
    int32_t getGlobalMetaStateLocked();

    int32_t mLedMetaState;
    void updateLedMetaStateLocked(int32_t metaState);
    int32_t getLedMetaStateLocked();

    void notifyExternalStylusPresenceChanged();
    void getExternalStylusDevicesLocked(std::vector<InputDeviceInfo>& outDevices);
    void dispatchExternalStylusState(const StylusState& state);
+3 −0
Original line number Diff line number Diff line
@@ -59,6 +59,9 @@ public:
    virtual EventHubInterface* getEventHub() = 0;

    virtual int32_t getNextId() = 0;

    virtual void updateLedMetaState(int32_t metaState) = 0;
    virtual int32_t getLedMetaState() = 0;
};

} // namespace android
Loading