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 committed 2024-09-24 16:52:05 -07:00
1 parent 5b569e764e
commit b633b9aa2b
4 files changed
+22 -9

No files matched your search

@@ -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))