From 03fa85ddccb30a6f1dcfeaec9dcbba062e5f8573 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Mon, 6 Mar 2017 15:14:50 -0500 Subject: [PATCH] Prevent creation of default channel. Test: runtest systemui-notification Change-Id: Id56debdca2a11bdac5ae11832eaaa04842f0a9be --- .../android/server/notification/RankingHelper.java | 3 +++ .../server/notification/RankingHelperTest.java | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java index bb0742adf465b..53d1068784198 100644 --- a/services/core/java/com/android/server/notification/RankingHelper.java +++ b/services/core/java/com/android/server/notification/RankingHelper.java @@ -507,6 +507,9 @@ public class RankingHelper implements RankingConfig { if (channel.getGroup() != null && !r.groups.containsKey(channel.getGroup())) { throw new IllegalArgumentException("NotificationChannelGroup doesn't exist"); } + if (NotificationChannel.DEFAULT_CHANNEL_ID.equals(channel.getId())) { + throw new IllegalArgumentException("Reserved id"); + } NotificationChannel existing = r.channels.get(channel.getId()); // Keep existing settings 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 25c29ee9566f1..876d4ad1eb8c9 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,7 @@ */ package com.android.server.notification; +import static android.app.NotificationManager.IMPORTANCE_HIGH; import static android.app.NotificationManager.IMPORTANCE_LOW; import static junit.framework.Assert.assertNull; @@ -770,6 +771,17 @@ public class RankingHelperTest { mHelper.getNotificationChannel(pkg, uid, newChannel.getId(), false)); } + @Test + public void testCreateChannel_defaultChannelId() throws Exception { + try { + mHelper.createNotificationChannel(pkg2, uid2, new NotificationChannel( + NotificationChannel.DEFAULT_CHANNEL_ID, "ha", IMPORTANCE_HIGH), true); + fail("Allowed to create default channel"); + } catch (IllegalArgumentException e) { + // pass + } + } + @Test public void testCreateChannel_alreadyExists() throws Exception { long[] vibration = new long[]{100, 67, 145, 156};