summaryrefslogtreecommitdiff
path: root/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java
diff options
context:
space:
mode:
authorPeter Collingbourne <pcc@google.com>2021-01-27 12:33:39 -0800
committerPeter Collingbourne <pcc@google.com>2021-02-19 15:31:45 -0800
commit2744b19f28ccdc9e2f1ade5fc1cad8a4a387dea8 (patch)
treea83440e1e23aca37743752d3199f0dc720bb726e /packages/SystemUI/src/com/android/systemui/BatteryMeterView.java
parent04d9bf62abd3ec34da7bbe937343550e6802ac21 (diff)
Add missing null check for mBatteryPercentView.
On an emulated device without a battery we've observed a NullPointerException coming from a call to setText() on a null mBatteryPercentView: FATAL EXCEPTION: main Process: com.android.systemui, PID: 4234 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference at com.android.systemui.BatteryMeterView.setPercentTextAtCurrentLevel(BatteryMeterView.java:380) at com.android.systemui.BatteryMeterView.lambda$updatePercentText$0(BatteryMeterView.java:366) at com.android.systemui.BatteryMeterView.lambda$updatePercentText$0$BatteryMeterView(Unknown Source:0) at com.android.systemui.-$$Lambda$BatteryMeterView$tE-TUFngFnD6fsDmUpqJf1miV_U.onBatteryRemainingEstimateRetrieved(Unknown Source:2) at com.android.systemui.statusbar.policy.BatteryControllerImpl.notifyEstimateFetchCallbacks(BatteryControllerImpl.java:308) at com.android.systemui.statusbar.policy.BatteryControllerImpl.lambda$0VzGTjPGwGKStizyJuiiH2rMVVk(Unknown Source:0) at com.android.systemui.statusbar.policy.-$$Lambda$BatteryControllerImpl$0VzGTjPGwGKStizyJuiiH2rMVVk.run(Unknown Source:2) It seems that it's possible for the battery meter to enter the hidden percentage state in between the check in updatePercentText() and the lambda callback. Guard against that possibility with a null check in the lambda. Bug: 178231152 Change-Id: Ia805a1a8497d4ad4f99c2864e17a88d46690d471
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/BatteryMeterView.java')
-rw-r--r--packages/SystemUI/src/com/android/systemui/BatteryMeterView.java3
1 files changed, 3 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java
index 176562799838..cd53a34fbbc2 100644
--- a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java
+++ b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java
@@ -326,6 +326,9 @@ public class BatteryMeterView extends LinearLayout implements
if (mBatteryPercentView != null) {
if (mShowPercentMode == MODE_ESTIMATE && !mCharging) {
mBatteryController.getEstimatedTimeRemainingString((String estimate) -> {
+ if (mBatteryPercentView == null) {
+ return;
+ }
if (estimate != null) {
mBatteryPercentView.setText(estimate);
setContentDescription(getContext().getString(