Fix for bug where we don't use default grid on comet, and migrate normally if not in a B&R case

-The grid migration where we just copy the grid and move everything one row up should only occur in a B&R scenario, so now we add that restriction
-We should default to 4x5 in comet if migrating from a 4x4 grid if the device we're migrating from does not have any other grids saved
-if we have other grids saved, then we'll try using the saved grid if possible. If not possible, we use the default grid for the new device

Bug: 360462379
Test: GridSizeMigrationUtilTest
Flag: EXEMPT bugfix
Change-Id: Ia905081046431c08dc058bd61b2b4ab42dee0506
This commit is contained in:
fbaron
2024-09-23 18:35:29 -07:00
parent 5b569e764e
commit b633b9aa2b
4 changed files with 22 additions and 9 deletions
@@ -354,7 +354,7 @@ public class InvariantDeviceProfile implements SafeCloseable {
*/
@Deprecated
public void reset(Context context) {
initGrid(context, getCurrentGridName(context));
initGrid(context, getDefaultGridName(context));
}
@VisibleForTesting
@@ -17,6 +17,7 @@
package com.android.launcher3.model;
import static com.android.launcher3.Flags.enableSmartspaceRemovalToggle;
import static com.android.launcher3.LauncherPrefs.IS_FIRST_LOAD_AFTER_RESTORE;
import static com.android.launcher3.LauncherSettings.Favorites.TABLE_NAME;
import static com.android.launcher3.LauncherSettings.Favorites.TMP_TABLE;
import static com.android.launcher3.Utilities.SHOULD_SHOW_FIRST_PAGE_WIDGET;
@@ -132,7 +133,8 @@ public class GridSizeMigrationUtil {
return true;
}
if (Flags.enableGridMigrationFix()
if (LauncherPrefs.get(context).get(IS_FIRST_LOAD_AFTER_RESTORE)
&& Flags.enableGridMigrationFix()
&& srcDeviceState.getColumns().equals(destDeviceState.getColumns())
&& srcDeviceState.getRows() < destDeviceState.getRows()) {
Log.i("b/360462379", "Grid migration fix entry point.");
@@ -75,7 +75,6 @@ import com.android.launcher3.util.ContentWriter;
import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.LogConfig;
import java.io.File;
import java.io.InvalidObjectException;
import java.util.Arrays;
import java.util.Collection;
@@ -127,12 +126,12 @@ public class RestoreDbTask {
if (Flags.enableNarrowGridRestore()) {
String oldPhoneFileName = idp.dbFile;
List<String> previousDbs = existingDbs();
List<String> previousDbs = existingDbs(context);
removeOldDBs(context, oldPhoneFileName);
// The idp before this contains data about the old phone, after this it becomes the idp
// of the current phone.
idp.reset(context);
trySettingPreviousGidAsCurrent(context, idp, oldPhoneFileName, previousDbs);
trySettingPreviousGridAsCurrent(context, idp, oldPhoneFileName, previousDbs);
} else {
idp.reinitializeAfterRestore(context);
}
@@ -143,7 +142,7 @@ public class RestoreDbTask {
* Try setting the gird used in the previous phone to the new one. If the current device doesn't
* support the previous grid option it will not be set.
*/
private static void trySettingPreviousGidAsCurrent(Context context, InvariantDeviceProfile idp,
private static void trySettingPreviousGridAsCurrent(Context context, InvariantDeviceProfile idp,
String oldPhoneDbFileName, List<String> previousDbs) {
InvariantDeviceProfile.GridOption oldPhoneGridOption = idp.getGridOptionFromFileName(
context, oldPhoneDbFileName);
@@ -166,17 +165,19 @@ public class RestoreDbTask {
/**
* Returns a list of paths of the existing launcher dbs.
*/
private static List<String> existingDbs() {
@VisibleForTesting
public static List<String> existingDbs(Context context) {
// At this point idp.dbFile contains the name of the dbFile from the previous phone
return LauncherFiles.GRID_DB_FILES.stream()
.filter(dbName -> new File(dbName).exists())
.filter(dbName -> context.getDatabasePath(dbName).exists())
.toList();
}
/**
* Only keep the last database used on the previous device.
*/
private static void removeOldDBs(Context context, String oldPhoneDbFileName) {
@VisibleForTesting
public static void removeOldDBs(Context context, String oldPhoneDbFileName) {
// At this point idp.dbFile contains the name of the dbFile from the previous phone
LauncherFiles.GRID_DB_FILES.stream()
.filter(dbName -> !dbName.equals(oldPhoneDbFileName))
@@ -23,6 +23,7 @@ import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import com.android.launcher3.Flags
import com.android.launcher3.LauncherPrefs
import com.android.launcher3.model.ModelDbController
import com.android.launcher3.provider.RestoreDbTask
import com.android.launcher3.util.Executors.MODEL_EXECUTOR
import com.android.launcher3.util.TestUtil
import com.android.launcher3.util.rule.BackAndRestoreRule
@@ -67,4 +68,13 @@ class BackupAndRestoreDBSelectionTest {
}
}
}
@Test
fun testExistingDbsAndRemovingDbs() {
var existingDbs = RestoreDbTask.existingDbs(getInstrumentation().targetContext)
assert(existingDbs.size == 4)
RestoreDbTask.removeOldDBs(getInstrumentation().targetContext, "launcher_4_by_4.db")
existingDbs = RestoreDbTask.existingDbs(getInstrumentation().targetContext)
assert(existingDbs.size == 1)
}
}