Loading core/java/android/app/INotificationManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -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. Loading services/core/java/com/android/server/notification/NotificationManagerService.java +6 −0 Original line number Diff line number Diff line Loading @@ -1826,6 +1826,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"); Loading services/core/java/com/android/server/notification/RankingHelper.java +17 −1 Original line number Diff line number Diff line Loading @@ -312,7 +312,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; } Loading Loading @@ -778,6 +779,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; Loading services/tests/notification/src/com/android/server/notification/RankingHelperTest.java +9 −0 Original line number Diff line number Diff line Loading @@ -872,6 +872,15 @@ public class RankingHelperTest extends NotificationTestCase { 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 { Loading Loading
core/java/android/app/INotificationManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -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. Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +6 −0 Original line number Diff line number Diff line Loading @@ -1826,6 +1826,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"); Loading
services/core/java/com/android/server/notification/RankingHelper.java +17 −1 Original line number Diff line number Diff line Loading @@ -312,7 +312,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; } Loading Loading @@ -778,6 +779,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; Loading
services/tests/notification/src/com/android/server/notification/RankingHelperTest.java +9 −0 Original line number Diff line number Diff line Loading @@ -872,6 +872,15 @@ public class RankingHelperTest extends NotificationTestCase { 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 { Loading