Fix crash in BatteryUtils

When enhanced estimation is enabled, it may still have malfunction
when getting data from it. This CL handles this case and fall back
to default estimation.

Change-Id: Id8d75b07316afa8a73a302b49dc7f8e8b77d4fa4
Fixes: 121213171
Test: RunSettingsRoboTests
This commit is contained in:
jackqdyulei
2018-12-18 15:20:22 -08:00
parent 18873b9278
commit 2def5ccb6c
2 changed files with 26 additions and 6 deletions

View File

@@ -449,12 +449,14 @@ public class BatteryUtils {
final BatteryStats stats = statsHelper.getStats();
BatteryInfo batteryInfo;
final Estimate estimate;
Estimate estimate = null;
// Get enhanced prediction if available
if (mPowerUsageFeatureProvider != null &&
mPowerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(mContext)) {
estimate = mPowerUsageFeatureProvider.getEnhancedBatteryPrediction(mContext);
} else {
}
if (estimate == null) {
estimate = new Estimate(
PowerUtil.convertUsToMs(stats.computeBatteryTimeRemaining(elapsedRealtimeUs)),
false /* isBasedOnUsage */,