From e47896cb915a0d7f1e7fb14901ec4f9b6649366a Mon Sep 17 00:00:00 2001 From: Samuel Fufa Date: Mon, 20 Jul 2020 12:30:02 -0700 Subject: [PATCH] Invalidate stale BgDataModel when predictions are disabled Launcher stores ItemInfos for cached predictions in list BgDataModel.cachedPredictedItems on Launcher start (LoaderTask#run). The list reused if launcher has to rebind UI. Hence, the list should be cleared if launcher receives empty predictions. Bug: 161245294 Test: Manual Change-Id: I275655d5f52f6a6e5297473dd2f642728c1964a6 --- src/com/android/launcher3/model/PredictionModel.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/com/android/launcher3/model/PredictionModel.java b/src/com/android/launcher3/model/PredictionModel.java index 1429843b7e..cb3903d4ed 100644 --- a/src/com/android/launcher3/model/PredictionModel.java +++ b/src/com/android/launcher3/model/PredictionModel.java @@ -14,6 +14,7 @@ * limitations under the License. */ package com.android.launcher3.model; + import static com.android.launcher3.util.Executors.MODEL_EXECUTOR; import android.content.ComponentName; @@ -24,6 +25,7 @@ import android.os.UserHandle; import androidx.annotation.AnyThread; import androidx.annotation.WorkerThread; +import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.pm.UserCache; @@ -64,18 +66,28 @@ public class PredictionModel implements ResourceBasedOverride { mUserCache = UserCache.INSTANCE.get(mContext); } + /** * Formats and stores a list of component key in device preferences. */ @AnyThread public void cachePredictionComponentKeys(List componentKeys) { MODEL_EXECUTOR.execute(() -> { + LauncherAppState appState = LauncherAppState.getInstance(mContext); StringBuilder builder = new StringBuilder(); int count = Math.min(componentKeys.size(), MAX_CACHE_ITEMS); for (int i = 0; i < count; i++) { builder.append(serializeComponentKeyToString(componentKeys.get(i))); builder.append("\n"); } + if (componentKeys.isEmpty() /* should invalidate loader items */) { + appState.getModel().enqueueModelUpdateTask(new BaseModelUpdateTask() { + @Override + public void execute(LauncherAppState app, BgDataModel model, AllAppsList apps) { + model.cachedPredictedItems.clear(); + } + }); + } mDevicePrefs.edit().putString(CACHED_ITEMS_KEY, builder.toString()).apply(); }); }