use of com.android.launcher3.Utilities.getPrefs in project android_packages_apps_Launcher3 by crdroidandroid.
the class GridSizeMigrationTask method needsToMigrate.
/**
* Check given a new IDP, if migration is necessary.
*/
public static boolean needsToMigrate(Context context, InvariantDeviceProfile idp) {
SharedPreferences prefs = Utilities.getPrefs(context);
String gridSizeString = getPointString(idp.numColumns, idp.numRows);
return !gridSizeString.equals(prefs.getString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, "")) || idp.numDatabaseHotseatIcons != prefs.getInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, -1);
}
use of com.android.launcher3.Utilities.getPrefs in project android_packages_apps_Launcher3 by crdroidandroid.
the class GridSizeMigrationTask method migrateGridIfNeeded.
/**
* Run the migration algorithm if needed. For preview, we provide the intended idp because it
* has not been changed. If idp is null, we read it from the context, for actual grid migration.
*
* @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);
long migrationStartTime = SystemClock.elapsedRealtime();
try (SQLiteTransaction transaction = (SQLiteTransaction) Settings.call(context.getContentResolver(), Settings.METHOD_NEW_TRANSACTION).getBinder(Settings.EXTRA_VALUE)) {
int srcHotseatCount = prefs.getInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, idp.numDatabaseHotseatIcons);
Point sourceSize = parsePoint(prefs.getString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, gridSizeString));
boolean dbChanged = false;
if (migrateForPreview) {
copyTable(transaction.getDb(), Favorites.TABLE_NAME, transaction.getDb(), Favorites.PREVIEW_TABLE_NAME, context);
}
GridBackupTable backupTable = new GridBackupTable(context, transaction.getDb(), srcHotseatCount, sourceSize.x, sourceSize.y);
if (migrateForPreview ? backupTable.restoreToPreviewIfBackupExists() : backupTable.backupOrRestoreAsNeeded()) {
dbChanged = true;
srcHotseatCount = backupTable.getRestoreHotseatAndGridSize(sourceSize);
}
HashSet<String> validPackages = getValidPackages(context);
// Hotseat.
if (srcHotseatCount != idp.numDatabaseHotseatIcons && new GridSizeMigrationTask(context, transaction.getDb(), validPackages, migrateForPreview, srcHotseatCount, idp.numDatabaseHotseatIcons).migrateHotseat()) {
dbChanged = true;
}
// Grid size
Point targetSize = new Point(idp.numColumns, idp.numRows);
if (new MultiStepMigrationTask(validPackages, context, transaction.getDb(), migrateForPreview).migrate(sourceSize, targetSize)) {
dbChanged = true;
}
if (dbChanged) {
// Make sure we haven't removed everything.
final Cursor c = context.getContentResolver().query(migrateForPreview ? Favorites.PREVIEW_CONTENT_URI : Favorites.CONTENT_URI, null, null, null, null);
boolean hasData = c.moveToNext();
c.close();
if (!hasData) {
throw new Exception("Removed every thing during grid resize");
}
}
transaction.commit();
if (!migrateForPreview) {
Settings.call(context.getContentResolver(), Settings.METHOD_REFRESH_BACKUP_TABLE);
}
return true;
} catch (Exception e) {
Log.e(TAG, "Error during preview grid migration", e);
return false;
} finally {
Log.v(TAG, "Preview workspace migration completed in " + (SystemClock.elapsedRealtime() - 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.Utilities.getPrefs in project android_packages_apps_Launcher3 by crdroidandroid.
the class GridSizeMigrationTaskV2 method needsToMigrate.
/**
* Check given a new IDP, if migration is necessary.
*/
public static boolean needsToMigrate(Context context, InvariantDeviceProfile idp) {
SharedPreferences prefs = Utilities.getPrefs(context);
String gridSizeString = getPointString(idp.numColumns, idp.numRows);
return !gridSizeString.equals(prefs.getString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, "")) || idp.numDatabaseHotseatIcons != prefs.getInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, -1);
}
use of com.android.launcher3.Utilities.getPrefs in project android_packages_apps_Launcher3 by crdroidandroid.
the class InvariantDeviceProfile method onConfigChanged.
private void onConfigChanged(Context context) {
// Re-init grid
String gridName = getCurrentGridName(context);
initGrid(context, Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, gridName));
for (OnIDPChangeListener listener : mChangeListeners) {
listener.onIdpChanged(this);
}
}
use of com.android.launcher3.Utilities.getPrefs in project android_packages_apps_Launcher3 by AOSPA.
the class RestoreDbTask method setPending.
/**
* Marks the DB state as pending restoration
*/
public static void setPending(Context context) {
FileLog.d(TAG, "Restore data received through full backup ");
Utilities.getPrefs(context).edit().putInt(RESTORED_DEVICE_TYPE, new DeviceGridState(context).getDeviceType()).commit();
}
Aggregations