From 6cd1c3dc4e84a7c43b85b14e58e61b37df77f872 Mon Sep 17 00:00:00 2001 From: Dmitri Plotnikov Date: Thu, 6 Oct 2022 18:10:45 -0700 Subject: Fix CPU power bracket initialization when /proc/uid_time_in_state file is unsupported Bug: 251552446 Test: atest FrameworksServicesTests Change-Id: I99c4133b2eef8cb52760fe60f378860da36583d3 --- .../core/java/com/android/server/power/stats/BatteryStatsImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/power/stats/BatteryStatsImpl.java b/services/core/java/com/android/server/power/stats/BatteryStatsImpl.java index 6e931717c1dd..77fb360ffb85 100644 --- a/services/core/java/com/android/server/power/stats/BatteryStatsImpl.java +++ b/services/core/java/com/android/server/power/stats/BatteryStatsImpl.java @@ -10818,6 +10818,8 @@ public class BatteryStatsImpl extends BatteryStats { public void setPowerProfileLocked(PowerProfile profile) { mPowerProfile = profile; + int totalSpeedStepCount = 0; + // We need to initialize the KernelCpuSpeedReaders to read from // the first cpu of each core. Once we have the PowerProfile, we have access to this // information. @@ -10829,11 +10831,12 @@ public class BatteryStatsImpl extends BatteryStats { mKernelCpuSpeedReaders[i] = new KernelCpuSpeedReader(firstCpuOfCluster, numSpeedSteps); firstCpuOfCluster += mPowerProfile.getNumCoresInCpuCluster(i); + totalSpeedStepCount += numSpeedSteps; } // Initialize CPU power bracket map, which combines CPU states (cluster/freq pairs) // into a small number of brackets - mCpuPowerBracketMap = new int[getCpuFreqCount()]; + mCpuPowerBracketMap = new int[totalSpeedStepCount]; int index = 0; int numCpuClusters = mPowerProfile.getNumCpuClusters(); for (int cluster = 0; cluster < numCpuClusters; cluster++) { -- cgit v1.2.3-59-g8ed1b