From 17717f5a6d46632cb75df78fd2a7038a4ac764ea Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Tue, 9 May 2017 11:46:06 -0400 Subject: [PATCH] Show misc channel with pre-upgrade fields - for apps that don't target O but use channges - Rename misc channel if it already exists - Add method so settings can tell if it needs to show legacy config Bug: 38120923 Test: runtest systemui-notification Change-Id: I5c7c077321f1792851b003b9d9e42505dddd50f0 --- .../java/android/app/INotificationManager.aidl | 1 + .../NotificationManagerService.java | 6 ++++++ .../server/notification/RankingHelper.java | 18 +++++++++++++++++- .../server/notification/RankingHelperTest.java | 9 +++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index cc7e0fd0fd397..1c1883b3b7f50 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -71,6 +71,7 @@ interface INotificationManager int getDeletedChannelCount(String pkg, int uid); void deleteNotificationChannelGroup(String pkg, String channelGroupId); ParceledListSlice getNotificationChannelGroups(String pkg); + boolean onlyHasDefaultChannel(String pkg, int uid); // TODO: Remove this when callers have been migrated to the equivalent // INotificationListener method. diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 598597b28aa4a..343aab102b471 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -1817,6 +1817,12 @@ public class NotificationManagerService extends SystemService { .getList().size(); } + @Override + public boolean onlyHasDefaultChannel(String pkg, int uid) { + enforceSystemOrSystemUI("onlyHasDefaultChannel"); + return mRankingHelper.onlyHasDefaultChannel(pkg, uid); + } + @Override public int getDeletedChannelCount(String pkg, int uid) { enforceSystemOrSystemUI("getDeletedChannelCount"); diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java index 7758516bfde4f..d4b6461feee72 100644 --- a/services/core/java/com/android/server/notification/RankingHelper.java +++ b/services/core/java/com/android/server/notification/RankingHelper.java @@ -301,7 +301,8 @@ public class RankingHelper implements RankingConfig { private void createDefaultChannelIfNeeded(Record r) throws NameNotFoundException { if (r.channels.containsKey(NotificationChannel.DEFAULT_CHANNEL_ID)) { - // Already exists + r.channels.get(NotificationChannel.DEFAULT_CHANNEL_ID).setName( + mContext.getString(R.string.default_notification_channel_label)); return; } @@ -770,6 +771,21 @@ public class RankingHelper implements RankingConfig { return new ParceledListSlice<>(channels); } + /** + * True for pre-O apps that only have the default channel, or pre O apps that have no + * channels yet. This method will create the default channel for pre-O apps that don't have it. + * Should never be true for O+ targeting apps, but that's enforced on boot/when an app + * upgrades. + */ + public boolean onlyHasDefaultChannel(String pkg, int uid) { + Record r = getOrCreateRecord(pkg, uid); + if (r.channels.size() == 1 + && r.channels.containsKey(NotificationChannel.DEFAULT_CHANNEL_ID)) { + return true; + } + return false; + } + public int getDeletedChannelCount(String pkg, int uid) { Preconditions.checkNotNull(pkg); int deletedCount = 0; 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 7bef0339297db..73372d5e98631 100644 --- a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java +++ b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java @@ -753,6 +753,15 @@ public class RankingHelperTest { mHelper.getNotificationChannel(PKG, UID, newChannel.getId(), false)); } + @Test + public void testOnlyHasDefaultChannel() throws Exception { + assertTrue(mHelper.onlyHasDefaultChannel(PKG, UID)); + assertFalse(mHelper.onlyHasDefaultChannel(UPDATED_PKG, UID2)); + + mHelper.createNotificationChannel(PKG, UID, getChannel(), true); + assertFalse(mHelper.onlyHasDefaultChannel(PKG, UID)); + } + @Test public void testCreateChannel_defaultChannelId() throws Exception { try {