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

Commit 9f10368b authored by Yuri Lin's avatar Yuri Lin Committed by Automerger Merge Worker
Browse files

Merge "When channels are deleted, remove notifications from recently dismissed...

Merge "When channels are deleted, remove notifications from recently dismissed list." into sc-dev am: 6d4e4b84

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14104334

Change-Id: I26051decde8dbdea989260b536079b6bc2775620
parents 7379cfee 6d4e4b84
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -685,6 +685,21 @@ public class NotificationManagerService extends SystemService {
                }
            }
        }

        // Remove notifications with the specified user & channel ID.
        public void removeChannelNotifications(String pkg, @UserIdInt int userId,
                String channelId) {
            for (int i = 0; i < mBuffer.size(); i++) {
                final Pair<StatusBarNotification, Integer> pair = mBuffer.get(i);
                if (pair.first != null
                        && userId == pair.first.getNormalizedUserId()
                        && pkg != null && pkg.equals(pair.first.getPackageName())
                        && pair.first.getNotification() != null
                        && Objects.equals(channelId, pair.first.getNotification().getChannelId())) {
                    mBuffer.remove(i);
                }
            }
        }
    }

    void loadDefaultApprovedServices(int userId) {
@@ -3625,6 +3640,8 @@ public class NotificationManagerService extends SystemService {
            cancelAllNotificationsInt(MY_UID, MY_PID, pkg, channelId, 0, 0, true,
                    callingUser, REASON_CHANNEL_REMOVED, null);
            mPreferencesHelper.deleteNotificationChannel(pkg, callingUid, channelId);
            // Remove from both recent notification archive and notification history
            mArchive.removeChannelNotifications(pkg, callingUser, channelId);
            mHistoryManager.deleteNotificationChannel(pkg, callingUid, channelId);
            mListeners.notifyNotificationChannelChanged(pkg,
                    UserHandle.getUserHandleForUid(callingUid),
@@ -8181,8 +8198,10 @@ public class NotificationManagerService extends SystemService {
            summaries.remove(r.getSbn().getPackageName());
        }

        // Save it for users of getHistoricalNotifications()
        // Save it for users of getHistoricalNotifications(), unless the whole channel was deleted
        if (reason != REASON_CHANNEL_REMOVED) {
            mArchive.record(r.getSbn(), reason);
        }

        final long now = System.currentTimeMillis();
        final LogMaker logMaker = r.getItemLogMaker()
+20 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ public class ArchiveTest extends UiServiceTestCase {
    }

    private StatusBarNotification getNotification(String pkg, int id, UserHandle user) {
        Notification n = new Notification.Builder(getContext(), "test")
        Notification n = new Notification.Builder(getContext(), "test" + id)
                .setContentTitle("A")
                .setWhen(1205)
                .build();
@@ -140,4 +140,23 @@ public class ArchiveTest extends UiServiceTestCase {
            assertThat(expected).contains(sbn.getKey());
        }
    }

    @Test
    public void testRemoveChannelNotifications() {
        List<String> expected = new ArrayList<>();
        for (int i = 0; i < SIZE; i++) {
            StatusBarNotification sbn = getNotification("pkg", i, UserHandle.of(USER_CURRENT));
            mArchive.record(sbn, REASON_CANCEL);
            if (i != 3) {
                // Will delete notification for this user in channel "test3".
                expected.add(sbn.getKey());
            }
        }
        mArchive.removeChannelNotifications("pkg", USER_CURRENT, "test3");
        List<StatusBarNotification> actual = Arrays.asList(mArchive.getArray(SIZE, true));
        assertThat(actual).hasSize(expected.size());
        for (StatusBarNotification sbn : actual) {
            assertThat(expected).contains(sbn.getKey());
        }
    }
}