use of com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction in project android_packages_apps_Launcher3 by crdroidandroid.
the class GridSizeMigrationTask method removeBrokenHotseatItems.
/**
* Removes any broken item from the hotseat.
*
* @return a map with occupied hotseat position set to non-null value.
*/
public static IntSparseArrayMap<Object> removeBrokenHotseatItems(Context context) throws Exception {
try (SQLiteTransaction transaction = (SQLiteTransaction) Settings.call(context.getContentResolver(), Settings.METHOD_NEW_TRANSACTION).getBinder(Settings.EXTRA_VALUE)) {
GridSizeMigrationTask task = new GridSizeMigrationTask(context, transaction.getDb(), getValidPackages(context), false, /* usePreviewTable */
Integer.MAX_VALUE, Integer.MAX_VALUE);
// Load all the valid entries
ArrayList<DbEntry> items = task.loadHotseatEntries();
// Delete any entry marked for deletion by above load.
task.applyOperations();
IntSparseArrayMap<Object> positions = new IntSparseArrayMap<>();
for (DbEntry item : items) {
positions.put(item.screenId, item);
}
transaction.commit();
return positions;
}
}
use of com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction in project android_packages_apps_Launcher3 by crdroidandroid.
the class GridSizeMigrationTaskV2 method migrateGridIfNeeded.
/**
* When migrating the grid for preview, we copy the table
* {@link LauncherSettings.Favorites.TABLE_NAME} into
* {@link LauncherSettings.Favorites.PREVIEW_TABLE_NAME}, run grid size migration from the
* former to the later, then use the later table for preview.
*
* Similarly when doing the actual grid migration, the former grid option's table
* {@link LauncherSettings.Favorites.TABLE_NAME} is copied into the new grid option's
* {@link LauncherSettings.Favorites.TMP_TABLE}, we then run the grid size migration algorithm
* to migrate the later to the former, and load the workspace from the default
* {@link LauncherSettings.Favorites.TABLE_NAME}.
*
* @return false if the migration failed.
*/
public static boolean migrateGridIfNeeded(Context context, InvariantDeviceProfile idp) {
boolean migrateForPreview = idp != null;
if (!migrateForPreview) {
idp = LauncherAppState.getIDP(context);
}
if (!needsToMigrate(context, idp)) {
return true;
}
SharedPreferences prefs = Utilities.getPrefs(context);
String gridSizeString = getPointString(idp.numColumns, idp.numRows);
HashSet<String> validPackages = getValidPackages(context);
int srcHotseatCount = prefs.getInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, idp.numDatabaseHotseatIcons);
if (migrateForPreview) {
if (!LauncherSettings.Settings.call(context.getContentResolver(), LauncherSettings.Settings.METHOD_PREP_FOR_PREVIEW, idp.dbFile).getBoolean(LauncherSettings.Settings.EXTRA_VALUE)) {
return false;
}
} else if (!LauncherSettings.Settings.call(context.getContentResolver(), LauncherSettings.Settings.METHOD_UPDATE_CURRENT_OPEN_HELPER).getBoolean(LauncherSettings.Settings.EXTRA_VALUE)) {
return false;
}
long migrationStartTime = System.currentTimeMillis();
try (SQLiteTransaction t = (SQLiteTransaction) LauncherSettings.Settings.call(context.getContentResolver(), LauncherSettings.Settings.METHOD_NEW_TRANSACTION).getBinder(LauncherSettings.Settings.EXTRA_VALUE)) {
DbReader srcReader = new DbReader(t.getDb(), migrateForPreview ? LauncherSettings.Favorites.TABLE_NAME : LauncherSettings.Favorites.TMP_TABLE, context, validPackages, srcHotseatCount);
DbReader destReader = new DbReader(t.getDb(), migrateForPreview ? LauncherSettings.Favorites.PREVIEW_TABLE_NAME : LauncherSettings.Favorites.TABLE_NAME, context, validPackages, idp.numDatabaseHotseatIcons);
Point targetSize = new Point(idp.numColumns, idp.numRows);
GridSizeMigrationTaskV2 task = new GridSizeMigrationTaskV2(context, t.getDb(), srcReader, destReader, idp.numDatabaseHotseatIcons, targetSize);
task.migrate();
if (!migrateForPreview) {
dropTable(t.getDb(), LauncherSettings.Favorites.TMP_TABLE);
}
t.commit();
return true;
} catch (Exception e) {
Log.e(TAG, "Error during grid migration", e);
return false;
} finally {
Log.v(TAG, "Workspace migration completed in " + (System.currentTimeMillis() - migrationStartTime));
if (!migrateForPreview) {
// Save current configuration, so that the migration does not run again.
prefs.edit().putString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, gridSizeString).putInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, idp.numDatabaseHotseatIcons).apply();
}
}
}
use of com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction in project android_packages_apps_Launcher3 by crdroidandroid.
the class RestoreDbTask method restoreIfPossible.
/**
* Restore the workspace if backup is available.
*/
public static boolean restoreIfPossible(@NonNull Context context, @NonNull DatabaseHelper helper, @NonNull BackupManager backupManager) {
final SQLiteDatabase db = helper.getWritableDatabase();
try (SQLiteTransaction t = new SQLiteTransaction(db)) {
RestoreDbTask task = new RestoreDbTask();
task.restoreWorkspace(context, db, helper, backupManager);
t.commit();
return true;
} catch (Exception e) {
FileLog.e(TAG, "Failed to restore db", e);
return false;
}
}
use of com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction in project android_packages_apps_Launcher3 by crdroidandroid.
the class RestoreDbTask method performRestore.
public static boolean performRestore(Context context, DatabaseHelper helper, BackupManager backupManager) {
SQLiteDatabase db = helper.getWritableDatabase();
try (SQLiteTransaction t = new SQLiteTransaction(db)) {
RestoreDbTask task = new RestoreDbTask();
task.backupWorkspace(context, db);
task.sanitizeDB(helper, db, backupManager);
task.restoreAppWidgetIdsIfExists(context);
t.commit();
return true;
} catch (Exception e) {
FileLog.e(TAG, "Failed to verify db", e);
return false;
}
}
use of com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction in project android_packages_apps_Launcher3 by crdroidandroid.
the class DbDowngradeHelper method onDowngrade.
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
ArrayList<String> allCommands = new ArrayList<>();
for (int i = oldVersion - 1; i >= newVersion; i--) {
String[] commands = mStatements.get(i);
if (commands == null) {
throw new SQLiteException("Downgrade path not supported to version " + i);
}
Collections.addAll(allCommands, commands);
}
try (SQLiteTransaction t = new SQLiteTransaction(db)) {
for (String sql : allCommands) {
db.execSQL(sql);
}
t.commit();
}
}
Aggregations