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
This commit is contained in:
Hsin-Yi Chen 2021-09-03 11:52:23 +08:00
parent 101c9db566
commit adac97fa08
2 changed files with 2 additions and 2 deletions

View file

@ -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;

View file

@ -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;