Use <chrono> for input-related timeouts
There is a lot of confusion in input tests about the units used for the
timeouts. In a lot of cases, the timeouts are set too short, which
causes failures when they start getting enforced. To avoid this, use
std::chrono::duration for the timeouts.
Ideally, we should convert InputWindowInfo and InputApplicationInfo to
use std::chrono::nanoseconds, but that would be a larger change reserved
for a future release.
Bug: 143459140
Test: atest inputflinger_tests libinput_tests inputflinger_benchmarks
Change-Id: Ie7536e8a042a71b372f03314501e0d635a6ac1d4
diff --git a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp
index 7c5c9c5..2116cbc 100644
--- a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp
+++ b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp
@@ -28,8 +28,8 @@
static const int32_t INJECTOR_PID = 999;
static const int32_t INJECTOR_UID = 1001;
-static const int32_t INJECT_EVENT_TIMEOUT = 5000;
-static const int32_t DISPATCHING_TIMEOUT = 100000;
+static constexpr std::chrono::duration INJECT_EVENT_TIMEOUT = 5s;
+static constexpr std::chrono::nanoseconds DISPATCHING_TIMEOUT = 100ms;
static nsecs_t now() {
return systemTime(SYSTEM_TIME_MONOTONIC);
@@ -98,7 +98,7 @@
virtual ~FakeApplicationHandle() {}
virtual bool updateInfo() {
- mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT;
+ mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT.count();
return true;
}
};
@@ -163,7 +163,7 @@
mInfo.name = "FakeWindowHandle";
mInfo.layoutParamsFlags = 0;
mInfo.layoutParamsType = InputWindowInfo::TYPE_APPLICATION;
- mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT;
+ mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT.count();
mInfo.frameLeft = mFrame.left;
mInfo.frameTop = mFrame.top;
mInfo.frameRight = mFrame.right;