Read cpu freq data only when needed.
Bug: 34133340
Test: cts-tradefed run singleCommand cts-dev -m ctsIncidentHostTestCases -t \
com.android.server.cts.BatteryStatsValidationTest
Change-Id: Ib235e166820b95b5cd0a496b6146ea353abdf844
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index 25d5fae..d72f57d 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -185,7 +185,7 @@
switch (msg.what) {
case MSG_UPDATE_WAKELOCKS:
synchronized (BatteryStatsImpl.this) {
- updateCpuTimeLocked();
+ updateCpuTimeLocked(false /* updateCpuFreqData */);
}
if (cb != null) {
cb.batteryNeedsCpuUpdate();
@@ -3480,7 +3480,7 @@
Slog.d(TAG, "Updating cpu time because screen is now " +
(unpluggedScreenOff ? "off" : "on"));
}
- updateCpuTimeLocked();
+ updateCpuTimeLocked(true /* updateCpuFreqData */);
mOnBatteryScreenOffTimeBase.setRunning(unpluggedScreenOff, uptime, realtime);
}
}
@@ -9936,7 +9936,7 @@
* and we are on battery with screen off, we give more of the cpu time to those apps holding
* wakelocks. If the screen is on, we just assign the actual cpu time an app used.
*/
- public void updateCpuTimeLocked() {
+ public void updateCpuTimeLocked(boolean updateCpuFreqData) {
if (mPowerProfile == null) {
return;
}
@@ -10051,7 +10051,9 @@
}
});
- readKernelUidCpuFreqTimesLocked();
+ if (updateCpuFreqData) {
+ readKernelUidCpuFreqTimesLocked();
+ }
final long elapse = (mClocks.elapsedRealtime() - startTimeMs);
if (DEBUG_ENERGY_CPU || (elapse >= 100)) {