Skip to content

Commit 7b1e9ae

Browse files
Treehugger RobotAndroid (Google) Code Review
authored andcommitted
Merge "InputReader_test: Wait for stylus gesture to be notified" into main
2 parents 9de2d94 + 40aee53 commit 7b1e9ae

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)