[Robustness] protect get battery stats from DeadSystemException
In some corner cases, we will receive the DeadSystemException from BatteryStatService when invoking getBatteryUsageStats() method. Before this issue is resolved by BatteryStatService team, we will add some protections to avoid Settings app is crashed. Bug: 195306545 Bug: 195467687 Test: make SettingsRoboTests Change-Id: I75fcf63f4f69d86d6dce0e12bd4d738b1219ae47
This commit is contained in:
@@ -368,8 +368,14 @@ public class BatteryUtils {
|
||||
public BatteryInfo getBatteryInfo(final String tag) {
|
||||
final BatteryStatsManager systemService = mContext.getSystemService(
|
||||
BatteryStatsManager.class);
|
||||
final BatteryUsageStats batteryUsageStats = systemService.getBatteryUsageStats(
|
||||
new BatteryUsageStatsQuery.Builder().includeBatteryHistory().build());
|
||||
BatteryUsageStats batteryUsageStats;
|
||||
try {
|
||||
batteryUsageStats = systemService.getBatteryUsageStats(
|
||||
new BatteryUsageStatsQuery.Builder().includeBatteryHistory().build());
|
||||
} catch (RuntimeException e) {
|
||||
Log.e(TAG, "getBatteryInfo() from getBatteryUsageStats()", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
final long startTime = System.currentTimeMillis();
|
||||
|
||||
|
Reference in New Issue
Block a user