summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChenyang Zhong <zhongcy95@gmail.com>2022-01-05 10:50:31 -0500
committeralk3pInjection <webmaster@raspii.tech>2022-01-27 18:50:18 +0800
commitd5f342cc6b415803cd3e72a8605c19624ddca17c (patch)
treec62cde28edb4edbe5d3b6be4213c68669aaa8aaa
parentf3b3ace29be7d7708f7578ee4f804381391bcf10 (diff)
MediaDataManager: use safe cast to avoid NPE
Casting the intent to dismissIntent may fail when the intent itself is null, possibly because the dismiss_intent from getParcelable does not always exist. E/AndroidRuntime( 2456): java.lang.NullPointerException: null cannot be cast to non-null type android.content.Intent E/AndroidRuntime( 2456): at java.util.Objects.requireNonNull(Objects.java:245) E/AndroidRuntime( 2456): at com.android.systemui.media.MediaDataManager.toSmartspaceMediaData(MediaDataManager.kt:889) E/AndroidRuntime( 2456): at com.android.systemui.media.MediaDataManager.onSmartspaceTargetsUpdated(MediaDataManager.kt:747) ... Therefore, use the safe cast operator [1], so the cast returns null on failure, which avoids NPE. SmartspaceMediaData data class allows dismissIntent to be nullable. Test: SystemUI no longer crashes when connecting to certain BT devices or wired headphones [1] https://kotlinlang.org/docs/typecasts.html#safe-nullable-cast-operator Change-Id: I3e7f08dfece5eccecf32adb4042ad76fe0405446 Signed-off-by: Chenyang Zhong <zhongcy95@gmail.com>
-rw-r--r--packages/SystemUI/src/com/android/systemui/media/MediaDataManager.kt2
1 files changed, 1 insertions, 1 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaDataManager.kt b/packages/SystemUI/src/com/android/systemui/media/MediaDataManager.kt
index eacdab6e537d..46e003c8bc76 100644
--- a/packages/SystemUI/src/com/android/systemui/media/MediaDataManager.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/MediaDataManager.kt
@@ -889,7 +889,7 @@ class MediaDataManager(
dismissIntent = target
.baseAction
.extras
- .getParcelable(EXTRAS_SMARTSPACE_DISMISS_INTENT_KEY) as Intent
+ .getParcelable(EXTRAS_SMARTSPACE_DISMISS_INTENT_KEY) as? Intent
}
packageName(target)?.let {
return SmartspaceMediaData(target.smartspaceTargetId, isActive, true, it,