Loading services/core/java/com/android/server/notification/RankingHelper.java +5 −0 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,8 @@ */ */ package com.android.server.notification; package com.android.server.notification; import static android.app.NotificationManager.IMPORTANCE_NONE; import com.android.internal.R; import com.android.internal.R; import android.app.Notification; import android.app.Notification; Loading Loading @@ -450,6 +452,9 @@ public class RankingHelper implements RankingConfig { @Override @Override public void createNotificationChannel(String pkg, int uid, NotificationChannel channel) { public void createNotificationChannel(String pkg, int uid, NotificationChannel channel) { Record r = getOrCreateRecord(pkg, uid); Record r = getOrCreateRecord(pkg, uid); if (IMPORTANCE_NONE == r.importance) { throw new IllegalArgumentException("Package blocked"); } if (r.channels.containsKey(channel.getId()) || channel.getName().equals( if (r.channels.containsKey(channel.getId()) || channel.getName().equals( mContext.getString(R.string.default_notification_channel_label))) { mContext.getString(R.string.default_notification_channel_label))) { throw new IllegalArgumentException("Channel already exists"); throw new IllegalArgumentException("Channel already exists"); Loading services/tests/notification/src/com/android/server/notification/RankingHelperTest.java +15 −0 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,8 @@ */ */ package com.android.server.notification; package com.android.server.notification; import static junit.framework.Assert.fail; import org.junit.Before; import org.junit.Before; import org.junit.Test; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runner.RunWith; Loading Loading @@ -347,6 +349,19 @@ public class RankingHelperTest { assertEquals(NotificationChannel.USER_LOCKED_VISIBILITY, updated2.getUserLockedFields()); assertEquals(NotificationChannel.USER_LOCKED_VISIBILITY, updated2.getUserLockedFields()); } } @Test public void testCreateChannel_blocked() throws Exception { mHelper.setImportance(pkg, uid, NotificationManager.IMPORTANCE_NONE); try { mHelper.createNotificationChannel(pkg, uid, new NotificationChannel(pkg, "", NotificationManager.IMPORTANCE_LOW)); fail("Channel creation should fail"); } catch (IllegalArgumentException e) { // pass } } @Test @Test public void testUpdate_userLockedImportance() throws Exception { public void testUpdate_userLockedImportance() throws Exception { // all fields locked by user // all fields locked by user Loading Loading
services/core/java/com/android/server/notification/RankingHelper.java +5 −0 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,8 @@ */ */ package com.android.server.notification; package com.android.server.notification; import static android.app.NotificationManager.IMPORTANCE_NONE; import com.android.internal.R; import com.android.internal.R; import android.app.Notification; import android.app.Notification; Loading Loading @@ -450,6 +452,9 @@ public class RankingHelper implements RankingConfig { @Override @Override public void createNotificationChannel(String pkg, int uid, NotificationChannel channel) { public void createNotificationChannel(String pkg, int uid, NotificationChannel channel) { Record r = getOrCreateRecord(pkg, uid); Record r = getOrCreateRecord(pkg, uid); if (IMPORTANCE_NONE == r.importance) { throw new IllegalArgumentException("Package blocked"); } if (r.channels.containsKey(channel.getId()) || channel.getName().equals( if (r.channels.containsKey(channel.getId()) || channel.getName().equals( mContext.getString(R.string.default_notification_channel_label))) { mContext.getString(R.string.default_notification_channel_label))) { throw new IllegalArgumentException("Channel already exists"); throw new IllegalArgumentException("Channel already exists"); Loading
services/tests/notification/src/com/android/server/notification/RankingHelperTest.java +15 −0 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,8 @@ */ */ package com.android.server.notification; package com.android.server.notification; import static junit.framework.Assert.fail; import org.junit.Before; import org.junit.Before; import org.junit.Test; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runner.RunWith; Loading Loading @@ -347,6 +349,19 @@ public class RankingHelperTest { assertEquals(NotificationChannel.USER_LOCKED_VISIBILITY, updated2.getUserLockedFields()); assertEquals(NotificationChannel.USER_LOCKED_VISIBILITY, updated2.getUserLockedFields()); } } @Test public void testCreateChannel_blocked() throws Exception { mHelper.setImportance(pkg, uid, NotificationManager.IMPORTANCE_NONE); try { mHelper.createNotificationChannel(pkg, uid, new NotificationChannel(pkg, "", NotificationManager.IMPORTANCE_LOW)); fail("Channel creation should fail"); } catch (IllegalArgumentException e) { // pass } } @Test @Test public void testUpdate_userLockedImportance() throws Exception { public void testUpdate_userLockedImportance() throws Exception { // all fields locked by user // all fields locked by user Loading