From 4c76f8db29a012e2702fea67fdecfdfacfe0391b Mon Sep 17 00:00:00 2001 From: Holly Sun Date: Fri, 3 Mar 2023 09:27:56 -0800 Subject: Solve NPE. `secondaryLabel` is public and may be changed from other threads, therefore make a local reference and use the local reference. Bug: 271270746 Test: build SystemUI and verify the secondary label works properly Change-Id: I71c79bcf380ce46ad5f0be6b8e2a7647df55f5bf --- .../SystemUI/plugin/src/com/android/systemui/plugins/qs/QSTile.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSTile.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSTile.java index 1d28c63f8398..c0b69c169ccd 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSTile.java +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QSTile.java @@ -189,10 +189,12 @@ public interface QSTile { /** Get the text for secondaryLabel. */ public String getSecondaryLabel(String stateText) { - if (TextUtils.isEmpty(secondaryLabel)) { + // Use a local reference as the value might change from other threads + CharSequence localSecondaryLabel = secondaryLabel; + if (TextUtils.isEmpty(localSecondaryLabel)) { return stateText; } - return secondaryLabel.toString(); + return localSecondaryLabel.toString(); } public boolean copyTo(State other) { -- cgit v1.2.3-59-g8ed1b