summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Fabian Kozynski <kozynski@google.com> 2019-11-13 13:30:23 -0500
committer Fabian Kozynski <kozynski@google.com> 2019-11-13 13:30:23 -0500
commit52b8b9e09c9dcb82ebde39cec7915c0af5ed5cee (patch)
tree22937e5655b21a4e70159e8ded4295477d55d72e
parentb814d6b3179c24849c4243a94d4742b1e90e40da (diff)
Prevent NPE in DateView
If the view is not attached, do nothing when receiving a broadcast. Test: build Test: manual, change date Fixes: 144427670 Change-Id: Ia5743a58e9a3d544eb442058ab3fe3a3ab9e5e4a
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/DateView.java11
1 files changed, 9 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DateView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DateView.java
index d48876778590..2e26711a3578 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DateView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DateView.java
@@ -23,6 +23,7 @@ import android.content.IntentFilter;
import android.content.res.TypedArray;
import android.icu.text.DateFormat;
import android.icu.text.DisplayContext;
+import android.os.Handler;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.TextView;
@@ -47,6 +48,12 @@ public class DateView extends TextView {
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
+ // If the handler is null, it means we received a broadcast while the view has not
+ // finished being attached or in the process of being detached.
+ // In that case, do not post anything.
+ Handler handler = getHandler();
+ if (handler == null) return;
+
final String action = intent.getAction();
if (Intent.ACTION_TIME_TICK.equals(action)
|| Intent.ACTION_TIME_CHANGED.equals(action)
@@ -55,9 +62,9 @@ public class DateView extends TextView {
if (Intent.ACTION_LOCALE_CHANGED.equals(action)
|| Intent.ACTION_TIMEZONE_CHANGED.equals(action)) {
// need to get a fresh date format
- getHandler().post(() -> mDateFormat = null);
+ handler.post(() -> mDateFormat = null);
}
- getHandler().post(() -> updateClock());
+ handler.post(() -> updateClock());
}
}
};