diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 904756bd4e3ff..fc582b0d1ea1a 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -3236,6 +3236,8 @@ public class NotificationManagerService extends SystemService { final String noChannelStr = "No Channel found for " + "pkg=" + pkg + ", channelId=" + channelId + + ", id=" + id + + ", tag=" + tag + ", opPkg=" + opPkg + ", callingUid=" + callingUid + ", userId=" + userId diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java index f00ef386ba591..55cb2f3ffba91 100644 --- a/services/core/java/com/android/server/notification/RankingHelper.java +++ b/services/core/java/com/android/server/notification/RankingHelper.java @@ -1115,6 +1115,7 @@ public class RankingHelper implements RankingConfig { Record fullRecord = getRecord(pkg, mPm.getPackageUidAsUser(pkg, changeUserId)); if (fullRecord != null) { + createDefaultChannelIfNeeded(fullRecord); deleteDefaultChannelIfNeeded(fullRecord); } } catch (NameNotFoundException e) {} 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 2c9c114039050..06b5821b50d23 100644 --- a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java +++ b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java @@ -123,6 +123,7 @@ public class RankingHelperTest extends NotificationTestCase { when(mPm.getApplicationInfoAsUser(eq(PKG), anyInt(), anyInt())).thenReturn(legacy); when(mPm.getApplicationInfoAsUser(eq(UPDATED_PKG), anyInt(), anyInt())).thenReturn(upgrade); when(mPm.getPackageUidAsUser(eq(PKG), anyInt())).thenReturn(UID); + when(mPm.getPackageUidAsUser(eq(UPDATED_PKG), anyInt())).thenReturn(UID2); when(mContext.getResources()).thenReturn( InstrumentationRegistry.getContext().getResources()); when(mContext.getPackageManager()).thenReturn(mPm); @@ -1045,6 +1046,24 @@ public class RankingHelperTest extends NotificationTestCase { assertEquals(0, mHelper.getNotificationChannelGroups(PKG, UID, true).getList().size()); } + @Test + public void testOnPackageChange_downgradeTargetSdk() throws Exception { + // create channel as api 26 + mHelper.createNotificationChannel(UPDATED_PKG, UID2, getChannel(), true); + + // install new app version targeting 25 + final ApplicationInfo legacy = new ApplicationInfo(); + legacy.targetSdkVersion = Build.VERSION_CODES.N_MR1; + when(mPm.getApplicationInfoAsUser(eq(UPDATED_PKG), anyInt(), anyInt())).thenReturn(legacy); + mHelper.onPackagesChanged( + false, UserHandle.USER_SYSTEM, new String[]{UPDATED_PKG}, new int[]{UID2}); + + // make sure the default channel was readded + //assertEquals(2, mHelper.getNotificationChannels(UPDATED_PKG, UID2, false).getList().size()); + assertNotNull(mHelper.getNotificationChannel( + UPDATED_PKG, UID2, NotificationChannel.DEFAULT_CHANNEL_ID, false)); + } + @Test public void testRecordDefaults() throws Exception { assertEquals(NotificationManager.IMPORTANCE_UNSPECIFIED, mHelper.getImportance(PKG, UID));