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

Commit 66b82f93 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Access mInputDevices with a lock

Before this CL, 'mInputDevices' was GUARDED_BY mLock, but for some
reason, those thread safety annotations weren't working.

This only got noticed after I added a debug print to the body of the
function 'getInputDevices'.

This appears to be a bug with thread safety annotations.

Still, the fix here is correct and needed.

Bug: 296235458
Test: atest inputflinger_tests
Change-Id: I0ae8cc7791e2042e47719ecd5a8ca00b4147be87
parent 66f2b3e0
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -158,7 +158,8 @@ const InputReaderConfiguration& FakeInputReaderPolicy::getReaderConfiguration()
    return mConfig;
}

const std::vector<InputDeviceInfo>& FakeInputReaderPolicy::getInputDevices() const {
const std::vector<InputDeviceInfo> FakeInputReaderPolicy::getInputDevices() const {
    std::scoped_lock lock(mLock);
    return mInputDevices;
}

@@ -228,7 +229,7 @@ std::shared_ptr<PointerControllerInterface> FakeInputReaderPolicy::obtainPointer

void FakeInputReaderPolicy::notifyInputDevicesChanged(
        const std::vector<InputDeviceInfo>& inputDevices) {
    std::scoped_lock<std::mutex> lock(mLock);
    std::scoped_lock lock(mLock);
    mInputDevices = inputDevices;
    mInputDevicesChanged = true;
    mDevicesChangedCondition.notify_all();
@@ -256,7 +257,7 @@ void FakeInputReaderPolicy::waitForInputDevices(std::function<void(bool)> proces
}

void FakeInputReaderPolicy::notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) {
    std::scoped_lock<std::mutex> lock(mLock);
    std::scoped_lock lock(mLock);
    mStylusGestureNotified = deviceId;
}

+2 −2
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ public:
    void removeDisabledDevice(int32_t deviceId);
    void setPointerController(std::shared_ptr<FakePointerController> controller);
    const InputReaderConfiguration& getReaderConfiguration() const;
    const std::vector<InputDeviceInfo>& getInputDevices() const;
    const std::vector<InputDeviceInfo> getInputDevices() const;
    TouchAffineTransformation getTouchAffineTransformation(const std::string& inputDeviceDescriptor,
                                                           ui::Rotation surfaceRotation);
    void setTouchAffineTransformation(const TouchAffineTransformation t);
@@ -91,7 +91,7 @@ private:
    void waitForInputDevices(std::function<void(bool)> processDevicesChanged);
    void notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) override;

    std::mutex mLock;
    mutable std::mutex mLock;
    std::condition_variable mDevicesChangedCondition;

    InputReaderConfiguration mConfig;