Loading services/inputflinger/tests/FakeInputReaderPolicy.cpp +17 −13 Original line number Diff line number Diff line Loading @@ -32,19 +32,23 @@ static const int HW_TIMEOUT_MULTIPLIER = base::GetIntProperty("ro.hw_timeout_mul } // namespace void FakeInputReaderPolicy::assertInputDevicesChanged() { waitForInputDevices([](bool devicesChanged) { waitForInputDevices( [](bool devicesChanged) { if (!devicesChanged) { FAIL() << "Timed out waiting for notifyInputDevicesChanged() to be called."; } }); }, ADD_INPUT_DEVICE_TIMEOUT); } void FakeInputReaderPolicy::assertInputDevicesNotChanged() { waitForInputDevices([](bool devicesChanged) { waitForInputDevices( [](bool devicesChanged) { if (devicesChanged) { FAIL() << "Expected notifyInputDevicesChanged() to not be called."; } }); }, INPUT_DEVICES_DIDNT_CHANGE_TIMEOUT); } void FakeInputReaderPolicy::assertStylusGestureNotified(int32_t deviceId) { Loading Loading @@ -261,13 +265,13 @@ std::string FakeInputReaderPolicy::getDeviceAlias(const InputDeviceIdentifier&) return ""; } void FakeInputReaderPolicy::waitForInputDevices(std::function<void(bool)> processDevicesChanged) { void FakeInputReaderPolicy::waitForInputDevices(std::function<void(bool)> processDevicesChanged, std::chrono::milliseconds timeout) { std::unique_lock<std::mutex> lock(mLock); base::ScopedLockAssertion assumeLocked(mLock); const bool devicesChanged = mDevicesChangedCondition.wait_for(lock, ADD_INPUT_DEVICE_TIMEOUT * HW_TIMEOUT_MULTIPLIER, mDevicesChangedCondition.wait_for(lock, timeout * HW_TIMEOUT_MULTIPLIER, [this]() REQUIRES(mLock) { return mInputDevicesChanged; }); Loading services/inputflinger/tests/FakeInputReaderPolicy.h +2 −1 Original line number Diff line number Diff line Loading @@ -88,7 +88,8 @@ private: std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay( const InputDeviceIdentifier&, const std::optional<KeyboardLayoutInfo>) override; std::string getDeviceAlias(const InputDeviceIdentifier&) override; void waitForInputDevices(std::function<void(bool)> processDevicesChanged); void waitForInputDevices(std::function<void(bool)> processDevicesChanged, std::chrono::milliseconds timeout); void notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) override; mutable std::mutex mLock; Loading services/inputflinger/tests/TestConstants.h +4 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,10 @@ namespace android { using std::chrono_literals::operator""ms; // Timeout for waiting for an input device to be added and processed static constexpr std::chrono::duration ADD_INPUT_DEVICE_TIMEOUT = 500ms; static constexpr std::chrono::duration ADD_INPUT_DEVICE_TIMEOUT = 5000ms; // Timeout for asserting that an input device change did not occur static constexpr std::chrono::duration INPUT_DEVICES_DIDNT_CHANGE_TIMEOUT = 100ms; // Timeout for waiting for an expected event static constexpr std::chrono::duration WAIT_TIMEOUT = 100ms; Loading Loading
services/inputflinger/tests/FakeInputReaderPolicy.cpp +17 −13 Original line number Diff line number Diff line Loading @@ -32,19 +32,23 @@ static const int HW_TIMEOUT_MULTIPLIER = base::GetIntProperty("ro.hw_timeout_mul } // namespace void FakeInputReaderPolicy::assertInputDevicesChanged() { waitForInputDevices([](bool devicesChanged) { waitForInputDevices( [](bool devicesChanged) { if (!devicesChanged) { FAIL() << "Timed out waiting for notifyInputDevicesChanged() to be called."; } }); }, ADD_INPUT_DEVICE_TIMEOUT); } void FakeInputReaderPolicy::assertInputDevicesNotChanged() { waitForInputDevices([](bool devicesChanged) { waitForInputDevices( [](bool devicesChanged) { if (devicesChanged) { FAIL() << "Expected notifyInputDevicesChanged() to not be called."; } }); }, INPUT_DEVICES_DIDNT_CHANGE_TIMEOUT); } void FakeInputReaderPolicy::assertStylusGestureNotified(int32_t deviceId) { Loading Loading @@ -261,13 +265,13 @@ std::string FakeInputReaderPolicy::getDeviceAlias(const InputDeviceIdentifier&) return ""; } void FakeInputReaderPolicy::waitForInputDevices(std::function<void(bool)> processDevicesChanged) { void FakeInputReaderPolicy::waitForInputDevices(std::function<void(bool)> processDevicesChanged, std::chrono::milliseconds timeout) { std::unique_lock<std::mutex> lock(mLock); base::ScopedLockAssertion assumeLocked(mLock); const bool devicesChanged = mDevicesChangedCondition.wait_for(lock, ADD_INPUT_DEVICE_TIMEOUT * HW_TIMEOUT_MULTIPLIER, mDevicesChangedCondition.wait_for(lock, timeout * HW_TIMEOUT_MULTIPLIER, [this]() REQUIRES(mLock) { return mInputDevicesChanged; }); Loading
services/inputflinger/tests/FakeInputReaderPolicy.h +2 −1 Original line number Diff line number Diff line Loading @@ -88,7 +88,8 @@ private: std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay( const InputDeviceIdentifier&, const std::optional<KeyboardLayoutInfo>) override; std::string getDeviceAlias(const InputDeviceIdentifier&) override; void waitForInputDevices(std::function<void(bool)> processDevicesChanged); void waitForInputDevices(std::function<void(bool)> processDevicesChanged, std::chrono::milliseconds timeout); void notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) override; mutable std::mutex mLock; Loading
services/inputflinger/tests/TestConstants.h +4 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,10 @@ namespace android { using std::chrono_literals::operator""ms; // Timeout for waiting for an input device to be added and processed static constexpr std::chrono::duration ADD_INPUT_DEVICE_TIMEOUT = 500ms; static constexpr std::chrono::duration ADD_INPUT_DEVICE_TIMEOUT = 5000ms; // Timeout for asserting that an input device change did not occur static constexpr std::chrono::duration INPUT_DEVICES_DIDNT_CHANGE_TIMEOUT = 100ms; // Timeout for waiting for an expected event static constexpr std::chrono::duration WAIT_TIMEOUT = 100ms; Loading