From f7ec124b5d8898602a77cac3699234e1d5943862 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Thu, 28 Apr 2022 16:07:14 -0400 Subject: [PATCH] Allow users to block notification channels On "fixed on" packages, if the app developer said that the given channel can be blocked. Test: PreferencesHelperTest, manually block a 'this app is drawing over other apps' notification Fixes: 230200565 Change-Id: I9598ce9ef438c3b237f1061f0fd0ab5680507304 --- .../notification/PreferencesHelper.java | 3 +- .../notification/PreferencesHelperTest.java | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/notification/PreferencesHelper.java b/services/core/java/com/android/server/notification/PreferencesHelper.java index 75d7a1f510b96..ebd092cd0adf8 100644 --- a/services/core/java/com/android/server/notification/PreferencesHelper.java +++ b/services/core/java/com/android/server/notification/PreferencesHelper.java @@ -1116,7 +1116,8 @@ public class PreferencesHelper implements RankingConfig { } if (mPermissionHelper.isMigrationEnabled()) { - if (mPermissionHelper.isPermissionFixed(r.pkg, UserHandle.getUserId(r.uid))) { + if (mPermissionHelper.isPermissionFixed(r.pkg, UserHandle.getUserId(r.uid)) + && !(channel.isBlockable() || channel.getImportance() == IMPORTANCE_NONE)) { updatedChannel.setImportance(channel.getImportance()); } } else { diff --git a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java index 7d5a0d0bf84d2..63d7453450d28 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java @@ -4015,6 +4015,45 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false).canBubble()); } + @Test + public void testUpdateNotificationChannel_fixedPermission_butUserPreviouslyBlockedIt() { + when(mPermissionHelper.isMigrationEnabled()).thenReturn(true); + when(mPermissionHelper.isPermissionFixed(PKG_O, 0)).thenReturn(true); + + NotificationChannel a = new NotificationChannel("a", "a", IMPORTANCE_NONE); + mHelper.createNotificationChannel(PKG_O, UID_O, a, false, false); + + NotificationChannel update = new NotificationChannel("a", "a", IMPORTANCE_HIGH); + update.setAllowBubbles(false); + + mHelper.updateNotificationChannel(PKG_O, UID_O, update, true); + + assertEquals(IMPORTANCE_HIGH, + mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false).getImportance()); + assertEquals(false, + mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false).canBubble()); + } + + @Test + public void testUpdateNotificationChannel_fixedPermission_butAppAllowsIt() { + when(mPermissionHelper.isMigrationEnabled()).thenReturn(true); + when(mPermissionHelper.isPermissionFixed(PKG_O, 0)).thenReturn(true); + + NotificationChannel a = new NotificationChannel("a", "a", IMPORTANCE_HIGH); + a.setBlockable(true); + mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false); + + NotificationChannel update = new NotificationChannel("a", "a", IMPORTANCE_NONE); + update.setAllowBubbles(false); + + mHelper.updateNotificationChannel(PKG_O, UID_O, update, true); + + assertEquals(IMPORTANCE_NONE, + mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false).getImportance()); + assertEquals(false, + mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false).canBubble()); + } + @Test public void testUpdateNotificationChannel_notFixedPermission() { when(mPermissionHelper.isMigrationEnabled()).thenReturn(true);