From d8c0ac42dee86997a7a06d15f9e7ccbc0da862e0 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Sun, 23 Apr 2017 13:11:40 -0400 Subject: [PATCH] Don't allow devs to create blocked channels Test: runtest systemui-notification Change-Id: I11942e4268acc70ffcbcda08eed4e13e64f4b12f Fixes: 37559814 --- .../android/server/notification/RankingHelper.java | 2 +- .../server/notification/RankingHelperTest.java | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java index 221b2bb0886ad..32de3166faae8 100644 --- a/services/core/java/com/android/server/notification/RankingHelper.java +++ b/services/core/java/com/android/server/notification/RankingHelper.java @@ -561,7 +561,7 @@ public class RankingHelper implements RankingConfig { updateConfig(); return; } - if (channel.getImportance() < NotificationManager.IMPORTANCE_NONE + if (channel.getImportance() < NotificationManager.IMPORTANCE_MIN || channel.getImportance() > NotificationManager.IMPORTANCE_MAX) { throw new IllegalArgumentException("Invalid importance level"); } 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 303054e777934..bc5c29d514a55 100644 --- a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java +++ b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java @@ -18,6 +18,7 @@ package com.android.server.notification; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.app.NotificationManager.IMPORTANCE_HIGH; import static android.app.NotificationManager.IMPORTANCE_LOW; +import static android.app.NotificationManager.IMPORTANCE_NONE; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.fail; @@ -504,12 +505,23 @@ public class RankingHelperTest { @Test public void testCreateChannel_blocked() throws Exception { - mHelper.setImportance(PKG, UID, NotificationManager.IMPORTANCE_NONE); + mHelper.setImportance(PKG, UID, IMPORTANCE_NONE); mHelper.createNotificationChannel(PKG, UID, new NotificationChannel("bananas", "bananas", IMPORTANCE_LOW), true); } + @Test + public void testCreateChannel_ImportanceNone() throws Exception { + try { + mHelper.createNotificationChannel(PKG, UID, + new NotificationChannel("bananas", "bananas", IMPORTANCE_NONE), true); + fail("Was allowed to create a blocked channel"); + } catch (IllegalArgumentException e) { + // yay + } + } + @Test public void testUpdate() throws Exception {