From 3e50bf6f97eb3b6ce45c5f5746687f76253ac38d Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Wed, 24 May 2017 16:33:32 -0400 Subject: [PATCH] Allow the creation of IMPORTANCE_NONE channels - Users will still be notified of foreground services by the system even if the app posts their fg service notification to a blocked channel so this restriction isn't needed - This allows apps to cleanly port over their pre-channels notification settings Fixes: 62028083 Test: runtest systemui-notification (cherry picked from commit 3f25f4d6fe24f3782d6e156f9969d98ab3c8b4bf) Change-Id: I1cd8cfaf31f00088e267bd3fb1bd7912f4397c69 --- .../server/notification/RankingHelper.java | 2 +- .../notification/RankingHelperTest.java | 25 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java index 55cb2f3ffba91..642af6e68dc2b 100644 --- a/services/core/java/com/android/server/notification/RankingHelper.java +++ b/services/core/java/com/android/server/notification/RankingHelper.java @@ -564,7 +564,7 @@ public class RankingHelper implements RankingConfig { updateConfig(); return; } - if (channel.getImportance() < NotificationManager.IMPORTANCE_MIN + if (channel.getImportance() < NotificationManager.IMPORTANCE_NONE || 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 06b5821b50d23..ce865c8ad2c72 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_MAX; import static android.app.NotificationManager.IMPORTANCE_NONE; import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED; @@ -512,14 +513,32 @@ public class RankingHelperTest extends NotificationTestCase { } @Test - public void testCreateChannel_ImportanceNone() throws Exception { + public void testCreateChannel_badImportance() throws Exception { try { mHelper.createNotificationChannel(PKG, UID, - new NotificationChannel("bananas", "bananas", IMPORTANCE_NONE), true); - fail("Was allowed to create a blocked channel"); + new NotificationChannel("bananas", "bananas", IMPORTANCE_NONE - 1), true); + fail("Was allowed to create a channel with invalid importance"); } catch (IllegalArgumentException e) { // yay } + try { + mHelper.createNotificationChannel(PKG, UID, + new NotificationChannel("bananas", "bananas", IMPORTANCE_UNSPECIFIED), true); + fail("Was allowed to create a channel with invalid importance"); + } catch (IllegalArgumentException e) { + // yay + } + try { + mHelper.createNotificationChannel(PKG, UID, + new NotificationChannel("bananas", "bananas", IMPORTANCE_MAX + 1), true); + fail("Was allowed to create a channel with invalid importance"); + } catch (IllegalArgumentException e) { + // yay + } + mHelper.createNotificationChannel(PKG, UID, + new NotificationChannel("bananas", "bananas", IMPORTANCE_NONE), true); + mHelper.createNotificationChannel(PKG, UID, + new NotificationChannel("bananas", "bananas", IMPORTANCE_MAX), true); }