OSDN Git Service

Prevent early boot crash reading PowerProfile
authorAdam Lesinski <adamlesinski@google.com>
Wed, 22 Jun 2016 17:28:47 +0000 (10:28 -0700)
committerAdam Lesinski <adamlesinski@google.com>
Wed, 22 Jun 2016 17:28:47 +0000 (10:28 -0700)
The PowerProfile in BatteryStatsImpl may not be ready when
resetting stats early in the boot sequence.

Bug:29559031
Change-Id: I51bba762231a08804f1b68505bb1b0523476081d

core/java/com/android/internal/os/BatteryStatsImpl.java

index f853e04..a1df8c1 100644 (file)
@@ -8186,7 +8186,12 @@ public class BatteryStatsImpl extends BatteryStats {
         for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
             mScreenBrightnessTimer[i].reset(false);
         }
-        mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity();
+
+        if (mPowerProfile != null) {
+            mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity();
+        } else {
+            mEstimatedBatteryCapacity = -1;
+        }
         mInteractiveTimer.reset(false);
         mPowerSaveModeEnabledTimer.reset(false);
         mLastIdleTimeStart = elapsedRealtimeMillis;