summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Julia Reynolds <juliacr@google.com> 2016-11-28 10:47:18 -0500
committer Julia Reynolds <juliacr@google.com> 2016-11-28 14:34:29 -0500
commit32c97ef3c8efae999f68664320fa1200ff435f12 (patch)
tree48281d4d5dc8b96e60914707c691833c010f41e5
parentf57de46d0b16fea790dc29062bf5e47cf63bae3e (diff)
Blocked packages can't create channels.
Test: runtest systemui-notification Change-Id: I3f0560a71adc33d9881021f920ce2824b96ddc14
-rw-r--r--services/core/java/com/android/server/notification/RankingHelper.java5
-rw-r--r--services/tests/notification/src/com/android/server/notification/RankingHelperTest.java15
2 files changed, 20 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java
index f4acef7a1c30..a41231dc4bc7 100644
--- a/services/core/java/com/android/server/notification/RankingHelper.java
+++ b/services/core/java/com/android/server/notification/RankingHelper.java
@@ -15,6 +15,8 @@
*/
package com.android.server.notification;
+import static android.app.NotificationManager.IMPORTANCE_NONE;
+
import com.android.internal.R;
import android.app.Notification;
@@ -450,6 +452,9 @@ public class RankingHelper implements RankingConfig {
@Override
public void createNotificationChannel(String pkg, int uid, NotificationChannel channel) {
Record r = getOrCreateRecord(pkg, uid);
+ if (IMPORTANCE_NONE == r.importance) {
+ throw new IllegalArgumentException("Package blocked");
+ }
if (r.channels.containsKey(channel.getId()) || channel.getName().equals(
mContext.getString(R.string.default_notification_channel_label))) {
throw new IllegalArgumentException("Channel already exists");
diff --git a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java
index cb7e6fbf9757..16d0a75e2657 100644
--- a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java
+++ b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java
@@ -15,6 +15,8 @@
*/
package com.android.server.notification;
+import static junit.framework.Assert.fail;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -348,6 +350,19 @@ public class RankingHelperTest {
}
@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
public void testUpdate_userLockedImportance() throws Exception {
// all fields locked by user
final NotificationChannel channel =