Loading packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java +2 −1 Original line number Diff line number Diff line Loading @@ -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. Loading packages/SystemUI/src/com/android/systemui/statusbar/NotificationBlockingHelperManager.java +15 −2 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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); } } packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationBlockingHelperManagerTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -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)); Loading Loading @@ -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); Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationGutsManagerTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -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), Loading @@ -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), Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java +7 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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") Loading Loading @@ -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()); Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java +2 −1 Original line number Diff line number Diff line Loading @@ -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. Loading
packages/SystemUI/src/com/android/systemui/statusbar/NotificationBlockingHelperManager.java +15 −2 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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); } }
packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationBlockingHelperManagerTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -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)); Loading Loading @@ -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); Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationGutsManagerTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -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), Loading @@ -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), Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java +7 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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") Loading Loading @@ -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()); Loading