Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryControllerImpl.java +8 −2 Original line number Original line Diff line number Diff line Loading @@ -57,6 +57,8 @@ import java.util.ArrayList; import java.util.List; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.concurrent.GuardedBy; /** /** * Default implementation of a {@link BatteryController}. This controller monitors for battery * Default implementation of a {@link BatteryController}. This controller monitors for battery * level change events that are broadcasted by the system. * level change events that are broadcasted by the system. Loading Loading @@ -94,7 +96,10 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC private boolean mTestMode = false; private boolean mTestMode = false; @VisibleForTesting @VisibleForTesting boolean mHasReceivedBattery = false; boolean mHasReceivedBattery = false; @GuardedBy("mEstimateLock") private Estimate mEstimate; private Estimate mEstimate; private final Object mEstimateLock = new Object(); private boolean mFetchingEstimate = false; private boolean mFetchingEstimate = false; // Use AtomicReference because we may request it from a different thread // Use AtomicReference because we may request it from a different thread Loading Loading @@ -321,7 +326,7 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC @Nullable @Nullable private String generateTimeRemainingString() { private String generateTimeRemainingString() { synchronized (mFetchCallbacks) { synchronized (mEstimateLock) { if (mEstimate == null) { if (mEstimate == null) { return null; return null; } } Loading @@ -340,7 +345,7 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC mFetchingEstimate = true; mFetchingEstimate = true; mBgHandler.post(() -> { mBgHandler.post(() -> { // Only fetch the estimate if they are enabled // Only fetch the estimate if they are enabled synchronized (mFetchCallbacks) { synchronized (mEstimateLock) { mEstimate = null; mEstimate = null; if (mEstimates.isHybridNotificationEnabled()) { if (mEstimates.isHybridNotificationEnabled()) { updateEstimate(); updateEstimate(); Loading @@ -363,6 +368,7 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC } } @WorkerThread @WorkerThread @GuardedBy("mEstimateLock") private void updateEstimate() { private void updateEstimate() { Assert.isNotMainThread(); Assert.isNotMainThread(); // if the estimate has been cached we can just use that, otherwise get a new one and // if the estimate has been cached we can just use that, otherwise get a new one and Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryControllerImpl.java +8 −2 Original line number Original line Diff line number Diff line Loading @@ -57,6 +57,8 @@ import java.util.ArrayList; import java.util.List; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.concurrent.GuardedBy; /** /** * Default implementation of a {@link BatteryController}. This controller monitors for battery * Default implementation of a {@link BatteryController}. This controller monitors for battery * level change events that are broadcasted by the system. * level change events that are broadcasted by the system. Loading Loading @@ -94,7 +96,10 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC private boolean mTestMode = false; private boolean mTestMode = false; @VisibleForTesting @VisibleForTesting boolean mHasReceivedBattery = false; boolean mHasReceivedBattery = false; @GuardedBy("mEstimateLock") private Estimate mEstimate; private Estimate mEstimate; private final Object mEstimateLock = new Object(); private boolean mFetchingEstimate = false; private boolean mFetchingEstimate = false; // Use AtomicReference because we may request it from a different thread // Use AtomicReference because we may request it from a different thread Loading Loading @@ -321,7 +326,7 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC @Nullable @Nullable private String generateTimeRemainingString() { private String generateTimeRemainingString() { synchronized (mFetchCallbacks) { synchronized (mEstimateLock) { if (mEstimate == null) { if (mEstimate == null) { return null; return null; } } Loading @@ -340,7 +345,7 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC mFetchingEstimate = true; mFetchingEstimate = true; mBgHandler.post(() -> { mBgHandler.post(() -> { // Only fetch the estimate if they are enabled // Only fetch the estimate if they are enabled synchronized (mFetchCallbacks) { synchronized (mEstimateLock) { mEstimate = null; mEstimate = null; if (mEstimates.isHybridNotificationEnabled()) { if (mEstimates.isHybridNotificationEnabled()) { updateEstimate(); updateEstimate(); Loading @@ -363,6 +368,7 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC } } @WorkerThread @WorkerThread @GuardedBy("mEstimateLock") private void updateEstimate() { private void updateEstimate() { Assert.isNotMainThread(); Assert.isNotMainThread(); // if the estimate has been cached we can just use that, otherwise get a new one and // if the estimate has been cached we can just use that, otherwise get a new one and Loading