From f26eb916987f7c0e5d32af2fc10ef09f62e83f16 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Mon, 22 May 2017 15:47:06 -0400 Subject: [PATCH] Re-add default channel on app targetsdk downgrade. Test: runtest systemui-notification, and manual: adb install the apk pulled off dogfood device, verify that sending an email results in a toast pre change and no toast + notification post change. Change-Id: Ia3db55959906f38a5dc34cb38a33072c1f2dd64f Fixes: 38437227 --- .../NotificationManagerService.java | 2 ++ .../server/notification/RankingHelper.java | 1 + .../notification/RankingHelperTest.java | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 9cd0dff539912..1ccd1719510e9 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -3238,6 +3238,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));