Prevent estimates from updating while callbacks are happening

It seems that for some people the estimate was being set to null
as part of the process to update the estimate as they were trying
to access it. This CL makes it so that we don't allow callbacks
to start if we are currently updating which will ensure that this
doesn't happen again.

Test: repro'd issue without change, issue gone with change
Bug: 131607084
Change-Id: I938d05a3977bb4bba2c5d28e800d94120b8425d2
(cherry picked from commit af36fb3c1c5f100e8c53d77aa15c7253330bfb9e)
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryControllerImpl.java
index 9c7a1e3..3fc9b44 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryControllerImpl.java
@@ -212,13 +212,15 @@
 
     @Nullable
     private String generateTimeRemainingString() {
-        if (mEstimate == null) {
-            return null;
-        }
+        synchronized (mFetchCallbacks) {
+            if (mEstimate == null) {
+                return null;
+            }
 
-        String percentage = NumberFormat.getPercentInstance().format((double) mLevel / 100.0);
-        return PowerUtil.getBatteryRemainingShortStringFormatted(
-                mContext, mEstimate.getEstimateMillis());
+            String percentage = NumberFormat.getPercentInstance().format((double) mLevel / 100.0);
+            return PowerUtil.getBatteryRemainingShortStringFormatted(
+                    mContext, mEstimate.getEstimateMillis());
+        }
     }
 
     private void updateEstimateInBackground() {
@@ -230,9 +232,11 @@
         mFetchingEstimate = true;
         Dependency.get(Dependency.BG_HANDLER).post(() -> {
             // Only fetch the estimate if they are enabled
-            mEstimate = null;
-            if (mEstimates.isHybridNotificationEnabled()) {
-                updateEstimate();
+            synchronized (mFetchCallbacks) {
+                mEstimate = null;
+                if (mEstimates.isHybridNotificationEnabled()) {
+                    updateEstimate();
+                }
             }
             mFetchingEstimate = false;
             Dependency.get(Dependency.MAIN_HANDLER).post(this::notifyEstimateFetchCallbacks);
@@ -240,9 +244,8 @@
     }
 
     private void notifyEstimateFetchCallbacks() {
-        String estimate = generateTimeRemainingString();
-
         synchronized (mFetchCallbacks) {
+            String estimate = generateTimeRemainingString();
             for (EstimateFetchCompletion completion : mFetchCallbacks) {
                 completion.onBatteryRemainingEstimateRetrieved(estimate);
             }