[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:
@@ -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();
|
||||
|
Reference in New Issue
Block a user