Loading src/com/android/launcher3/AppWidgetsRestoredReceiver.java +8 −5 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ import androidx.annotation.NonNull; import androidx.annotation.WorkerThread; import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.model.DatabaseHelper; import com.android.launcher3.model.LoaderTask; import com.android.launcher3.model.WidgetsModel; import com.android.launcher3.model.data.LauncherAppWidgetInfo; Loading Loading @@ -51,8 +52,8 @@ public class AppWidgetsRestoredReceiver extends BroadcastReceiver { * Updates the app widgets whose id has changed during the restore process. */ @WorkerThread public static void restoreAppWidgetIds(Context context, int[] oldWidgetIds, int[] newWidgetIds, @NonNull AppWidgetHost host) { public static void restoreAppWidgetIds(Context context, DatabaseHelper helper, int[] oldWidgetIds, int[] newWidgetIds, @NonNull AppWidgetHost host) { if (WidgetsModel.GO_DISABLE_WIDGETS) { Log.e(TAG, "Skipping widget ID remap as widgets not supported"); host.deleteHost(); Loading Loading @@ -90,14 +91,16 @@ public class AppWidgetsRestoredReceiver extends BroadcastReceiver { String oldWidgetId = Integer.toString(oldWidgetIds[i]); final String where = "appWidgetId=? and (restored & 1) = 1 and profileId=?"; 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.RESTORED, state) .commit(); if (result == 0) { Cursor cursor = cr.query(Favorites.CONTENT_URI, Cursor cursor = helper.getWritableDatabase().query( Favorites.TABLE_NAME, new String[] {Favorites.APPWIDGET_ID}, "appWidgetId=?", new String[] { oldWidgetId }, null); "appWidgetId=?", new String[] { oldWidgetId }, null, null, null); try { if (!cursor.moveToFirst()) { // The widget no long exists. Loading src/com/android/launcher3/LauncherModel.java +8 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ import com.android.launcher3.model.CacheDataUpdatedTask; import com.android.launcher3.model.ItemInstallQueue; import com.android.launcher3.model.LauncherBinder; import com.android.launcher3.model.LoaderTask; import com.android.launcher3.model.ModelDbController; import com.android.launcher3.model.ModelDelegate; import com.android.launcher3.model.ModelWriter; import com.android.launcher3.model.PackageIncrementalDownloadUpdatedTask; Loading Loading @@ -94,6 +95,8 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi @NonNull private final LauncherAppState mApp; @NonNull private final ModelDbController mModelDbController; @NonNull private final Object mLock = new Object(); @Nullable private LoaderTask mLoaderTask; Loading Loading @@ -143,6 +146,7 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi @NonNull final IconCache iconCache, @NonNull final AppFilter appFilter, final boolean isPrimaryInstance) { mApp = app; mModelDbController = new ModelDbController(context); mBgAllAppsList = new AllAppsList(iconCache, appFilter); mModelDelegate = ModelDelegate.newInstance(context, app, mBgAllAppsList, mBgDataModel, isPrimaryInstance); Loading @@ -153,6 +157,10 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi return mModelDelegate; } public ModelDbController getModelDbController() { return mModelDbController; } /** * Adds the provided items to the workspace. */ Loading src/com/android/launcher3/LauncherProvider.java +22 −21 Original line number Diff line number Diff line Loading @@ -50,8 +50,6 @@ public class LauncherProvider extends ContentProvider { public static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".settings"; protected ModelDbController mModelDbController; /** * $ adb shell dumpsys activity provider com.android.launcher3 */ Loading @@ -69,7 +67,6 @@ public class LauncherProvider extends ContentProvider { if (FeatureFlags.IS_STUDIO_BUILD) { Log.d(TAG, "Launcher process started"); } mModelDbController = new ModelDbController(getContext()); // The content provider exists for the entire duration of the launcher main process and // is the first component to get created. Loading @@ -77,6 +74,10 @@ public class LauncherProvider extends ContentProvider { return true; } public ModelDbController getModelDbController() { return LauncherAppState.getInstance(getContext()).getModel().getModelDbController(); } @Override public String getType(Uri uri) { SqlArguments args = new SqlArguments(uri, null, null); Loading @@ -95,7 +96,7 @@ public class LauncherProvider extends ContentProvider { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(args.table); Cursor result = mModelDbController.query( Cursor result = getModelDbController().query( args.table, projection, args.where, args.args, sortOrder); result.setNotificationUri(getContext().getContentResolver(), uri); return result; Loading @@ -120,7 +121,7 @@ public class LauncherProvider extends ContentProvider { } SqlArguments args = new SqlArguments(uri); int rowId = mModelDbController.insert(args.table, initialValues); int rowId = getModelDbController().insert(args.table, initialValues); if (rowId < 0) return null; uri = ContentUris.withAppendedId(uri, rowId); Loading @@ -130,7 +131,7 @@ public class LauncherProvider extends ContentProvider { private boolean initializeExternalAdd(ContentValues values) { // 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); // 2. In the case of an app widget, and if no app widget id is specified, we Loading Loading @@ -171,7 +172,7 @@ public class LauncherProvider extends ContentProvider { @Override public int bulkInsert(Uri uri, ContentValues[] values) { SqlArguments args = new SqlArguments(uri); mModelDbController.bulkInsert(args.table, values); getModelDbController().bulkInsert(args.table, values); reloadLauncherIfExternal(); return values.length; } Loading @@ -180,7 +181,7 @@ public class LauncherProvider extends ContentProvider { @Override public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { try (SQLiteTransaction t = mModelDbController.newTransaction()) { try (SQLiteTransaction t = getModelDbController().newTransaction()) { final int numOperations = operations.size(); final ContentProviderResult[] results = new ContentProviderResult[numOperations]; for (int i = 0; i < numOperations; i++) { Loading @@ -196,7 +197,7 @@ public class LauncherProvider extends ContentProvider { @Override public int delete(Uri uri, String selection, String[] 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) { reloadLauncherIfExternal(); } Loading @@ -206,7 +207,7 @@ public class LauncherProvider extends ContentProvider { @Override public int update(Uri uri, ContentValues values, String selection, String[] 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(); return count; } Loading @@ -219,59 +220,59 @@ public class LauncherProvider extends ContentProvider { switch (method) { case LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG: { mModelDbController.clearEmptyDbFlag(); getModelDbController().clearEmptyDbFlag(); return null; } case LauncherSettings.Settings.METHOD_DELETE_EMPTY_FOLDERS: { Bundle result = new Bundle(); result.putIntArray(LauncherSettings.Settings.EXTRA_VALUE, mModelDbController.deleteEmptyFolders().toArray()); getModelDbController().deleteEmptyFolders().toArray()); return result; } case LauncherSettings.Settings.METHOD_NEW_ITEM_ID: { Bundle result = new Bundle(); result.putInt(LauncherSettings.Settings.EXTRA_VALUE, mModelDbController.generateNewItemId()); getModelDbController().generateNewItemId()); return result; } case LauncherSettings.Settings.METHOD_NEW_SCREEN_ID: { Bundle result = new Bundle(); result.putInt(LauncherSettings.Settings.EXTRA_VALUE, mModelDbController.getNewScreenId()); getModelDbController().getNewScreenId()); return result; } case LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB: { mModelDbController.createEmptyDB(); getModelDbController().createEmptyDB(); return null; } case LauncherSettings.Settings.METHOD_LOAD_DEFAULT_FAVORITES: { mModelDbController.loadDefaultFavoritesIfNecessary(); getModelDbController().loadDefaultFavoritesIfNecessary(); return null; } case LauncherSettings.Settings.METHOD_REMOVE_GHOST_WIDGETS: { mModelDbController.removeGhostWidgets(); getModelDbController().removeGhostWidgets(); return null; } case LauncherSettings.Settings.METHOD_NEW_TRANSACTION: { Bundle result = new Bundle(); result.putBinder(LauncherSettings.Settings.EXTRA_VALUE, mModelDbController.newTransaction()); getModelDbController().newTransaction()); return result; } case LauncherSettings.Settings.METHOD_REFRESH_HOTSEAT_RESTORE_TABLE: { mModelDbController.refreshHotseatRestoreTable(); getModelDbController().refreshHotseatRestoreTable(); return null; } case LauncherSettings.Settings.METHOD_UPDATE_CURRENT_OPEN_HELPER: { Bundle result = new Bundle(); result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE, mModelDbController.updateCurrentOpenHelper(arg /* dbFile */)); getModelDbController().updateCurrentOpenHelper(arg /* dbFile */)); return result; } case LauncherSettings.Settings.METHOD_PREP_FOR_PREVIEW: { Bundle result = new Bundle(); result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE, mModelDbController.prepareForPreview(arg /* dbFile */)); getModelDbController().prepareForPreview(arg /* dbFile */)); return result; } } Loading src/com/android/launcher3/model/LoaderCursor.java +3 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,7 @@ public class LoaderCursor extends CursorWrapper { private final LongSparseArray<UserHandle> allUsers; private final LauncherAppState mApp; private final Uri mContentUri; private final Context mContext; private final PackageManager mPM; Loading Loading @@ -111,6 +112,7 @@ public class LoaderCursor extends CursorWrapper { UserManagerState userManagerState) { super(cursor); mApp = app; allUsers = userManagerState.allUsers; mContentUri = contentUri; mContext = app.getContext(); Loading Loading @@ -388,6 +390,7 @@ public class LoaderCursor extends CursorWrapper { */ public ContentWriter updater() { return new ContentWriter(mContext, new ContentWriter.CommitParams( mApp.getModel().getModelDbController().getDatabaseHelper(), BaseColumns._ID + "= ?", new String[]{Integer.toString(id)})); } Loading src/com/android/launcher3/model/ModelDbController.java +19 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,8 @@ import android.util.Base64; import android.util.Log; import android.util.Xml; import androidx.annotation.WorkerThread; import com.android.launcher3.AutoInstallsLayout; import com.android.launcher3.AutoInstallsLayout.SourceResources; import com.android.launcher3.DefaultLayoutParser; Loading Loading @@ -115,6 +117,7 @@ public class ModelDbController { /** * Refer {@link SQLiteDatabase#query} */ @WorkerThread public Cursor query(String table, String[] projection, String selection, String[] selectionArgs, String sortOrder) { createDbIfNotExists(); Loading @@ -131,6 +134,7 @@ public class ModelDbController { /** * Refer {@link SQLiteDatabase#insert(String, String, ContentValues)} */ @WorkerThread public int insert(String table, ContentValues initialValues) { createDbIfNotExists(); Loading @@ -146,6 +150,7 @@ public class ModelDbController { /** * Similar to insert but for adding multiple values in a transaction. */ @WorkerThread public int bulkInsert(String table, ContentValues[] values) { createDbIfNotExists(); Loading @@ -167,6 +172,7 @@ public class ModelDbController { /** * Refer {@link SQLiteDatabase#delete(String, String, String[])} */ @WorkerThread public int delete(String table, String selection, String[] selectionArgs) { createDbIfNotExists(); SQLiteDatabase db = mOpenHelper.getWritableDatabase(); Loading @@ -185,6 +191,7 @@ public class ModelDbController { /** * Refer {@link SQLiteDatabase#update(String, ContentValues, String, String[])} */ @WorkerThread public int update(String table, ContentValues values, String selection, String[] selectionArgs) { createDbIfNotExists(); Loading @@ -198,6 +205,7 @@ public class ModelDbController { /** * Clears a previously set flag corresponding to empty db creation */ @WorkerThread public void clearEmptyDbFlag() { createDbIfNotExists(); clearFlagEmptyDbCreated(); Loading @@ -206,6 +214,7 @@ public class ModelDbController { /** * Generates an id to be used for new item in the favorites table */ @WorkerThread public int generateNewItemId() { createDbIfNotExists(); return mOpenHelper.generateNewItemId(); Loading @@ -214,6 +223,7 @@ public class ModelDbController { /** * Generates an id to be used for new workspace screen */ @WorkerThread public int getNewScreenId() { createDbIfNotExists(); return mOpenHelper.getNewScreenId(); Loading @@ -222,6 +232,7 @@ public class ModelDbController { /** * Creates an empty DB clearing all existing data */ @WorkerThread public void createEmptyDB() { createDbIfNotExists(); mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase()); Loading @@ -230,6 +241,7 @@ public class ModelDbController { /** * Removes any widget which are present in the framework, but not in out internal DB */ @WorkerThread public void removeGhostWidgets() { createDbIfNotExists(); mOpenHelper.removeGhostWidgets(mOpenHelper.getWritableDatabase()); Loading @@ -238,6 +250,7 @@ public class ModelDbController { /** * Returns a new {@link SQLiteTransaction} */ @WorkerThread public SQLiteTransaction newTransaction() { createDbIfNotExists(); return new SQLiteTransaction(mOpenHelper.getWritableDatabase()); Loading @@ -246,6 +259,7 @@ public class ModelDbController { /** * Refreshes the internal state corresponding to presence of hotseat table */ @WorkerThread public void refreshHotseatRestoreTable() { createDbIfNotExists(); mOpenHelper.mHotseatRestoreTableExists = tableExists( Loading @@ -256,6 +270,7 @@ public class ModelDbController { * Updates the current DB and copies all the existing data to the temp table * @param dbFile name of the target db file name */ @WorkerThread public boolean updateCurrentOpenHelper(String dbFile) { createDbIfNotExists(); return prepForMigration( Loading @@ -270,6 +285,7 @@ public class ModelDbController { * Returns the current DatabaseHelper. * Only for tests */ @WorkerThread public DatabaseHelper getDatabaseHelper() { createDbIfNotExists(); return mOpenHelper; Loading @@ -278,6 +294,7 @@ public class ModelDbController { /** * Prepares the DB for preview by copying all existing data to preview table */ @WorkerThread public boolean prepareForPreview(String dbFile) { createDbIfNotExists(); return prepForMigration( Loading @@ -296,6 +313,7 @@ public class ModelDbController { * Deletes any empty folder from the DB. * @return Ids of deleted folders. */ @WorkerThread public IntArray deleteEmptyFolders() { createDbIfNotExists(); Loading Loading @@ -338,6 +356,7 @@ public class ModelDbController { * 3) From a partner configuration APK, already in the system image * 4) The default configuration for the particular device */ @WorkerThread public synchronized void loadDefaultFavoritesIfNecessary() { createDbIfNotExists(); SharedPreferences sp = LauncherPrefs.getPrefs(mContext); Loading Loading
src/com/android/launcher3/AppWidgetsRestoredReceiver.java +8 −5 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ import androidx.annotation.NonNull; import androidx.annotation.WorkerThread; import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.model.DatabaseHelper; import com.android.launcher3.model.LoaderTask; import com.android.launcher3.model.WidgetsModel; import com.android.launcher3.model.data.LauncherAppWidgetInfo; Loading Loading @@ -51,8 +52,8 @@ public class AppWidgetsRestoredReceiver extends BroadcastReceiver { * Updates the app widgets whose id has changed during the restore process. */ @WorkerThread public static void restoreAppWidgetIds(Context context, int[] oldWidgetIds, int[] newWidgetIds, @NonNull AppWidgetHost host) { public static void restoreAppWidgetIds(Context context, DatabaseHelper helper, int[] oldWidgetIds, int[] newWidgetIds, @NonNull AppWidgetHost host) { if (WidgetsModel.GO_DISABLE_WIDGETS) { Log.e(TAG, "Skipping widget ID remap as widgets not supported"); host.deleteHost(); Loading Loading @@ -90,14 +91,16 @@ public class AppWidgetsRestoredReceiver extends BroadcastReceiver { String oldWidgetId = Integer.toString(oldWidgetIds[i]); final String where = "appWidgetId=? and (restored & 1) = 1 and profileId=?"; 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.RESTORED, state) .commit(); if (result == 0) { Cursor cursor = cr.query(Favorites.CONTENT_URI, Cursor cursor = helper.getWritableDatabase().query( Favorites.TABLE_NAME, new String[] {Favorites.APPWIDGET_ID}, "appWidgetId=?", new String[] { oldWidgetId }, null); "appWidgetId=?", new String[] { oldWidgetId }, null, null, null); try { if (!cursor.moveToFirst()) { // The widget no long exists. Loading
src/com/android/launcher3/LauncherModel.java +8 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ import com.android.launcher3.model.CacheDataUpdatedTask; import com.android.launcher3.model.ItemInstallQueue; import com.android.launcher3.model.LauncherBinder; import com.android.launcher3.model.LoaderTask; import com.android.launcher3.model.ModelDbController; import com.android.launcher3.model.ModelDelegate; import com.android.launcher3.model.ModelWriter; import com.android.launcher3.model.PackageIncrementalDownloadUpdatedTask; Loading Loading @@ -94,6 +95,8 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi @NonNull private final LauncherAppState mApp; @NonNull private final ModelDbController mModelDbController; @NonNull private final Object mLock = new Object(); @Nullable private LoaderTask mLoaderTask; Loading Loading @@ -143,6 +146,7 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi @NonNull final IconCache iconCache, @NonNull final AppFilter appFilter, final boolean isPrimaryInstance) { mApp = app; mModelDbController = new ModelDbController(context); mBgAllAppsList = new AllAppsList(iconCache, appFilter); mModelDelegate = ModelDelegate.newInstance(context, app, mBgAllAppsList, mBgDataModel, isPrimaryInstance); Loading @@ -153,6 +157,10 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi return mModelDelegate; } public ModelDbController getModelDbController() { return mModelDbController; } /** * Adds the provided items to the workspace. */ Loading
src/com/android/launcher3/LauncherProvider.java +22 −21 Original line number Diff line number Diff line Loading @@ -50,8 +50,6 @@ public class LauncherProvider extends ContentProvider { public static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".settings"; protected ModelDbController mModelDbController; /** * $ adb shell dumpsys activity provider com.android.launcher3 */ Loading @@ -69,7 +67,6 @@ public class LauncherProvider extends ContentProvider { if (FeatureFlags.IS_STUDIO_BUILD) { Log.d(TAG, "Launcher process started"); } mModelDbController = new ModelDbController(getContext()); // The content provider exists for the entire duration of the launcher main process and // is the first component to get created. Loading @@ -77,6 +74,10 @@ public class LauncherProvider extends ContentProvider { return true; } public ModelDbController getModelDbController() { return LauncherAppState.getInstance(getContext()).getModel().getModelDbController(); } @Override public String getType(Uri uri) { SqlArguments args = new SqlArguments(uri, null, null); Loading @@ -95,7 +96,7 @@ public class LauncherProvider extends ContentProvider { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(args.table); Cursor result = mModelDbController.query( Cursor result = getModelDbController().query( args.table, projection, args.where, args.args, sortOrder); result.setNotificationUri(getContext().getContentResolver(), uri); return result; Loading @@ -120,7 +121,7 @@ public class LauncherProvider extends ContentProvider { } SqlArguments args = new SqlArguments(uri); int rowId = mModelDbController.insert(args.table, initialValues); int rowId = getModelDbController().insert(args.table, initialValues); if (rowId < 0) return null; uri = ContentUris.withAppendedId(uri, rowId); Loading @@ -130,7 +131,7 @@ public class LauncherProvider extends ContentProvider { private boolean initializeExternalAdd(ContentValues values) { // 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); // 2. In the case of an app widget, and if no app widget id is specified, we Loading Loading @@ -171,7 +172,7 @@ public class LauncherProvider extends ContentProvider { @Override public int bulkInsert(Uri uri, ContentValues[] values) { SqlArguments args = new SqlArguments(uri); mModelDbController.bulkInsert(args.table, values); getModelDbController().bulkInsert(args.table, values); reloadLauncherIfExternal(); return values.length; } Loading @@ -180,7 +181,7 @@ public class LauncherProvider extends ContentProvider { @Override public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { try (SQLiteTransaction t = mModelDbController.newTransaction()) { try (SQLiteTransaction t = getModelDbController().newTransaction()) { final int numOperations = operations.size(); final ContentProviderResult[] results = new ContentProviderResult[numOperations]; for (int i = 0; i < numOperations; i++) { Loading @@ -196,7 +197,7 @@ public class LauncherProvider extends ContentProvider { @Override public int delete(Uri uri, String selection, String[] 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) { reloadLauncherIfExternal(); } Loading @@ -206,7 +207,7 @@ public class LauncherProvider extends ContentProvider { @Override public int update(Uri uri, ContentValues values, String selection, String[] 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(); return count; } Loading @@ -219,59 +220,59 @@ public class LauncherProvider extends ContentProvider { switch (method) { case LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG: { mModelDbController.clearEmptyDbFlag(); getModelDbController().clearEmptyDbFlag(); return null; } case LauncherSettings.Settings.METHOD_DELETE_EMPTY_FOLDERS: { Bundle result = new Bundle(); result.putIntArray(LauncherSettings.Settings.EXTRA_VALUE, mModelDbController.deleteEmptyFolders().toArray()); getModelDbController().deleteEmptyFolders().toArray()); return result; } case LauncherSettings.Settings.METHOD_NEW_ITEM_ID: { Bundle result = new Bundle(); result.putInt(LauncherSettings.Settings.EXTRA_VALUE, mModelDbController.generateNewItemId()); getModelDbController().generateNewItemId()); return result; } case LauncherSettings.Settings.METHOD_NEW_SCREEN_ID: { Bundle result = new Bundle(); result.putInt(LauncherSettings.Settings.EXTRA_VALUE, mModelDbController.getNewScreenId()); getModelDbController().getNewScreenId()); return result; } case LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB: { mModelDbController.createEmptyDB(); getModelDbController().createEmptyDB(); return null; } case LauncherSettings.Settings.METHOD_LOAD_DEFAULT_FAVORITES: { mModelDbController.loadDefaultFavoritesIfNecessary(); getModelDbController().loadDefaultFavoritesIfNecessary(); return null; } case LauncherSettings.Settings.METHOD_REMOVE_GHOST_WIDGETS: { mModelDbController.removeGhostWidgets(); getModelDbController().removeGhostWidgets(); return null; } case LauncherSettings.Settings.METHOD_NEW_TRANSACTION: { Bundle result = new Bundle(); result.putBinder(LauncherSettings.Settings.EXTRA_VALUE, mModelDbController.newTransaction()); getModelDbController().newTransaction()); return result; } case LauncherSettings.Settings.METHOD_REFRESH_HOTSEAT_RESTORE_TABLE: { mModelDbController.refreshHotseatRestoreTable(); getModelDbController().refreshHotseatRestoreTable(); return null; } case LauncherSettings.Settings.METHOD_UPDATE_CURRENT_OPEN_HELPER: { Bundle result = new Bundle(); result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE, mModelDbController.updateCurrentOpenHelper(arg /* dbFile */)); getModelDbController().updateCurrentOpenHelper(arg /* dbFile */)); return result; } case LauncherSettings.Settings.METHOD_PREP_FOR_PREVIEW: { Bundle result = new Bundle(); result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE, mModelDbController.prepareForPreview(arg /* dbFile */)); getModelDbController().prepareForPreview(arg /* dbFile */)); return result; } } Loading
src/com/android/launcher3/model/LoaderCursor.java +3 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,7 @@ public class LoaderCursor extends CursorWrapper { private final LongSparseArray<UserHandle> allUsers; private final LauncherAppState mApp; private final Uri mContentUri; private final Context mContext; private final PackageManager mPM; Loading Loading @@ -111,6 +112,7 @@ public class LoaderCursor extends CursorWrapper { UserManagerState userManagerState) { super(cursor); mApp = app; allUsers = userManagerState.allUsers; mContentUri = contentUri; mContext = app.getContext(); Loading Loading @@ -388,6 +390,7 @@ public class LoaderCursor extends CursorWrapper { */ public ContentWriter updater() { return new ContentWriter(mContext, new ContentWriter.CommitParams( mApp.getModel().getModelDbController().getDatabaseHelper(), BaseColumns._ID + "= ?", new String[]{Integer.toString(id)})); } Loading
src/com/android/launcher3/model/ModelDbController.java +19 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,8 @@ import android.util.Base64; import android.util.Log; import android.util.Xml; import androidx.annotation.WorkerThread; import com.android.launcher3.AutoInstallsLayout; import com.android.launcher3.AutoInstallsLayout.SourceResources; import com.android.launcher3.DefaultLayoutParser; Loading Loading @@ -115,6 +117,7 @@ public class ModelDbController { /** * Refer {@link SQLiteDatabase#query} */ @WorkerThread public Cursor query(String table, String[] projection, String selection, String[] selectionArgs, String sortOrder) { createDbIfNotExists(); Loading @@ -131,6 +134,7 @@ public class ModelDbController { /** * Refer {@link SQLiteDatabase#insert(String, String, ContentValues)} */ @WorkerThread public int insert(String table, ContentValues initialValues) { createDbIfNotExists(); Loading @@ -146,6 +150,7 @@ public class ModelDbController { /** * Similar to insert but for adding multiple values in a transaction. */ @WorkerThread public int bulkInsert(String table, ContentValues[] values) { createDbIfNotExists(); Loading @@ -167,6 +172,7 @@ public class ModelDbController { /** * Refer {@link SQLiteDatabase#delete(String, String, String[])} */ @WorkerThread public int delete(String table, String selection, String[] selectionArgs) { createDbIfNotExists(); SQLiteDatabase db = mOpenHelper.getWritableDatabase(); Loading @@ -185,6 +191,7 @@ public class ModelDbController { /** * Refer {@link SQLiteDatabase#update(String, ContentValues, String, String[])} */ @WorkerThread public int update(String table, ContentValues values, String selection, String[] selectionArgs) { createDbIfNotExists(); Loading @@ -198,6 +205,7 @@ public class ModelDbController { /** * Clears a previously set flag corresponding to empty db creation */ @WorkerThread public void clearEmptyDbFlag() { createDbIfNotExists(); clearFlagEmptyDbCreated(); Loading @@ -206,6 +214,7 @@ public class ModelDbController { /** * Generates an id to be used for new item in the favorites table */ @WorkerThread public int generateNewItemId() { createDbIfNotExists(); return mOpenHelper.generateNewItemId(); Loading @@ -214,6 +223,7 @@ public class ModelDbController { /** * Generates an id to be used for new workspace screen */ @WorkerThread public int getNewScreenId() { createDbIfNotExists(); return mOpenHelper.getNewScreenId(); Loading @@ -222,6 +232,7 @@ public class ModelDbController { /** * Creates an empty DB clearing all existing data */ @WorkerThread public void createEmptyDB() { createDbIfNotExists(); mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase()); Loading @@ -230,6 +241,7 @@ public class ModelDbController { /** * Removes any widget which are present in the framework, but not in out internal DB */ @WorkerThread public void removeGhostWidgets() { createDbIfNotExists(); mOpenHelper.removeGhostWidgets(mOpenHelper.getWritableDatabase()); Loading @@ -238,6 +250,7 @@ public class ModelDbController { /** * Returns a new {@link SQLiteTransaction} */ @WorkerThread public SQLiteTransaction newTransaction() { createDbIfNotExists(); return new SQLiteTransaction(mOpenHelper.getWritableDatabase()); Loading @@ -246,6 +259,7 @@ public class ModelDbController { /** * Refreshes the internal state corresponding to presence of hotseat table */ @WorkerThread public void refreshHotseatRestoreTable() { createDbIfNotExists(); mOpenHelper.mHotseatRestoreTableExists = tableExists( Loading @@ -256,6 +270,7 @@ public class ModelDbController { * Updates the current DB and copies all the existing data to the temp table * @param dbFile name of the target db file name */ @WorkerThread public boolean updateCurrentOpenHelper(String dbFile) { createDbIfNotExists(); return prepForMigration( Loading @@ -270,6 +285,7 @@ public class ModelDbController { * Returns the current DatabaseHelper. * Only for tests */ @WorkerThread public DatabaseHelper getDatabaseHelper() { createDbIfNotExists(); return mOpenHelper; Loading @@ -278,6 +294,7 @@ public class ModelDbController { /** * Prepares the DB for preview by copying all existing data to preview table */ @WorkerThread public boolean prepareForPreview(String dbFile) { createDbIfNotExists(); return prepForMigration( Loading @@ -296,6 +313,7 @@ public class ModelDbController { * Deletes any empty folder from the DB. * @return Ids of deleted folders. */ @WorkerThread public IntArray deleteEmptyFolders() { createDbIfNotExists(); Loading Loading @@ -338,6 +356,7 @@ public class ModelDbController { * 3) From a partner configuration APK, already in the system image * 4) The default configuration for the particular device */ @WorkerThread public synchronized void loadDefaultFavoritesIfNecessary() { createDbIfNotExists(); SharedPreferences sp = LauncherPrefs.getPrefs(mContext); Loading