Loading services/core/java/com/android/server/notification/PreferencesHelper.java +4 −5 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE; import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL; import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.app.NotificationManager.IMPORTANCE_MAX; import static android.app.NotificationManager.IMPORTANCE_NONE; import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED; import static android.util.StatsLog.ANNOTATION_ID_IS_UID; Loading Loading @@ -905,6 +906,9 @@ public class PreferencesHelper implements RankingConfig { Objects.requireNonNull(channel); Objects.requireNonNull(channel.getId()); Preconditions.checkArgument(!TextUtils.isEmpty(channel.getName())); Preconditions.checkArgument(channel.getImportance() >= IMPORTANCE_NONE && channel.getImportance() <= IMPORTANCE_MAX, "Invalid importance level"); boolean needsPolicyFileChange = false, wasUndeleted = false, needsDndChange = false; synchronized (mPackagePreferences) { PackagePreferences r = getOrCreatePackagePreferencesLocked(pkg, uid); Loading Loading @@ -993,11 +997,6 @@ public class PreferencesHelper implements RankingConfig { needsPolicyFileChange = true; if (channel.getImportance() < IMPORTANCE_NONE || channel.getImportance() > NotificationManager.IMPORTANCE_MAX) { throw new IllegalArgumentException("Invalid importance level"); } // Reset fields that apps aren't allowed to set. if (fromTargetApp && !hasDndAccess) { channel.setBypassDnd(r.priority == Notification.PRIORITY_MAX); Loading services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +42 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,7 @@ import static junit.framework.Assert.fail; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; Loading Loading @@ -1576,6 +1577,47 @@ public class PreferencesHelperTest extends UiServiceTestCase { new NotificationChannel("bananas", "bananas", IMPORTANCE_MAX), true, false)); } @Test public void testUpdateChannel_downgradeImportance() { mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, new NotificationChannel("bananas", "bananas", IMPORTANCE_DEFAULT), true, false); assertTrue(mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, new NotificationChannel("bananas", "bananas", IMPORTANCE_LOW), true, false)); } @Test public void testUpdateChannel_upgradeImportance_ignored() { mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, new NotificationChannel("bananas", "bananas", IMPORTANCE_DEFAULT), true, false); assertFalse(mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, new NotificationChannel("bananas", "bananas", IMPORTANCE_MAX), true, false)); } @Test public void testUpdateChannel_badImportance() { mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, new NotificationChannel("bananas", "bananas", IMPORTANCE_DEFAULT), true, false); assertThrows(IllegalArgumentException.class, () -> mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, new NotificationChannel("bananas", "bananas", IMPORTANCE_NONE - 1), true, false)); assertThrows(IllegalArgumentException.class, () -> mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, new NotificationChannel("bananas", "bananas", IMPORTANCE_UNSPECIFIED), true, false)); assertThrows(IllegalArgumentException.class, () -> mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, new NotificationChannel("bananas", "bananas", IMPORTANCE_MAX + 1), true, false)); } @Test public void testUpdate() throws Exception { Loading Loading
services/core/java/com/android/server/notification/PreferencesHelper.java +4 −5 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE; import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL; import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.app.NotificationManager.IMPORTANCE_MAX; import static android.app.NotificationManager.IMPORTANCE_NONE; import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED; import static android.util.StatsLog.ANNOTATION_ID_IS_UID; Loading Loading @@ -905,6 +906,9 @@ public class PreferencesHelper implements RankingConfig { Objects.requireNonNull(channel); Objects.requireNonNull(channel.getId()); Preconditions.checkArgument(!TextUtils.isEmpty(channel.getName())); Preconditions.checkArgument(channel.getImportance() >= IMPORTANCE_NONE && channel.getImportance() <= IMPORTANCE_MAX, "Invalid importance level"); boolean needsPolicyFileChange = false, wasUndeleted = false, needsDndChange = false; synchronized (mPackagePreferences) { PackagePreferences r = getOrCreatePackagePreferencesLocked(pkg, uid); Loading Loading @@ -993,11 +997,6 @@ public class PreferencesHelper implements RankingConfig { needsPolicyFileChange = true; if (channel.getImportance() < IMPORTANCE_NONE || channel.getImportance() > NotificationManager.IMPORTANCE_MAX) { throw new IllegalArgumentException("Invalid importance level"); } // Reset fields that apps aren't allowed to set. if (fromTargetApp && !hasDndAccess) { channel.setBypassDnd(r.priority == Notification.PRIORITY_MAX); Loading
services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +42 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,7 @@ import static junit.framework.Assert.fail; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; Loading Loading @@ -1576,6 +1577,47 @@ public class PreferencesHelperTest extends UiServiceTestCase { new NotificationChannel("bananas", "bananas", IMPORTANCE_MAX), true, false)); } @Test public void testUpdateChannel_downgradeImportance() { mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, new NotificationChannel("bananas", "bananas", IMPORTANCE_DEFAULT), true, false); assertTrue(mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, new NotificationChannel("bananas", "bananas", IMPORTANCE_LOW), true, false)); } @Test public void testUpdateChannel_upgradeImportance_ignored() { mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, new NotificationChannel("bananas", "bananas", IMPORTANCE_DEFAULT), true, false); assertFalse(mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, new NotificationChannel("bananas", "bananas", IMPORTANCE_MAX), true, false)); } @Test public void testUpdateChannel_badImportance() { mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, new NotificationChannel("bananas", "bananas", IMPORTANCE_DEFAULT), true, false); assertThrows(IllegalArgumentException.class, () -> mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, new NotificationChannel("bananas", "bananas", IMPORTANCE_NONE - 1), true, false)); assertThrows(IllegalArgumentException.class, () -> mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, new NotificationChannel("bananas", "bananas", IMPORTANCE_UNSPECIFIED), true, false)); assertThrows(IllegalArgumentException.class, () -> mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, new NotificationChannel("bananas", "bananas", IMPORTANCE_MAX + 1), true, false)); } @Test public void testUpdate() throws Exception { Loading