diff options
3 files changed, 12 insertions, 70 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index d8d099bd3fd3..a8959c56ae22 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -3189,12 +3189,6 @@ public class NotificationManagerService extends SystemService { final NotificationChannel channel = mRankingHelper.getNotificationChannel(pkg, notificationUid, channelId, false /* includeDeleted */); if (channel == null) { - // STOPSHIP TODO: remove before release - should always throw without a valid channel. - if (channelId == null) { - Log.e(TAG, "Cannot post notification without channel ID when targeting O " - + " - notification=" + notification); - return; - } final String noChannelStr = "No Channel found for " + "pkg=" + pkg + ", channelId=" + channelId @@ -3211,12 +3205,6 @@ public class NotificationManagerService extends SystemService { "Failed to post notification on channel \"" + channelId + "\"\n" + "See log for more details"); return; - } else if (channelId == null && shouldWarnUseChannels(pkg, notificationUid)) { - // STOPSHIP TODO: remove once default channel is removed for all apps that target O. - Log.e(TAG, "Developer Warning for package " + pkg - + ", no channel specified for posted notification: " + notification); - doDebugOnlyToast("Developer warning for package \"" + pkg + "\"\n" + - "Posted notification should specify a channel"); } final StatusBarNotification n = new StatusBarNotification( @@ -3259,19 +3247,6 @@ public class NotificationManagerService extends SystemService { } } - // STOPSHIP - Remove once RankingHelper deletes default channel for all apps targeting O. - private boolean shouldWarnUseChannels(String pkg, int uid) { - try { - final int userId = UserHandle.getUserId(uid); - final ApplicationInfo applicationInfo = - mPackageManagerClient.getApplicationInfoAsUser(pkg, 0, userId); - return applicationInfo.targetSdkVersion > Build.VERSION_CODES.N_MR1; - } catch (NameNotFoundException e) { - Slog.e(TAG, e.toString()); - return false; - } - } - private int resolveNotificationUid(String opPackageName, int callingUid, int userId) { // The system can post notifications on behalf of any package it wants if (isCallerSystemOrPhone() && opPackageName != null && !"android".equals(opPackageName)) { diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java index 6d18c8393dd4..850b730f3dff 100644 --- a/services/core/java/com/android/server/notification/RankingHelper.java +++ b/services/core/java/com/android/server/notification/RankingHelper.java @@ -275,29 +275,13 @@ public class RankingHelper implements RankingConfig { private boolean shouldHaveDefaultChannel(Record r) throws NameNotFoundException { final int userId = UserHandle.getUserId(r.uid); final ApplicationInfo applicationInfo = mPm.getApplicationInfoAsUser(r.pkg, 0, userId); - if (applicationInfo.targetSdkVersion <= Build.VERSION_CODES.N_MR1) { - // Pre-O apps should have it. - return true; - } - - // STOPSHIP TODO: remove before release - O+ apps should never have a default channel. - // But for now, leave the default channel until an app has created its first channel. - boolean hasCreatedAChannel = false; - final int size = r.channels.size(); - for (int i = 0; i < size; i++) { - final NotificationChannel notificationChannel = r.channels.valueAt(i); - if (notificationChannel != null && - !notificationChannel.getId().equals(NotificationChannel.DEFAULT_CHANNEL_ID)) { - hasCreatedAChannel = true; - break; - } - } - if (!hasCreatedAChannel) { - return true; + if (applicationInfo.targetSdkVersion > Build.VERSION_CODES.N_MR1) { + // O apps should not have the default channel. + return false; } - // Otherwise, should not have the default channel. - return false; + // Otherwise, this app should have the default channel. + return true; } private void deleteDefaultChannelIfNeeded(Record r) throws NameNotFoundException { 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 ce899e31d7b6..c48e73879b13 100644 --- a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java +++ b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java @@ -314,8 +314,6 @@ public class RankingHelperTest { assertEquals(channel1, mHelper.getNotificationChannel(PKG, UID, channel1.getId(), false)); compareChannels(channel2, mHelper.getNotificationChannel(PKG, UID, channel2.getId(), false)); - assertNotNull(mHelper.getNotificationChannel( - PKG, UID, NotificationChannel.DEFAULT_CHANNEL_ID, false)); List<NotificationChannelGroup> actualGroups = mHelper.getNotificationChannelGroups(PKG, UID, false).getList(); @@ -381,12 +379,7 @@ public class RankingHelperTest { @Test public void testChannelXml_defaultChannelLegacyApp_noUserSettings() throws Exception { - NotificationChannel channel1 = - new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_DEFAULT); - - mHelper.createNotificationChannel(PKG, UID, channel1, true); - - ByteArrayOutputStream baos = writeXmlAndPurge(PKG, UID, false, channel1.getId(), + ByteArrayOutputStream baos = writeXmlAndPurge(PKG, UID, false, NotificationChannel.DEFAULT_CHANNEL_ID); loadStreamXml(baos); @@ -401,16 +394,12 @@ public class RankingHelperTest { @Test public void testChannelXml_defaultChannelUpdatedApp_userSettings() throws Exception { - NotificationChannel channel1 = - new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_MIN); - mHelper.createNotificationChannel(PKG, UID, channel1, true); - final NotificationChannel defaultChannel = mHelper.getNotificationChannel(PKG, UID, NotificationChannel.DEFAULT_CHANNEL_ID, false); defaultChannel.setImportance(NotificationManager.IMPORTANCE_LOW); mHelper.updateNotificationChannel(PKG, UID, defaultChannel); - ByteArrayOutputStream baos = writeXmlAndPurge(PKG, UID, false, channel1.getId(), + ByteArrayOutputStream baos = writeXmlAndPurge(PKG, UID, false, NotificationChannel.DEFAULT_CHANNEL_ID); loadStreamXml(baos); @@ -445,12 +434,9 @@ public class RankingHelperTest { | NotificationChannel.USER_LOCKED_VISIBILITY, updated1.getUserLockedFields()); - // STOPSHIP - this should be reversed after the STOPSHIP is removed in the tested code. // No Default Channel created for updated packages - // assertEquals(null, mHelper.getNotificationChannel(UPDATED_PKG, UID2, - // NotificationChannel.DEFAULT_CHANNEL_ID, false)); - assertTrue(mHelper.getNotificationChannel(UPDATED_PKG, UID2, - NotificationChannel.DEFAULT_CHANNEL_ID, false) != null); + assertEquals(null, mHelper.getNotificationChannel(UPDATED_PKG, UID2, + NotificationChannel.DEFAULT_CHANNEL_ID, false)); } @Test @@ -466,12 +452,9 @@ public class RankingHelperTest { when(mPm.getApplicationInfoAsUser(eq(PKG), anyInt(), anyInt())).thenReturn(upgraded); loadStreamXml(baos); - // STOPSHIP - this should be reversed after the STOPSHIP is removed in the tested code. // Default Channel should be gone. - // assertEquals(null, mHelper.getNotificationChannel(PKG, UID, - // NotificationChannel.DEFAULT_CHANNEL_ID, false)); - assertTrue(mHelper.getNotificationChannel(UPDATED_PKG, UID2, - NotificationChannel.DEFAULT_CHANNEL_ID, false) != null); + assertEquals(null, mHelper.getNotificationChannel(PKG, UID, + NotificationChannel.DEFAULT_CHANNEL_ID, false)); } @Test @@ -1067,7 +1050,7 @@ public class RankingHelperTest { for (int i = 0; i < numPackages; i++) { JSONObject object = actual.getJSONObject(i); assertTrue(expectedChannels.containsKey(object.get("packageName"))); - assertEquals(expectedChannels.get(object.get("packageName")).intValue() + 1, + assertEquals(expectedChannels.get(object.get("packageName")).intValue(), object.getInt("channelCount")); } } |