Use a different timesource in recurrent timer.
Previously we used elapsedRealtimeNanos in recurrent timer which will still go even if the system is in deep sleep. This causes all the events "happened" during suspension to be replayed immediately after the wake up, which causes a spam of messages. uptimeNanos meanwhile, does not go if the system is in sleep, so we use that instead. Test: atest VehicleHalVehicleUtilsTest Bug: 235262127 Change-Id: Ib67c2e2251af3231cefd875416d5bcb15953ba5e
This commit is contained in:
parent
848fcb49b4
commit
5e50873793
1 changed files with 3 additions and 3 deletions
|
@ -50,7 +50,7 @@ void RecurrentTimer::registerTimerCallback(int64_t intervalInNano,
|
|||
std::scoped_lock<std::mutex> lockGuard(mLock);
|
||||
|
||||
// Aligns the nextTime to multiply of interval.
|
||||
int64_t nextTime = ceil(elapsedRealtimeNano() / intervalInNano) * intervalInNano;
|
||||
int64_t nextTime = ceil(uptimeNanos() / intervalInNano) * intervalInNano;
|
||||
|
||||
std::unique_ptr<CallbackInfo> info = std::make_unique<CallbackInfo>();
|
||||
info->callback = callback;
|
||||
|
@ -130,7 +130,7 @@ void RecurrentTimer::loop() {
|
|||
}
|
||||
// The first element is the nearest next event.
|
||||
int64_t nextTime = mCallbackQueue[0]->nextTime;
|
||||
int64_t now = elapsedRealtimeNano();
|
||||
int64_t now = uptimeNanos();
|
||||
if (nextTime > now) {
|
||||
interval = nextTime - now;
|
||||
} else {
|
||||
|
@ -148,7 +148,7 @@ void RecurrentTimer::loop() {
|
|||
|
||||
{
|
||||
ScopedLockAssertion lockAssertion(mLock);
|
||||
int64_t now = elapsedRealtimeNano();
|
||||
int64_t now = uptimeNanos();
|
||||
while (mCallbackQueue.size() > 0) {
|
||||
int64_t nextTime = mCallbackQueue[0]->nextTime;
|
||||
if (nextTime > now) {
|
||||
|
|
Loading…
Reference in a new issue