Fix crash when loading string cache
Crash was caused by a null context in ModelDelegate
Fixes: 218305827
Test: manual
Change-Id: I1b046e24427dbdc6752ac100f488c428838ac31f
diff --git a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java
index 2f3d5d8..fd11b37 100644
--- a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java
+++ b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java
@@ -47,7 +47,6 @@
import com.android.launcher3.model.BgDataModel;
import com.android.launcher3.model.GridSizeMigrationTaskV2;
import com.android.launcher3.model.LoaderTask;
-import com.android.launcher3.model.ModelDelegate;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.RunnableList;
import com.android.launcher3.util.Themes;
@@ -156,9 +155,10 @@
PreviewContext previewContext = new PreviewContext(inflationContext, mIdp);
new LoaderTask(
LauncherAppState.getInstance(previewContext),
- null,
+ /* bgAllAppsList= */ null,
new BgDataModel(),
- new ModelDelegate(), null) {
+ LauncherAppState.getInstance(previewContext).getModel().getModelDelegate(),
+ /* results= */ null) {
@Override
public void run() {
diff --git a/src/com/android/launcher3/model/ModelDelegate.java b/src/com/android/launcher3/model/ModelDelegate.java
index 60ca63b..cc42258 100644
--- a/src/com/android/launcher3/model/ModelDelegate.java
+++ b/src/com/android/launcher3/model/ModelDelegate.java
@@ -44,11 +44,7 @@
boolean isPrimaryInstance) {
ModelDelegate delegate = Overrides.getObject(
ModelDelegate.class, context, R.string.model_delegate_class);
- delegate.mApp = app;
- delegate.mAppsList = appsList;
- delegate.mDataModel = dataModel;
- delegate.mIsPrimaryInstance = isPrimaryInstance;
- delegate.mContext = context;
+ delegate.init(context, app, appsList, dataModel, isPrimaryInstance);
return delegate;
}
@@ -61,6 +57,18 @@
public ModelDelegate() { }
/**
+ * Initializes the object with the given params.
+ */
+ private void init(Context context, LauncherAppState app, AllAppsList appsList,
+ BgDataModel dataModel, boolean isPrimaryInstance) {
+ this.mApp = app;
+ this.mAppsList = appsList;
+ this.mDataModel = dataModel;
+ this.mIsPrimaryInstance = isPrimaryInstance;
+ this.mContext = context;
+ }
+
+ /**
* Called periodically to validate and update any data
*/
@WorkerThread