Storing form factor as part of backup and disabling restore if form-factor is different

Bug: 195301649
Test: Manual
Change-Id: I9a9c4bc9246f40af2209cb914b3966319bc78bff
This commit is contained in:
Sunny Goyal
2021-08-02 12:23:44 -07:00
parent 9016e17988
commit 68031ca3f9
10 changed files with 178 additions and 114 deletions

View File

@@ -16,9 +16,6 @@
package com.android.launcher3.model;
import static com.android.launcher3.InvariantDeviceProfile.KEY_MIGRATION_SRC_HOTSEAT_COUNT;
import static com.android.launcher3.InvariantDeviceProfile.KEY_MIGRATION_SRC_WORKSPACE_SIZE;
import static com.android.launcher3.Utilities.getPointString;
import static com.android.launcher3.provider.LauncherDbUtils.dropTable;
import android.content.ComponentName;
@@ -107,11 +104,7 @@ public class GridSizeMigrationTaskV2 {
* 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);
return !new DeviceGridState(idp).equals(new DeviceGridState(context));
}
/** See {@link #migrateGridIfNeeded(Context, InvariantDeviceProfile)} */
@@ -124,15 +117,15 @@ public class GridSizeMigrationTaskV2 {
/**
* 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
* {@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
* {@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}.
* {@link LauncherSettings.Favorites#TABLE_NAME}.
*
* @return false if the migration failed.
*/
@@ -147,10 +140,7 @@ public class GridSizeMigrationTaskV2 {
}
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(
@@ -175,11 +165,11 @@ public class GridSizeMigrationTaskV2 {
DbReader srcReader = new DbReader(t.getDb(),
migrateForPreview ? LauncherSettings.Favorites.TABLE_NAME
: LauncherSettings.Favorites.TMP_TABLE,
context, validPackages, srcHotseatCount);
context, validPackages);
DbReader destReader = new DbReader(t.getDb(),
migrateForPreview ? LauncherSettings.Favorites.PREVIEW_TABLE_NAME
: LauncherSettings.Favorites.TABLE_NAME,
context, validPackages, idp.numDatabaseHotseatIcons);
context, validPackages);
Point targetSize = new Point(idp.numColumns, idp.numRows);
GridSizeMigrationTaskV2 task = new GridSizeMigrationTaskV2(context, t.getDb(),
@@ -202,10 +192,7 @@ public class GridSizeMigrationTaskV2 {
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();
new DeviceGridState(idp).writeToPrefs(context);
}
}
}
@@ -504,7 +491,6 @@ public class GridSizeMigrationTaskV2 {
private final String mTableName;
private final Context mContext;
private final HashSet<String> mValidPackages;
private final int mHotseatSize;
private int mLastScreenId = -1;
private final ArrayList<DbEntry> mHotseatEntries = new ArrayList<>();
@@ -513,12 +499,11 @@ public class GridSizeMigrationTaskV2 {
new ArrayMap<>();
DbReader(SQLiteDatabase db, String tableName, Context context,
HashSet<String> validPackages, int hotseatSize) {
HashSet<String> validPackages) {
mDb = db;
mTableName = tableName;
mContext = context;
mValidPackages = validPackages;
mHotseatSize = hotseatSize;
}
protected ArrayList<DbEntry> loadHotseatEntries() {
@@ -543,11 +528,6 @@ public class GridSizeMigrationTaskV2 {
entry.itemType = c.getInt(indexItemType);
entry.screenId = c.getInt(indexScreen);
if (entry.screenId >= mHotseatSize) {
entriesToRemove.add(entry.id);
continue;
}
try {
// calculate weight
switch (entry.itemType) {