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

Commit d0a5b168 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Don't backup deleted channels.

Change-Id: I58a23700c9f6ccf5d3d6b7fa9f80be78ef9421f0
Fixes: 36381209
Test: runtest systemui-notification
parent 95502300
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -204,7 +204,6 @@ public class RankingHelper implements RankingConfig {
                                CharSequence channelName = parser.getAttributeValue(null, ATT_NAME);
                                CharSequence channelName = parser.getAttributeValue(null, ATT_NAME);
                                int channelImportance =
                                int channelImportance =
                                        safeInt(parser, ATT_IMPORTANCE, DEFAULT_IMPORTANCE);
                                        safeInt(parser, ATT_IMPORTANCE, DEFAULT_IMPORTANCE);

                                if (!TextUtils.isEmpty(id) && !TextUtils.isEmpty(channelName)) {
                                if (!TextUtils.isEmpty(id) && !TextUtils.isEmpty(channelName)) {
                                    NotificationChannel channel = new NotificationChannel(id,
                                    NotificationChannel channel = new NotificationChannel(id,
                                            channelName, channelImportance);
                                            channelName, channelImportance);
@@ -342,8 +341,10 @@ public class RankingHelper implements RankingConfig {
                }
                }


                for (NotificationChannel channel : r.channels.values()) {
                for (NotificationChannel channel : r.channels.values()) {
                    if (!forBackup || (forBackup && !channel.isDeleted())) {
                        channel.writeXml(out);
                        channel.writeXml(out);
                    }
                    }
                }


                out.endTag(null, TAG_PACKAGE);
                out.endTag(null, TAG_PACKAGE);
            }
            }
+47 −6
Original line number Original line Diff line number Diff line
@@ -173,6 +173,7 @@ public class RankingHelperTest {
        try {
        try {
            when(mPm.getApplicationInfoAsUser(eq(pkg), anyInt(), anyInt())).thenReturn(legacy);
            when(mPm.getApplicationInfoAsUser(eq(pkg), anyInt(), anyInt())).thenReturn(legacy);
            when(mPm.getApplicationInfoAsUser(eq(pkg2), anyInt(), anyInt())).thenReturn(upgrade);
            when(mPm.getApplicationInfoAsUser(eq(pkg2), anyInt(), anyInt())).thenReturn(upgrade);
            when(mPm.getPackageUidAsUser(eq(pkg), anyInt())).thenReturn(uid);
        } catch (PackageManager.NameNotFoundException e) {
        } catch (PackageManager.NameNotFoundException e) {
        }
        }
    }
    }
