From c562fc69373e8fbaa737104ddd9d7a5567ff87bb Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Wed, 7 Aug 2019 10:50:44 -0400 Subject: [PATCH] Prevent NPEs in NLSes NLSs (rightly) assume that the SBN they get from onNotification[X] calls will not be null. If it is, log and bail early. Bug: 78279961 Test: reboot device Change-Id: Id2bba6b15aeea2d701d92d6c63022463f0f8c1df --- .../notification/NotificationAssistantService.java | 9 +++++++++ .../notification/NotificationListenerService.java | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/core/java/android/service/notification/NotificationAssistantService.java b/core/java/android/service/notification/NotificationAssistantService.java index 12d3228e567df..da4025419656b 100644 --- a/core/java/android/service/notification/NotificationAssistantService.java +++ b/core/java/android/service/notification/NotificationAssistantService.java @@ -293,6 +293,11 @@ public abstract class NotificationAssistantService extends NotificationListenerS Log.w(TAG, "onNotificationEnqueued: Error receiving StatusBarNotification", e); return; } + if (sbn == null) { + Log.w(TAG, "onNotificationEnqueuedWithChannel: " + + "Error receiving StatusBarNotification"); + return; + } SomeArgs args = SomeArgs.obtain(); args.arg1 = sbn; @@ -311,6 +316,10 @@ public abstract class NotificationAssistantService extends NotificationListenerS Log.w(TAG, "onNotificationSnoozed: Error receiving StatusBarNotification", e); return; } + if (sbn == null) { + Log.w(TAG, "onNotificationSnoozed: Error receiving StatusBarNotification"); + return; + } SomeArgs args = SomeArgs.obtain(); args.arg1 = sbn; diff --git a/core/java/android/service/notification/NotificationListenerService.java b/core/java/android/service/notification/NotificationListenerService.java index b44c9d59ebe55..78e30ab8cdc31 100644 --- a/core/java/android/service/notification/NotificationListenerService.java +++ b/core/java/android/service/notification/NotificationListenerService.java @@ -1272,6 +1272,10 @@ public abstract class NotificationListenerService extends Service { Log.w(TAG, "onNotificationPosted: Error receiving StatusBarNotification", e); return; } + if (sbn == null) { + Log.w(TAG, "onNotificationPosted: Error receiving StatusBarNotification"); + return; + } try { // convert icon metadata to legacy format for older clients @@ -1313,6 +1317,10 @@ public abstract class NotificationListenerService extends Service { Log.w(TAG, "onNotificationRemoved: Error receiving StatusBarNotification", e); return; } + if (sbn == null) { + Log.w(TAG, "onNotificationRemoved: Error receiving StatusBarNotification"); + return; + } // protect subclass from concurrent modifications of (@link mNotificationKeys}. synchronized (mLock) { applyUpdateLocked(update);