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

Commit c3cca795 authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Moving ModelDbController from LauncehrProvider to LauncherModel" into udc-dev

parents ffff442e ce953a36
Loading
Loading
Loading
Loading
+8 −5
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.WorkerThread;
import androidx.annotation.WorkerThread;


import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.model.DatabaseHelper;
import com.android.launcher3.model.LoaderTask;
import com.android.launcher3.model.LoaderTask;
import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
@@ -51,8 +52,8 @@ public class AppWidgetsRestoredReceiver extends BroadcastReceiver {
     * Updates the app widgets whose id has changed during the restore process.
     * Updates the app widgets whose id has changed during the restore process.
     */
     */
    @WorkerThread
    @WorkerThread
    public static void restoreAppWidgetIds(Context context, int[] oldWidgetIds, int[] newWidgetIds,
    public static void restoreAppWidgetIds(Context context, DatabaseHelper helper,
            @NonNull AppWidgetHost host) {
            int[] oldWidgetIds, int[] newWidgetIds, @NonNull AppWidgetHost host) {
        if (WidgetsModel.GO_DISABLE_WIDGETS) {
        if (WidgetsModel.GO_DISABLE_WIDGETS) {
            Log.e(TAG, "Skipping widget ID remap as widgets not supported");
            Log.e(TAG, "Skipping widget ID remap as widgets not supported");
            host.deleteHost();
            host.deleteHost();
@@ -90,14 +91,16 @@ public class AppWidgetsRestoredReceiver extends BroadcastReceiver {
            String oldWidgetId = Integer.toString(oldWidgetIds[i]);
            String oldWidgetId = Integer.toString(oldWidgetIds[i]);
            final String where = "appWidgetId=? and (restored & 1) = 1 and profileId=?";
            final String where = "appWidgetId=? and (restored & 1) = 1 and profileId=?";
            final String[] args = new String[] { oldWidgetId, Long.toString(mainProfileId) };
            final String[] args = new String[] { oldWidgetId, Long.toString(mainProfileId) };
            int result = new ContentWriter(context, new ContentWriter.CommitParams(where, args))
            int result = new ContentWriter(context,
                            new ContentWriter.CommitParams(helper, where, args))
                    .put(LauncherSettings.Favorites.APPWIDGET_ID, newWidgetIds[i])
                    .put(LauncherSettings.Favorites.APPWIDGET_ID, newWidgetIds[i])
                    .put(LauncherSettings.Favorites.RESTORED, state)
                    .put(LauncherSettings.Favorites.RESTORED, state)
                    .commit();
                    .commit();
            if (result == 0) {
            if (result == 0) {
                Cursor cursor = cr.query(Favorites.CONTENT_URI,
                Cursor cursor = helper.getWritableDatabase().query(
                        Favorites.TABLE_NAME,
                        new String[] {Favorites.APPWIDGET_ID},
                        new String[] {Favorites.APPWIDGET_ID},
                        "appWidgetId=?", new String[] { oldWidgetId }, null);
                        "appWidgetId=?", new String[] { oldWidgetId }, null, null, null);
                try {
                try {
                    if (!cursor.moveToFirst()) {
                    if (!cursor.moveToFirst()) {
                        // The widget no long exists.
                        // The widget no long exists.
+8 −0
Original line number Original line Diff line number Diff line
@@ -50,6 +50,7 @@ import com.android.launcher3.model.CacheDataUpdatedTask;
import com.android.launcher3.model.ItemInstallQueue;
import com.android.launcher3.model.ItemInstallQueue;
import com.android.launcher3.model.LauncherBinder;
import com.android.launcher3.model.LauncherBinder;
import com.android.launcher3.model.LoaderTask;
import com.android.launcher3.model.LoaderTask;
import com.android.launcher3.model.ModelDbController;
import com.android.launcher3.model.ModelDelegate;
import com.android.launcher3.model.ModelDelegate;
import com.android.launcher3.model.ModelWriter;
import com.android.launcher3.model.ModelWriter;
import com.android.launcher3.model.PackageIncrementalDownloadUpdatedTask;
import com.android.launcher3.model.PackageIncrementalDownloadUpdatedTask;
@@ -94,6 +95,8 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
    @NonNull
    @NonNull
    private final LauncherAppState mApp;
    private final LauncherAppState mApp;
    @NonNull
    @NonNull
    private final ModelDbController mModelDbController;
    @NonNull
    private final Object mLock = new Object();
    private final Object mLock = new Object();
    @Nullable
    @Nullable
    private LoaderTask mLoaderTask;
    private LoaderTask mLoaderTask;
@@ -143,6 +146,7 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
            @NonNull final IconCache iconCache, @NonNull final AppFilter appFilter,
            @NonNull final IconCache iconCache, @NonNull final AppFilter appFilter,
            final boolean isPrimaryInstance) {
            final boolean isPrimaryInstance) {
        mApp = app;
        mApp = app;
        mModelDbController = new ModelDbController(context);
        mBgAllAppsList = new AllAppsList(iconCache, appFilter);
        mBgAllAppsList = new AllAppsList(iconCache, appFilter);
        mModelDelegate = ModelDelegate.newInstance(context, app, mBgAllAppsList, mBgDataModel,
        mModelDelegate = ModelDelegate.newInstance(context, app, mBgAllAppsList, mBgDataModel,
                isPrimaryInstance);
                isPrimaryInstance);
@@ -153,6 +157,10 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
        return mModelDelegate;
        return mModelDelegate;
    }
    }


    public ModelDbController getModelDbController() {
        return mModelDbController;
    }

    /**
    /**
     * Adds the provided items to the workspace.
     * Adds the provided items to the workspace.
     */
     */
+22 −21
Original line number Original line Diff line number Diff line
@@ -50,8 +50,6 @@ public class LauncherProvider extends ContentProvider {


    public static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".settings";
    public static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".settings";


    protected ModelDbController mModelDbController;

    /**
    /**
     * $ adb shell dumpsys activity provider com.android.launcher3
     * $ adb shell dumpsys activity provider com.android.launcher3
     */
     */
@@ -69,7 +67,6 @@ public class LauncherProvider extends ContentProvider {
        if (FeatureFlags.IS_STUDIO_BUILD) {
        if (FeatureFlags.IS_STUDIO_BUILD) {
            Log.d(TAG, "Launcher process started");
            Log.d(TAG, "Launcher process started");
        }
        }
        mModelDbController = new ModelDbController(getContext());


        // The content provider exists for the entire duration of the launcher main process and
        // The content provider exists for the entire duration of the launcher main process and
        // is the first component to get created.
        // is the first component to get created.
@@ -77,6 +74,10 @@ public class LauncherProvider extends ContentProvider {
        return true;
        return true;
    }
    }


    public ModelDbController getModelDbController() {
        return LauncherAppState.getInstance(getContext()).getModel().getModelDbController();
    }

    @Override
    @Override
    public String getType(Uri uri) {
    public String getType(Uri uri) {
        SqlArguments args = new SqlArguments(uri, null, null);
        SqlArguments args = new SqlArguments(uri, null, null);
@@ -95,7 +96,7 @@ public class LauncherProvider extends ContentProvider {
        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
        qb.setTables(args.table);
        qb.setTables(args.table);


        Cursor result = mModelDbController.query(
        Cursor result = getModelDbController().query(
                args.table, projection, args.where, args.args, sortOrder);
                args.table, projection, args.where, args.args, sortOrder);
        result.setNotificationUri(getContext().getContentResolver(), uri);
        result.setNotificationUri(getContext().getContentResolver(), uri);
        return result;
        return result;
@@ -120,7 +121,7 @@ public class LauncherProvider extends ContentProvider {
        }
        }


        SqlArguments args = new SqlArguments(uri);
        SqlArguments args = new SqlArguments(uri);
        int rowId = mModelDbController.insert(args.table, initialValues);
        int rowId = getModelDbController().insert(args.table, initialValues);
        if (rowId < 0) return null;
        if (rowId < 0) return null;


        uri = ContentUris.withAppendedId(uri, rowId);
        uri = ContentUris.withAppendedId(uri, rowId);
@@ -130,7 +131,7 @@ public class LauncherProvider extends ContentProvider {


    private boolean initializeExternalAdd(ContentValues values) {
    private boolean initializeExternalAdd(ContentValues values) {
        // 1. Ensure that externally added items have a valid item id
        // 1. Ensure that externally added items have a valid item id
        int id = mModelDbController.generateNewItemId();
        int id = getModelDbController().generateNewItemId();
        values.put(LauncherSettings.Favorites._ID, id);
        values.put(LauncherSettings.Favorites._ID, id);


        // 2. In the case of an app widget, and if no app widget id is specified, we
        // 2. In the case of an app widget, and if no app widget id is specified, we
@@ -171,7 +172,7 @@ public class LauncherProvider extends ContentProvider {
    @Override
    @Override
    public int bulkInsert(Uri uri, ContentValues[] values) {
    public int bulkInsert(Uri uri, ContentValues[] values) {
        SqlArguments args = new SqlArguments(uri);
        SqlArguments args = new SqlArguments(uri);
        mModelDbController.bulkInsert(args.table, values);
        getModelDbController().bulkInsert(args.table, values);
        reloadLauncherIfExternal();
        reloadLauncherIfExternal();
        return values.length;
        return values.length;
    }
    }
@@ -180,7 +181,7 @@ public class LauncherProvider extends ContentProvider {
    @Override
    @Override
    public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
    public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
            throws OperationApplicationException {
            throws OperationApplicationException {
        try (SQLiteTransaction t = mModelDbController.newTransaction()) {
        try (SQLiteTransaction t = getModelDbController().newTransaction()) {
            final int numOperations = operations.size();
            final int numOperations = operations.size();
            final ContentProviderResult[] results = new ContentProviderResult[numOperations];
            final ContentProviderResult[] results = new ContentProviderResult[numOperations];
            for (int i = 0; i < numOperations; i++) {
            for (int i = 0; i < numOperations; i++) {
@@ -196,7 +197,7 @@ public class LauncherProvider extends ContentProvider {
    @Override
    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
        SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
        int count = mModelDbController.delete(args.table, args.where, args.args);
        int count = getModelDbController().delete(args.table, args.where, args.args);
        if (count > 0) {
        if (count > 0) {
            reloadLauncherIfExternal();
            reloadLauncherIfExternal();
        }
        }
@@ -206,7 +207,7 @@ public class LauncherProvider extends ContentProvider {
    @Override
    @Override
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
        SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
        int count = mModelDbController.update(args.table, values, args.where, args.args);
        int count = getModelDbController().update(args.table, values, args.where, args.args);
        reloadLauncherIfExternal();
        reloadLauncherIfExternal();
        return count;
        return count;
    }
    }
@@ -219,59 +220,59 @@ public class LauncherProvider extends ContentProvider {


        switch (method) {
        switch (method) {
            case LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG: {
            case LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG: {
                mModelDbController.clearEmptyDbFlag();
                getModelDbController().clearEmptyDbFlag();
                return null;
                return null;
            }
            }
            case LauncherSettings.Settings.METHOD_DELETE_EMPTY_FOLDERS: {
            case LauncherSettings.Settings.METHOD_DELETE_EMPTY_FOLDERS: {
                Bundle result = new Bundle();
                Bundle result = new Bundle();
                result.putIntArray(LauncherSettings.Settings.EXTRA_VALUE,
                result.putIntArray(LauncherSettings.Settings.EXTRA_VALUE,
                        mModelDbController.deleteEmptyFolders().toArray());
                        getModelDbController().deleteEmptyFolders().toArray());
                return result;
                return result;
            }
            }
            case LauncherSettings.Settings.METHOD_NEW_ITEM_ID: {
            case LauncherSettings.Settings.METHOD_NEW_ITEM_ID: {
                Bundle result = new Bundle();
                Bundle result = new Bundle();
                result.putInt(LauncherSettings.Settings.EXTRA_VALUE,
                result.putInt(LauncherSettings.Settings.EXTRA_VALUE,
                        mModelDbController.generateNewItemId());
                        getModelDbController().generateNewItemId());
                return result;
                return result;
            }
            }
            case LauncherSettings.Settings.METHOD_NEW_SCREEN_ID: {
            case LauncherSettings.Settings.METHOD_NEW_SCREEN_ID: {
                Bundle result = new Bundle();
                Bundle result = new Bundle();
                result.putInt(LauncherSettings.Settings.EXTRA_VALUE,
                result.putInt(LauncherSettings.Settings.EXTRA_VALUE,
                        mModelDbController.getNewScreenId());
                        getModelDbController().getNewScreenId());
                return result;
                return result;
            }
            }
            case LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB: {
            case LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB: {
                mModelDbController.createEmptyDB();
                getModelDbController().createEmptyDB();
                return null;
                return null;
            }
            }
            case LauncherSettings.Settings.METHOD_LOAD_DEFAULT_FAVORITES: {
            case LauncherSettings.Settings.METHOD_LOAD_DEFAULT_FAVORITES: {
                mModelDbController.loadDefaultFavoritesIfNecessary();
                getModelDbController().loadDefaultFavoritesIfNecessary();
                return null;
                return null;
            }
            }
            case LauncherSettings.Settings.METHOD_REMOVE_GHOST_WIDGETS: {
            case LauncherSettings.Settings.METHOD_REMOVE_GHOST_WIDGETS: {
                mModelDbController.removeGhostWidgets();
                getModelDbController().removeGhostWidgets();
                return null;
                return null;
            }
            }
            case LauncherSettings.Settings.METHOD_NEW_TRANSACTION: {
            case LauncherSettings.Settings.METHOD_NEW_TRANSACTION: {
                Bundle result = new Bundle();
                Bundle result = new Bundle();
                result.putBinder(LauncherSettings.Settings.EXTRA_VALUE,
                result.putBinder(LauncherSettings.Settings.EXTRA_VALUE,
                        mModelDbController.newTransaction());
                        getModelDbController().newTransaction());
                return result;
                return result;
            }
            }
            case LauncherSettings.Settings.METHOD_REFRESH_HOTSEAT_RESTORE_TABLE: {
            case LauncherSettings.Settings.METHOD_REFRESH_HOTSEAT_RESTORE_TABLE: {
                mModelDbController.refreshHotseatRestoreTable();
                getModelDbController().refreshHotseatRestoreTable();
                return null;
                return null;
            }
            }
            case LauncherSettings.Settings.METHOD_UPDATE_CURRENT_OPEN_HELPER: {
            case LauncherSettings.Settings.METHOD_UPDATE_CURRENT_OPEN_HELPER: {
                Bundle result = new Bundle();
                Bundle result = new Bundle();
                result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE,
                result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE,
                        mModelDbController.updateCurrentOpenHelper(arg /* dbFile */));
                        getModelDbController().updateCurrentOpenHelper(arg /* dbFile */));
                return result;
                return result;
            }
            }
            case LauncherSettings.Settings.METHOD_PREP_FOR_PREVIEW: {
            case LauncherSettings.Settings.METHOD_PREP_FOR_PREVIEW: {
                Bundle result = new Bundle();
                Bundle result = new Bundle();
                result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE,
                result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE,
                        mModelDbController.prepareForPreview(arg /* dbFile */));
                        getModelDbController().prepareForPreview(arg /* dbFile */));
                return result;
                return result;
            }
            }
        }
        }
+3 −0
Original line number Original line Diff line number Diff line
@@ -65,6 +65,7 @@ public class LoaderCursor extends CursorWrapper {


    private final LongSparseArray<UserHandle> allUsers;
    private final LongSparseArray<UserHandle> allUsers;


    private final LauncherAppState mApp;
    private final Uri mContentUri;
    private final Uri mContentUri;
    private final Context mContext;
    private final Context mContext;
    private final PackageManager mPM;
    private final PackageManager mPM;
@@ -111,6 +112,7 @@ public class LoaderCursor extends CursorWrapper {
            UserManagerState userManagerState) {
            UserManagerState userManagerState) {
        super(cursor);
        super(cursor);


        mApp = app;
        allUsers = userManagerState.allUsers;
        allUsers = userManagerState.allUsers;
        mContentUri = contentUri;
        mContentUri = contentUri;
        mContext = app.getContext();
        mContext = app.getContext();
@@ -388,6 +390,7 @@ public class LoaderCursor extends CursorWrapper {
     */
     */
    public ContentWriter updater() {
    public ContentWriter updater() {
       return new ContentWriter(mContext, new ContentWriter.CommitParams(
       return new ContentWriter(mContext, new ContentWriter.CommitParams(
               mApp.getModel().getModelDbController().getDatabaseHelper(),
               BaseColumns._ID + "= ?", new String[]{Integer.toString(id)}));
               BaseColumns._ID + "= ?", new String[]{Integer.toString(id)}));
    }
    }


+19 −0
Original line number Original line Diff line number Diff line
@@ -50,6 +50,8 @@ import android.util.Base64;
import android.util.Log;
import android.util.Log;
import android.util.Xml;
import android.util.Xml;


import androidx.annotation.WorkerThread;

import com.android.launcher3.AutoInstallsLayout;
import com.android.launcher3.AutoInstallsLayout;
import com.android.launcher3.AutoInstallsLayout.SourceResources;
import com.android.launcher3.AutoInstallsLayout.SourceResources;
import com.android.launcher3.DefaultLayoutParser;
import com.android.launcher3.DefaultLayoutParser;
@@ -115,6 +117,7 @@ public class ModelDbController {
    /**
    /**
     * Refer {@link SQLiteDatabase#query}
     * Refer {@link SQLiteDatabase#query}
     */
     */
    @WorkerThread
    public Cursor query(String table, String[] projection, String selection,
    public Cursor query(String table, String[] projection, String selection,
            String[] selectionArgs, String sortOrder) {
            String[] selectionArgs, String sortOrder) {
        createDbIfNotExists();
        createDbIfNotExists();
@@ -131,6 +134,7 @@ public class ModelDbController {
    /**
    /**
     * Refer {@link SQLiteDatabase#insert(String, String, ContentValues)}
     * Refer {@link SQLiteDatabase#insert(String, String, ContentValues)}
     */
     */
    @WorkerThread
    public int insert(String table, ContentValues initialValues) {
    public int insert(String table, ContentValues initialValues) {
        createDbIfNotExists();
        createDbIfNotExists();


@@ -146,6 +150,7 @@ public class ModelDbController {
    /**
    /**
     * Similar to insert but for adding multiple values in a transaction.
     * Similar to insert but for adding multiple values in a transaction.
     */
     */
    @WorkerThread
    public int bulkInsert(String table, ContentValues[] values) {
    public int bulkInsert(String table, ContentValues[] values) {
        createDbIfNotExists();
        createDbIfNotExists();


@@ -167,6 +172,7 @@ public class ModelDbController {
    /**
    /**
     * Refer {@link SQLiteDatabase#delete(String, String, String[])}
     * Refer {@link SQLiteDatabase#delete(String, String, String[])}
     */
     */
    @WorkerThread
    public int delete(String table, String selection, String[] selectionArgs) {
    public int delete(String table, String selection, String[] selectionArgs) {
        createDbIfNotExists();
        createDbIfNotExists();
        SQLiteDatabase db = mOpenHelper.getWritableDatabase();
        SQLiteDatabase db = mOpenHelper.getWritableDatabase();
@@ -185,6 +191,7 @@ public class ModelDbController {
    /**
    /**
     * Refer {@link SQLiteDatabase#update(String, ContentValues, String, String[])}
     * Refer {@link SQLiteDatabase#update(String, ContentValues, String, String[])}
     */
     */
    @WorkerThread
    public int update(String table, ContentValues values,
    public int update(String table, ContentValues values,
            String selection, String[] selectionArgs) {
            String selection, String[] selectionArgs) {
        createDbIfNotExists();
        createDbIfNotExists();
@@ -198,6 +205,7 @@ public class ModelDbController {
    /**
    /**
     * Clears a previously set flag corresponding to empty db creation
     * Clears a previously set flag corresponding to empty db creation
     */
     */
    @WorkerThread
    public void clearEmptyDbFlag() {
    public void clearEmptyDbFlag() {
        createDbIfNotExists();
        createDbIfNotExists();
        clearFlagEmptyDbCreated();
        clearFlagEmptyDbCreated();
@@ -206,6 +214,7 @@ public class ModelDbController {
    /**
    /**
     * Generates an id to be used for new item in the favorites table
     * Generates an id to be used for new item in the favorites table
     */
     */
    @WorkerThread
    public int generateNewItemId() {
    public int generateNewItemId() {
        createDbIfNotExists();
        createDbIfNotExists();
        return mOpenHelper.generateNewItemId();
        return mOpenHelper.generateNewItemId();
@@ -214,6 +223,7 @@ public class ModelDbController {
    /**
    /**
     * Generates an id to be used for new workspace screen
     * Generates an id to be used for new workspace screen
     */
     */
    @WorkerThread
    public int getNewScreenId() {
    public int getNewScreenId() {
        createDbIfNotExists();
        createDbIfNotExists();
        return mOpenHelper.getNewScreenId();
        return mOpenHelper.getNewScreenId();
@@ -222,6 +232,7 @@ public class ModelDbController {
    /**
    /**
     * Creates an empty DB clearing all existing data
     * Creates an empty DB clearing all existing data
     */
     */
    @WorkerThread
    public void createEmptyDB() {
    public void createEmptyDB() {
        createDbIfNotExists();
        createDbIfNotExists();
        mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
        mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
@@ -230,6 +241,7 @@ public class ModelDbController {
    /**
    /**
     * Removes any widget which are present in the framework, but not in out internal DB
     * Removes any widget which are present in the framework, but not in out internal DB
     */
     */
    @WorkerThread
    public void removeGhostWidgets() {
    public void removeGhostWidgets() {
        createDbIfNotExists();
        createDbIfNotExists();
        mOpenHelper.removeGhostWidgets(mOpenHelper.getWritableDatabase());
        mOpenHelper.removeGhostWidgets(mOpenHelper.getWritableDatabase());
@@ -238,6 +250,7 @@ public class ModelDbController {
    /**
    /**
     * Returns a new {@link SQLiteTransaction}
     * Returns a new {@link SQLiteTransaction}
     */
     */
    @WorkerThread
    public SQLiteTransaction newTransaction() {
    public SQLiteTransaction newTransaction() {
        createDbIfNotExists();
        createDbIfNotExists();
        return new SQLiteTransaction(mOpenHelper.getWritableDatabase());
        return new SQLiteTransaction(mOpenHelper.getWritableDatabase());
@@ -246,6 +259,7 @@ public class ModelDbController {
    /**
    /**
     * Refreshes the internal state corresponding to presence of hotseat table
     * Refreshes the internal state corresponding to presence of hotseat table
     */
     */
    @WorkerThread
    public void refreshHotseatRestoreTable() {
    public void refreshHotseatRestoreTable() {
        createDbIfNotExists();
        createDbIfNotExists();
        mOpenHelper.mHotseatRestoreTableExists = tableExists(
        mOpenHelper.mHotseatRestoreTableExists = tableExists(
@@ -256,6 +270,7 @@ public class ModelDbController {
     * Updates the current DB and copies all the existing data to the temp table
     * Updates the current DB and copies all the existing data to the temp table
     * @param dbFile name of the target db file name
     * @param dbFile name of the target db file name
     */
     */
    @WorkerThread
    public boolean updateCurrentOpenHelper(String dbFile) {
    public boolean updateCurrentOpenHelper(String dbFile) {
        createDbIfNotExists();
        createDbIfNotExists();
        return prepForMigration(
        return prepForMigration(
@@ -270,6 +285,7 @@ public class ModelDbController {
     * Returns the current DatabaseHelper.
     * Returns the current DatabaseHelper.
     * Only for tests
     * Only for tests
     */
     */
    @WorkerThread
    public DatabaseHelper getDatabaseHelper() {
    public DatabaseHelper getDatabaseHelper() {
        createDbIfNotExists();
        createDbIfNotExists();
        return mOpenHelper;
        return mOpenHelper;
@@ -278,6 +294,7 @@ public class ModelDbController {
    /**
    /**
     * Prepares the DB for preview by copying all existing data to preview table
     * Prepares the DB for preview by copying all existing data to preview table
     */
     */
    @WorkerThread
    public boolean prepareForPreview(String dbFile) {
    public boolean prepareForPreview(String dbFile) {
        createDbIfNotExists();
        createDbIfNotExists();
        return prepForMigration(
        return prepForMigration(
@@ -296,6 +313,7 @@ public class ModelDbController {
     * Deletes any empty folder from the DB.
     * Deletes any empty folder from the DB.
     * @return Ids of deleted folders.
     * @return Ids of deleted folders.
     */
     */
    @WorkerThread
    public IntArray deleteEmptyFolders() {
    public IntArray deleteEmptyFolders() {
        createDbIfNotExists();
        createDbIfNotExists();


@@ -338,6 +356,7 @@ public class ModelDbController {
     *   3) From a partner configuration APK, already in the system image
     *   3) From a partner configuration APK, already in the system image
     *   4) The default configuration for the particular device
     *   4) The default configuration for the particular device
     */
     */
    @WorkerThread
    public synchronized void loadDefaultFavoritesIfNecessary() {
    public synchronized void loadDefaultFavoritesIfNecessary() {
        createDbIfNotExists();
        createDbIfNotExists();
        SharedPreferences sp = LauncherPrefs.getPrefs(mContext);
        SharedPreferences sp = LauncherPrefs.getPrefs(mContext);
Loading