Make the estimator cache logic is the same as SysUI flow

Ensure the remaining time estimator cache logic is the same as SysUI
https://source.corp.google.com/android/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryControllerImpl.java;l=375-386

Test: presubmit
Fix: 285747156
Change-Id: If7218dc70792aafaec45c71018897bed80df7f3d
This commit is contained in:
ykhung
2023-06-05 01:01:55 +08:00
committed by YK Hung
parent 4834abe241
commit 53f48c4a97

View File

@@ -451,12 +451,10 @@ public class BatteryUtils {
@VisibleForTesting @VisibleForTesting
Estimate getEnhancedEstimate() { Estimate getEnhancedEstimate() {
Estimate estimate = null; // Align the same logic in the BatteryControllerImpl.updateEstimate()
// Get enhanced prediction if available Estimate estimate = Estimate.getCachedEstimateIfAvailable(mContext);
if (Duration.between(Estimate.getLastCacheUpdateTime(mContext), Instant.now()) if (estimate == null &&
.compareTo(Duration.ofSeconds(10)) < 0) { mPowerUsageFeatureProvider != null &&
estimate = Estimate.getCachedEstimateIfAvailable(mContext);
} else if (mPowerUsageFeatureProvider != null &&
mPowerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(mContext)) { mPowerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(mContext)) {
estimate = mPowerUsageFeatureProvider.getEnhancedBatteryPrediction(mContext); estimate = mPowerUsageFeatureProvider.getEnhancedBatteryPrediction(mContext);
if (estimate != null) { if (estimate != null) {