Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5e508737 authored by Yu Shan's avatar Yu Shan
Browse files

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
parent 848fcb49
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -50,7 +50,7 @@ void RecurrentTimer::registerTimerCallback(int64_t intervalInNano,
        std::scoped_lock<std::mutex> lockGuard(mLock);
        std::scoped_lock<std::mutex> lockGuard(mLock);


        // Aligns the nextTime to multiply of interval.
        // 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>();
        std::unique_ptr<CallbackInfo> info = std::make_unique<CallbackInfo>();
        info->callback = callback;
        info->callback = callback;
@@ -130,7 +130,7 @@ void RecurrentTimer::loop() {
            }
            }
            // The first element is the nearest next event.
            // The first element is the nearest next event.
            int64_t nextTime = mCallbackQueue[0]->nextTime;
            int64_t nextTime = mCallbackQueue[0]->nextTime;
            int64_t now = elapsedRealtimeNano();
            int64_t now = uptimeNanos();
            if (nextTime > now) {
            if (nextTime > now) {
                interval = nextTime - now;
                interval = nextTime - now;
            } else {
            } else {
@@ -148,7 +148,7 @@ void RecurrentTimer::loop() {


        {
        {
            ScopedLockAssertion lockAssertion(mLock);
            ScopedLockAssertion lockAssertion(mLock);
            int64_t now = elapsedRealtimeNano();
            int64_t now = uptimeNanos();
            while (mCallbackQueue.size() > 0) {
            while (mCallbackQueue.size() > 0) {
                int64_t nextTime = mCallbackQueue[0]->nextTime;
                int64_t nextTime = mCallbackQueue[0]->nextTime;
                if (nextTime > now) {
                if (nextTime > now) {