Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09917874 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Merge cherrypicks of [7306025] into qt-release

Change-Id: I5c46d334c22a5b681782cc7aeaf43d92ef5df004
parents a978ba17 373400a5
Loading
Loading
Loading
Loading
+14 −11
Original line number Diff line number Diff line
@@ -212,6 +212,7 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC

    @Nullable
    private String generateTimeRemainingString() {
        synchronized (mFetchCallbacks) {
            if (mEstimate == null) {
                return null;
            }
@@ -220,6 +221,7 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC
            return PowerUtil.getBatteryRemainingShortStringFormatted(
                    mContext, mEstimate.getEstimateMillis());
        }
    }

    private void updateEstimateInBackground() {
        if (mFetchingEstimate) {
@@ -230,19 +232,20 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC
        mFetchingEstimate = true;
        Dependency.get(Dependency.BG_HANDLER).post(() -> {
            // Only fetch the estimate if they are enabled
            synchronized (mFetchCallbacks) {
                mEstimate = null;
                if (mEstimates.isHybridNotificationEnabled()) {
                    updateEstimate();
                }
            }
            mFetchingEstimate = false;
            Dependency.get(Dependency.MAIN_HANDLER).post(this::notifyEstimateFetchCallbacks);
        });
    }

    private void notifyEstimateFetchCallbacks() {
        String estimate = generateTimeRemainingString();

        synchronized (mFetchCallbacks) {
            String estimate = generateTimeRemainingString();
            for (EstimateFetchCompletion completion : mFetchCallbacks) {
                completion.onBatteryRemainingEstimateRetrieved(estimate);
            }