Loading packages/SettingsLib/src/com/android/settingslib/fuelgauge/Estimate.kt +1 −1 Original line number Diff line number Diff line Loading @@ -45,7 +45,7 @@ class Estimate( Settings.Global.getLong( resolver, Settings.Global.BATTERY_ESTIMATES_LAST_UPDATE_TIME, -1)) return if (Duration.between(lastUpdateTime, Instant.now()).compareTo(Duration.ofMinutes(2)) > 0) { Instant.now()).compareTo(Duration.ofMinutes(1)) > 0) { null } else Estimate( Settings.Global.getLong(resolver, Loading packages/SystemUI/src/com/android/systemui/BatteryMeterView.java +9 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import android.graphics.Rect; import android.net.Uri; import android.os.Handler; import android.provider.Settings; import android.text.TextUtils; import android.util.ArraySet; import android.util.AttributeSet; import android.util.TypedValue; Loading Loading @@ -319,6 +320,9 @@ public class BatteryMeterView extends LinearLayout implements mUser = ActivityManager.getCurrentUser(); getContext().getContentResolver().registerContentObserver( Settings.System.getUriFor(SHOW_BATTERY_PERCENT), false, mSettingObserver, mUser); getContext().getContentResolver().registerContentObserver( Settings.Global.getUriFor(Settings.Global.BATTERY_ESTIMATES_LAST_UPDATE_TIME), false, mSettingObserver); updateShowPercent(); subscribeForTunerUpdates(); mUserTracker.startTracking(); Loading Loading @@ -493,6 +497,11 @@ public class BatteryMeterView extends LinearLayout implements public void onChange(boolean selfChange, Uri uri) { super.onChange(selfChange, uri); updateShowPercent(); if (TextUtils.equals(uri.getLastPathSegment(), Settings.Global.BATTERY_ESTIMATES_LAST_UPDATE_TIME)) { // update the text for sure if the estimate in the cache was updated updatePercentText(); } } } } packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryControllerImpl.java +13 −12 Original line number Diff line number Diff line Loading @@ -73,7 +73,6 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC private boolean mTestmode = false; private boolean mHasReceivedBattery = false; private Estimate mEstimate; private long mLastEstimateTimestamp = -1; private boolean mFetchingEstimate = false; @Inject Loading Loading @@ -203,13 +202,6 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC @Override public void getEstimatedTimeRemainingString(EstimateFetchCompletion completion) { if (mEstimate != null && mLastEstimateTimestamp > System.currentTimeMillis() - UPDATE_GRANULARITY_MSEC) { String percentage = generateTimeRemainingString(); completion.onBatteryRemainingEstimateRetrieved(percentage); return; } // Need to fetch or refresh the estimate, but it may involve binder calls so offload the // work synchronized (mFetchCallbacks) { Loading Loading @@ -238,8 +230,10 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC mFetchingEstimate = true; Dependency.get(Dependency.BG_HANDLER).post(() -> { // Only fetch the estimate if they are enabled mEstimate = mEstimates.isHybridNotificationEnabled() ? mEstimates.getEstimate() : null; mLastEstimateTimestamp = System.currentTimeMillis(); mEstimate = null; if (mEstimates.isHybridNotificationEnabled()) { updateEstimate(); } mFetchingEstimate = false; Dependency.get(Dependency.MAIN_HANDLER).post(this::notifyEstimateFetchCallbacks); }); Loading @@ -258,8 +252,15 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC } private void updateEstimate() { // if the estimate has been cached we can just use that, otherwise get a new one and // throw it in the cache. mEstimate = Estimate.getCachedEstimateIfAvailable(mContext); if (mEstimate == null) { mEstimate = mEstimates.getEstimate(); mLastEstimateTimestamp = System.currentTimeMillis(); if (mEstimate != null) { Estimate.storeCachedEstimate(mContext, mEstimate); } } } private void updatePowerSave() { Loading Loading
packages/SettingsLib/src/com/android/settingslib/fuelgauge/Estimate.kt +1 −1 Original line number Diff line number Diff line Loading @@ -45,7 +45,7 @@ class Estimate( Settings.Global.getLong( resolver, Settings.Global.BATTERY_ESTIMATES_LAST_UPDATE_TIME, -1)) return if (Duration.between(lastUpdateTime, Instant.now()).compareTo(Duration.ofMinutes(2)) > 0) { Instant.now()).compareTo(Duration.ofMinutes(1)) > 0) { null } else Estimate( Settings.Global.getLong(resolver, Loading
packages/SystemUI/src/com/android/systemui/BatteryMeterView.java +9 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import android.graphics.Rect; import android.net.Uri; import android.os.Handler; import android.provider.Settings; import android.text.TextUtils; import android.util.ArraySet; import android.util.AttributeSet; import android.util.TypedValue; Loading Loading @@ -319,6 +320,9 @@ public class BatteryMeterView extends LinearLayout implements mUser = ActivityManager.getCurrentUser(); getContext().getContentResolver().registerContentObserver( Settings.System.getUriFor(SHOW_BATTERY_PERCENT), false, mSettingObserver, mUser); getContext().getContentResolver().registerContentObserver( Settings.Global.getUriFor(Settings.Global.BATTERY_ESTIMATES_LAST_UPDATE_TIME), false, mSettingObserver); updateShowPercent(); subscribeForTunerUpdates(); mUserTracker.startTracking(); Loading Loading @@ -493,6 +497,11 @@ public class BatteryMeterView extends LinearLayout implements public void onChange(boolean selfChange, Uri uri) { super.onChange(selfChange, uri); updateShowPercent(); if (TextUtils.equals(uri.getLastPathSegment(), Settings.Global.BATTERY_ESTIMATES_LAST_UPDATE_TIME)) { // update the text for sure if the estimate in the cache was updated updatePercentText(); } } } }
packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryControllerImpl.java +13 −12 Original line number Diff line number Diff line Loading @@ -73,7 +73,6 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC private boolean mTestmode = false; private boolean mHasReceivedBattery = false; private Estimate mEstimate; private long mLastEstimateTimestamp = -1; private boolean mFetchingEstimate = false; @Inject Loading Loading @@ -203,13 +202,6 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC @Override public void getEstimatedTimeRemainingString(EstimateFetchCompletion completion) { if (mEstimate != null && mLastEstimateTimestamp > System.currentTimeMillis() - UPDATE_GRANULARITY_MSEC) { String percentage = generateTimeRemainingString(); completion.onBatteryRemainingEstimateRetrieved(percentage); return; } // Need to fetch or refresh the estimate, but it may involve binder calls so offload the // work synchronized (mFetchCallbacks) { Loading Loading @@ -238,8 +230,10 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC mFetchingEstimate = true; Dependency.get(Dependency.BG_HANDLER).post(() -> { // Only fetch the estimate if they are enabled mEstimate = mEstimates.isHybridNotificationEnabled() ? mEstimates.getEstimate() : null; mLastEstimateTimestamp = System.currentTimeMillis(); mEstimate = null; if (mEstimates.isHybridNotificationEnabled()) { updateEstimate(); } mFetchingEstimate = false; Dependency.get(Dependency.MAIN_HANDLER).post(this::notifyEstimateFetchCallbacks); }); Loading @@ -258,8 +252,15 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC } private void updateEstimate() { // if the estimate has been cached we can just use that, otherwise get a new one and // throw it in the cache. mEstimate = Estimate.getCachedEstimateIfAvailable(mContext); if (mEstimate == null) { mEstimate = mEstimates.getEstimate(); mLastEstimateTimestamp = System.currentTimeMillis(); if (mEstimate != null) { Estimate.storeCachedEstimate(mContext, mEstimate); } } } private void updatePowerSave() { Loading