Fixing nullpointer when creating new DB

LauncherProvider is not ready until the DBHelper is created
Change-Id: Iabd61005892f15fd4a31d882100d87df2b2a7b85
This commit is contained in:
Sunny Goyal 2015-06-16 15:10:36 -07:00
parent b42120300e
commit b4cbea4ad4
2 changed files with 15 additions and 15 deletions

View File

@ -99,6 +99,7 @@ public class LauncherProvider extends ContentProvider {
public void setLauncherProviderChangeListener(LauncherProviderChangeListener listener) {
mListener = listener;
mOpenHelper.mListener = mListener;
}
@Override
@ -270,18 +271,6 @@ public class LauncherProvider extends ContentProvider {
}
}
@Thunk void notifyAppWidgetHostReset() {
new MainThreadExecutor().execute(new Runnable() {
@Override
public void run() {
if (mListener != null) {
mListener.onAppWidgetHostReset();
}
}
});
}
@Thunk static void addModifiedTime(ContentValues values) {
values.put(LauncherSettings.ChangeLogColumns.MODIFIED, System.currentTimeMillis());
}
@ -429,6 +418,7 @@ public class LauncherProvider extends ContentProvider {
SQLiteDatabase.deleteDatabase(dbFile);
}
mOpenHelper = new DatabaseHelper(getContext());
mOpenHelper.mListener = mListener;
}
private static class DatabaseHelper extends SQLiteOpenHelper implements LayoutParserCallback {
@ -439,6 +429,8 @@ public class LauncherProvider extends ContentProvider {
private boolean mNewDbCreated = false;
@Thunk LauncherProviderChangeListener mListener;
DatabaseHelper(Context context) {
super(context, LauncherFiles.LAUNCHER_DB, null, DATABASE_VERSION);
mContext = context;
@ -508,7 +500,15 @@ public class LauncherProvider extends ContentProvider {
* want to re-call {@link AppWidgetHost#startListening()} to ensure
* callbacks are correctly set.
*/
LauncherAppState.getLauncherProvider().notifyAppWidgetHostReset();
new MainThreadExecutor().execute(new Runnable() {
@Override
public void run() {
if (mListener != null) {
mListener.onAppWidgetHostReset();
}
}
});
}
// Fresh and clean launcher DB.

View File

@ -59,7 +59,7 @@ public class WidgetPreviewLoader {
* Note: synchronized block used for this variable is expensive and the block should always
* be posted to a background thread.
*/
@Thunk Set<Bitmap> mUnusedBitmaps =
@Thunk final Set<Bitmap> mUnusedBitmaps =
Collections.newSetFromMap(new WeakHashMap<Bitmap, Boolean>());
private final Context mContext;
@ -540,7 +540,7 @@ public class WidgetPreviewLoader {
*/
public class PreviewLoadRequest {
private final PreviewLoadTask mTask;
@Thunk final PreviewLoadTask mTask;
public PreviewLoadRequest(PreviewLoadTask task) {
mTask = task;