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

Commit 619fb805 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Improved timekeeping logic for USAP Pool refill mechanism. am: d8ef1169 am: c57c1c33

Change-Id: Idd8eb17a943cff74c68ecc2d0d10c7d8d17ef197
parents ff624af5 c57c1c33
Loading
Loading
Loading
Loading
+10 −3
Original line number Original line Diff line number Diff line
@@ -490,16 +490,23 @@ class ZygoteServer {
            if (mUsapPoolRefillTriggerTimestamp == INVALID_TIMESTAMP) {
            if (mUsapPoolRefillTriggerTimestamp == INVALID_TIMESTAMP) {
                pollTimeoutMs = -1;
                pollTimeoutMs = -1;
            } else {
            } else {
                int elapsedTimeMs =
                long elapsedTimeMs = System.currentTimeMillis() - mUsapPoolRefillTriggerTimestamp;
                        (int) (System.currentTimeMillis() - mUsapPoolRefillTriggerTimestamp);


                if (elapsedTimeMs >= mUsapPoolRefillDelayMs) {
                if (elapsedTimeMs >= mUsapPoolRefillDelayMs) {
                    // Normalize the poll timeout value when the time between one poll event and the
                    // Normalize the poll timeout value when the time between one poll event and the
                    // next pushes us over the delay value.  This prevents poll receiving a 0
                    // next pushes us over the delay value.  This prevents poll receiving a 0
                    // timeout value, which would result in it returning immediately.
                    // timeout value, which would result in it returning immediately.
                    pollTimeoutMs = -1;
                    pollTimeoutMs = -1;

                } else if (elapsedTimeMs <= 0) {
                    // This can occur if the clock used by currentTimeMillis is reset, which is
                    // possible because it is not guaranteed to be monotonic.  Because we can't tell
                    // how far back the clock was set the best way to recover is to simply re-start
                    // the respawn delay countdown.
                    pollTimeoutMs = mUsapPoolRefillDelayMs;

                } else {
                } else {
                    pollTimeoutMs = mUsapPoolRefillDelayMs - elapsedTimeMs;
                    pollTimeoutMs = (int) (mUsapPoolRefillDelayMs - elapsedTimeMs);
                }
                }
            }
            }