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

Commit 40aee53b authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

InputReader_test: Wait for stylus gesture to be notified

This is required because of the following change:
I818b1e688565d30867295019c5baae29cb5bdbf2

Previously, the policy was notified of the stylus gesture changing
before the events were flushed to the listener. This meant the policy
was always notified of the stylus gesture by the time the listener
received the stylus DOWN event.

After the aforementioned change, this is no longer true, so we cannot
use the DOWN event as a sync signal. Instead, we need to wait for the
policy to be notified.

Bug: 324318955
Test: atest inputflinger_tests
Change-Id: I8219e0db092c14da5907337b3ea5b5c6f7dddd4a
parent fa32f893
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -41,15 +41,21 @@ void FakeInputReaderPolicy::assertInputDevicesNotChanged() {
}

void FakeInputReaderPolicy::assertStylusGestureNotified(int32_t deviceId) {
    std::scoped_lock lock(mLock);
    ASSERT_TRUE(mStylusGestureNotified);
    ASSERT_EQ(deviceId, *mStylusGestureNotified);
    mStylusGestureNotified.reset();
    std::unique_lock lock(mLock);
    base::ScopedLockAssertion assumeLocked(mLock);

    const bool success =
            mStylusGestureNotifiedCondition.wait_for(lock, WAIT_TIMEOUT, [this]() REQUIRES(mLock) {
                return mDeviceIdOfNotifiedStylusGesture.has_value();
            });
    ASSERT_TRUE(success) << "Timed out waiting for stylus gesture to be notified";
    ASSERT_EQ(deviceId, *mDeviceIdOfNotifiedStylusGesture);
    mDeviceIdOfNotifiedStylusGesture.reset();
}

void FakeInputReaderPolicy::assertStylusGestureNotNotified() {
    std::scoped_lock lock(mLock);
    ASSERT_FALSE(mStylusGestureNotified);
    ASSERT_FALSE(mDeviceIdOfNotifiedStylusGesture);
}

void FakeInputReaderPolicy::clearViewports() {
@@ -258,7 +264,8 @@ void FakeInputReaderPolicy::waitForInputDevices(std::function<void(bool)> proces

void FakeInputReaderPolicy::notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) {
    std::scoped_lock lock(mLock);
    mStylusGestureNotified = deviceId;
    mDeviceIdOfNotifiedStylusGesture = deviceId;
    mStylusGestureNotifiedCondition.notify_all();
}

std::optional<DisplayViewport> FakeInputReaderPolicy::getPointerViewportForAssociatedDisplay(
+3 −1
Original line number Diff line number Diff line
@@ -102,9 +102,11 @@ private:
    bool mInputDevicesChanged GUARDED_BY(mLock){false};
    std::vector<DisplayViewport> mViewports;
    TouchAffineTransformation transform;
    std::optional<int32_t /*deviceId*/> mStylusGestureNotified GUARDED_BY(mLock){};
    bool mIsInputMethodConnectionActive{false};

    std::condition_variable mStylusGestureNotifiedCondition;
    std::optional<DeviceId> mDeviceIdOfNotifiedStylusGesture GUARDED_BY(mLock){};

    uint32_t mNextPointerCaptureSequenceNumber{0};
};