Loading services/core/java/com/android/server/notification/NotificationManagerService.java +0 −25 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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( Loading Loading @@ -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)) { Loading services/core/java/com/android/server/notification/RankingHelper.java +5 −21 Original line number Diff line number Diff line Loading @@ -275,31 +275,15 @@ 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; if (applicationInfo.targetSdkVersion > Build.VERSION_CODES.N_MR1) { // O apps should not have the default channel. return false; } // 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) { // Otherwise, this app should have the default channel. return true; } // Otherwise, should not have the default channel. return false; } private void deleteDefaultChannelIfNeeded(Record r) throws NameNotFoundException { if (!r.channels.containsKey(NotificationChannel.DEFAULT_CHANNEL_ID)) { // Not present Loading services/tests/notification/src/com/android/server/notification/RankingHelperTest.java +7 −24 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -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); Loading @@ -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); Loading Loading @@ -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 Loading @@ -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 Loading Loading @@ -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")); } } Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +0 −25 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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( Loading Loading @@ -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)) { Loading
services/core/java/com/android/server/notification/RankingHelper.java +5 −21 Original line number Diff line number Diff line Loading @@ -275,31 +275,15 @@ 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; if (applicationInfo.targetSdkVersion > Build.VERSION_CODES.N_MR1) { // O apps should not have the default channel. return false; } // 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) { // Otherwise, this app should have the default channel. return true; } // Otherwise, should not have the default channel. return false; } private void deleteDefaultChannelIfNeeded(Record r) throws NameNotFoundException { if (!r.channels.containsKey(NotificationChannel.DEFAULT_CHANNEL_ID)) { // Not present Loading
services/tests/notification/src/com/android/server/notification/RankingHelperTest.java +7 −24 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -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); Loading @@ -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); Loading Loading @@ -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 Loading @@ -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 Loading Loading @@ -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")); } } Loading