Protect against null channel
Add a test with notif with no channel.. Test: atest BubbleControllerTest Bug: 123540415 Change-Id: I7617d314bff340b58bab199c9e69e084591933c0
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user