Fix ConcurrentModificationExceptions during binding.

The same lists of extra items stored in BgModelData are also stored in
UI components. This is causing ConcurrentModificationExceptions. The
solution is to clone these lists or mark them as immutable before storing
them in their respective components.

Bug: 206918543
Test: Verified that crash no longer occurs after fix.
Change-Id: I571a2c451af58137aa7513b372b6a8ecf9bd3ff6
This commit is contained in:
Stefan Andonian committed 2022-11-17 20:46:51 +00:00
1 parent 698239e16a
commit a04de842d1
6 files changed
+17 -28

No files matched your search

@@ -25,6 +25,7 @@ import androidx.annotation.NonNull;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.model.BgDataModel.FixedContainerItems;
import com.android.launcher3.model.QuickstepModelDelegate.PredictorState;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.widget.PendingAddWidgetInfo;
@@ -91,10 +92,12 @@ public final class WidgetsPredictionUpdateTask extends BaseModelUpdateTask {
if (servicePredictedItems.isEmpty()) {
servicePredictedItems.addAll(localFilteredWidgets);
}
List<ItemInfo> items = servicePredictedItems.stream()
.map(it -> new PendingAddWidgetInfo(it.widgetInfo, CONTAINER_WIDGETS_PREDICTION))
.collect(Collectors.toList());
FixedContainerItems fixedContainerItems =
new FixedContainerItems(mPredictorState.containerId);
servicePredictedItems.forEach(w -> fixedContainerItems.items.add(
new PendingAddWidgetInfo(w.widgetInfo, CONTAINER_WIDGETS_PREDICTION)));
new FixedContainerItems(mPredictorState.containerId, items);
dataModel.extraItems.put(mPredictorState.containerId, fixedContainerItems);
bindExtraContainerItems(fixedContainerItems);