This only happens in new device with broken power_profile.xml, in
which it doesn't have screen power model.
This CL catches the null pointer crash and log it.
Change-Id: Iac23e3a8fc51385bdb22979c4b59000319f6fd49
Fixes:
74617269
Test: RunSettingsRoboTests
}
if (totalActivityTimeMs >= 10 * DateUtils.MINUTE_IN_MILLIS) {
+ if (screenSipper == null) {
+ Log.e(TAG, "screen sipper is null even when app screen time is not zero");
+ return;
+ }
+
final double screenPowerMah = screenSipper.totalPowerMah;
for (int i = 0, size = sippers.size(); i < size; i++) {
final BatterySipper sipper = sippers.get(i);
}
@Test
+ public void testSmearScreenBatterySipper_screenSipperNull_shouldNotCrash() {
+ final BatterySipper sipperFg = createTestSmearBatterySipper(TIME_FOREGROUND,
+ BATTERY_APP_USAGE, 2 /* uid */, false /* isUidNull */);
+
+ final List<BatterySipper> sippers = new ArrayList<>();
+ sippers.add(sipperFg);
+
+ // Shouldn't crash
+ mBatteryUtils.smearScreenBatterySipper(sippers, null /* screenSipper */);
+ }
+
+ @Test
public void testCalculateRunningTimeBasedOnStatsType() {
assertThat(mBatteryUtils.calculateRunningTimeBasedOnStatsType(mBatteryStatsHelper,
BatteryStats.STATS_SINCE_CHARGED)).isEqualTo(TIME_SINCE_LAST_FULL_CHARGE_MS);