summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2015-09-21 16:54:52 -0700
committerAdam Lesinski <adamlesinski@google.com>2015-09-21 17:38:52 -0700
commit52290c9c4fca5bec384382406dd1b4d28b424a89 (patch)
treee41fd478cfbe2e699c2d3bb6afba3823318a5669
parent88f92ec5a76c94dcb084ffcc8a4fc36a66bb9ca2 (diff)
downloadframeworks_base-52290c9c4fca5bec384382406dd1b4d28b424a89.zip
frameworks_base-52290c9c4fca5bec384382406dd1b4d28b424a89.tar.gz
frameworks_base-52290c9c4fca5bec384382406dd1b4d28b424a89.tar.bz2
Fix Array Index Out of Bounds in BatteryStatsImpl
If the power profile was not set yet, the default sizes of cpu freq arrays could have been too small. Bug:24244089 Change-Id: Ic17a1e8f2058c51fbdda14db35b7b62f4880be00
-rw-r--r--core/java/com/android/internal/os/BatteryStatsImpl.java17
1 files changed, 13 insertions, 4 deletions
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index 6ccdd08..e39bf60 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -8044,6 +8044,10 @@ public final class BatteryStatsImpl extends BatteryStats {
* wakelocks. If the screen is on, we just assign the actual cpu time an app used.
*/
public void updateCpuTimeLocked() {
+ if (mPowerProfile == null) {
+ return;
+ }
+
if (DEBUG_ENERGY_CPU) {
Slog.d(TAG, "!Cpu updating!");
}
@@ -8131,14 +8135,19 @@ public final class BatteryStatsImpl extends BatteryStats {
// Add the cpu speeds to this UID. These are used as a ratio
// for computing the power this UID used.
- if (u.mCpuClusterSpeed == null) {
- u.mCpuClusterSpeed = new LongSamplingCounter[clusterSpeeds.length][];
+ final int numClusters = mPowerProfile.getNumCpuClusters();
+ if (u.mCpuClusterSpeed == null || u.mCpuClusterSpeed.length !=
+ numClusters) {
+ u.mCpuClusterSpeed = new LongSamplingCounter[numClusters][];
}
for (int cluster = 0; cluster < clusterSpeeds.length; cluster++) {
- if (u.mCpuClusterSpeed[cluster] == null) {
+ final int speedsInCluster = mPowerProfile.getNumSpeedStepsInCpuCluster(
+ cluster);
+ if (u.mCpuClusterSpeed[cluster] == null || speedsInCluster !=
+ u.mCpuClusterSpeed[cluster].length) {
u.mCpuClusterSpeed[cluster] =
- new LongSamplingCounter[clusterSpeeds[cluster].length];
+ new LongSamplingCounter[speedsInCluster];
}
final LongSamplingCounter[] cpuSpeeds = u.mCpuClusterSpeed[cluster];