Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c11bde0 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Re-add default channel on app targetsdk downgrade." into oc-dev

parents ce7e3e3a f26eb916
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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
+1 −0
Original line number Diff line number Diff line
@@ -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) {}
+19 −0
Original line number Diff line number Diff line
@@ -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));