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

Commit 1ab5741b authored by Brian Isganitis's avatar Brian Isganitis Committed by Android (Google) Code Review
Browse files

Merge "Avoid race condition with hotseat predictions."

parents 22153770 f7c2adf8
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -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()
        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()));
        fci.items.clear();
                        .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));
+9 −8
Original line number Diff line number Diff line
@@ -119,18 +119,19 @@ public class QuickstepModelDelegate extends ModelDelegate {

        WorkspaceItemFactory allAppsFactory = new WorkspaceItemFactory(
                mApp, ums, pinnedShortcuts, mIDP.numDatabaseAllAppsColumns);
        mAllAppsState.items.setItems(
        FixedContainerItems allAppsItems = new FixedContainerItems(mAllAppsState.containerId,
                mAllAppsState.storage.read(mApp.getContext(), allAppsFactory, ums.allUsers::get));
        mDataModel.extraItems.put(CONTAINER_PREDICTION, mAllAppsState.items);
        mDataModel.extraItems.put(mAllAppsState.containerId, allAppsItems);

        WorkspaceItemFactory hotseatFactory =
                new WorkspaceItemFactory(mApp, ums, pinnedShortcuts, mIDP.numDatabaseHotseatIcons);
        mHotseatState.items.setItems(
        FixedContainerItems hotseatItems = new FixedContainerItems(mHotseatState.containerId,
                mHotseatState.storage.read(mApp.getContext(), hotseatFactory, ums.allUsers::get));
        mDataModel.extraItems.put(CONTAINER_HOTSEAT_PREDICTION, mHotseatState.items);
        mDataModel.extraItems.put(mHotseatState.containerId, hotseatItems);

        // Widgets prediction isn't used frequently. And thus, it is not persisted on disk.
        mDataModel.extraItems.put(CONTAINER_WIDGETS_PREDICTION, mWidgetsRecommendationState.items);
        mDataModel.extraItems.put(mWidgetsRecommendationState.containerId,
                new FixedContainerItems(mWidgetsRecommendationState.containerId));
        mActive = true;
    }

@@ -371,14 +372,14 @@ public class QuickstepModelDelegate extends ModelDelegate {

    static class PredictorState {

        public final FixedContainerItems items;
        public final int containerId;
        public final PersistedItemArray<ItemInfo> storage;
        public AppPredictor predictor;

        private List<AppTarget> mLastTargets;

        PredictorState(int container, String storageName) {
            items = new FixedContainerItems(container);
        PredictorState(int containerId, String storageName) {
            this.containerId = containerId;
            storage = new PersistedItemArray<>(storageName);
            mLastTargets = Collections.emptyList();
        }
+3 −2
Original line number Diff line number Diff line
@@ -59,8 +59,8 @@ public final class WidgetsPredictionUpdateTask extends BaseModelUpdateTask {
        Map<PackageUserKey, List<WidgetItem>> allWidgets =
                dataModel.widgetsModel.getAllWidgetsWithoutShortcuts();

        FixedContainerItems fixedContainerItems = mPredictorState.items;
        fixedContainerItems.items.clear();
        FixedContainerItems fixedContainerItems =
                new FixedContainerItems(mPredictorState.containerId);

        if (FeatureFlags.ENABLE_LOCAL_RECOMMENDED_WIDGETS_FILTER.get()) {
            for (AppTarget app : mTargets) {
@@ -100,6 +100,7 @@ public final class WidgetsPredictionUpdateTask extends BaseModelUpdateTask {
                }
            }
        }
        dataModel.extraItems.put(mPredictorState.containerId, fixedContainerItems);
        bindExtraContainerItems(fixedContainerItems);

        // Don't store widgets prediction to disk because it is not used frequently.
+3 −3
Original line number Diff line number Diff line
@@ -456,10 +456,10 @@ public class LauncherPreviewRenderer extends ContextWrapper
        }
        IntArray ranks = getMissingHotseatRanks(currentWorkspaceItems,
                mDp.numShownHotseatIcons);
        FixedContainerItems hotseatpredictions =
        FixedContainerItems hotseatPredictions =
                dataModel.extraItems.get(CONTAINER_HOTSEAT_PREDICTION);
        List<ItemInfo> predictions = hotseatpredictions == null
                ? Collections.emptyList() : hotseatpredictions.items;
        List<ItemInfo> predictions = hotseatPredictions == null
                ? Collections.emptyList() : hotseatPredictions.items;
        int count = Math.min(ranks.size(), predictions.size());
        for (int i = 0; i < count; i++) {
            int rank = ranks.get(i);