DO NOT MERGE: Update BatteryStatsImpl to handle change in no. of freqs.
Bug: 62240247
Test: cts-tradefed run singleCommand cts-dev -m CtsIncidentHostTestCases -t \
com.android.server.cts.BatteryStatsValidationTest
Change-Id: I1328fe7bf29229e9563cde6eea80addf2b91ea5d
diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java
index 6d44330..cea5715 100644
--- a/core/java/android/os/BatteryStats.java
+++ b/core/java/android/os/BatteryStats.java
@@ -3667,25 +3667,29 @@
0 /* old cpu power, keep for compatibility */);
}
- final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which);
- // If total cpuFreqTimes is null, then we don't need to check for screenOffCpuFreqTimes.
- if (cpuFreqTimeMs != null) {
- sb.setLength(0);
- for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
- sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]);
- }
- final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which);
- if (screenOffCpuFreqTimeMs != null) {
- for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) {
- sb.append("," + screenOffCpuFreqTimeMs[i]);
- }
- } else {
+ // If the cpuFreqs is null, then don't bother checking for cpu freq times.
+ if (cpuFreqs != null) {
+ final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which);
+ // If total cpuFreqTimes is null, then we don't need to check for
+ // screenOffCpuFreqTimes.
+ if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) {
+ sb.setLength(0);
for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
- sb.append(",0");
+ sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]);
}
+ final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which);
+ if (screenOffCpuFreqTimeMs != null) {
+ for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) {
+ sb.append("," + screenOffCpuFreqTimeMs[i]);
+ }
+ } else {
+ for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
+ sb.append(",0");
+ }
+ }
+ dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL,
+ cpuFreqTimeMs.length, sb.toString());
}
- dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL,
- cpuFreqTimeMs.length, sb.toString());
}
final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index 611c4b8..41fc0650 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -1063,6 +1063,10 @@
}
}
+ public int getSize() {
+ return mCounts == null ? 0 : mCounts.length;
+ }
+
/**
* Clear state of this counter.
*/
@@ -10526,11 +10530,13 @@
return;
}
final Uid u = getUidStatsLocked(uid);
- if (u.mCpuFreqTimeMs == null) {
+ if (u.mCpuFreqTimeMs == null
+ || u.mCpuFreqTimeMs.getSize() != cpuFreqTimeMs.length) {
u.mCpuFreqTimeMs = new LongSamplingCounterArray(mOnBatteryTimeBase);
}
u.mCpuFreqTimeMs.addCountLocked(cpuFreqTimeMs);
- if (u.mScreenOffCpuFreqTimeMs == null) {
+ if (u.mScreenOffCpuFreqTimeMs == null
+ || u.mScreenOffCpuFreqTimeMs.getSize() != cpuFreqTimeMs.length) {
u.mScreenOffCpuFreqTimeMs = new LongSamplingCounterArray(
mOnBatteryScreenOffTimeBase);
}