Use enhanced estimate battery info when available
This CL updates the battery page to get the updated strings and other relevant battery info from directly from SettingsLib by providing it an overrided drain time instead of manually changing the value in the returned info. This will provide the added benefit of using the new strings when appropriate that tell the user that the estimate provided is based on their usage. Test: robotests Bug: 38399659 Change-Id: I0db572c2ea78910756314b6bf066d37e9f90a15c
This commit is contained in:
@@ -189,12 +189,11 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
final long elapsedRealtimeUs = SystemClock.elapsedRealtime() * 1000;
|
||||
final long elapsedRealtimeUs =
|
||||
mBatteryUtils.convertMsToUs(SystemClock.elapsedRealtime());
|
||||
Intent batteryBroadcast = getContext().registerReceiver(null,
|
||||
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
BatteryInfo batteryInfo = BatteryInfo.getBatteryInfo(getContext(),
|
||||
batteryBroadcast, mStatsHelper.getStats(), elapsedRealtimeUs, false);
|
||||
useEnhancedEstimateIfAvailable(getContext(), batteryInfo);
|
||||
BatteryInfo batteryInfo = getBatteryInfo(elapsedRealtimeUs, batteryBroadcast);
|
||||
updateHeaderPreference(batteryInfo);
|
||||
}
|
||||
|
||||
@@ -499,12 +498,10 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
|
||||
initAnomalyDetectionIfPossible();
|
||||
|
||||
final long elapsedRealtimeUs = SystemClock.elapsedRealtime() * 1000;
|
||||
final long elapsedRealtimeUs = mBatteryUtils.convertMsToUs(SystemClock.elapsedRealtime());
|
||||
Intent batteryBroadcast = context.registerReceiver(null,
|
||||
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
BatteryInfo batteryInfo = BatteryInfo.getBatteryInfo(context, batteryBroadcast,
|
||||
mStatsHelper.getStats(), elapsedRealtimeUs, false);
|
||||
useEnhancedEstimateIfAvailable(context, batteryInfo);
|
||||
BatteryInfo batteryInfo = getBatteryInfo(elapsedRealtimeUs, batteryBroadcast);
|
||||
updateHeaderPreference(batteryInfo);
|
||||
|
||||
final long runningTime = calculateRunningTimeBasedOnStatsType();
|
||||
@@ -665,7 +662,7 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
|
||||
@VisibleForTesting
|
||||
long calculateRunningTimeBasedOnStatsType() {
|
||||
final long elapsedRealtimeUs = SystemClock.elapsedRealtime() * 1000;
|
||||
final long elapsedRealtimeUs = mBatteryUtils.convertMsToUs(SystemClock.elapsedRealtime());
|
||||
// Return the battery time (millisecond) on status mStatsType
|
||||
return mStatsHelper.getStats().computeBatteryRealtime(elapsedRealtimeUs,
|
||||
mStatsType /* STATS_SINCE_CHARGED */) / 1000;
|
||||
@@ -748,17 +745,20 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void useEnhancedEstimateIfAvailable(Context context, BatteryInfo batteryInfo) {
|
||||
if (mEnhancedEstimate > 0
|
||||
&& mPowerFeatureProvider.isEnhancedBatteryPredictionEnabled(context)) {
|
||||
final Resources resources = context.getResources();
|
||||
batteryInfo.remainingTimeUs = mEnhancedEstimate;
|
||||
String timeString = Formatter.formatShortElapsedTime(context, mEnhancedEstimate);
|
||||
batteryInfo.remainingLabel = resources.getString(
|
||||
com.android.settingslib.R.string.power_remaining_duration_only,
|
||||
timeString);
|
||||
private BatteryInfo getBatteryInfo(long elapsedRealtimeUs, Intent batteryBroadcast) {
|
||||
BatteryInfo batteryInfo;
|
||||
if (mEnhancedEstimate > 0 &&
|
||||
mPowerFeatureProvider.isEnhancedBatteryPredictionEnabled(
|
||||
getContext())) {
|
||||
// Drain time is in micro-seconds so we have to multiply by 1000
|
||||
batteryInfo = BatteryInfo.getBatteryInfo(getContext(), batteryBroadcast,
|
||||
mStatsHelper.getStats(), elapsedRealtimeUs, false,
|
||||
mBatteryUtils.convertMsToUs(mEnhancedEstimate), true);
|
||||
} else {
|
||||
batteryInfo = BatteryInfo.getBatteryInfo(getContext(), batteryBroadcast,
|
||||
mStatsHelper.getStats(), elapsedRealtimeUs, false);
|
||||
}
|
||||
return batteryInfo;
|
||||
}
|
||||
|
||||
private static List<BatterySipper> getFakeStats() {
|
||||
|
Reference in New Issue
Block a user