From c18ba96b3f97aa8254caea877d1eaeef4ec86aec Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Tue, 29 Jan 2019 11:11:56 -0800 Subject: [PATCH] Protect against null channel Add a test with notif with no channel.. Test: atest BubbleControllerTest Bug: 123540415 Change-Id: I7617d314bff340b58bab199c9e69e084591933c0 --- .../com/android/systemui/bubbles/BubbleController.java | 9 ++++++--- .../android/systemui/bubbles/BubbleControllerTest.java | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java index da29ab4e63d25..e3f6add99df7b 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java @@ -26,6 +26,7 @@ import static com.android.systemui.statusbar.notification.NotificationAlertingMa import android.annotation.Nullable; import android.app.INotificationManager; import android.app.Notification; +import android.app.NotificationChannel; import android.app.PendingIntent; import android.content.Context; import android.content.pm.ActivityInfo; @@ -414,7 +415,8 @@ public class BubbleController { /** * Whether the notification has been developer configured to bubble and is allowed by the user. */ - private boolean shouldBubble(NotificationEntry entry) { + @VisibleForTesting + protected boolean shouldBubble(NotificationEntry entry) { StatusBarNotification n = entry.notification; boolean canAppOverlay = false; try { @@ -424,8 +426,9 @@ public class BubbleController { Log.w(TAG, "Error calling NoMan to determine if app can overlay", e); } - boolean canChannelOverlay = mNotificationEntryManager.getNotificationData().getChannel( - entry.key).canBubble(); + NotificationChannel channel = mNotificationEntryManager.getNotificationData().getChannel( + entry.key); + boolean canChannelOverlay = channel != null && channel.canBubble(); boolean hasOverlayIntent = n.getNotification().getBubbleMetadata() != null && n.getNotification().getBubbleMetadata().getIntent() != null; return DEBUG_ENABLE_AUTO_BUBBLE && hasOverlayIntent && canChannelOverlay && canAppOverlay; diff --git a/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java index 44ff4a73a4a7c..6a3bd735fc61c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleControllerTest.java @@ -73,6 +73,7 @@ public class BubbleControllerTest extends SysuiTestCase { private NotificationTestHelper mNotificationTestHelper; private ExpandableNotificationRow mRow; private ExpandableNotificationRow mRow2; + private ExpandableNotificationRow mNoChannelRow; @Mock private NotificationData mNotificationData; @@ -92,10 +93,12 @@ public class BubbleControllerTest extends SysuiTestCase { mNotificationTestHelper = new NotificationTestHelper(mContext); mRow = mNotificationTestHelper.createBubble(); mRow2 = mNotificationTestHelper.createBubble(); + mNoChannelRow = mNotificationTestHelper.createBubble(); // Return non-null notification data from the NEM when(mNotificationEntryManager.getNotificationData()).thenReturn(mNotificationData); when(mNotificationData.getChannel(mRow.getEntry().key)).thenReturn(mRow.getEntry().channel); + when(mNotificationData.getChannel(mNoChannelRow.getEntry().key)).thenReturn(null); mBubbleController = new TestableBubbleController(mContext, mStatusBarWindowController); @@ -184,6 +187,11 @@ public class BubbleControllerTest extends SysuiTestCase { assertTrue(mRow.getEntry().showInShadeWhenBubble()); } + @Test + public void testNotificationWithoutChannel() { + assertFalse(mBubbleController.shouldBubble(mNoChannelRow.getEntry())); + } + static class TestableBubbleController extends BubbleController { TestableBubbleController(Context context,