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
This commit is contained in:
@@ -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<ComponentKey> 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();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user