Avoid race condition with hotseat predictions.

Make sure that the ArrayList cannot be cleared on the model thread while
it is being used on the UI thread to render a launcher preview.

Test: Manual
Fix: 210123588
Change-Id: I5a47cb3f28f5ac9e400f6ae535e410c345e14ee1
This commit is contained in:
Brian Isganitis
2021-12-13 16:52:54 +00:00
parent 7512ab6025
commit f7c2adf861
4 changed files with 22 additions and 20 deletions

View File

@@ -34,7 +34,6 @@ import com.android.launcher3.model.QuickstepModelDelegate.PredictorState;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@@ -60,13 +59,13 @@ public class PredictionUpdateTask extends BaseModelUpdateTask {
Utilities.getDevicePrefs(context).edit()
.putBoolean(LAST_PREDICTION_ENABLED_STATE, !mTargets.isEmpty()).apply();
FixedContainerItems fci = mPredictorState.items;
Set<UserHandle> usersForChangedShortcuts = new HashSet<>(fci.items.stream()
.filter(info -> info.itemType == ITEM_TYPE_DEEP_SHORTCUT)
.map(info -> info.user)
.collect(Collectors.toSet()));
fci.items.clear();
Set<UserHandle> usersForChangedShortcuts =
dataModel.extraItems.get(mPredictorState.containerId).items.stream()
.filter(info -> info.itemType == ITEM_TYPE_DEEP_SHORTCUT)
.map(info -> info.user)
.collect(Collectors.toSet());
FixedContainerItems fci = new FixedContainerItems(mPredictorState.containerId);
for (AppTarget target : mTargets) {
WorkspaceItemInfo itemInfo;
ShortcutInfo si = target.getShortcutInfo();
@@ -109,6 +108,7 @@ public class PredictionUpdateTask extends BaseModelUpdateTask {
fci.items.add(itemInfo);
}
dataModel.extraItems.put(fci.containerId, fci);
bindExtraContainerItems(fci);
usersForChangedShortcuts.forEach(
u -> dataModel.updateShortcutPinnedState(app.getContext(), u));