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

Commit 9c54983d authored by Andreas Miko's avatar Andreas Miko
Browse files

Fix ConcurrentModificationException when dismissing bundled notifs

The iterator in `mNotifTracker` would throw a
ConcurrentModificationException when clicking done on a bundled notif.

Other code already worked with ArrayList copies but generalizing this
to the set object itself and using a java standard lib is more efficient
and less prone to similar bugs in the future.

Bug: b/389839492
Test: manual tested dismissing bundled notif
Flag: com.android.systemui.notification_bundle_ui
Change-Id: I71f90c00c53d8423366a387df2b2d3abf7de7fb9
parent 8c5cb3ec
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -33,9 +33,9 @@ import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.shared.NotificationBundleUi;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import javax.inject.Inject;

@@ -56,9 +56,9 @@ public class GroupExpansionManagerImpl implements GroupExpansionManager, Dumpabl
     * NOTE: This should not be modified without notifying listeners, so prefer using
     * {@code setGroupExpanded} when making changes.
     */
    private final Set<NotificationEntry> mExpandedGroups = new HashSet<>();
    private final Set<NotificationEntry> mExpandedGroups = ConcurrentHashMap.newKeySet();

    private final Set<EntryAdapter> mExpandedCollections = new HashSet<>();
    private final Set<EntryAdapter> mExpandedCollections = ConcurrentHashMap.newKeySet();

    @Inject
    public GroupExpansionManagerImpl(DumpManager dumpManager,
@@ -123,7 +123,9 @@ public class GroupExpansionManagerImpl implements GroupExpansionManager, Dumpabl
    @Override
    public boolean isGroupExpanded(NotificationEntry entry) {
        NotificationBundleUi.assertInLegacyMode();
        return mExpandedGroups.contains(mGroupMembershipManager.getGroupSummary(entry));
        NotificationEntry groupSummary = mGroupMembershipManager.getGroupSummary(entry);
        if (groupSummary == null) return false;
        return mExpandedGroups.contains(groupSummary);
    }

    @Override
@@ -140,6 +142,7 @@ public class GroupExpansionManagerImpl implements GroupExpansionManager, Dumpabl
            }
        }

        if (groupSummary == null) return;
        boolean changed;
        if (expanded) {
            changed = mExpandedGroups.add(groupSummary);
@@ -207,11 +210,11 @@ public class GroupExpansionManagerImpl implements GroupExpansionManager, Dumpabl
    @Override
    public void collapseGroups() {
        if (NotificationBundleUi.isEnabled()) {
            for (EntryAdapter entry : new ArrayList<>(mExpandedCollections)) {
            for (EntryAdapter entry : mExpandedCollections) {
                setGroupExpanded(entry, false);
            }
        } else {
            for (NotificationEntry entry : new ArrayList<>(mExpandedGroups)) {
            for (NotificationEntry entry : mExpandedGroups) {
                setGroupExpanded(entry, false);
            }
        }