From d378715deec70cd8628dd9b41a206912d1380c50 Mon Sep 17 00:00:00 2001 From: Dmitri Plotnikov Date: Wed, 21 Jul 2021 21:14:45 -0700 Subject: [PATCH] Fix KernelCpuUidUserSysTimeReaderTest#testThrottler by injecting a mock clock Bug: 180015146 Bug: 180473895 Test: atest FrameworksCoreTests:KernelCpuUidUserSysTimeReaderTest#testThrottler Change-Id: I441646b4d5817b62c34bea9cccf0a5a13901736b --- .../android/internal/os/BatteryStatsImpl.java | 835 +++++++++--------- .../os/BatteryUsageStatsProvider.java | 6 +- core/java/com/android/internal/os/Clock.java | 57 ++ .../os/KernelCpuProcStringReader.java | 11 +- .../internal/os/KernelCpuUidTimeReader.java | 75 +- .../os/BatteryStatsBackgroundStatsTest.java | 12 +- .../os/BatteryStatsBinderCallStatsTest.java | 4 +- .../internal/os/BatteryStatsCounterTest.java | 4 +- .../internal/os/BatteryStatsCpuTimesTest.java | 4 +- .../os/BatteryStatsDualTimerTest.java | 2 +- .../os/BatteryStatsDurationTimerTest.java | 8 +- .../internal/os/BatteryStatsNoteTest.java | 32 +- .../os/BatteryStatsSamplingTimerTest.java | 8 +- .../internal/os/BatteryStatsSensorTest.java | 16 +- .../os/BatteryStatsStopwatchTimerTest.java | 4 +- .../internal/os/BatteryStatsTimerTest.java | 27 +- .../internal/os/BatteryStatsUidTest.java | 2 +- .../internal/os/BatteryUsageStatsRule.java | 14 +- .../os/BatteryUsageStatsStoreTest.java | 26 +- .../internal/os/BatteryUsageStatsTest.java | 4 +- .../os/KernelCpuUidUserSysTimeReaderTest.java | 22 +- .../internal/os/MockBatteryStatsImpl.java | 10 +- .../os/{MockClocks.java => MockClock.java} | 2 +- 23 files changed, 624 insertions(+), 561 deletions(-) create mode 100644 core/java/com/android/internal/os/Clock.java rename core/tests/coretests/src/com/android/internal/os/{MockClocks.java => MockClock.java} (94%) diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java index 434f617d4619f..40430605f186c 100644 --- a/core/java/com/android/internal/os/BatteryStatsImpl.java +++ b/core/java/com/android/internal/os/BatteryStatsImpl.java @@ -196,7 +196,7 @@ public class BatteryStatsImpl extends BatteryStats { public static final int RESET_REASON_FULL_CHARGE = 3; public static final int RESET_REASON_MEASURED_ENERGY_BUCKETS_CHANGE = 4; - protected Clocks mClocks; + protected Clock mClock; private final AtomicFile mStatsFile; public final AtomicFile mCheckinFile; @@ -215,19 +215,15 @@ public class BatteryStatsImpl extends BatteryStats { private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats(); @VisibleForTesting - protected KernelCpuUidUserSysTimeReader mCpuUidUserSysTimeReader = - new KernelCpuUidUserSysTimeReader(true); + protected KernelCpuUidUserSysTimeReader mCpuUidUserSysTimeReader; @VisibleForTesting protected KernelCpuSpeedReader[] mKernelCpuSpeedReaders; @VisibleForTesting - protected KernelCpuUidFreqTimeReader mCpuUidFreqTimeReader = - new KernelCpuUidFreqTimeReader(true); + protected KernelCpuUidFreqTimeReader mCpuUidFreqTimeReader; @VisibleForTesting - protected KernelCpuUidActiveTimeReader mCpuUidActiveTimeReader = - new KernelCpuUidActiveTimeReader(true); + protected KernelCpuUidActiveTimeReader mCpuUidActiveTimeReader; @VisibleForTesting - protected KernelCpuUidClusterTimeReader mCpuUidClusterTimeReader = - new KernelCpuUidClusterTimeReader(true); + protected KernelCpuUidClusterTimeReader mCpuUidClusterTimeReader; @VisibleForTesting protected KernelSingleUidTimeReader mKernelSingleUidTimeReader; @VisibleForTesting @@ -387,8 +383,8 @@ public class BatteryStatsImpl extends BatteryStats { } boolean changed = setChargingLocked(true); if (changed) { - final long uptimeMs = mClocks.uptimeMillis(); - final long elapsedRealtimeMs = mClocks.elapsedRealtime(); + final long uptimeMs = mClock.uptimeMillis(); + final long elapsedRealtimeMs = mClock.elapsedRealtime(); addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); } } @@ -512,7 +508,7 @@ public class BatteryStatsImpl extends BatteryStats { */ @GuardedBy("this") public void clearPendingRemovedUidsLocked() { - long cutOffTimeMs = mClocks.elapsedRealtime() - mConstants.UID_REMOVE_DELAY_MS; + long cutOffTimeMs = mClock.elapsedRealtime() - mConstants.UID_REMOVE_DELAY_MS; while (!mPendingRemovedUids.isEmpty() && mPendingRemovedUids.peek().getUidRemovalTimestamp() < cutOffTimeMs) { mPendingRemovedUids.poll().removeLocked(); @@ -613,35 +609,6 @@ public class BatteryStatsImpl extends BatteryStats { return true; } - public interface Clocks { - /** Elapsed Realtime, see SystemClock.elapsedRealtime() */ - long elapsedRealtime(); - - /** Uptime, see SystemClock.uptimeMillis() */ - long uptimeMillis(); - - /** Wall-clock time as per System.currentTimeMillis() */ - long currentTimeMillis(); - } - - public static class SystemClocks implements Clocks { - - @Override - public long elapsedRealtime() { - return SystemClock.elapsedRealtime(); - } - - @Override - public long uptimeMillis() { - return SystemClock.uptimeMillis(); - } - - @Override - public long currentTimeMillis() { - return System.currentTimeMillis(); - } - } - public interface ExternalStatsSync { int UPDATE_CPU = 0x01; int UPDATE_WIFI = 0x02; @@ -1180,12 +1147,12 @@ public class BatteryStatsImpl extends BatteryStats { } public BatteryStatsImpl() { - this(new SystemClocks()); + this(Clock.SYSTEM_CLOCK); } - public BatteryStatsImpl(Clocks clocks) { - init(clocks); - mStartClockTimeMs = clocks.currentTimeMillis(); + public BatteryStatsImpl(Clock clock) { + init(clock); + mStartClockTimeMs = clock.currentTimeMillis(); mStatsFile = null; mCheckinFile = null; mDailyFile = null; @@ -1198,8 +1165,12 @@ public class BatteryStatsImpl extends BatteryStats { clearHistoryLocked(); } - private void init(Clocks clocks) { - mClocks = clocks; + private void init(Clock clock) { + mClock = clock; + mCpuUidUserSysTimeReader = new KernelCpuUidUserSysTimeReader(true, clock); + mCpuUidFreqTimeReader = new KernelCpuUidFreqTimeReader(true, clock); + mCpuUidActiveTimeReader = new KernelCpuUidActiveTimeReader(true, clock); + mCpuUidClusterTimeReader = new KernelCpuUidClusterTimeReader(true, clock); } /** @@ -1755,7 +1726,7 @@ public class BatteryStatsImpl extends BatteryStats { * State for keeping track of timing information. */ public static abstract class Timer extends BatteryStats.Timer implements TimeBaseObs { - protected final Clocks mClocks; + protected final Clock mClock; protected final int mType; protected final TimeBase mTimeBase; @@ -1783,8 +1754,8 @@ public class BatteryStatsImpl extends BatteryStats { * @param timeBase * @param in */ - public Timer(Clocks clocks, int type, TimeBase timeBase, Parcel in) { - mClocks = clocks; + public Timer(Clock clock, int type, TimeBase timeBase, Parcel in) { + mClock = clock; mType = type; mTimeBase = timeBase; @@ -1795,8 +1766,8 @@ public class BatteryStatsImpl extends BatteryStats { if (DEBUG) Log.i(TAG, "**** READ TIMER #" + mType + ": mTotalTime=" + mTotalTimeUs); } - public Timer(Clocks clocks, int type, TimeBase timeBase) { - mClocks = clocks; + public Timer(Clock clock, int type, TimeBase timeBase) { + mClock = clock; mType = type; mTimeBase = timeBase; timeBase.add(this); @@ -1825,7 +1796,7 @@ public class BatteryStatsImpl extends BatteryStats { */ @Override public boolean reset(boolean detachIfReset) { - return reset(detachIfReset, mClocks.elapsedRealtime() * 1000); + return reset(detachIfReset, mClock.elapsedRealtime() * 1000); } @Override @@ -1971,8 +1942,8 @@ public class BatteryStatsImpl extends BatteryStats { int mUpdateVersion; @VisibleForTesting - public SamplingTimer(Clocks clocks, TimeBase timeBase, Parcel in) { - super(clocks, 0, timeBase, in); + public SamplingTimer(Clock clock, TimeBase timeBase, Parcel in) { + super(clock, 0, timeBase, in); mCurrentReportedCount = in.readInt(); mUnpluggedReportedCount = in.readInt(); mCurrentReportedTotalTimeUs = in.readLong(); @@ -1982,8 +1953,8 @@ public class BatteryStatsImpl extends BatteryStats { } @VisibleForTesting - public SamplingTimer(Clocks clocks, TimeBase timeBase) { - super(clocks, 0, timeBase); + public SamplingTimer(Clock clock, TimeBase timeBase) { + super(clock, 0, timeBase); mTrackingReportedValues = false; mTimeBaseRunning = timeBase.isRunning(); } @@ -1993,7 +1964,7 @@ public class BatteryStatsImpl extends BatteryStats { * be less than the values used for a previous invocation. */ public void endSample() { - endSample(mClocks.elapsedRealtime() * 1000); + endSample(mClock.elapsedRealtime() * 1000); } /** @@ -2028,7 +1999,7 @@ public class BatteryStatsImpl extends BatteryStats { * @param count total number of times the event being sampled occurred. */ public void updated(long totalTimeUs, int count) { - update(totalTimeUs, count, mClocks.elapsedRealtime() * 1000); + update(totalTimeUs, count, mClock.elapsedRealtime() * 1000); } /** @@ -2058,7 +2029,7 @@ public class BatteryStatsImpl extends BatteryStats { * @param deltaCount additional number of times the event being sampled occurred. */ public void add(long deltaTimeUs, int deltaCount) { - add(deltaTimeUs, deltaCount, mClocks.elapsedRealtime() * 1000); + add(deltaTimeUs, deltaCount, mClock.elapsedRealtime() * 1000); } /** @@ -2148,16 +2119,16 @@ public class BatteryStatsImpl extends BatteryStats { */ boolean mInDischarge; - BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase, Parcel in) { - super(clocks, type, timeBase, in); + BatchTimer(Clock clock, Uid uid, int type, TimeBase timeBase, Parcel in) { + super(clock, type, timeBase, in); mUid = uid; mLastAddedTimeUs = in.readLong(); mLastAddedDurationUs = in.readLong(); mInDischarge = timeBase.isRunning(); } - BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase) { - super(clocks, type, timeBase); + BatchTimer(Clock clock, Uid uid, int type, TimeBase timeBase) { + super(clock, type, timeBase); mUid = uid; mInDischarge = timeBase.isRunning(); } @@ -2220,7 +2191,7 @@ public class BatteryStatsImpl extends BatteryStats { } public void addDuration(BatteryStatsImpl stats, long durationMs) { - addDuration(stats, durationMs, mClocks.elapsedRealtime()); + addDuration(stats, durationMs, mClock.elapsedRealtime()); } public void addDuration(BatteryStatsImpl stats, long durationMs, long elapsedRealtimeMs) { @@ -2235,7 +2206,7 @@ public class BatteryStatsImpl extends BatteryStats { } public void abortLastDuration(BatteryStatsImpl stats) { - abortLastDuration(stats, mClocks.elapsedRealtime()); + abortLastDuration(stats, mClock.elapsedRealtime()); } public void abortLastDuration(BatteryStatsImpl stats, long elapsedRealtimeMs) { @@ -2303,17 +2274,17 @@ public class BatteryStatsImpl extends BatteryStats { */ long mTotalDurationMs; - public DurationTimer(Clocks clocks, Uid uid, int type, ArrayList timerPool, + public DurationTimer(Clock clock, Uid uid, int type, ArrayList timerPool, TimeBase timeBase, Parcel in) { - super(clocks, uid, type, timerPool, timeBase, in); + super(clock, uid, type, timerPool, timeBase, in); mMaxDurationMs = in.readLong(); mTotalDurationMs = in.readLong(); mCurrentDurationMs = in.readLong(); } - public DurationTimer(Clocks clocks, Uid uid, int type, ArrayList timerPool, + public DurationTimer(Clock clock, Uid uid, int type, ArrayList timerPool, TimeBase timeBase) { - super(clocks, uid, type, timerPool, timeBase); + super(clock, uid, type, timerPool, timeBase); } @Override @@ -2514,17 +2485,17 @@ public class BatteryStatsImpl extends BatteryStats { @VisibleForTesting public boolean mInList; - public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList timerPool, + public StopwatchTimer(Clock clock, Uid uid, int type, ArrayList timerPool, TimeBase timeBase, Parcel in) { - super(clocks, type, timeBase, in); + super(clock, type, timeBase, in); mUid = uid; mTimerPool = timerPool; mUpdateTimeUs = in.readLong(); } - public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList timerPool, + public StopwatchTimer(Clock clock, Uid uid, int type, ArrayList timerPool, TimeBase timeBase) { - super(clocks, type, timeBase); + super(clock, type, timeBase); mUid = uid; mTimerPool = timerPool; } @@ -2732,10 +2703,10 @@ public class BatteryStatsImpl extends BatteryStats { * The mSubTimer is based on the given subTimeBase. The mSubTimer is not pooled, even if * the main timer is. */ - public DualTimer(Clocks clocks, Uid uid, int type, ArrayList timerPool, + public DualTimer(Clock clock, Uid uid, int type, ArrayList timerPool, TimeBase timeBase, TimeBase subTimeBase, Parcel in) { - super(clocks, uid, type, timerPool, timeBase, in); - mSubTimer = new DurationTimer(clocks, uid, type, null, subTimeBase, in); + super(clock, uid, type, timerPool, timeBase, in); + mSubTimer = new DurationTimer(clock, uid, type, null, subTimeBase, in); } /** @@ -2744,10 +2715,10 @@ public class BatteryStatsImpl extends BatteryStats { * The mSubTimer is based on the given subTimeBase. The mSubTimer is not pooled, even if * the main timer is. */ - public DualTimer(Clocks clocks, Uid uid, int type, ArrayList timerPool, + public DualTimer(Clock clock, Uid uid, int type, ArrayList timerPool, TimeBase timeBase, TimeBase subTimeBase) { - super(clocks, uid, type, timerPool, timeBase); - mSubTimer = new DurationTimer(clocks, uid, type, null, subTimeBase); + super(clock, uid, type, timerPool, timeBase); + mSubTimer = new DurationTimer(clock, uid, type, null, subTimeBase); } /** Get the secondary timer. */ @@ -3168,7 +3139,7 @@ public class BatteryStatsImpl extends BatteryStats { public SamplingTimer getRpmTimerLocked(String name) { SamplingTimer rpmt = mRpmStats.get(name); if (rpmt == null) { - rpmt = new SamplingTimer(mClocks, mOnBatteryTimeBase); + rpmt = new SamplingTimer(mClock, mOnBatteryTimeBase); mRpmStats.put(name, rpmt); } return rpmt; @@ -3178,7 +3149,7 @@ public class BatteryStatsImpl extends BatteryStats { public SamplingTimer getScreenOffRpmTimerLocked(String name) { SamplingTimer rpmt = mScreenOffRpmStats.get(name); if (rpmt == null) { - rpmt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); + rpmt = new SamplingTimer(mClock, mOnBatteryScreenOffTimeBase); mScreenOffRpmStats.put(name, rpmt); } return rpmt; @@ -3191,7 +3162,7 @@ public class BatteryStatsImpl extends BatteryStats { public SamplingTimer getWakeupReasonTimerLocked(String name) { SamplingTimer timer = mWakeupReasonStats.get(name); if (timer == null) { - timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); + timer = new SamplingTimer(mClock, mOnBatteryTimeBase); mWakeupReasonStats.put(name, timer); } return timer; @@ -3204,7 +3175,7 @@ public class BatteryStatsImpl extends BatteryStats { public SamplingTimer getKernelWakelockTimerLocked(String name) { SamplingTimer kwlt = mKernelWakelockStats.get(name); if (kwlt == null) { - kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); + kwlt = new SamplingTimer(mClock, mOnBatteryScreenOffTimeBase); mKernelWakelockStats.put(name, kwlt); } return kwlt; @@ -3213,7 +3184,7 @@ public class BatteryStatsImpl extends BatteryStats { public SamplingTimer getKernelMemoryTimerLocked(long bucket) { SamplingTimer kmt = mKernelMemoryStats.get(bucket); if (kmt == null) { - kmt = new SamplingTimer(mClocks, mOnBatteryTimeBase); + kmt = new SamplingTimer(mClock, mOnBatteryTimeBase); mKernelMemoryStats.put(bucket, kmt); } return kmt; @@ -3618,8 +3589,8 @@ public class BatteryStatsImpl extends BatteryStats { } public void createFakeHistoryEvents(long numEvents) { - final long elapsedRealtimeMs = mClocks.elapsedRealtime(); - final long uptimeMs = mClocks.uptimeMillis(); + final long elapsedRealtimeMs = mClock.elapsedRealtime(); + final long uptimeMs = mClock.uptimeMillis(); for(long i = 0; i < numEvents; i++) { noteLongPartialWakelockStart("name1", "historyName1", 1000, elapsedRealtimeMs, uptimeMs); @@ -3716,7 +3687,7 @@ public class BatteryStatsImpl extends BatteryStats { if (dataSize == 0) { // The history is currently empty; we need it to start with a time stamp. - cur.currentTime = mClocks.currentTimeMillis(); + cur.currentTime = mClock.currentTimeMillis(); addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_RESET, cur); } addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE, cur); @@ -3878,7 +3849,7 @@ public class BatteryStatsImpl extends BatteryStats { public void addIsolatedUidLocked(int isolatedUid, int appUid) { addIsolatedUidLocked(isolatedUid, appUid, - mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + mClock.elapsedRealtime(), mClock.uptimeMillis()); } public void addIsolatedUidLocked(int isolatedUid, int appUid, @@ -3923,7 +3894,7 @@ public class BatteryStatsImpl extends BatteryStats { } public void noteEventLocked(int code, String name, int uid) { - noteEventLocked(code, name, uid, mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + noteEventLocked(code, name, uid, mClock.elapsedRealtime(), mClock.uptimeMillis()); } public void noteEventLocked(int code, String name, int uid, @@ -3936,9 +3907,9 @@ public class BatteryStatsImpl extends BatteryStats { } public void noteCurrentTimeChangedLocked() { - final long currentTime = mClocks.currentTimeMillis(); - final long elapsedRealtime = mClocks.elapsedRealtime(); - final long uptime = mClocks.uptimeMillis(); + final long currentTime = mClock.currentTimeMillis(); + final long elapsedRealtime = mClock.elapsedRealtime(); + final long uptime = mClock.uptimeMillis(); noteCurrentTimeChangedLocked(currentTime, elapsedRealtime, uptime); } @@ -3948,7 +3919,7 @@ public class BatteryStatsImpl extends BatteryStats { } public void noteProcessStartLocked(String name, int uid) { - noteProcessStartLocked(name, uid, mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + noteProcessStartLocked(name, uid, mClock.elapsedRealtime(), mClock.uptimeMillis()); } public void noteProcessStartLocked(String name, int uid, @@ -3968,7 +3939,7 @@ public class BatteryStatsImpl extends BatteryStats { } public void noteProcessCrashLocked(String name, int uid) { - noteProcessCrashLocked(name, uid, mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + noteProcessCrashLocked(name, uid, mClock.elapsedRealtime(), mClock.uptimeMillis()); } public void noteProcessCrashLocked(String name, int uid, @@ -3981,7 +3952,7 @@ public class BatteryStatsImpl extends BatteryStats { } public void noteProcessAnrLocked(String name, int uid) { - noteProcessAnrLocked(name, uid, mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + noteProcessAnrLocked(name, uid, mClock.elapsedRealtime(), mClock.uptimeMillis()); } public void noteProcessAnrLocked(String name, int uid, long elapsedRealtimeMs, long uptimeMs) { @@ -3993,7 +3964,7 @@ public class BatteryStatsImpl extends BatteryStats { } public void noteUidProcessStateLocked(int uid, int state) { - noteUidProcessStateLocked(uid, state, mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + noteUidProcessStateLocked(uid, state, mClock.elapsedRealtime(), mClock.uptimeMillis()); } public void noteUidProcessStateLocked(int uid, int state, @@ -4014,7 +3985,7 @@ public class BatteryStatsImpl extends BatteryStats { } public void noteProcessFinishLocked(String name, int uid) { - noteProcessFinishLocked(name, uid, mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + noteProcessFinishLocked(name, uid, mClock.elapsedRealtime(), mClock.uptimeMillis()); } public void noteProcessFinishLocked(String name, int uid, @@ -4031,7 +4002,7 @@ public class BatteryStatsImpl extends BatteryStats { } public void noteSyncStartLocked(String name, int uid) { - noteSyncStartLocked(name, uid, mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + noteSyncStartLocked(name, uid, mClock.elapsedRealtime(), mClock.uptimeMillis()); } public void noteSyncStartLocked(String name, int uid, long elapsedRealtimeMs, long uptimeMs) { @@ -4045,7 +4016,7 @@ public class BatteryStatsImpl extends BatteryStats { } public void noteSyncFinishLocked(String name, int uid) { - noteSyncFinishLocked(name, uid, mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + noteSyncFinishLocked(name, uid, mClock.elapsedRealtime(), mClock.uptimeMillis()); } public void noteSyncFinishLocked(String name, int uid, long elapsedRealtimeMs, long uptimeMs) { @@ -4060,7 +4031,7 @@ public class BatteryStatsImpl extends BatteryStats { } public void noteJobStartLocked(String name, int uid) { - noteJobStartLocked(name, uid, mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + noteJobStartLocked(name, uid, mClock.elapsedRealtime(), mClock.uptimeMillis()); } public void noteJobStartLocked(String name, int uid, long elapsedRealtimeMs, long uptimeMs) { @@ -4075,7 +4046,7 @@ public class BatteryStatsImpl extends BatteryStats { public void noteJobFinishLocked(String name, int uid, int stopReason) { noteJobFinishLocked(name, uid, stopReason, - mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + mClock.elapsedRealtime(), mClock.uptimeMillis()); } public void noteJobFinishLocked(String name, int uid, int stopReason, @@ -4091,7 +4062,7 @@ public class BatteryStatsImpl extends BatteryStats { public void noteJobsDeferredLocked(int uid, int numDeferred, long sinceLast) { noteJobsDeferredLocked(uid, numDeferred, sinceLast, - mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + mClock.elapsedRealtime(), mClock.uptimeMillis()); } public void noteJobsDeferredLocked(int uid, int numDeferred, long sinceLast, @@ -4103,7 +4074,7 @@ public class BatteryStatsImpl extends BatteryStats { public void noteAlarmStartLocked(String name, WorkSource workSource, int uid) { noteAlarmStartLocked(name, workSource, uid, - mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + mClock.elapsedRealtime(), mClock.uptimeMillis()); } public void noteAlarmStartLocked(String name, WorkSource workSource, int uid, @@ -4114,7 +4085,7 @@ public class BatteryStatsImpl extends BatteryStats { public void noteAlarmFinishLocked(String name, WorkSource workSource, int uid) { noteAlarmFinishLocked(name, workSource, uid, - mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + mClock.elapsedRealtime(), mClock.uptimeMillis()); } public void noteAlarmFinishLocked(String name, WorkSource workSource, int uid, @@ -4126,7 +4097,7 @@ public class BatteryStatsImpl extends BatteryStats { private void noteAlarmStartOrFinishLocked(int historyItem, String name, WorkSource workSource, int uid) { noteAlarmStartOrFinishLocked(historyItem, name, workSource, uid, - mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + mClock.elapsedRealtime(), mClock.uptimeMillis()); } private void noteAlarmStartOrFinishLocked(int historyItem, String name, WorkSource workSource, @@ -4164,7 +4135,7 @@ public class BatteryStatsImpl extends BatteryStats { public void noteWakupAlarmLocked(String packageName, int uid, WorkSource workSource, String tag) { noteWakupAlarmLocked(packageName, uid, workSource, tag, - mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + mClock.elapsedRealtime(), mClock.uptimeMillis()); } public void noteWakupAlarmLocked(String packageName, int uid, WorkSource workSource, @@ -4223,8 +4194,8 @@ public class BatteryStatsImpl extends BatteryStats { HashMap active = mActiveEvents.getStateForEvent( HistoryItem.EVENT_PROC); if (active != null) { - long mSecRealtime = mClocks.elapsedRealtime(); - final long mSecUptime = mClocks.uptimeMillis(); + long mSecRealtime = mClock.elapsedRealtime(); + final long mSecUptime = mClock.uptimeMillis(); for (HashMap.Entry ent : active.entrySet()) { SparseIntArray uids = ent.getValue(); for (int j=0; j active = mActiveEvents.getStateForEvent( HistoryItem.EVENT_PROC); if (active != null) { - long mSecRealtime = mClocks.elapsedRealtime(); - final long mSecUptime = mClocks.uptimeMillis(); + long mSecRealtime = mClock.elapsedRealtime(); + final long mSecUptime = mClock.uptimeMillis(); for (HashMap.Entry ent : active.entrySet()) { SparseIntArray uids = ent.getValue(); for (int j=0; j callStats) { noteBinderCallStats(workSourceUid, incrementalCallCount, callStats, - mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + mClock.elapsedRealtime(), mClock.uptimeMillis()); } public void noteBinderCallStats(int workSourceUid, long incrementalCallCount, @@ -7011,16 +6982,16 @@ public class BatteryStatsImpl extends BatteryStats { } @Override public long getStartClockTime() { - final long currentTimeMs = mClocks.currentTimeMillis(); + final long currentTimeMs = mClock.currentTimeMillis(); if ((currentTimeMs > MILLISECONDS_IN_YEAR && mStartClockTimeMs < (currentTimeMs - MILLISECONDS_IN_YEAR)) || (mStartClockTimeMs > currentTimeMs)) { // 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. - recordCurrentTimeChangeLocked(currentTimeMs, mClocks.elapsedRealtime(), - mClocks.uptimeMillis()); - return currentTimeMs - (mClocks.elapsedRealtime() - (mRealtimeStartUs / 1000)); + recordCurrentTimeChangeLocked(currentTimeMs, mClock.elapsedRealtime(), + mClock.uptimeMillis()); + return currentTimeMs - (mClock.elapsedRealtime() - (mRealtimeStartUs / 1000)); } return mStartClockTimeMs; } @@ -7383,7 +7354,7 @@ public class BatteryStatsImpl extends BatteryStats { private double mProportionalSystemServiceUsage; public Uid(BatteryStatsImpl bsi, int uid) { - this(bsi, uid, bsi.mClocks.elapsedRealtime(), bsi.mClocks.uptimeMillis()); + this(bsi, uid, bsi.mClock.elapsedRealtime(), bsi.mClock.uptimeMillis()); } public Uid(BatteryStatsImpl bsi, int uid, long elapsedRealtimeMs, long uptimeMs) { @@ -7409,25 +7380,25 @@ public class BatteryStatsImpl extends BatteryStats { }; mSyncStats = mBsi.new OverflowArrayMap(uid) { @Override public DualTimer instantiateObject() { - return new DualTimer(mBsi.mClocks, Uid.this, SYNC, null, + return new DualTimer(mBsi.mClock, Uid.this, SYNC, null, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); } }; mJobStats = mBsi.new OverflowArrayMap(uid) { @Override public DualTimer instantiateObject() { - return new DualTimer(mBsi.mClocks, Uid.this, JOB, null, + return new DualTimer(mBsi.mClock, Uid.this, JOB, null, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); } }; - mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_RUNNING, + mWifiRunningTimer = new StopwatchTimer(mBsi.mClock, this, WIFI_RUNNING, mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); - mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, this, FULL_WIFI_LOCK, + mFullWifiLockTimer = new StopwatchTimer(mBsi.mClock, this, FULL_WIFI_LOCK, mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); - mWifiScanTimer = new DualTimer(mBsi.mClocks, this, WIFI_SCAN, + mWifiScanTimer = new DualTimer(mBsi.mClock, this, WIFI_SCAN, mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; - mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_MULTICAST_ENABLED, + mWifiMulticastTimer = new StopwatchTimer(mBsi.mClock, this, WIFI_MULTICAST_ENABLED, mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); mProcessStateTimer = new StopwatchTimer[NUM_PROCESS_STATE]; mJobsDeferredEventCount = new Counter(mBsi.mOnBatteryTimeBase); @@ -7625,7 +7596,7 @@ public class BatteryStatsImpl extends BatteryStats { if (!mWifiRunning) { mWifiRunning = true; if (mWifiRunningTimer == null) { - mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, + mWifiRunningTimer = new StopwatchTimer(mBsi.mClock, Uid.this, WIFI_RUNNING, mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); } mWifiRunningTimer.startRunningLocked(elapsedRealtimeMs); @@ -7645,7 +7616,7 @@ public class BatteryStatsImpl extends BatteryStats { if (!mFullWifiLockOut) { mFullWifiLockOut = true; if (mFullWifiLockTimer == null) { - mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, + mFullWifiLockTimer = new StopwatchTimer(mBsi.mClock, Uid.this, FULL_WIFI_LOCK, mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); } mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs); @@ -7665,7 +7636,7 @@ public class BatteryStatsImpl extends BatteryStats { if (!mWifiScanStarted) { mWifiScanStarted = true; if (mWifiScanTimer == null) { - mWifiScanTimer = new DualTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, + mWifiScanTimer = new DualTimer(mBsi.mClock, Uid.this, WIFI_SCAN, mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); } @@ -7715,7 +7686,7 @@ public class BatteryStatsImpl extends BatteryStats { public void noteWifiMulticastEnabledLocked(long elapsedRealtimeMs) { if (mWifiMulticastWakelockCount == 0) { if (mWifiMulticastTimer == null) { - mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, + mWifiMulticastTimer = new StopwatchTimer(mBsi.mClock, Uid.this, WIFI_MULTICAST_ENABLED, mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); } mWifiMulticastTimer.startRunningLocked(elapsedRealtimeMs); @@ -7904,7 +7875,7 @@ public class BatteryStatsImpl extends BatteryStats { public StopwatchTimer createAudioTurnedOnTimerLocked() { if (mAudioTurnedOnTimer == null) { - mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, + mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClock, Uid.this, AUDIO_TURNED_ON, mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase); } return mAudioTurnedOnTimer; @@ -7928,7 +7899,7 @@ public class BatteryStatsImpl extends BatteryStats { public StopwatchTimer createVideoTurnedOnTimerLocked() { if (mVideoTurnedOnTimer == null) { - mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, + mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClock, Uid.this, VIDEO_TURNED_ON, mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase); } return mVideoTurnedOnTimer; @@ -7952,7 +7923,7 @@ public class BatteryStatsImpl extends BatteryStats { public StopwatchTimer createFlashlightTurnedOnTimerLocked() { if (mFlashlightTurnedOnTimer == null) { - mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, + mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClock, Uid.this, FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase); } return mFlashlightTurnedOnTimer; @@ -7976,7 +7947,7 @@ public class BatteryStatsImpl extends BatteryStats { public StopwatchTimer createCameraTurnedOnTimerLocked() { if (mCameraTurnedOnTimer == null) { - mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, + mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClock, Uid.this, CAMERA_TURNED_ON, mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase); } return mCameraTurnedOnTimer; @@ -8000,7 +7971,7 @@ public class BatteryStatsImpl extends BatteryStats { public StopwatchTimer createForegroundActivityTimerLocked() { if (mForegroundActivityTimer == null) { - mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, + mForegroundActivityTimer = new StopwatchTimer(mBsi.mClock, Uid.this, FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase); } return mForegroundActivityTimer; @@ -8008,7 +7979,7 @@ public class BatteryStatsImpl extends BatteryStats { public StopwatchTimer createForegroundServiceTimerLocked() { if (mForegroundServiceTimer == null) { - mForegroundServiceTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, + mForegroundServiceTimer = new StopwatchTimer(mBsi.mClock, Uid.this, FOREGROUND_SERVICE, null, mBsi.mOnBatteryTimeBase); } return mForegroundServiceTimer; @@ -8016,7 +7987,7 @@ public class BatteryStatsImpl extends BatteryStats { public DualTimer createAggregatedPartialWakelockTimerLocked() { if (mAggregatedPartialWakelockTimer == null) { - mAggregatedPartialWakelockTimer = new DualTimer(mBsi.mClocks, this, + mAggregatedPartialWakelockTimer = new DualTimer(mBsi.mClock, this, AGGREGATED_WAKE_TYPE_PARTIAL, null, mBsi.mOnBatteryScreenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase); } @@ -8025,7 +7996,7 @@ public class BatteryStatsImpl extends BatteryStats { public DualTimer createBluetoothScanTimerLocked() { if (mBluetoothScanTimer == null) { - mBluetoothScanTimer = new DualTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, + mBluetoothScanTimer = new DualTimer(mBsi.mClock, Uid.this, BLUETOOTH_SCAN_ON, mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); } @@ -8034,7 +8005,7 @@ public class BatteryStatsImpl extends BatteryStats { public DualTimer createBluetoothUnoptimizedScanTimerLocked() { if (mBluetoothUnoptimizedScanTimer == null) { - mBluetoothUnoptimizedScanTimer = new DualTimer(mBsi.mClocks, Uid.this, + mBluetoothUnoptimizedScanTimer = new DualTimer(mBsi.mClock, Uid.this, BLUETOOTH_UNOPTIMIZED_SCAN_ON, null, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); } @@ -8112,7 +8083,7 @@ public class BatteryStatsImpl extends BatteryStats { public BatchTimer createVibratorOnTimerLocked() { if (mVibratorOnTimer == null) { - mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, + mVibratorOnTimer = new BatchTimer(mBsi.mClock, Uid.this, VIBRATOR_ON, mBsi.mOnBatteryTimeBase); } return mVibratorOnTimer; @@ -8298,10 +8269,10 @@ public class BatteryStatsImpl extends BatteryStats { detachIfNotNull(mProcessStateTimer[i]); if (in == null) { - mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, + mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClock, this, PROCESS_STATE, null, mBsi.mOnBatteryTimeBase); } else { - mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, + mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClock, this, PROCESS_STATE, null, mBsi.mOnBatteryTimeBase, in); } } @@ -8362,10 +8333,10 @@ public class BatteryStatsImpl extends BatteryStats { } detachIfNotNull(mWifiBatchedScanTimer[i]); if (in == null) { - mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, + mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClock, this, WIFI_BATCHED_SCAN, collected, mBsi.mOnBatteryTimeBase); } else { - mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, + mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClock, this, WIFI_BATCHED_SCAN, collected, mBsi.mOnBatteryTimeBase, in); } } @@ -9159,7 +9130,7 @@ public class BatteryStatsImpl extends BatteryStats { for (int j = 0; j < numSyncs; j++) { String syncName = in.readString(); if (in.readInt() != 0) { - mSyncStats.add(syncName, new DualTimer(mBsi.mClocks, Uid.this, SYNC, null, + mSyncStats.add(syncName, new DualTimer(mBsi.mClock, Uid.this, SYNC, null, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in)); } } @@ -9169,7 +9140,7 @@ public class BatteryStatsImpl extends BatteryStats { for (int j = 0; j < numJobs; j++) { String jobName = in.readString(); if (in.readInt() != 0) { - mJobStats.add(jobName, new DualTimer(mBsi.mClocks, Uid.this, JOB, null, + mJobStats.add(jobName, new DualTimer(mBsi.mClock, Uid.this, JOB, null, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in)); } } @@ -9214,21 +9185,21 @@ public class BatteryStatsImpl extends BatteryStats { mWifiRunning = false; if (in.readInt() != 0) { - mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, + mWifiRunningTimer = new StopwatchTimer(mBsi.mClock, Uid.this, WIFI_RUNNING, mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase, in); } else { mWifiRunningTimer = null; } mFullWifiLockOut = false; if (in.readInt() != 0) { - mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, + mFullWifiLockTimer = new StopwatchTimer(mBsi.mClock, Uid.this, FULL_WIFI_LOCK, mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase, in); } else { mFullWifiLockTimer = null; } mWifiScanStarted = false; if (in.readInt() != 0) { - mWifiScanTimer = new DualTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, + mWifiScanTimer = new DualTimer(mBsi.mClock, Uid.this, WIFI_SCAN, mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in); } else { @@ -9244,49 +9215,50 @@ public class BatteryStatsImpl extends BatteryStats { } mWifiMulticastWakelockCount = 0; if (in.readInt() != 0) { - mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_MULTICAST_ENABLED, + mWifiMulticastTimer = new StopwatchTimer(mBsi.mClock, Uid.this, + WIFI_MULTICAST_ENABLED, mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase, in); } else { mWifiMulticastTimer = null; } if (in.readInt() != 0) { - mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, + mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClock, Uid.this, AUDIO_TURNED_ON, mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); } else { mAudioTurnedOnTimer = null; } if (in.readInt() != 0) { - mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, + mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClock, Uid.this, VIDEO_TURNED_ON, mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); } else { mVideoTurnedOnTimer = null; } if (in.readInt() != 0) { - mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, + mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClock, Uid.this, FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); } else { mFlashlightTurnedOnTimer = null; } if (in.readInt() != 0) { - mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, + mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClock, Uid.this, CAMERA_TURNED_ON, mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); } else { mCameraTurnedOnTimer = null; } if (in.readInt() != 0) { - mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, + mForegroundActivityTimer = new StopwatchTimer(mBsi.mClock, Uid.this, FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase, in); } else { mForegroundActivityTimer = null; } if (in.readInt() != 0) { - mForegroundServiceTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, + mForegroundServiceTimer = new StopwatchTimer(mBsi.mClock, Uid.this, FOREGROUND_SERVICE, null, mBsi.mOnBatteryTimeBase, in); } else { mForegroundServiceTimer = null; } if (in.readInt() != 0) { - mAggregatedPartialWakelockTimer = new DualTimer(mBsi.mClocks, this, + mAggregatedPartialWakelockTimer = new DualTimer(mBsi.mClock, this, AGGREGATED_WAKE_TYPE_PARTIAL, null, mBsi.mOnBatteryScreenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase, in); @@ -9294,14 +9266,14 @@ public class BatteryStatsImpl extends BatteryStats { mAggregatedPartialWakelockTimer = null; } if (in.readInt() != 0) { - mBluetoothScanTimer = new DualTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, + mBluetoothScanTimer = new DualTimer(mBsi.mClock, Uid.this, BLUETOOTH_SCAN_ON, mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in); } else { mBluetoothScanTimer = null; } if (in.readInt() != 0) { - mBluetoothUnoptimizedScanTimer = new DualTimer(mBsi.mClocks, Uid.this, + mBluetoothUnoptimizedScanTimer = new DualTimer(mBsi.mClock, Uid.this, BLUETOOTH_UNOPTIMIZED_SCAN_ON, null, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in); } else { @@ -9326,7 +9298,7 @@ public class BatteryStatsImpl extends BatteryStats { } } if (in.readInt() != 0) { - mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, + mVibratorOnTimer = new BatchTimer(mBsi.mClock, Uid.this, VIBRATOR_ON, mBsi.mOnBatteryTimeBase, in); } else { mVibratorOnTimer = null; @@ -9536,7 +9508,7 @@ public class BatteryStatsImpl extends BatteryStats { return null; } - return new StopwatchTimer(mBsi.mClocks, mUid, type, pool, timeBase, in); + return new StopwatchTimer(mBsi.mClock, mUid, type, pool, timeBase, in); } /** @@ -9552,7 +9524,7 @@ public class BatteryStatsImpl extends BatteryStats { return null; } - return new DualTimer(mBsi.mClocks, mUid, type, pool, timeBase, bgTimeBase, in); + return new DualTimer(mBsi.mClock, mUid, type, pool, timeBase, bgTimeBase, in); } boolean reset(long elapsedRealtimeUs) { @@ -9649,7 +9621,7 @@ public class BatteryStatsImpl extends BatteryStats { pool = new ArrayList(); mBsi.mSensorTimers.put(mHandle, pool); } - return new DualTimer(mBsi.mClocks, mUid, 0, pool, timeBase, bgTimeBase, in); + return new DualTimer(mBsi.mClock, mUid, 0, pool, timeBase, bgTimeBase, in); } boolean reset(long elapsedRealtimeUs) { @@ -10151,7 +10123,7 @@ public class BatteryStatsImpl extends BatteryStats { @UnsupportedAppUsage public void startLaunchedLocked() { - startLaunchedLocked(mBsi.mClocks.uptimeMillis()); + startLaunchedLocked(mBsi.mClock.uptimeMillis()); } public void startLaunchedLocked(long uptimeMs) { @@ -10164,7 +10136,7 @@ public class BatteryStatsImpl extends BatteryStats { @UnsupportedAppUsage public void stopLaunchedLocked() { - stopLaunchedLocked(mBsi.mClocks.uptimeMillis()); + stopLaunchedLocked(mBsi.mClock.uptimeMillis()); } public void stopLaunchedLocked(long uptimeMs) { @@ -10182,7 +10154,7 @@ public class BatteryStatsImpl extends BatteryStats { @UnsupportedAppUsage public void startRunningLocked() { - startRunningLocked(mBsi.mClocks.uptimeMillis()); + startRunningLocked(mBsi.mClock.uptimeMillis()); } public void startRunningLocked(long uptimeMs) { @@ -10195,7 +10167,7 @@ public class BatteryStatsImpl extends BatteryStats { @UnsupportedAppUsage public void stopRunningLocked() { - stopRunningLocked(mBsi.mClocks.uptimeMillis()); + stopRunningLocked(mBsi.mClock.uptimeMillis()); } public void stopRunningLocked(long uptimeMs) { @@ -10254,7 +10226,7 @@ public class BatteryStatsImpl extends BatteryStats { @GuardedBy("mBsi") public void updateUidProcessStateLocked(int procState) { updateUidProcessStateLocked(procState, - mBsi.mClocks.elapsedRealtime(), mBsi.mClocks.uptimeMillis()); + mBsi.mClock.elapsedRealtime(), mBsi.mClock.uptimeMillis()); } public void updateUidProcessStateLocked(int procState, @@ -10419,7 +10391,7 @@ public class BatteryStatsImpl extends BatteryStats { timers = new ArrayList(); mBsi.mSensorTimers.put(sensor, timers); } - t = new DualTimer(mBsi.mClocks, this, BatteryStats.SENSOR, timers, + t = new DualTimer(mBsi.mClock, this, BatteryStats.SENSOR, timers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); se.mTimer = t; return t; @@ -10470,7 +10442,7 @@ public class BatteryStatsImpl extends BatteryStats { case WAKE_TYPE_PARTIAL: { DualTimer t = wl.mTimerPartial; if (t == null) { - t = new DualTimer(mBsi.mClocks, this, WAKE_TYPE_PARTIAL, + t = new DualTimer(mBsi.mClock, this, WAKE_TYPE_PARTIAL, mBsi.mPartialTimers, mBsi.mOnBatteryScreenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase); wl.mTimerPartial = t; @@ -10480,7 +10452,7 @@ public class BatteryStatsImpl extends BatteryStats { case WAKE_TYPE_FULL: { StopwatchTimer t = wl.mTimerFull; if (t == null) { - t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_FULL, + t = new StopwatchTimer(mBsi.mClock, this, WAKE_TYPE_FULL, mBsi.mFullTimers, mBsi.mOnBatteryTimeBase); wl.mTimerFull = t; } @@ -10489,7 +10461,7 @@ public class BatteryStatsImpl extends BatteryStats { case WAKE_TYPE_WINDOW: { StopwatchTimer t = wl.mTimerWindow; if (t == null) { - t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_WINDOW, + t = new StopwatchTimer(mBsi.mClock, this, WAKE_TYPE_WINDOW, mBsi.mWindowTimers, mBsi.mOnBatteryTimeBase); wl.mTimerWindow = t; } @@ -10498,7 +10470,7 @@ public class BatteryStatsImpl extends BatteryStats { case WAKE_TYPE_DRAW: { StopwatchTimer t = wl.mTimerDraw; if (t == null) { - t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_DRAW, + t = new StopwatchTimer(mBsi.mClock, this, WAKE_TYPE_DRAW, mBsi.mDrawTimers, mBsi.mOnBatteryTimeBase); wl.mTimerDraw = t; } @@ -10586,13 +10558,13 @@ public class BatteryStatsImpl extends BatteryStats { public BatteryStatsImpl(File systemDir, Handler handler, PlatformIdleStateCallback cb, MeasuredEnergyRetriever energyStatsCb, UserInfoProvider userInfoProvider) { - this(new SystemClocks(), systemDir, handler, cb, energyStatsCb, userInfoProvider); + this(Clock.SYSTEM_CLOCK, systemDir, handler, cb, energyStatsCb, userInfoProvider); } - private BatteryStatsImpl(Clocks clocks, File systemDir, Handler handler, + private BatteryStatsImpl(Clock clock, File systemDir, Handler handler, PlatformIdleStateCallback cb, MeasuredEnergyRetriever energyStatsCb, UserInfoProvider userInfoProvider) { - init(clocks); + init(clock); if (systemDir == null) { mStatsFile = null; @@ -10608,8 +10580,8 @@ public class BatteryStatsImpl extends BatteryStats { mStartCount++; initTimersAndCounters(); mOnBattery = mOnBatteryInternal = false; - long uptimeUs = mClocks.uptimeMillis() * 1000; - long realtimeUs = mClocks.elapsedRealtime() * 1000; + long uptimeUs = mClock.uptimeMillis() * 1000; + long realtimeUs = mClock.elapsedRealtime() * 1000; initTimes(uptimeUs, realtimeUs); mStartPlatformVersion = mEndPlatformVersion = Build.ID; initDischarge(realtimeUs); @@ -10626,29 +10598,29 @@ public class BatteryStatsImpl extends BatteryStats { @VisibleForTesting protected void initTimersAndCounters() { - mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase); - mScreenDozeTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase); + mScreenOnTimer = new StopwatchTimer(mClock, null, -1, null, mOnBatteryTimeBase); + mScreenDozeTimer = new StopwatchTimer(mClock, null, -1, null, mOnBatteryTimeBase); for (int i=0; i 0) { hasData = true; @@ -11171,7 +11143,7 @@ public class BatteryStatsImpl extends BatteryStats { } void initTimes(long uptimeUs, long realtimeUs) { - mStartClockTimeMs = mClocks.currentTimeMillis(); + mStartClockTimeMs = mClock.currentTimeMillis(); mOnBatteryTimeBase.init(uptimeUs, realtimeUs); mOnBatteryScreenOffTimeBase.init(uptimeUs, realtimeUs); mRealtimeUs = 0; @@ -11203,9 +11175,9 @@ public class BatteryStatsImpl extends BatteryStats { } public void resetAllStatsCmdLocked() { - final long mSecUptime = mClocks.uptimeMillis(); + final long mSecUptime = mClock.uptimeMillis(); long uptimeUs = mSecUptime * 1000; - long mSecRealtime = mClocks.elapsedRealtime(); + long mSecRealtime = mClock.elapsedRealtime(); long realtimeUs = mSecRealtime * 1000; resetAllStatsLocked(mSecUptime, mSecRealtime, RESET_REASON_ADB_COMMAND); mDischargeStartLevel = mHistoryCur.batteryLevel; @@ -12739,7 +12711,7 @@ public class BatteryStatsImpl extends BatteryStats { * Read and distribute kernel wake lock use across apps. */ public void updateKernelWakelocksLocked() { - updateKernelWakelocksLocked(mClocks.elapsedRealtime() * 1000); + updateKernelWakelocksLocked(mClock.elapsedRealtime() * 1000); } /** @@ -12760,7 +12732,7 @@ public class BatteryStatsImpl extends BatteryStats { SamplingTimer kwlt = mKernelWakelockStats.get(name); if (kwlt == null) { - kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); + kwlt = new SamplingTimer(mClock, mOnBatteryScreenOffTimeBase); mKernelWakelockStats.put(name, kwlt); } @@ -12802,7 +12774,7 @@ public class BatteryStatsImpl extends BatteryStats { * Reads the newest memory stats from the kernel. */ public void updateKernelMemoryBandwidthLocked() { - updateKernelMemoryBandwidthLocked(mClocks.elapsedRealtime() * 1000); + updateKernelMemoryBandwidthLocked(mClock.elapsedRealtime() * 1000); } public void updateKernelMemoryBandwidthLocked(long elapsedRealtimeUs) { @@ -12815,7 +12787,7 @@ public class BatteryStatsImpl extends BatteryStats { if ((index = mKernelMemoryStats.indexOfKey(bandwidthEntries.keyAt(i))) >= 0) { timer = mKernelMemoryStats.valueAt(index); } else { - timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); + timer = new SamplingTimer(mClock, mOnBatteryTimeBase); mKernelMemoryStats.put(bandwidthEntries.keyAt(i), timer); } timer.update(bandwidthEntries.valueAt(i), 1, elapsedRealtimeUs); @@ -13113,8 +13085,8 @@ public class BatteryStatsImpl extends BatteryStats { // So, we distribute total time spent by an uid to different cpu freqs based on the // amount of time cpu was running at that freq. final int updatedUidsCount = updatedUids.size(); - final long elapsedRealtimeMs = mClocks.elapsedRealtime(); - final long uptimeMs = mClocks.uptimeMillis(); + final long elapsedRealtimeMs = mClock.elapsedRealtime(); + final long uptimeMs = mClock.uptimeMillis(); for (int i = 0; i < updatedUidsCount; ++i) { final Uid u = getUidStatsLocked(updatedUids.keyAt(i), elapsedRealtimeMs, uptimeMs); final long appCpuTimeUs = updatedUids.valueAt(i); @@ -13166,8 +13138,8 @@ public class BatteryStatsImpl extends BatteryStats { @Nullable SparseLongArray updatedUids, boolean onBattery) { mTempTotalCpuUserTimeUs = mTempTotalCpuSystemTimeUs = 0; final int numWakelocks = partialTimers == null ? 0 : partialTimers.size(); - final long startTimeMs = mClocks.uptimeMillis(); - final long elapsedRealtimeMs = mClocks.elapsedRealtime(); + final long startTimeMs = mClock.uptimeMillis(); + final long elapsedRealtimeMs = mClock.elapsedRealtime(); mCpuUidUserSysTimeReader.readDelta(false, (uid, timesUs) -> { long userTimeUs = timesUs[0], systemTimeUs = timesUs[1]; @@ -13222,7 +13194,7 @@ public class BatteryStatsImpl extends BatteryStats { } }); - final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; + final long elapsedTimeMs = mClock.uptimeMillis() - startTimeMs; if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { Slog.d(TAG, "Reading cpu stats took " + elapsedTimeMs + "ms"); } @@ -13283,8 +13255,8 @@ public class BatteryStatsImpl extends BatteryStats { final int numWakelocks = partialTimers == null ? 0 : partialTimers.size(); final int numClusters = mPowerProfile.getNumCpuClusters(); mWakeLockAllocationsUs = null; - final long startTimeMs = mClocks.uptimeMillis(); - final long elapsedRealtimeMs = mClocks.elapsedRealtime(); + final long startTimeMs = mClock.uptimeMillis(); + final long elapsedRealtimeMs = mClock.elapsedRealtime(); // If power is being accumulated for attribution, data needs to be read immediately. final boolean forceRead = powerAccumulator != null; mCpuUidFreqTimeReader.readDelta(forceRead, (uid, cpuFreqTimeMs) -> { @@ -13359,7 +13331,7 @@ public class BatteryStatsImpl extends BatteryStats { } }); - final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; + final long elapsedTimeMs = mClock.uptimeMillis() - startTimeMs; if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { Slog.d(TAG, "Reading cpu freq times took " + elapsedTimeMs + "ms"); } @@ -13407,8 +13379,8 @@ public class BatteryStatsImpl extends BatteryStats { */ @VisibleForTesting public void readKernelUidCpuActiveTimesLocked(boolean onBattery) { - final long startTimeMs = mClocks.uptimeMillis(); - final long elapsedRealtimeMs = mClocks.elapsedRealtime(); + final long startTimeMs = mClock.uptimeMillis(); + final long elapsedRealtimeMs = mClock.elapsedRealtime(); mCpuUidActiveTimeReader.readDelta(false, (uid, cpuActiveTimesMs) -> { uid = mapUid(uid); if (Process.isIsolated(uid)) { @@ -13423,7 +13395,7 @@ public class BatteryStatsImpl extends BatteryStats { u.mCpuActiveTimeMs.addCountLocked(cpuActiveTimesMs, onBattery); }); - final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; + final long elapsedTimeMs = mClock.uptimeMillis() - startTimeMs; if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { Slog.d(TAG, "Reading cpu active times took " + elapsedTimeMs + "ms"); } @@ -13440,8 +13412,8 @@ public class BatteryStatsImpl extends BatteryStats { @VisibleForTesting public void readKernelUidCpuClusterTimesLocked(boolean onBattery, @Nullable CpuDeltaPowerAccumulator powerAccumulator) { - final long startTimeMs = mClocks.uptimeMillis(); - final long elapsedRealtimeMs = mClocks.elapsedRealtime(); + final long startTimeMs = mClock.uptimeMillis(); + final long elapsedRealtimeMs = mClock.elapsedRealtime(); // If power is being accumulated for attribution, data needs to be read immediately. final boolean forceRead = powerAccumulator != null; mCpuUidClusterTimeReader.readDelta(forceRead, (uid, cpuClusterTimesMs) -> { @@ -13462,7 +13434,7 @@ public class BatteryStatsImpl extends BatteryStats { } }); - final long elapsedTimeMs = mClocks.uptimeMillis() - startTimeMs; + final long elapsedTimeMs = mClock.uptimeMillis() - startTimeMs; if (DEBUG_ENERGY_CPU || elapsedTimeMs >= 100) { Slog.d(TAG, "Reading cpu cluster times took " + elapsedTimeMs + "ms"); } @@ -13641,7 +13613,7 @@ public class BatteryStatsImpl extends BatteryStats { private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, boolean reset) { mRecordingHistory = true; - mHistoryCur.currentTime = mClocks.currentTimeMillis(); + mHistoryCur.currentTime = mClock.currentTimeMillis(); addHistoryBufferLocked(elapsedRealtimeMs, reset ? HistoryItem.CMD_RESET : HistoryItem.CMD_CURRENT_TIME, mHistoryCur); @@ -13683,7 +13655,7 @@ public class BatteryStatsImpl extends BatteryStats { final int chargeFullUah, final long chargeTimeToFullSeconds) { setBatteryStateLocked(status, health, plugType, level, temp, voltageMv, chargeUah, chargeFullUah, chargeTimeToFullSeconds, - mClocks.elapsedRealtime(), mClocks.uptimeMillis(), mClocks.currentTimeMillis()); + mClock.elapsedRealtime(), mClock.uptimeMillis(), mClock.currentTimeMillis()); } public void setBatteryStateLocked(final int status, final int health, final int plugType, @@ -13920,12 +13892,12 @@ public class BatteryStatsImpl extends BatteryStats { public long getAwakeTimeBattery() { // This previously evaluated to mOnBatteryTimeBase.getUptime(getBatteryUptimeLocked()); // for over a decade, but surely that was a mistake. - return getBatteryUptimeLocked(mClocks.uptimeMillis()); + return getBatteryUptimeLocked(mClock.uptimeMillis()); } @UnsupportedAppUsage public long getAwakeTimePlugged() { - return (mClocks.uptimeMillis() * 1000) - getAwakeTimeBattery(); + return (mClock.uptimeMillis() * 1000) - getAwakeTimeBattery(); } @Override @@ -14175,7 +14147,7 @@ public class BatteryStatsImpl extends BatteryStats { * @return battery uptime in microseconds */ protected long getBatteryUptimeLocked() { - return getBatteryUptimeLocked(mClocks.uptimeMillis()); + return getBatteryUptimeLocked(mClock.uptimeMillis()); } /** @@ -14348,7 +14320,7 @@ public class BatteryStatsImpl extends BatteryStats { */ @UnsupportedAppUsage public Uid getUidStatsLocked(int uid) { - return getUidStatsLocked(uid, mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + return getUidStatsLocked(uid, mClock.elapsedRealtime(), mClock.uptimeMillis()); } public Uid getUidStatsLocked(int uid, long elapsedRealtimeMs, long uptimeMs) { @@ -14410,7 +14382,7 @@ public class BatteryStatsImpl extends BatteryStats { */ @UnsupportedAppUsage public void removeUidStatsLocked(int uid) { - removeUidStatsLocked(uid, mClocks.elapsedRealtime()); + removeUidStatsLocked(uid, mClock.elapsedRealtime()); } /** @@ -14464,7 +14436,7 @@ public class BatteryStatsImpl extends BatteryStats { */ @UnsupportedAppUsage public Uid.Proc getProcessStatsLocked(int uid, String name) { - return getProcessStatsLocked(uid, name, mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + return getProcessStatsLocked(uid, name, mClock.elapsedRealtime(), mClock.uptimeMillis()); } /** @@ -14483,7 +14455,7 @@ public class BatteryStatsImpl extends BatteryStats { */ @UnsupportedAppUsage public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { - return getPackageStatsLocked(uid, pkg, mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + return getPackageStatsLocked(uid, pkg, mClock.elapsedRealtime(), mClock.uptimeMillis()); } /** @@ -14503,7 +14475,7 @@ public class BatteryStatsImpl extends BatteryStats { @UnsupportedAppUsage public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { return getServiceStatsLocked(uid, pkg, name, - mClocks.elapsedRealtime(), mClocks.uptimeMillis()); + mClock.elapsedRealtime(), mClock.uptimeMillis()); } public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name, @@ -14514,7 +14486,7 @@ public class BatteryStatsImpl extends BatteryStats { } public void shutdownLocked() { - recordShutdownLocked(mClocks.currentTimeMillis(), mClocks.elapsedRealtime()); + recordShutdownLocked(mClock.currentTimeMillis(), mClock.elapsedRealtime()); writeSyncLocked(); mShuttingDown = true; } @@ -14736,7 +14708,7 @@ public class BatteryStatsImpl extends BatteryStats { mNumSingleUidCpuTimeReads = 0; mNumBatchedSingleUidCpuTimeReads = 0; - mCpuTimeReadsTrackingStartTimeMs = mClocks.uptimeMillis(); + mCpuTimeReadsTrackingStartTimeMs = mClock.uptimeMillis(); } } @@ -14745,7 +14717,7 @@ public class BatteryStatsImpl extends BatteryStats { if (oldDelayMillis != newDelayMillis) { mNumSingleUidCpuTimeReads = 0; mNumBatchedSingleUidCpuTimeReads = 0; - mCpuTimeReadsTrackingStartTimeMs = mClocks.uptimeMillis(); + mCpuTimeReadsTrackingStartTimeMs = mClock.uptimeMillis(); } } @@ -14925,7 +14897,7 @@ public class BatteryStatsImpl extends BatteryStats { Slog.d(TAG, "writeSummaryToParcel duration ms:" + (SystemClock.uptimeMillis() - start) + " bytes:" + p.dataSize()); } - mLastWriteTimeMs = mClocks.elapsedRealtime(); + mLastWriteTimeMs = mClock.elapsedRealtime(); writeParcelToFileLocked(p, mStatsFile, sync); } @@ -15059,13 +15031,13 @@ public class BatteryStatsImpl extends BatteryStats { if (mHistoryBuffer.dataPosition() > 0 || mBatteryStatsHistory.getFilesNumbers().size() > 1) { mRecordingHistory = true; - final long elapsedRealtimeMs = mClocks.elapsedRealtime(); - final long uptimeMs = mClocks.uptimeMillis(); + final long elapsedRealtimeMs = mClock.elapsedRealtime(); + final long uptimeMs = mClock.uptimeMillis(); addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_START, mHistoryCur); startRecordingHistory(elapsedRealtimeMs, uptimeMs, false); } - recordDailyStatsIfNeededLocked(false, mClocks.currentTimeMillis()); + recordDailyStatsIfNeededLocked(false, mClock.currentTimeMillis()); } public int describeContents() { @@ -15117,7 +15089,7 @@ public class BatteryStatsImpl extends BatteryStats { // We are just arbitrarily going to insert 1 minute from the sample of // the last run until samples in this run. if (mHistoryBaseTimeMs > 0) { - long oldnow = mClocks.elapsedRealtime(); + long oldnow = mClock.elapsedRealtime(); mHistoryBaseTimeMs = mHistoryBaseTimeMs - oldnow + 1; if (DEBUG_HISTORY) { StringBuilder sb = new StringBuilder(128); @@ -15368,8 +15340,8 @@ public class BatteryStatsImpl extends BatteryStats { if (NU > 10000) { throw new ParcelFormatException("File corrupt: too many uids " + NU); } - final long elapsedRealtimeMs = mClocks.elapsedRealtime(); - final long uptimeMs = mClocks.uptimeMillis(); + final long elapsedRealtimeMs = mClock.elapsedRealtime(); + final long uptimeMs = mClock.uptimeMillis(); for (int iu = 0; iu < NU; iu++) { int uid = in.readInt(); Uid u = new Uid(this, uid, elapsedRealtimeMs, uptimeMs); @@ -15677,8 +15649,8 @@ public class BatteryStatsImpl extends BatteryStats { // if we had originally pulled a time before the RTC was set. getStartClockTime(); - final long NOW_SYS = mClocks.uptimeMillis() * 1000; - final long NOWREAL_SYS = mClocks.elapsedRealtime() * 1000; + final long nowUptime = mClock.uptimeMillis() * 1000; + final long nowRealtime = mClock.elapsedRealtime() * 1000; out.writeInt(VERSION); @@ -15697,13 +15669,13 @@ public class BatteryStatsImpl extends BatteryStats { } out.writeInt(mStartCount); - out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); - out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); + out.writeLong(computeUptime(nowUptime, STATS_SINCE_CHARGED)); + out.writeLong(computeRealtime(nowRealtime, STATS_SINCE_CHARGED)); out.writeLong(mStartClockTimeMs); out.writeString(mStartPlatformVersion); out.writeString(mEndPlatformVersion); - mOnBatteryTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); - mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); + mOnBatteryTimeBase.writeSummaryToParcel(out, nowUptime, nowRealtime); + mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, nowUptime, nowRealtime); out.writeInt(mDischargeUnplugLevel); out.writeInt(mDischargePlugLevel); out.writeInt(mDischargeCurrentLevel); @@ -15745,52 +15717,52 @@ public class BatteryStatsImpl extends BatteryStats { MeasuredEnergyStats.writeSummaryToParcel(mGlobalMeasuredEnergyStats, out, false, false); - mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); - mScreenDozeTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + mScreenOnTimer.writeSummaryFromParcelLocked(out, nowRealtime); + mScreenDozeTimer.writeSummaryFromParcelLocked(out, nowRealtime); for (int i=0; i ent : mRpmStats.entrySet()) { @@ -15809,7 +15781,7 @@ public class BatteryStatsImpl extends BatteryStats { if (rpmt != null) { out.writeInt(1); out.writeString(ent.getKey()); - rpmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + rpmt.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } @@ -15820,7 +15792,7 @@ public class BatteryStatsImpl extends BatteryStats { if (rpmt != null) { out.writeInt(1); out.writeString(ent.getKey()); - rpmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + rpmt.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } @@ -15832,7 +15804,7 @@ public class BatteryStatsImpl extends BatteryStats { if (kwlt != null) { out.writeInt(1); out.writeString(ent.getKey()); - kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + kwlt.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } @@ -15844,7 +15816,7 @@ public class BatteryStatsImpl extends BatteryStats { if (timer != null) { out.writeInt(1); out.writeString(ent.getKey()); - timer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + timer.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } @@ -15856,7 +15828,7 @@ public class BatteryStatsImpl extends BatteryStats { if (kmt != null) { out.writeInt(1); out.writeLong(mKernelMemoryStats.keyAt(i)); - kmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + kmt.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } @@ -15868,92 +15840,93 @@ public class BatteryStatsImpl extends BatteryStats { out.writeInt(mUidStats.keyAt(iu)); Uid u = mUidStats.valueAt(iu); - u.mOnBatteryBackgroundTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); - u.mOnBatteryScreenOffBackgroundTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); + u.mOnBatteryBackgroundTimeBase.writeSummaryToParcel(out, nowUptime, nowRealtime); + u.mOnBatteryScreenOffBackgroundTimeBase.writeSummaryToParcel(out, nowUptime, + nowRealtime); if (u.mWifiRunningTimer != null) { out.writeInt(1); - u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } if (u.mFullWifiLockTimer != null) { out.writeInt(1); - u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } if (u.mWifiScanTimer != null) { out.writeInt(1); - u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + u.mWifiScanTimer.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { if (u.mWifiBatchedScanTimer[i] != null) { out.writeInt(1); - u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); + u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } } if (u.mWifiMulticastTimer != null) { out.writeInt(1); - u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } if (u.mAudioTurnedOnTimer != null) { out.writeInt(1); - u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } if (u.mVideoTurnedOnTimer != null) { out.writeInt(1); - u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } if (u.mFlashlightTurnedOnTimer != null) { out.writeInt(1); - u.mFlashlightTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + u.mFlashlightTurnedOnTimer.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } if (u.mCameraTurnedOnTimer != null) { out.writeInt(1); - u.mCameraTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + u.mCameraTurnedOnTimer.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } if (u.mForegroundActivityTimer != null) { out.writeInt(1); - u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } if (u.mForegroundServiceTimer != null) { out.writeInt(1); - u.mForegroundServiceTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + u.mForegroundServiceTimer.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } if (u.mAggregatedPartialWakelockTimer != null) { out.writeInt(1); - u.mAggregatedPartialWakelockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + u.mAggregatedPartialWakelockTimer.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } if (u.mBluetoothScanTimer != null) { out.writeInt(1); - u.mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + u.mBluetoothScanTimer.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } if (u.mBluetoothUnoptimizedScanTimer != null) { out.writeInt(1); - u.mBluetoothUnoptimizedScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + u.mBluetoothUnoptimizedScanTimer.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } @@ -15972,14 +15945,14 @@ public class BatteryStatsImpl extends BatteryStats { for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { if (u.mProcessStateTimer[i] != null) { out.writeInt(1); - u.mProcessStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); + u.mProcessStateTimer[i].writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } } if (u.mVibratorOnTimer != null) { out.writeInt(1); - u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } @@ -16078,25 +16051,25 @@ public class BatteryStatsImpl extends BatteryStats { Uid.Wakelock wl = wakeStats.valueAt(iw); if (wl.mTimerFull != null) { out.writeInt(1); - wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + wl.mTimerFull.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } if (wl.mTimerPartial != null) { out.writeInt(1); - wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + wl.mTimerPartial.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } if (wl.mTimerWindow != null) { out.writeInt(1); - wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + wl.mTimerWindow.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } if (wl.mTimerDraw != null) { out.writeInt(1); - wl.mTimerDraw.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + wl.mTimerDraw.writeSummaryFromParcelLocked(out, nowRealtime); } else { out.writeInt(0); } @@ -16107,7 +16080,7 @@ public class BatteryStatsImpl extends BatteryStats { out.writeInt(NS); for (int is=0; is jobStats = u.mJobStats.getMap(); @@ -16115,7 +16088,7 @@ public class BatteryStatsImpl extends BatteryStats { out.writeInt(NJ); for (int ij=0; ij 0 && (SystemClock.elapsedRealtime() - mLastReadTime < FRESHNESS); + return mSize > 0 && (mClock.elapsedRealtime() - mLastReadTime < FRESHNESS); } /** diff --git a/core/java/com/android/internal/os/KernelCpuUidTimeReader.java b/core/java/com/android/internal/os/KernelCpuUidTimeReader.java index 50df166605dbd..faeb8fc237ec0 100644 --- a/core/java/com/android/internal/os/KernelCpuUidTimeReader.java +++ b/core/java/com/android/internal/os/KernelCpuUidTimeReader.java @@ -21,7 +21,6 @@ import static com.android.internal.util.Preconditions.checkNotNull; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.StrictMode; -import android.os.SystemClock; import android.util.IntArray; import android.util.Slog; import android.util.SparseArray; @@ -60,6 +59,7 @@ public abstract class KernelCpuUidTimeReader { final boolean mThrottle; protected boolean mBpfTimesAvailable; final KernelCpuUidBpfMapReader mBpfReader; + private final Clock mClock; private long mMinTimeBetweenRead = DEFAULT_MIN_TIME_BETWEEN_READ; private long mLastReadTimeMs = 0; @@ -76,15 +76,17 @@ public abstract class KernelCpuUidTimeReader { void onUidCpuTime(int uid, T time); } - KernelCpuUidTimeReader(KernelCpuProcStringReader reader, @Nullable KernelCpuUidBpfMapReader bpfReader, boolean throttle) { + KernelCpuUidTimeReader(KernelCpuProcStringReader reader, + @Nullable KernelCpuUidBpfMapReader bpfReader, boolean throttle, Clock clock) { mReader = reader; mThrottle = throttle; mBpfReader = bpfReader; + mClock = clock; mBpfTimesAvailable = (mBpfReader != null); } - KernelCpuUidTimeReader(KernelCpuProcStringReader reader, boolean throttle) { - this(reader, null, throttle); + KernelCpuUidTimeReader(KernelCpuProcStringReader reader, boolean throttle, Clock clock) { + this(reader, null, throttle, clock); } /** @@ -104,17 +106,17 @@ public abstract class KernelCpuUidTimeReader { */ public void readDelta(boolean force, @Nullable Callback cb) { if (!mThrottle) { - readDeltaImpl(cb); + readDeltaImpl(cb, force); return; } - final long currTimeMs = SystemClock.elapsedRealtime(); + final long currTimeMs = mClock.elapsedRealtime(); if (!force && currTimeMs < mLastReadTimeMs + mMinTimeBetweenRead) { if (DEBUG) { Slog.d(mTag, "Throttle readDelta"); } return; } - readDeltaImpl(cb); + readDeltaImpl(cb, force); mLastReadTimeMs = currTimeMs; } @@ -128,7 +130,7 @@ public abstract class KernelCpuUidTimeReader { readAbsoluteImpl(cb); return; } - final long currTimeMs = SystemClock.elapsedRealtime(); + final long currTimeMs = mClock.elapsedRealtime(); if (currTimeMs < mLastReadTimeMs + mMinTimeBetweenRead) { if (DEBUG) { Slog.d(mTag, "Throttle readAbsolute"); @@ -139,7 +141,7 @@ public abstract class KernelCpuUidTimeReader { mLastReadTimeMs = currTimeMs; } - abstract void readDeltaImpl(@Nullable Callback cb); + abstract void readDeltaImpl(@Nullable Callback cb, boolean forceRead); abstract void readAbsoluteImpl(Callback callback); @@ -216,17 +218,22 @@ public abstract class KernelCpuUidTimeReader { private final long[] mUsrSysTime = new long[2]; public KernelCpuUidUserSysTimeReader(boolean throttle) { - super(KernelCpuProcStringReader.getUserSysTimeReaderInstance(), throttle); + this(throttle, Clock.SYSTEM_CLOCK); + } + + public KernelCpuUidUserSysTimeReader(boolean throttle, Clock clock) { + super(KernelCpuProcStringReader.getUserSysTimeReaderInstance(), throttle, clock); } @VisibleForTesting - public KernelCpuUidUserSysTimeReader(KernelCpuProcStringReader reader, boolean throttle) { - super(reader, throttle); + public KernelCpuUidUserSysTimeReader(KernelCpuProcStringReader reader, boolean throttle, + Clock clock) { + super(reader, throttle, clock); } @Override - void readDeltaImpl(@Nullable Callback cb) { - try (ProcFileIterator iter = mReader.open(!mThrottle)) { + void readDeltaImpl(@Nullable Callback cb, boolean forceRead) { + try (ProcFileIterator iter = mReader.open(!mThrottle || forceRead)) { if (iter == null) { return; } @@ -348,14 +355,23 @@ public abstract class KernelCpuUidTimeReader { private boolean mAllUidTimesAvailable = true; public KernelCpuUidFreqTimeReader(boolean throttle) { + this(throttle, Clock.SYSTEM_CLOCK); + } + + public KernelCpuUidFreqTimeReader(boolean throttle, Clock clock) { this(UID_TIMES_PROC_FILE, KernelCpuProcStringReader.getFreqTimeReaderInstance(), - KernelCpuUidBpfMapReader.getFreqTimeReaderInstance(), throttle); + KernelCpuUidBpfMapReader.getFreqTimeReaderInstance(), throttle, clock); } @VisibleForTesting public KernelCpuUidFreqTimeReader(String procFile, KernelCpuProcStringReader reader, KernelCpuUidBpfMapReader bpfReader, boolean throttle) { - super(reader, bpfReader, throttle); + this(procFile, reader, bpfReader, throttle, Clock.SYSTEM_CLOCK); + } + + private KernelCpuUidFreqTimeReader(String procFile, KernelCpuProcStringReader reader, + KernelCpuUidBpfMapReader bpfReader, boolean throttle, Clock clock) { + super(reader, bpfReader, throttle, clock); mProcFilePath = Paths.get(procFile); } @@ -496,7 +512,7 @@ public abstract class KernelCpuUidTimeReader { } @Override - void readDeltaImpl(@Nullable Callback cb) { + void readDeltaImpl(@Nullable Callback cb, boolean forceRead) { if (mBpfTimesAvailable) { try (BpfMapIterator iter = mBpfReader.open(!mThrottle)) { if (checkPrecondition(iter)) { @@ -628,13 +644,18 @@ public abstract class KernelCpuUidTimeReader { private long[] mBuffer; public KernelCpuUidActiveTimeReader(boolean throttle) { + this(throttle, Clock.SYSTEM_CLOCK); + } + + public KernelCpuUidActiveTimeReader(boolean throttle, Clock clock) { super(KernelCpuProcStringReader.getActiveTimeReaderInstance(), - KernelCpuUidBpfMapReader.getActiveTimeReaderInstance(), throttle); + KernelCpuUidBpfMapReader.getActiveTimeReaderInstance(), throttle, clock); } @VisibleForTesting - public KernelCpuUidActiveTimeReader(KernelCpuProcStringReader reader, KernelCpuUidBpfMapReader bpfReader, boolean throttle) { - super(reader, bpfReader, throttle); + public KernelCpuUidActiveTimeReader(KernelCpuProcStringReader reader, + KernelCpuUidBpfMapReader bpfReader, boolean throttle) { + super(reader, bpfReader, throttle, Clock.SYSTEM_CLOCK); } private void processUidDelta(@Nullable Callback cb) { @@ -655,7 +676,7 @@ public abstract class KernelCpuUidTimeReader { } @Override - void readDeltaImpl(@Nullable Callback cb) { + void readDeltaImpl(@Nullable Callback cb, boolean forceRead) { if (mBpfTimesAvailable) { try (BpfMapIterator iter = mBpfReader.open(!mThrottle)) { if (checkPrecondition(iter)) { @@ -800,14 +821,18 @@ public abstract class KernelCpuUidTimeReader { private long[] mDeltaTime; public KernelCpuUidClusterTimeReader(boolean throttle) { + this(throttle, Clock.SYSTEM_CLOCK); + } + + public KernelCpuUidClusterTimeReader(boolean throttle, Clock clock) { super(KernelCpuProcStringReader.getClusterTimeReaderInstance(), - KernelCpuUidBpfMapReader.getClusterTimeReaderInstance(), throttle); + KernelCpuUidBpfMapReader.getClusterTimeReaderInstance(), throttle, clock); } @VisibleForTesting public KernelCpuUidClusterTimeReader(KernelCpuProcStringReader reader, - KernelCpuUidBpfMapReader bpfReader, boolean throttle) { - super(reader, bpfReader, throttle); + KernelCpuUidBpfMapReader bpfReader, boolean throttle) { + super(reader, bpfReader, throttle, Clock.SYSTEM_CLOCK); } void processUidDelta(@Nullable Callback cb) { @@ -838,7 +863,7 @@ public abstract class KernelCpuUidTimeReader { } @Override - void readDeltaImpl(@Nullable Callback cb) { + void readDeltaImpl(@Nullable Callback cb, boolean forceRead) { if (mBpfTimesAvailable) { try (BpfMapIterator iter = mBpfReader.open(!mThrottle)) { if (checkPrecondition(iter)) { diff --git a/core/tests/coretests/src/com/android/internal/os/BatteryStatsBackgroundStatsTest.java b/core/tests/coretests/src/com/android/internal/os/BatteryStatsBackgroundStatsTest.java index b6878013b2543..25bc1ee149ad7 100644 --- a/core/tests/coretests/src/com/android/internal/os/BatteryStatsBackgroundStatsTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BatteryStatsBackgroundStatsTest.java @@ -38,7 +38,7 @@ public class BatteryStatsBackgroundStatsTest extends TestCase { /** Test that BatteryStatsImpl.Uid.mOnBatteryBackgroundTimeBase works correctly. */ @SmallTest public void testBgTimeBase() throws Exception { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); long cur = 0; // realtime in us @@ -106,7 +106,7 @@ public class BatteryStatsBackgroundStatsTest extends TestCase { /** Test that BatteryStatsImpl.Uid.mOnBatteryScreenOffBackgroundTimeBase works correctly. */ @SmallTest public void testScreenOffBgTimeBase() throws Exception { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); long cur = 0; // realtime in us @@ -154,7 +154,7 @@ public class BatteryStatsBackgroundStatsTest extends TestCase { @SmallTest public void testWifiScan() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); long curr = 0; // realtime in us @@ -207,7 +207,7 @@ public class BatteryStatsBackgroundStatsTest extends TestCase { } private void doTestAppBluetoothScanInternal(WorkSource ws) throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); long curr = 0; // realtime in us @@ -276,7 +276,7 @@ public class BatteryStatsBackgroundStatsTest extends TestCase { @SmallTest public void testJob() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); final String jobName = "job_name"; long curr = 0; // realtime in us @@ -337,7 +337,7 @@ public class BatteryStatsBackgroundStatsTest extends TestCase { @SmallTest public void testSyncs() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); final String syncName = "sync_name"; long curr = 0; // realtime in us diff --git a/core/tests/coretests/src/com/android/internal/os/BatteryStatsBinderCallStatsTest.java b/core/tests/coretests/src/com/android/internal/os/BatteryStatsBinderCallStatsTest.java index 85f9c97629e39..8ca0da022559c 100644 --- a/core/tests/coretests/src/com/android/internal/os/BatteryStatsBinderCallStatsTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BatteryStatsBinderCallStatsTest.java @@ -46,7 +46,7 @@ public class BatteryStatsBinderCallStatsTest extends TestCase { */ @Test public void testNoteBinderCallStats() throws Exception { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); int callingUid = Process.FIRST_APPLICATION_UID + 1; @@ -89,7 +89,7 @@ public class BatteryStatsBinderCallStatsTest extends TestCase { @Test public void testProportionalSystemServiceUsage_noStatsForSomeMethods() throws Exception { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); int callingUid = Process.FIRST_APPLICATION_UID + 1; diff --git a/core/tests/coretests/src/com/android/internal/os/BatteryStatsCounterTest.java b/core/tests/coretests/src/com/android/internal/os/BatteryStatsCounterTest.java index ade3a991b5766..6ff2b6411282f 100644 --- a/core/tests/coretests/src/com/android/internal/os/BatteryStatsCounterTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BatteryStatsCounterTest.java @@ -30,7 +30,7 @@ public class BatteryStatsCounterTest extends TestCase { @SmallTest public void testCounter() throws Exception { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms final BatteryStatsImpl.TimeBase timeBase = new BatteryStatsImpl.TimeBase(); timeBase.init(clocks.uptimeMillis(), clocks.elapsedRealtime()); @@ -70,7 +70,7 @@ public class BatteryStatsCounterTest extends TestCase { @SmallTest public void testParceling() throws Exception { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms final BatteryStatsImpl.TimeBase timeBase = new BatteryStatsImpl.TimeBase(); timeBase.init(clocks.uptimeMillis(), clocks.elapsedRealtime()); diff --git a/core/tests/coretests/src/com/android/internal/os/BatteryStatsCpuTimesTest.java b/core/tests/coretests/src/com/android/internal/os/BatteryStatsCpuTimesTest.java index 65df390e91338..1ac89eac241e4 100644 --- a/core/tests/coretests/src/com/android/internal/os/BatteryStatsCpuTimesTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BatteryStatsCpuTimesTest.java @@ -96,7 +96,7 @@ public class BatteryStatsCpuTimesTest { @Mock PowerProfile mPowerProfile; - private MockClocks mClocks; + private MockClock mClocks; private MockBatteryStatsImpl mBatteryStatsImpl; private KernelCpuSpeedReader[] mKernelCpuSpeedReaders; @@ -104,7 +104,7 @@ public class BatteryStatsCpuTimesTest { public void setUp() { MockitoAnnotations.initMocks(this); - mClocks = new MockClocks(); + mClocks = new MockClock(); mBatteryStatsImpl = new MockBatteryStatsImpl(mClocks) .setKernelCpuUidUserSysTimeReader(mCpuUidUserSysTimeReader) .setKernelCpuUidFreqTimeReader(mCpuUidFreqTimeReader) diff --git a/core/tests/coretests/src/com/android/internal/os/BatteryStatsDualTimerTest.java b/core/tests/coretests/src/com/android/internal/os/BatteryStatsDualTimerTest.java index efb871027830b..678d3eeaef626 100644 --- a/core/tests/coretests/src/com/android/internal/os/BatteryStatsDualTimerTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BatteryStatsDualTimerTest.java @@ -29,7 +29,7 @@ public class BatteryStatsDualTimerTest extends TestCase { @SmallTest public void testResetDetach() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); clocks.realtime = clocks.uptime = 100; final BatteryStatsImpl.TimeBase timeBase = new BatteryStatsImpl.TimeBase(); diff --git a/core/tests/coretests/src/com/android/internal/os/BatteryStatsDurationTimerTest.java b/core/tests/coretests/src/com/android/internal/os/BatteryStatsDurationTimerTest.java index 78fa3fb734d67..b7edb174a2961 100644 --- a/core/tests/coretests/src/com/android/internal/os/BatteryStatsDurationTimerTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BatteryStatsDurationTimerTest.java @@ -33,7 +33,7 @@ public class BatteryStatsDurationTimerTest extends TestCase { @SmallTest public void testStartStop() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); final BatteryStatsImpl.TimeBase timeBase = new BatteryStatsImpl.TimeBase(); timeBase.init(clocks.uptimeMillis(), clocks.elapsedRealtime()); @@ -105,7 +105,7 @@ public class BatteryStatsDurationTimerTest extends TestCase { */ @SmallTest public void testReset() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); final BatteryStatsImpl.TimeBase timeBase = new BatteryStatsImpl.TimeBase(); timeBase.init(clocks.uptimeMillis(), clocks.elapsedRealtime()); @@ -141,7 +141,7 @@ public class BatteryStatsDurationTimerTest extends TestCase { */ @SmallTest public void testResetAndDetach() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); final BatteryStatsImpl.TimeBase timeBase = new BatteryStatsImpl.TimeBase(); timeBase.init(clocks.uptimeMillis(), clocks.elapsedRealtime()); @@ -168,7 +168,7 @@ public class BatteryStatsDurationTimerTest extends TestCase { @SmallTest public void testParceling() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); final BatteryStatsImpl.TimeBase timeBase = new BatteryStatsImpl.TimeBase(); timeBase.init(clocks.uptimeMillis(), clocks.elapsedRealtime()); diff --git a/core/tests/coretests/src/com/android/internal/os/BatteryStatsNoteTest.java b/core/tests/coretests/src/com/android/internal/os/BatteryStatsNoteTest.java index 464412f177226..7a842016cf6a3 100644 --- a/core/tests/coretests/src/com/android/internal/os/BatteryStatsNoteTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BatteryStatsNoteTest.java @@ -60,7 +60,7 @@ public class BatteryStatsNoteTest extends TestCase { */ @SmallTest public void testNoteBluetoothScanResultLocked() throws Exception { - MockBatteryStatsImpl bi = new MockBatteryStatsImpl(new MockClocks()); + MockBatteryStatsImpl bi = new MockBatteryStatsImpl(new MockClock()); bi.updateTimeBasesLocked(true, Display.STATE_OFF, 0, 0); bi.noteUidProcessStateLocked(UID, ActivityManager.PROCESS_STATE_TOP); @@ -89,7 +89,7 @@ public class BatteryStatsNoteTest extends TestCase { */ @SmallTest public void testNoteStartWakeLocked() throws Exception { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); int pid = 10; @@ -120,7 +120,7 @@ public class BatteryStatsNoteTest extends TestCase { */ @SmallTest public void testNoteUidProcessStateLocked() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); // map of ActivityManager process states and how long to simulate run time in each state @@ -205,7 +205,7 @@ public class BatteryStatsNoteTest extends TestCase { */ @SmallTest public void testUpdateTimeBasesLocked() throws Exception { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); bi.updateTimeBasesLocked(false, Display.STATE_OFF, 0, 0); @@ -229,7 +229,7 @@ public class BatteryStatsNoteTest extends TestCase { */ @SmallTest public void testNoteScreenStateLocked() throws Exception { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); bi.updateTimeBasesLocked(true, Display.STATE_ON, 0, 0); @@ -258,7 +258,7 @@ public class BatteryStatsNoteTest extends TestCase { */ @SmallTest public void testNoteScreenStateTimersLocked() throws Exception { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); clocks.realtime = clocks.uptime = 100; @@ -297,7 +297,7 @@ public class BatteryStatsNoteTest extends TestCase { @SmallTest @SkipPresubmit("b/180015146") public void testAlarmStartAndFinishLocked() throws Exception { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); bi.setRecordAllHistoryLocked(true); bi.forceRecordAllHistory(); @@ -335,7 +335,7 @@ public class BatteryStatsNoteTest extends TestCase { @SmallTest @SkipPresubmit("b/180015146") public void testAlarmStartAndFinishLocked_workSource() throws Exception { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); bi.setRecordAllHistoryLocked(true); bi.forceRecordAllHistory(); @@ -379,7 +379,7 @@ public class BatteryStatsNoteTest extends TestCase { @SmallTest public void testNoteWakupAlarmLocked() { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); bi.setRecordAllHistoryLocked(true); bi.forceRecordAllHistory(); @@ -397,7 +397,7 @@ public class BatteryStatsNoteTest extends TestCase { @SmallTest public void testNoteWakupAlarmLocked_workSource_uid() { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); bi.setRecordAllHistoryLocked(true); bi.forceRecordAllHistory(); @@ -430,7 +430,7 @@ public class BatteryStatsNoteTest extends TestCase { @SmallTest public void testNoteWakupAlarmLocked_workSource_workChain() { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); bi.setRecordAllHistoryLocked(true); bi.forceRecordAllHistory(); @@ -456,7 +456,7 @@ public class BatteryStatsNoteTest extends TestCase { @SmallTest public void testNoteGpsChanged() { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); bi.setRecordAllHistoryLocked(true); bi.forceRecordAllHistory(); @@ -480,7 +480,7 @@ public class BatteryStatsNoteTest extends TestCase { @SmallTest public void testNoteGpsChanged_workSource() { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); bi.setRecordAllHistoryLocked(true); bi.forceRecordAllHistory(); @@ -504,7 +504,7 @@ public class BatteryStatsNoteTest extends TestCase { @SmallTest public void testUpdateDisplayMeasuredEnergyStatsLocked() { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms final MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); bi.initMeasuredEnergyStats(); @@ -589,7 +589,7 @@ public class BatteryStatsNoteTest extends TestCase { @SmallTest public void testUpdateCustomMeasuredEnergyStatsLocked_neverCalled() { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms final MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); bi.initMeasuredEnergyStats(); bi.setOnBatteryInternal(true); @@ -603,7 +603,7 @@ public class BatteryStatsNoteTest extends TestCase { @SmallTest public void testUpdateCustomMeasuredEnergyStatsLocked() { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms final MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); bi.initMeasuredEnergyStats(); diff --git a/core/tests/coretests/src/com/android/internal/os/BatteryStatsSamplingTimerTest.java b/core/tests/coretests/src/com/android/internal/os/BatteryStatsSamplingTimerTest.java index 53845a797ff4b..0d2249f33e98f 100644 --- a/core/tests/coretests/src/com/android/internal/os/BatteryStatsSamplingTimerTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BatteryStatsSamplingTimerTest.java @@ -30,7 +30,7 @@ public class BatteryStatsSamplingTimerTest extends TestCase { @SmallTest public void testSettingStalePreservesData() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); final BatteryStatsImpl.SamplingTimer timer = new BatteryStatsImpl.SamplingTimer(clocks, Mockito.mock(BatteryStatsImpl.TimeBase.class)); @@ -57,7 +57,7 @@ public class BatteryStatsSamplingTimerTest extends TestCase { @SmallTest public void testEndSampleAndContinueWhenTimeOrCountDecreases() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); final BatteryStatsImpl.TimeBase timeBase = Mockito.mock(BatteryStatsImpl.TimeBase.class); final BatteryStatsImpl.SamplingTimer timer = new BatteryStatsImpl.SamplingTimer(clocks, timeBase); @@ -107,7 +107,7 @@ public class BatteryStatsSamplingTimerTest extends TestCase { @SmallTest public void testFirstUpdateIsAbsorbed() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); final BatteryStatsImpl.TimeBase timeBase = Mockito.mock(BatteryStatsImpl.TimeBase.class); BatteryStatsImpl.SamplingTimer timer = new BatteryStatsImpl.SamplingTimer(clocks, timeBase); @@ -146,7 +146,7 @@ public class BatteryStatsSamplingTimerTest extends TestCase { @SmallTest public void testSampleTimerSummaryParceling() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); clocks.realtime = 0; clocks.uptime = 0; diff --git a/core/tests/coretests/src/com/android/internal/os/BatteryStatsSensorTest.java b/core/tests/coretests/src/com/android/internal/os/BatteryStatsSensorTest.java index b851f0ad34142..f833981da1b52 100644 --- a/core/tests/coretests/src/com/android/internal/os/BatteryStatsSensorTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BatteryStatsSensorTest.java @@ -34,7 +34,7 @@ public class BatteryStatsSensorTest extends TestCase { @SmallTest public void testSensorStartStop() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); bi.mForceOnBattery = true; clocks.realtime = 100; @@ -71,7 +71,7 @@ public class BatteryStatsSensorTest extends TestCase { @SmallTest public void testCountingWhileOffBattery() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); long curr = 0; // realtime in us @@ -107,7 +107,7 @@ public class BatteryStatsSensorTest extends TestCase { @SmallTest public void testCountingWhileOnBattery() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); long curr = 0; // realtime in us @@ -142,7 +142,7 @@ public class BatteryStatsSensorTest extends TestCase { @SmallTest public void testBatteryStatusOnToOff() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); long curr = 0; // realtime in us @@ -188,7 +188,7 @@ public class BatteryStatsSensorTest extends TestCase { @SmallTest public void testBatteryStatusOffToOn() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); long curr = 0; // realtime in us @@ -240,7 +240,7 @@ public class BatteryStatsSensorTest extends TestCase { @SmallTest public void testPooledBackgroundUsage() throws Exception { final int UID_2 = 20000; // second uid for testing pool usage - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); bi.mForceOnBattery = true; long curr = 0; // realtime in us @@ -377,7 +377,7 @@ public class BatteryStatsSensorTest extends TestCase { @SmallTest public void testSensorReset() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); bi.mForceOnBattery = true; clocks.realtime = 100; @@ -421,7 +421,7 @@ public class BatteryStatsSensorTest extends TestCase { @SmallTest public void testSensorResetTimes() throws Exception { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); MockBatteryStatsImpl bi = new MockBatteryStatsImpl(clocks); final int which = BatteryStats.STATS_SINCE_CHARGED; bi.mForceOnBattery = true; diff --git a/core/tests/coretests/src/com/android/internal/os/BatteryStatsStopwatchTimerTest.java b/core/tests/coretests/src/com/android/internal/os/BatteryStatsStopwatchTimerTest.java index f76f31619f797..94092f148c604 100644 --- a/core/tests/coretests/src/com/android/internal/os/BatteryStatsStopwatchTimerTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BatteryStatsStopwatchTimerTest.java @@ -31,7 +31,7 @@ public class BatteryStatsStopwatchTimerTest extends TestCase { // negative values of count. @SmallTest public void testCount() throws Exception { - final MockClocks clocks = new MockClocks(); // holds realtime and uptime in ms + final MockClock clocks = new MockClock(); // holds realtime and uptime in ms final BatteryStatsImpl.TimeBase timeBase = new BatteryStatsImpl.TimeBase(); timeBase.init(clocks.uptimeMillis(), clocks.elapsedRealtime()); final BatteryStatsImpl.StopwatchTimer timer = new BatteryStatsImpl.StopwatchTimer(clocks, @@ -142,7 +142,7 @@ public class BatteryStatsStopwatchTimerTest extends TestCase { assertEquals(expectedCount, timer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED)); } - private static long updateTime(MockClocks clocks, long time) { + private static long updateTime(MockClock clocks, long time) { return clocks.realtime = clocks.uptime = time; } } diff --git a/core/tests/coretests/src/com/android/internal/os/BatteryStatsTimerTest.java b/core/tests/coretests/src/com/android/internal/os/BatteryStatsTimerTest.java index 11a01b3a42dc3..be3fc8a2f59c5 100644 --- a/core/tests/coretests/src/com/android/internal/os/BatteryStatsTimerTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BatteryStatsTimerTest.java @@ -22,7 +22,6 @@ import android.util.StringBuilderPrinter; import androidx.test.filters.SmallTest; -import com.android.internal.os.BatteryStatsImpl.Clocks; import com.android.internal.os.BatteryStatsImpl.TimeBase; import com.android.internal.os.BatteryStatsImpl.Timer; @@ -41,12 +40,12 @@ public class BatteryStatsTimerTest extends TestCase { int nextComputeCurrentCount; - TestTimer(Clocks clocks, int type, TimeBase timeBase, Parcel in) { - super(clocks, type, timeBase, in); + TestTimer(Clock clock, int type, TimeBase timeBase, Parcel in) { + super(clock, type, timeBase, in); } - TestTimer(Clocks clocks, int type, TimeBase timeBase) { - super(clocks, type, timeBase); + TestTimer(Clock clock, int type, TimeBase timeBase) { + super(clock, type, timeBase); } @Override @@ -91,7 +90,7 @@ public class BatteryStatsTimerTest extends TestCase { @SmallTest public void testRunning() throws Exception { TimeBase timeBase = new TimeBase(); - MockClocks clocks = new MockClocks(); + MockClock clocks = new MockClock(); TestTimer timer = new TestTimer(clocks, 0, timeBase); timer.nextComputeCurrentCount = 3000; @@ -112,7 +111,7 @@ public class BatteryStatsTimerTest extends TestCase { @SmallTest public void testParceling() throws Exception { TimeBase timeBase = new TimeBase(); - MockClocks clocks = new MockClocks(); + MockClock clocks = new MockClock(); // Test write then read TestTimer timer1 = new TestTimer(clocks, 0, timeBase); @@ -157,7 +156,7 @@ public class BatteryStatsTimerTest extends TestCase { @SmallTest public void testResetNoDetach() throws Exception { TimeBase timeBase = new TimeBase(); - MockClocks clocks = new MockClocks(); + MockClock clocks = new MockClock(); TestTimer timer = new TestTimer(clocks, 0, timeBase); timer.setCount(1); @@ -180,7 +179,7 @@ public class BatteryStatsTimerTest extends TestCase { @SmallTest public void testResetDetach() throws Exception { TimeBase timeBase = new TimeBase(); - MockClocks clocks = new MockClocks(); + MockClock clocks = new MockClock(); TestTimer timer = new TestTimer(clocks, 0, timeBase); timer.setCount(1); @@ -208,7 +207,7 @@ public class BatteryStatsTimerTest extends TestCase { Assert.assertEquals(40, timeBase.getRealtime(200)); // the past uptime is 35 and the past runtime is 40 - MockClocks clocks = new MockClocks(); + MockClock clocks = new MockClock(); TestTimer timer1 = new TestTimer(clocks, 0, timeBase); timer1.setCount(1); @@ -250,7 +249,7 @@ public class BatteryStatsTimerTest extends TestCase { timeBase.setRunning(false, 45, 60); Assert.assertEquals(40, timeBase.getRealtime(200)); - MockClocks clocks = new MockClocks(); + MockClock clocks = new MockClock(); TestTimer timer = new TestTimer(clocks, 0, timeBase); timer.setCount(1); @@ -275,7 +274,7 @@ public class BatteryStatsTimerTest extends TestCase { timeBase.setRunning(false, 45, 60); Assert.assertEquals(40, timeBase.getRealtime(200)); - MockClocks clocks = new MockClocks(); + MockClock clocks = new MockClock(); TestTimer timer = new TestTimer(clocks, 0, timeBase); timer.setCount(1); @@ -296,7 +295,7 @@ public class BatteryStatsTimerTest extends TestCase { timeBase.setRunning(false, 45, 60); Assert.assertEquals(40, timeBase.getRealtime(200)); - MockClocks clocks = new MockClocks(); + MockClock clocks = new MockClock(); TestTimer timer = new TestTimer(clocks, 0, timeBase); timer.setCount(1); @@ -313,7 +312,7 @@ public class BatteryStatsTimerTest extends TestCase { @SmallTest public void testLogState() throws Exception { TimeBase timeBase = new TimeBase(); - MockClocks clocks = new MockClocks(); + MockClock clocks = new MockClock(); TestTimer timer = new TestTimer(clocks, 0, timeBase); timer.setTotalTime(100); diff --git a/core/tests/coretests/src/com/android/internal/os/BatteryStatsUidTest.java b/core/tests/coretests/src/com/android/internal/os/BatteryStatsUidTest.java index 4df3190cc2d72..9270346c03884 100644 --- a/core/tests/coretests/src/com/android/internal/os/BatteryStatsUidTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BatteryStatsUidTest.java @@ -27,7 +27,7 @@ public class BatteryStatsUidTest extends TestCase { private static final String TAG = "BatteryStatsTimeBaseTest"; static class TestBsi extends BatteryStatsImpl { - TestBsi(MockClocks clocks) { + TestBsi(MockClock clocks) { super(clocks); } } diff --git a/core/tests/coretests/src/com/android/internal/os/BatteryUsageStatsRule.java b/core/tests/coretests/src/com/android/internal/os/BatteryUsageStatsRule.java index 083090c54619d..e7fa6566f16f7 100644 --- a/core/tests/coretests/src/com/android/internal/os/BatteryUsageStatsRule.java +++ b/core/tests/coretests/src/com/android/internal/os/BatteryUsageStatsRule.java @@ -50,7 +50,7 @@ public class BatteryUsageStatsRule implements TestRule { .build(); private final PowerProfile mPowerProfile; - private final MockClocks mMockClocks = new MockClocks(); + private final MockClock mMockClock = new MockClock(); private final MockBatteryStatsImpl mBatteryStats; private BatteryUsageStats mBatteryUsageStats; @@ -63,8 +63,8 @@ public class BatteryUsageStatsRule implements TestRule { public BatteryUsageStatsRule(long currentTime) { Context context = InstrumentationRegistry.getContext(); mPowerProfile = spy(new PowerProfile(context, true /* forTest */)); - mMockClocks.currentTime = currentTime; - mBatteryStats = new MockBatteryStatsImpl(mMockClocks); + mMockClock.currentTime = currentTime; + mBatteryStats = new MockBatteryStatsImpl(mMockClock); mBatteryStats.setPowerProfile(mPowerProfile); mBatteryStats.onSystemReady(); } @@ -166,12 +166,12 @@ public class BatteryUsageStatsRule implements TestRule { } public void setTime(long realtimeMs, long uptimeMs) { - mMockClocks.realtime = realtimeMs; - mMockClocks.uptime = uptimeMs; + mMockClock.realtime = realtimeMs; + mMockClock.uptime = uptimeMs; } public void setCurrentTime(long currentTimeMs) { - mMockClocks.currentTime = currentTimeMs; + mMockClock.currentTime = currentTimeMs; } BatteryUsageStats apply(PowerCalculator... calculators) { @@ -191,7 +191,7 @@ public class BatteryUsageStatsRule implements TestRule { } for (PowerCalculator calculator : calculators) { - calculator.calculate(builder, mBatteryStats, mMockClocks.realtime, mMockClocks.uptime, + calculator.calculate(builder, mBatteryStats, mMockClock.realtime, mMockClock.uptime, query); } diff --git a/core/tests/coretests/src/com/android/internal/os/BatteryUsageStatsStoreTest.java b/core/tests/coretests/src/com/android/internal/os/BatteryUsageStatsStoreTest.java index e478cd7765585..51f20f380475e 100644 --- a/core/tests/coretests/src/com/android/internal/os/BatteryUsageStatsStoreTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BatteryUsageStatsStoreTest.java @@ -47,7 +47,7 @@ import java.util.Arrays; public class BatteryUsageStatsStoreTest { private static final long MAX_BATTERY_STATS_SNAPSHOT_STORAGE_BYTES = 2 * 1024; - private final MockClocks mMockClocks = new MockClocks(); + private final MockClock mMockClock = new MockClock(); private MockBatteryStatsImpl mBatteryStats; private BatteryUsageStatsStore mBatteryUsageStatsStore; private BatteryUsageStatsProvider mBatteryUsageStatsProvider; @@ -55,8 +55,8 @@ public class BatteryUsageStatsStoreTest { @Before public void setup() { - mMockClocks.currentTime = 123; - mBatteryStats = new MockBatteryStatsImpl(mMockClocks); + mMockClock.currentTime = 123; + mBatteryStats = new MockBatteryStatsImpl(mMockClock); mBatteryStats.setNoAutoReset(true); mBatteryStats.setPowerProfile(mock(PowerProfile.class)); mBatteryStats.onSystemReady(); @@ -75,7 +75,7 @@ public class BatteryUsageStatsStoreTest { @Test public void testStoreSnapshot() { - mMockClocks.currentTime = 1_600_000; + mMockClock.currentTime = 1_600_000; prepareBatteryStats(); mBatteryStats.resetAllStatsCmdLocked(); @@ -99,9 +99,9 @@ public class BatteryUsageStatsStoreTest { public void testGarbageCollectOldSnapshots() throws Exception { prepareBatteryStats(); - mMockClocks.realtime = 10_000_000; - mMockClocks.uptime = 10_000_000; - mMockClocks.currentTime = 10_000_000; + mMockClock.realtime = 10_000_000; + mMockClock.uptime = 10_000_000; + mMockClock.currentTime = 10_000_000; final int snapshotFileSize = getSnapshotFileSize(); final int numberOfSnapshots = @@ -109,9 +109,9 @@ public class BatteryUsageStatsStoreTest { for (int i = 0; i < numberOfSnapshots + 2; i++) { mBatteryStats.resetAllStatsCmdLocked(); - mMockClocks.realtime += 10_000_000; - mMockClocks.uptime += 10_000_000; - mMockClocks.currentTime += 10_000_000; + mMockClock.realtime += 10_000_000; + mMockClock.uptime += 10_000_000; + mMockClock.currentTime += 10_000_000; prepareBatteryStats(); } @@ -137,11 +137,11 @@ public class BatteryUsageStatsStoreTest { private void prepareBatteryStats() { mBatteryStats.setBatteryStateLocked(BatteryManager.BATTERY_STATUS_DISCHARGING, 100, /* plugType */ 0, 90, 72, 3700, 3_600_000, 4_000_000, 0, - mMockClocks.realtime, mMockClocks.uptime, mMockClocks.currentTime); + mMockClock.realtime, mMockClock.uptime, mMockClock.currentTime); mBatteryStats.setBatteryStateLocked(BatteryManager.BATTERY_STATUS_DISCHARGING, 100, /* plugType */ 0, 85, 72, 3700, 3_000_000, 4_000_000, 0, - mMockClocks.realtime + 500_000, mMockClocks.uptime + 500_000, - mMockClocks.currentTime + 500_000); + mMockClock.realtime + 500_000, mMockClock.uptime + 500_000, + mMockClock.currentTime + 500_000); } private void clearDirectory(File dir) { diff --git a/core/tests/coretests/src/com/android/internal/os/BatteryUsageStatsTest.java b/core/tests/coretests/src/com/android/internal/os/BatteryUsageStatsTest.java index fedbf7a9868e2..c58df4e641636 100644 --- a/core/tests/coretests/src/com/android/internal/os/BatteryUsageStatsTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BatteryUsageStatsTest.java @@ -228,7 +228,7 @@ public class BatteryUsageStatsTest { } private BatteryUsageStats.Builder buildBatteryUsageStats1(boolean includeUserBatteryConsumer) { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); final MockBatteryStatsImpl batteryStats = new MockBatteryStatsImpl(clocks); final BatteryUsageStats.Builder builder = @@ -267,7 +267,7 @@ public class BatteryUsageStatsTest { } private BatteryUsageStats.Builder buildBatteryUsageStats2(String[] customPowerComponentNames) { - final MockClocks clocks = new MockClocks(); + final MockClock clocks = new MockClock(); final MockBatteryStatsImpl batteryStats = new MockBatteryStatsImpl(clocks); final BatteryUsageStats.Builder builder = diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidUserSysTimeReaderTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidUserSysTimeReaderTest.java index 177f34875894c..1da1a9095d878 100644 --- a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidUserSysTimeReaderTest.java +++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidUserSysTimeReaderTest.java @@ -23,7 +23,6 @@ import static org.junit.Assert.assertTrue; import android.content.Context; import android.os.FileUtils; -import android.os.SystemClock; import android.util.SparseArray; import androidx.test.InstrumentationRegistry; @@ -56,7 +55,7 @@ public class KernelCpuUidUserSysTimeReaderTest { private KernelCpuUidTimeReader.KernelCpuUidUserSysTimeReader mReader; private VerifiableCallback mCallback; - private Random mRand = new Random(12345); + private final Random mRand = new Random(12345); private final int[] mUids = {0, 1, 22, 333, 4444, 55555}; private final long[][] mInitialTimes = new long[][]{ {15334000, 310964000}, @@ -67,6 +66,8 @@ public class KernelCpuUidUserSysTimeReaderTest { {47000, 17000} }; + private final MockClock mMockClock = new MockClock(); + private Context getContext() { return InstrumentationRegistry.getContext(); } @@ -76,7 +77,8 @@ public class KernelCpuUidUserSysTimeReaderTest { mTestDir = getContext().getDir("test", Context.MODE_PRIVATE); mTestFile = new File(mTestDir, "test.file"); mReader = new KernelCpuUidUserSysTimeReader( - new KernelCpuProcStringReader(mTestFile.getAbsolutePath()), false); + new KernelCpuProcStringReader(mTestFile.getAbsolutePath(), mMockClock), + false, mMockClock); mCallback = new VerifiableCallback(); } @@ -87,10 +89,13 @@ public class KernelCpuUidUserSysTimeReaderTest { } @Test - @SkipPresubmit("b/180015146") public void testThrottler() throws Exception { + mMockClock.realtime = 1000; + mReader = new KernelCpuUidUserSysTimeReader( - new KernelCpuProcStringReader(mTestFile.getAbsolutePath()), true); + new KernelCpuProcStringReader(mTestFile.getAbsolutePath(), mMockClock), + true, mMockClock); + mReader.setThrottle(500); writeToFile(uidLines(mUids, mInitialTimes)); @@ -103,8 +108,7 @@ public class KernelCpuUidUserSysTimeReaderTest { mReader.readDelta(false, mCallback); assertEquals(0, mCallback.mData.size()); - // TODO(b/180473895): Replace sleeps with injected simulated time. - SystemClock.sleep(600); + mMockClock.realtime += 600; long[][] times2 = increaseTime(times1); writeToFile(uidLines(mUids, times2)); @@ -123,7 +127,7 @@ public class KernelCpuUidUserSysTimeReaderTest { mReader.readDelta(true, mCallback); assertEquals(6, mCallback.mData.size()); - SystemClock.sleep(600); + mMockClock.realtime += 600; long[][] times4 = increaseTime(times3); writeToFile(uidLines(mUids, times4)); @@ -138,7 +142,7 @@ public class KernelCpuUidUserSysTimeReaderTest { mReader.readDelta(false, mCallback); assertEquals(0, mCallback.mData.size()); - SystemClock.sleep(600); + mMockClock.realtime += 600; mCallback.clear(); mReader.readDelta(false, mCallback); diff --git a/core/tests/coretests/src/com/android/internal/os/MockBatteryStatsImpl.java b/core/tests/coretests/src/com/android/internal/os/MockBatteryStatsImpl.java index d9b69b1493554..c8387cb232196 100644 --- a/core/tests/coretests/src/com/android/internal/os/MockBatteryStatsImpl.java +++ b/core/tests/coretests/src/com/android/internal/os/MockBatteryStatsImpl.java @@ -36,13 +36,13 @@ import java.util.concurrent.Future; * Mocks a BatteryStatsImpl object. */ public class MockBatteryStatsImpl extends BatteryStatsImpl { - public BatteryStatsImpl.Clocks clocks; + public Clock mClock; public boolean mForceOnBattery; private NetworkStats mNetworkStats; - MockBatteryStatsImpl(Clocks clocks) { - super(clocks); - this.clocks = mClocks; + MockBatteryStatsImpl(Clock clock) { + super(clock); + this.mClock = mClock; initTimersAndCounters(); setExternalStatsSyncLocked(new DummyExternalStatsSync()); @@ -54,7 +54,7 @@ public class MockBatteryStatsImpl extends BatteryStatsImpl { } MockBatteryStatsImpl() { - this(new MockClocks()); + this(new MockClock()); } public void initMeasuredEnergyStats() { diff --git a/core/tests/coretests/src/com/android/internal/os/MockClocks.java b/core/tests/coretests/src/com/android/internal/os/MockClock.java similarity index 94% rename from core/tests/coretests/src/com/android/internal/os/MockClocks.java rename to core/tests/coretests/src/com/android/internal/os/MockClock.java index c26505e57346b..ac69c33e50a2b 100644 --- a/core/tests/coretests/src/com/android/internal/os/MockClocks.java +++ b/core/tests/coretests/src/com/android/internal/os/MockClock.java @@ -16,7 +16,7 @@ package com.android.internal.os; -public class MockClocks implements BatteryStatsImpl.Clocks { +public class MockClock extends Clock { /** ElapsedRealtime in ms */ public long realtime; /** Uptime in ms */