Skip to content

Commit 40aee53

Browse files
committed
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
1 parent fa32f89 commit 40aee53

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

services/inputflinger/tests/FakeInputReaderPolicy.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,21 @@ void FakeInputReaderPolicy::assertInputDevicesNotChanged() {
4141
}
4242

4343
void FakeInputReaderPolicy::assertStylusGestureNotified(int32_t deviceId) {
44-
std::scoped_lock lock(mLock);
45-
ASSERT_TRUE(mStylusGestureNotified);
46-
ASSERT_EQ(deviceId, *mStylusGestureNotified);
47-
mStylusGestureNotified.reset();
44+
std::unique_lock lock(mLock);
45+
base::ScopedLockAssertion assumeLocked(mLock);
46+
47+
const bool success =
48+
mStylusGestureNotifiedCondition.wait_for(lock, WAIT_TIMEOUT, [this]() REQUIRES(mLock) {
49+
return mDeviceIdOfNotifiedStylusGesture.has_value();
50+
});
51+
ASSERT_TRUE(success) << "Timed out waiting for stylus gesture to be notified";
52+
ASSERT_EQ(deviceId, *mDeviceIdOfNotifiedStylusGesture);
53+
mDeviceIdOfNotifiedStylusGesture.reset();
4854
}
4955

5056
void FakeInputReaderPolicy::assertStylusGestureNotNotified() {
5157
std::scoped_lock lock(mLock);
52-
ASSERT_FALSE(mStylusGestureNotified);
58+
ASSERT_FALSE(mDeviceIdOfNotifiedStylusGesture);
5359
}
5460

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

259265
void FakeInputReaderPolicy::notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) {
260266
std::scoped_lock lock(mLock);
261-
mStylusGestureNotified = deviceId;
267+
mDeviceIdOfNotifiedStylusGesture = deviceId;
268+
mStylusGestureNotifiedCondition.notify_all();
262269
}
263270

264271
std::optional<DisplayViewport> FakeInputReaderPolicy::getPointerViewportForAssociatedDisplay(

services/inputflinger/tests/FakeInputReaderPolicy.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ class FakeInputReaderPolicy : public InputReaderPolicyInterface {
102102
bool mInputDevicesChanged GUARDED_BY(mLock){false};
103103
std::vector<DisplayViewport> mViewports;
104104
TouchAffineTransformation transform;
105-
std::optional<int32_t /*deviceId*/> mStylusGestureNotified GUARDED_BY(mLock){};
106105
bool mIsInputMethodConnectionActive{false};
107106

107+
std::condition_variable mStylusGestureNotifiedCondition;
108+
std::optional<DeviceId> mDeviceIdOfNotifiedStylusGesture GUARDED_BY(mLock){};
109+
108110
uint32_t mNextPointerCaptureSequenceNumber{0};
109111
};
110112

0 commit comments

Comments
 (0)