[Robustness] protect get battery stats from DeadSystemException

Refine the original workaround patch in the ag/15527095 from NPE to
return default BatteryUsageStats instance as we merged in the
ag/15919139 (align the same solution).

Bug: 195306545
Test: make SettingsRoboTests
Change-Id: Ic03e8296d16ecb8629155f75727e9cde48c303eb
This commit is contained in:
ykhung
2021-09-28 17:30:04 +08:00
committed by YUKAI HUNG
parent d9db89af86
commit e893a890ca
5 changed files with 12 additions and 20 deletions

View File

@@ -373,8 +373,11 @@ public class BatteryUtils {
batteryUsageStats = systemService.getBatteryUsageStats(
new BatteryUsageStatsQuery.Builder().includeBatteryHistory().build());
} catch (RuntimeException e) {
Log.e(TAG, "getBatteryInfo() from getBatteryUsageStats()", e);
return null;
Log.e(TAG, "getBatteryInfo() error from getBatteryUsageStats()", e);
// Use default BatteryUsageStats.
batteryUsageStats =
new BatteryUsageStats.Builder(new String[0], /* includePowerModels */ false)
.build();
}
final long startTime = System.currentTimeMillis();