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

Commit 4a368659 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "Fix issue #22414729: Checkin start clock time is different from hsitory...

Merge "Fix issue #22414729: Checkin start clock time is different from hsitory reset time" into mnc-dev
parents f2170644 d48954fb
Loading
Loading
Loading
Loading
+17 −15
Original line number Diff line number Diff line
@@ -2560,14 +2560,24 @@ public final class BatteryStatsImpl extends BatteryStats {
        addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid);
    }

    boolean ensureStartClockTime(final long currentTime) {
        final long ABOUT_ONE_YEAR = 365*24*60*60*1000L;
        if (currentTime > ABOUT_ONE_YEAR && mStartClockTime < (currentTime-ABOUT_ONE_YEAR)) {
            // If the start clock time has changed by more than a year, then presumably
            // the previous time was completely bogus.  So we are going to figure out a
            // new time based on how much time has elapsed since we started counting.
            mStartClockTime = currentTime - (SystemClock.elapsedRealtime()-(mRealtimeStart/1000));
            return true;
        }
        return false;
    }

    public void noteCurrentTimeChangedLocked() {
        final long currentTime = System.currentTimeMillis();
        final long elapsedRealtime = SystemClock.elapsedRealtime();
        final long uptime = SystemClock.uptimeMillis();
        recordCurrentTimeChangeLocked(currentTime, elapsedRealtime, uptime);
        if (isStartClockTimeValid()) {
            mStartClockTime = currentTime;
        }
        ensureStartClockTime(currentTime);
    }

    public void noteProcessStartLocked(String name, int uid) {
@@ -4306,20 +4316,12 @@ public final class BatteryStatsImpl extends BatteryStats {
        }
    }

    boolean isStartClockTimeValid() {
        return mStartClockTime > 365*24*60*60*1000L;
    }

    @Override public long getStartClockTime() {
        if (!isStartClockTimeValid()) {
            // If the last clock time we got was very small, then we hadn't had a real
            // time yet, so try to get it again.
            mStartClockTime = System.currentTimeMillis();
            if (isStartClockTimeValid()) {
                recordCurrentTimeChangeLocked(mStartClockTime, SystemClock.elapsedRealtime(),
        final long currentTime = System.currentTimeMillis();
        if (ensureStartClockTime(currentTime)) {
            recordCurrentTimeChangeLocked(currentTime, SystemClock.elapsedRealtime(),
                    SystemClock.uptimeMillis());
        }
        }
        return mStartClockTime;
    }