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

Commit 8dee4f7c authored by James Lemieux's avatar James Lemieux Committed by Android (Google) Code Review
Browse files

Merge "Avoid applying negative time deltas - DO NOT MERGE" into ub-deskclock-gatling

parents 3127a152 528d8d90
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static com.android.deskclock.Utils.wallClock;
import static com.android.deskclock.data.Stopwatch.State.PAUSED;
import static com.android.deskclock.data.Stopwatch.State.RESET;
import static com.android.deskclock.data.Stopwatch.State.RUNNING;
import static com.android.deskclock.provider.ClockContract.AUTHORITY;

/**
 * A read-only domain object representing a stopwatch.
@@ -118,7 +117,9 @@ public final class Stopwatch {
        }
        final long timeSinceBoot = now();
        final long wallClockTime = wallClock();
        final long delta = wallClockTime - mLastStartWallClockTime;
        // Avoid negative time deltas. They can happen in practice, but they can't be used. Simply
        // update the recorded times and proceed with no change in accumulated time.
        final long delta = Math.max(0, wallClockTime - mLastStartWallClockTime);
        return new Stopwatch(mState, timeSinceBoot, wallClockTime, mAccumulatedTime + delta);
    }

@@ -130,6 +131,9 @@ public final class Stopwatch {
        final long wallClockTime = wallClock();
        final long delta = timeSinceBoot - mLastStartTime;
        if (delta < 0) {
            // Avoid negative time deltas. They typically happen following reboots when TIME_SET is
            // broadcast before BOOT_COMPLETED. Simply ignore the time update and hope
            // updateAfterReboot() can successfully correct the data at a later time.
            return this;
        }
        return new Stopwatch(mState, timeSinceBoot, wallClockTime, mAccumulatedTime + delta);
+6 −1
Original line number Diff line number Diff line
@@ -258,7 +258,9 @@ public final class Timer {

        final long timeSinceBoot = now();
        final long wallClockTime = wallClock();
        final long delta = wallClockTime - mLastStartWallClockTime;
        // Avoid negative time deltas. They can happen in practice, but they can't be used. Simply
        // update the recorded times and proceed with no change in accumulated time.
        final long delta = Math.max(0, wallClockTime - mLastStartWallClockTime);
        final long remainingTime = mRemainingTime - delta;
        return new Timer(mId, mState, mLength, mTotalLength, timeSinceBoot, wallClockTime,
                remainingTime, mLabel, mDeleteAfterUse);
@@ -277,6 +279,9 @@ public final class Timer {
        final long delta = timeSinceBoot - mLastStartTime;
        final long remainingTime = mRemainingTime - delta;
        if (delta < 0) {
            // Avoid negative time deltas. They typically happen following reboots when TIME_SET is
            // broadcast before BOOT_COMPLETED. Simply ignore the time update and hope
            // updateAfterReboot() can successfully correct the data at a later time.
            return this;
        }
        return new Timer(mId, mState, mLength, mTotalLength, timeSinceBoot, wallClockTime,