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

Commit 72b28443 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Fix channel locking post cleardata

Apps/notification channels that had been marked
non-blockable by oems were being unlocked
post a clear data action until the next time the
device was rebooted. this keeps them locked the
whole time.

Bug: 142065414
Test: atest
Change-Id: If11238efd6f6b3e2d9e97d24adb24626689a87f2
parent 97d3ca1e
Loading
Loading
Loading
Loading
+7 −8
Original line number Original line Diff line number Diff line
@@ -757,7 +757,7 @@ public class PreferencesHelper implements RankingConfig {
            clearLockedFieldsLocked(channel);
            clearLockedFieldsLocked(channel);
            channel.setImportanceLockedByOEM(r.oemLockedImportance);
            channel.setImportanceLockedByOEM(r.oemLockedImportance);
            if (!channel.isImportanceLockedByOEM()) {
            if (!channel.isImportanceLockedByOEM()) {
                if (r.futureOemLockedChannels.remove(channel.getId())) {
                if (r.oemLockedChannels.contains(channel.getId())) {
                    channel.setImportanceLockedByOEM(true);
                    channel.setImportanceLockedByOEM(true);
                }
                }
            }
            }
@@ -952,11 +952,10 @@ public class PreferencesHelper implements RankingConfig {
                                    NotificationChannel channel = r.channels.get(channelId);
                                    NotificationChannel channel = r.channels.get(channelId);
                                    if (channel != null) {
                                    if (channel != null) {
                                        channel.setImportanceLockedByOEM(true);
                                        channel.setImportanceLockedByOEM(true);
                                    } else {
                                        // if this channel shows up in the future, make sure it'll
                                        // be locked immediately
                                        r.futureOemLockedChannels.add(channelId);
                                    }
                                    }
                                    // Also store the locked channels on the record, so they aren't
                                    // temporarily lost when data is cleared on the package
                                    r.oemLockedChannels.add(channelId);
                                }
                                }
                            }
                            }
                        }
                        }
@@ -1528,9 +1527,9 @@ public class PreferencesHelper implements RankingConfig {
                    pw.print(" oemLocked=");
                    pw.print(" oemLocked=");
                    pw.print(r.oemLockedImportance);
                    pw.print(r.oemLockedImportance);
                }
                }
                if (!r.futureOemLockedChannels.isEmpty()) {
                if (!r.oemLockedChannels.isEmpty()) {
                    pw.print(" futureLockedChannels=");
                    pw.print(" futureLockedChannels=");
                    pw.print(r.futureOemLockedChannels);
                    pw.print(r.oemLockedChannels);
                }
                }
                pw.println();
                pw.println();
                for (NotificationChannel channel : r.channels.values()) {
                for (NotificationChannel channel : r.channels.values()) {
@@ -1940,7 +1939,7 @@ public class PreferencesHelper implements RankingConfig {
        // these fields are loaded on boot from a different source of truth and so are not
        // these fields are loaded on boot from a different source of truth and so are not
        // written to notification policy xml
        // written to notification policy xml
        boolean oemLockedImportance = DEFAULT_OEM_LOCKED_IMPORTANCE;
        boolean oemLockedImportance = DEFAULT_OEM_LOCKED_IMPORTANCE;
        List<String> futureOemLockedChannels = new ArrayList<>();
        List<String> oemLockedChannels = new ArrayList<>();
        boolean defaultAppLockedImportance = DEFAULT_APP_LOCKED_IMPORTANCE;
        boolean defaultAppLockedImportance = DEFAULT_APP_LOCKED_IMPORTANCE;


        Delegate delegate = null;
        Delegate delegate = null;
+18 −0
Original line number Original line Diff line number Diff line
@@ -2416,6 +2416,24 @@ public class PreferencesHelperTest extends UiServiceTestCase {
                .isImportanceLockedByOEM());
                .isImportanceLockedByOEM());
    }
    }


    @Test
    public void testLockChannelsForOEM_channelSpecific_clearData() {
        NotificationChannel a = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
        mHelper.getImportance(PKG_O, UID_O);
        mHelper.lockChannelsForOEM(new String[] {PKG_O + ":" + a.getId()});
        mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false);
        assertTrue(mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false)
                .isImportanceLockedByOEM());

        mHelper.clearData(PKG_O, UID_O);

        // it's back!
        mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false);
        // and still locked
        assertTrue(mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false)
                .isImportanceLockedByOEM());
    }

    @Test
    @Test
    public void testLockChannelsForOEM_channelDoesNotExistYet_appWide() {
    public void testLockChannelsForOEM_channelDoesNotExistYet_appWide() {
        NotificationChannel a = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
        NotificationChannel a = new NotificationChannel("a", "a", IMPORTANCE_HIGH);