From adac97fa08e515d50f3205d0cde5bfa4dddd9423 Mon Sep 17 00:00:00 2001 From: Hsin-Yi Chen Date: Fri, 3 Sep 2021 11:52:23 +0800 Subject: [PATCH] Use CLOCK_BOOTTIME for default sensor implementation The sensor implementation used to generate periodic signals according to CLOCK_REALTIME. The clock can be adjusted by user or synchronization service and results in wrong period. This commit changes it to CLOCK_BOOTTIME which is monotonic. Test: atest VtsHalSensorsV2_0TargetTest Test: atest VtsHalSensorsV2_1TargetTest Test: atest CtsSensorTestCases Bug: 194030777 Change-Id: Iac39c93d6d2518b1abe8fc07fd695b9bb2cf30a5 --- sensors/common/default/2.X/Sensor.cpp | 2 +- .../common/default/2.X/multihal/tests/fake_subhal/Sensor.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sensors/common/default/2.X/Sensor.cpp b/sensors/common/default/2.X/Sensor.cpp index 1a7c62853f..23c98032d1 100644 --- a/sensors/common/default/2.X/Sensor.cpp +++ b/sensors/common/default/2.X/Sensor.cpp @@ -114,7 +114,7 @@ void Sensor::run() { }); } else { timespec curTime; - clock_gettime(CLOCK_REALTIME, &curTime); + clock_gettime(CLOCK_BOOTTIME, &curTime); int64_t now = (curTime.tv_sec * kNanosecondsInSeconds) + curTime.tv_nsec; int64_t nextSampleTime = mLastSampleTimeNs + mSamplingPeriodNs; diff --git a/sensors/common/default/2.X/multihal/tests/fake_subhal/Sensor.cpp b/sensors/common/default/2.X/multihal/tests/fake_subhal/Sensor.cpp index 69debb6885..f5745c5793 100644 --- a/sensors/common/default/2.X/multihal/tests/fake_subhal/Sensor.cpp +++ b/sensors/common/default/2.X/multihal/tests/fake_subhal/Sensor.cpp @@ -125,7 +125,7 @@ void Sensor::run() { }); } else { timespec curTime; - clock_gettime(CLOCK_REALTIME, &curTime); + clock_gettime(CLOCK_BOOTTIME, &curTime); int64_t now = (curTime.tv_sec * kNanosecondsInSeconds) + curTime.tv_nsec; int64_t nextSampleTime = mLastSampleTimeNs + mSamplingPeriodNs;