@@ -182,14 +183,15 @@ public class RankingHelperTest {
                IMPORTANCE_LOW);
                IMPORTANCE_LOW);
    }
    }


    private ByteArrayOutputStream writeXmlAndPurge(String pkg, int uid, String... channelIds)
    private ByteArrayOutputStream writeXmlAndPurge(String pkg, int uid, boolean forBackup,
            String... channelIds)
            throws Exception {
            throws Exception {
        XmlSerializer serializer = new FastXmlSerializer();
        XmlSerializer serializer = new FastXmlSerializer();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        serializer.setOutput(new BufferedOutputStream(baos), "utf-8");
        serializer.setOutput(new BufferedOutputStream(baos), "utf-8");
        serializer.startDocument(null, true);
        serializer.startDocument(null, true);
        serializer.startTag(null, "ranking");
        serializer.startTag(null, "ranking");
        mHelper.writeXml(serializer, false);
        mHelper.writeXml(serializer, forBackup);
        serializer.endTag(null, "ranking");
        serializer.endTag(null, "ranking");
        serializer.endDocument();
        serializer.endDocument();
        serializer.flush();
        serializer.flush();
@@ -295,8 +297,8 @@ public class RankingHelperTest {
        mHelper.setShowBadge(pkg, uid, true);
        mHelper.setShowBadge(pkg, uid, true);
        mHelper.setShowBadge(pkg2, uid2, false);
        mHelper.setShowBadge(pkg2, uid2, false);


        ByteArrayOutputStream baos = writeXmlAndPurge(pkg, uid, channel1.getId(), channel2.getId(),
        ByteArrayOutputStream baos = writeXmlAndPurge(pkg, uid, false, channel1.getId(),
                NotificationChannel.DEFAULT_CHANNEL_ID);
                channel2.getId(), NotificationChannel.DEFAULT_CHANNEL_ID);
        mHelper.onPackagesChanged(true, UserHandle.myUserId(), new String[]{pkg}, new int[]{uid});
        mHelper.onPackagesChanged(true, UserHandle.myUserId(), new String[]{pkg}, new int[]{uid});


        XmlPullParser parser = Xml.newPullParser();
        XmlPullParser parser = Xml.newPullParser();
@@ -336,6 +338,45 @@ public class RankingHelperTest {
        assertTrue(foundChannel2Group);
        assertTrue(foundChannel2Group);
    }
    }


    @Test
    public void testChannelXml_backup() throws Exception {
        NotificationChannelGroup ncg = new NotificationChannelGroup("1", "bye");
        NotificationChannelGroup ncg2 = new NotificationChannelGroup("2", "hello");
        NotificationChannel channel1 =
                new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH);
        NotificationChannel channel2 =
                new NotificationChannel("id2", "name2", IMPORTANCE_LOW);
        NotificationChannel channel3 =
                new NotificationChannel("id3", "name3", IMPORTANCE_LOW);
        channel3.setGroup(ncg.getId());

        mHelper.createNotificationChannelGroup(pkg, uid, ncg, true);
        mHelper.createNotificationChannelGroup(pkg, uid, ncg2, true);
        mHelper.createNotificationChannel(pkg, uid, channel1, true);
        mHelper.createNotificationChannel(pkg, uid, channel2, false);
        mHelper.createNotificationChannel(pkg, uid, channel3, true);

        mHelper.deleteNotificationChannel(pkg, uid, channel1.getId());
        mHelper.deleteNotificationChannelGroup(pkg, uid, ncg.getId());
        assertEquals(channel2, mHelper.getNotificationChannel(pkg, uid, channel2.getId(), false));

        ByteArrayOutputStream baos = writeXmlAndPurge(pkg, uid, true, channel1.getId(),
                channel2.getId(), channel3.getId(), NotificationChannel.DEFAULT_CHANNEL_ID);
        mHelper.onPackagesChanged(true, UserHandle.myUserId(), new String[]{pkg}, new int[]{uid});

        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(new BufferedInputStream(new ByteArrayInputStream(baos.toByteArray())),
                null);
        parser.nextTag();
        mHelper.readXml(parser, true);

        assertNull(mHelper.getNotificationChannel(pkg, uid, channel1.getId(), false));
        assertNull(mHelper.getNotificationChannel(pkg, uid, channel3.getId(), false));
        assertNull(mHelper.getNotificationChannelGroup(ncg.getId(), pkg, uid));
        //assertEquals(ncg2, mHelper.getNotificationChannelGroup(ncg2.getId(), pkg, uid));
        assertEquals(channel2, mHelper.getNotificationChannel(pkg, uid, channel2.getId(), false));
    }

    @Test
    @Test
    public void testChannelXml_defaultChannelLegacyApp_noUserSettings() throws Exception {
    public void testChannelXml_defaultChannelLegacyApp_noUserSettings() throws Exception {
        NotificationChannel channel1 =
        NotificationChannel channel1 =
@@ -343,7 +384,7 @@ public class RankingHelperTest {


        mHelper.createNotificationChannel(pkg, uid, channel1, true);
        mHelper.createNotificationChannel(pkg, uid, channel1, true);


        ByteArrayOutputStream baos = writeXmlAndPurge(pkg, uid, channel1.getId(),
        ByteArrayOutputStream baos = writeXmlAndPurge(pkg, uid,false, channel1.getId(),
                NotificationChannel.DEFAULT_CHANNEL_ID);
                NotificationChannel.DEFAULT_CHANNEL_ID);


        XmlPullParser parser = Xml.newPullParser();
        XmlPullParser parser = Xml.newPullParser();
@@ -371,7 +412,7 @@ public class RankingHelperTest {
        defaultChannel.setImportance(IMPORTANCE_LOW);
        defaultChannel.setImportance(IMPORTANCE_LOW);
        mHelper.updateNotificationChannel(pkg, uid, defaultChannel);
        mHelper.updateNotificationChannel(pkg, uid, defaultChannel);


        ByteArrayOutputStream baos = writeXmlAndPurge(pkg, uid, channel1.getId(),
        ByteArrayOutputStream baos = writeXmlAndPurge(pkg, uid, false, channel1.getId(),
                NotificationChannel.DEFAULT_CHANNEL_ID);
                NotificationChannel.DEFAULT_CHANNEL_ID);


        XmlPullParser parser = Xml.newPullParser();
        XmlPullParser parser = Xml.newPullParser();