Don't iterate channel list in bgthread
To avoid a ConcurrentModificationException
Fixes: 173674911
Test: manual
Change-Id: If35c6f66a2cfae7ee4a6f8e83dd70aa5877f8362
diff --git a/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java b/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java
index 684a27a..297bfdb 100644
--- a/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java
+++ b/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java
@@ -59,7 +59,7 @@
private RestrictedSwitchPreference mAllNotificationsToggle;
private PreferenceCategory mPreferenceCategory;
- private final List<NotificationChannel> mChannels = new ArrayList<>();
+ private List<NotificationChannel> mChannels = new ArrayList<>();
public AppChannelsBypassingDndPreferenceController(
Context context,
@@ -126,17 +126,18 @@
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... unused) {
+ List<NotificationChannel> newChannelList = new ArrayList<>();
List<NotificationChannelGroup> mChannelGroupList = mBackend.getGroups(mAppRow.pkg,
mAppRow.uid).getList();
- mChannels.clear();
for (NotificationChannelGroup channelGroup : mChannelGroupList) {
for (NotificationChannel channel : channelGroup.getChannels()) {
if (!isConversation(channel)) {
- mChannels.add(channel);
+ newChannelList.add(channel);
}
}
}
- Collections.sort(mChannels, CHANNEL_COMPARATOR);
+ Collections.sort(newChannelList, CHANNEL_COMPARATOR);
+ mChannels = newChannelList;
return null;
}