diff options
5 files changed, 45 insertions, 6 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java index 60dea3a35e29..135b03791ea6 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java @@ -438,7 +438,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView */ public boolean getIsNonblockable() { boolean isNonblockable = Dependency.get(NotificationBlockingHelperManager.class) - .isNonblockablePackage(mStatusBarNotification.getPackageName()); + .isNonblockable(mStatusBarNotification.getPackageName(), + mEntry.channel.getId()); // If the SystemNotifAsyncTask hasn't finished running or retrieved a value, we'll try once // again, but in-place on the main thread this time. This should rarely ever get called. diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationBlockingHelperManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationBlockingHelperManager.java index 6f5e8cb3e8d8..c78ab8db2ff7 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationBlockingHelperManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationBlockingHelperManager.java @@ -144,8 +144,15 @@ public class NotificationBlockingHelperManager { /** * Returns whether the given package name is in the list of non-blockable packages. */ - public boolean isNonblockablePackage(String packageName) { - return mNonBlockablePkgs.contains(packageName); + public boolean isNonblockable(String packageName, String channelName) { + return mNonBlockablePkgs.contains(packageName) + || mNonBlockablePkgs.contains(makeChannelKey(packageName, channelName)); + } + + // Format must stay in sync with frameworks/base/core/res/res/values/config.xml + // config_nonBlockableNotificationPackages + private String makeChannelKey(String pkg, String channel) { + return pkg + ":" + channel; } @VisibleForTesting @@ -157,4 +164,10 @@ public class NotificationBlockingHelperManager { void setBlockingHelperRowForTest(ExpandableNotificationRow blockingHelperRowForTest) { mBlockingHelperRow = blockingHelperRowForTest; } + + @VisibleForTesting + void setNonBlockablePkgs(String[] pkgsAndChannels) { + mNonBlockablePkgs = new HashSet<>(); + Collections.addAll(mNonBlockablePkgs, pkgsAndChannels); + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationBlockingHelperManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationBlockingHelperManagerTest.java index 9638541ead42..43660328e783 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationBlockingHelperManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationBlockingHelperManagerTest.java @@ -147,6 +147,7 @@ public class NotificationBlockingHelperManagerTest extends SysuiTestCase { // of the child row. ExpandableNotificationRow childRow = groupRow.getChildrenContainer().getViewAtPosition(0); childRow.getEntry().userSentiment = USER_SENTIMENT_NEGATIVE; + assertFalse(childRow.getIsNonblockable()); assertTrue(mBlockingHelperManager.perhapsShowBlockingHelper(childRow, mMenuRow)); @@ -220,6 +221,24 @@ public class NotificationBlockingHelperManagerTest extends SysuiTestCase { verify(mEntryManager).updateNotifications(); } + @Test + public void testNonBlockable_package() { + mBlockingHelperManager.setNonBlockablePkgs(new String[] {"banana", "strawberry:pie"}); + + assertFalse(mBlockingHelperManager.isNonblockable("orange", "pie")); + + assertTrue(mBlockingHelperManager.isNonblockable("banana", "pie")); + } + + @Test + public void testNonBlockable_channel() { + mBlockingHelperManager.setNonBlockablePkgs(new String[] {"banana", "strawberry:pie"}); + + assertFalse(mBlockingHelperManager.isNonblockable("strawberry", "shortcake")); + + assertTrue(mBlockingHelperManager.isNonblockable("strawberry", "pie")); + } + private ExpandableNotificationRow createBlockableRowSpy() throws Exception { ExpandableNotificationRow row = spy(mHelper.createRow()); when(row.getIsNonblockable()).thenReturn(false); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationGutsManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationGutsManagerTest.java index cba1b548611b..72255f3c8fa4 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationGutsManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationGutsManagerTest.java @@ -280,7 +280,7 @@ public class NotificationGutsManagerTest extends SysuiTestCase { any(PackageManager.class), any(INotificationManager.class), eq(statusBarNotification.getPackageName()), - isNull(), + any(NotificationChannel.class), anyInt(), eq(statusBarNotification), any(NotificationInfo.CheckSaveListener.class), @@ -306,7 +306,7 @@ public class NotificationGutsManagerTest extends SysuiTestCase { any(PackageManager.class), any(INotificationManager.class), eq(statusBarNotification.getPackageName()), - isNull(), + any(NotificationChannel.class), anyInt(), eq(statusBarNotification), any(NotificationInfo.CheckSaveListener.class), diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java index 2b0c6bfac988..c6bcd36c1abf 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java @@ -16,10 +16,13 @@ package com.android.systemui.statusbar; +import static android.app.NotificationManager.IMPORTANCE_DEFAULT; + import android.annotation.Nullable; import android.app.ActivityManager; import android.app.Instrumentation; import android.app.Notification; +import android.app.NotificationChannel; import android.content.Context; import android.os.UserHandle; import android.service.notification.StatusBarNotification; @@ -118,7 +121,7 @@ public class NotificationTestHelper { R.layout.custom_view_dark)) .build(); Notification.Builder notificationBuilder = - new Notification.Builder(mContext) + new Notification.Builder(mContext, "channelId") .setSmallIcon(R.drawable.ic_person) .setContentTitle("Title") .setContentText("Text") @@ -166,6 +169,9 @@ public class NotificationTestHelper { NotificationData.Entry entry = new NotificationData.Entry(sbn); entry.row = row; entry.createIcons(mContext, sbn); + entry.channel = new NotificationChannel( + notification.getChannelId(), notification.getChannelId(), IMPORTANCE_DEFAULT); + entry.channel.setBlockableSystem(true); NotificationInflaterTest.runThenWaitForInflation( () -> row.updateNotification(entry), row.getNotificationInflater()); |