diff options
4 files changed, 22 insertions, 9 deletions
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index 54aea38ef3..5ea7bd9fbb 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -354,7 +354,7 @@ public class InvariantDeviceProfile implements SafeCloseable { */ @Deprecated public void reset(Context context) { - initGrid(context, getCurrentGridName(context)); + initGrid(context, getDefaultGridName(context)); } @VisibleForTesting diff --git a/src/com/android/launcher3/model/GridSizeMigrationUtil.java b/src/com/android/launcher3/model/GridSizeMigrationUtil.java index 942b97cb19..4c017e9c0c 100644 --- a/src/com/android/launcher3/model/GridSizeMigrationUtil.java +++ b/src/com/android/launcher3/model/GridSizeMigrationUtil.java @@ -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; @@ -129,7 +130,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."); diff --git a/src/com/android/launcher3/provider/RestoreDbTask.java b/src/com/android/launcher3/provider/RestoreDbTask.java index 21897bffb8..775d248290 100644 --- a/src/com/android/launcher3/provider/RestoreDbTask.java +++ b/src/com/android/launcher3/provider/RestoreDbTask.java @@ -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)) diff --git a/tests/src/com/android/launcher3/backuprestore/BackupAndRestoreDBSelectionTest.kt b/tests/src/com/android/launcher3/backuprestore/BackupAndRestoreDBSelectionTest.kt index 479b201f61..35ac0a1027 100644 --- a/tests/src/com/android/launcher3/backuprestore/BackupAndRestoreDBSelectionTest.kt +++ b/tests/src/com/android/launcher3/backuprestore/BackupAndRestoreDBSelectionTest.kt @@ -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) + } } |