Revert "Add a check to verify that the grid we're migrating to is valid"

This reverts commit 0d16b52156153d7dbeda5d260e3c2e8634e3975f.

Reason for revert: doesn't resolve the issue since IDP is still a different grid, it just doesn't migrate the icons over to the new grid, but the new grid would still appear

Bug: 419252682
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:3b9bf4ce15719bd764364dc2b60ea48f76813e6d)
Merged-In: I4313f5aab726d07c906167fcaa340efae2c0e317
Change-Id: I4313f5aab726d07c906167fcaa340efae2c0e317
diff --git a/src/com/android/launcher3/model/GridMigrationOption.kt b/src/com/android/launcher3/model/GridMigrationOption.kt
deleted file mode 100644
index cfbdb13..0000000
--- a/src/com/android/launcher3/model/GridMigrationOption.kt
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (C) 2025 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.launcher3.model
-
-/**
- * This has all the valid grids as data objects so that we can check if we're going to be able to do
- * a migration. In order to be able to do the migration the source grid and destination grid both
- * have to be instantiated here, and it has to be a valid destination from that particular source
- * grid. We purposely don't allow all grid sizes on all device types. e.g: Grid migrations from a
- * unique-to-tablet configuration (6x5) to a unique-to-phone configuration (4x5) and vice-versa
- * might occur when restoring from one of these device to another, but can't be manually switched by
- * a user).
- *
- * This helps address b/419252682.
- *
- * @param columns is the number of columns of the grid.
- * @param rows is the number of rows of the grid.
- */
-sealed class GridMigrationOption(val columns: Int, val rows: Int) {
-
-    /**
-     * Method that checks if we are able to migrate from one grid to another.
-     *
-     * @param destGridMigrationOption is the grid migration option we're going to.
-     * @param isAfterRestore is a boolean that is true when in a backup and restore scenario.
-     * @return a boolean that lets us know whether we can migrate from source to destination.
-     */
-    fun canMigrate(destGridMigrationOption: GridMigrationOption, isAfterRestore: Boolean): Boolean {
-        return validDestinations.contains(destGridMigrationOption) && !isAfterRestore
-    }
-
-    private val validDestinations: List<GridMigrationOption>
-        get() =
-            when (this) {
-                TwoByTwo,
-                ThreeByThree,
-                FourByFour,
-                FourByFive,
-                FourBySix,
-                FiveByFive,
-                FiveBySix -> validDestinationsForPhone
-                SixByFive -> validDestinationsForTablet
-            }
-
-    private val validDestinationsForPhone: List<GridMigrationOption>
-        get() =
-            listOf(TwoByTwo, ThreeByThree, FourByFour, FourByFive, FourBySix, FiveByFive, FiveBySix)
-
-    private val validDestinationsForTablet: List<GridMigrationOption>
-        get() = listOf(SixByFive)
-
-    data object TwoByTwo : GridMigrationOption(columns = 2, rows = 2)
-
-    data object ThreeByThree : GridMigrationOption(columns = 3, rows = 3)
-
-    data object FourByFour : GridMigrationOption(columns = 4, rows = 4)
-
-    data object FourByFive : GridMigrationOption(columns = 4, rows = 5)
-
-    data object FourBySix : GridMigrationOption(columns = 4, rows = 6)
-
-    data object FiveByFive : GridMigrationOption(columns = 5, rows = 5)
-
-    data object FiveBySix : GridMigrationOption(columns = 5, rows = 6)
-
-    data object SixByFive : GridMigrationOption(columns = 6, rows = 5)
-
-    companion object {
-        /**
-         * Factory method that creates an instance of GridMigrationOption if valid.
-         *
-         * @param columns is the number of columns of the grid.
-         * @param rows is the number of rows of the grid.
-         */
-        fun from(columns: Int, rows: Int): GridMigrationOption? {
-            when {
-                columns == 2 && rows == 2 -> {
-                    return TwoByTwo
-                }
-                columns == 3 && rows == 3 -> {
-                    return ThreeByThree
-                }
-                columns == 4 && rows == 4 -> {
-                    return FourByFour
-                }
-                columns == 4 && rows == 5 -> {
-                    return FourByFive
-                }
-                columns == 4 && rows == 6 -> {
-                    return FourBySix
-                }
-                columns == 5 && rows == 5 -> {
-                    return FiveByFive
-                }
-                columns == 5 && rows == 6 -> {
-                    return FiveBySix
-                }
-                columns == 6 && rows == 5 -> {
-                    return SixByFive
-                }
-                else -> {
-                    return null
-                }
-            }
-        }
-    }
-}
diff --git a/src/com/android/launcher3/model/GridSizeMigrationLogic.kt b/src/com/android/launcher3/model/GridSizeMigrationLogic.kt
index 1165c47..8c0a907 100644
--- a/src/com/android/launcher3/model/GridSizeMigrationLogic.kt
+++ b/src/com/android/launcher3/model/GridSizeMigrationLogic.kt
@@ -58,15 +58,13 @@
         isDestNewDb: Boolean,
         modelDelegate: ModelDelegate,
     ) {
-
-        val isAfterRestore = get(context).get(LauncherPrefs.IS_FIRST_LOAD_AFTER_RESTORE)
-
         if (!GridSizeMigrationDBController.needsToMigrate(srcDeviceState, destDeviceState)) {
             return
         }
 
         val statsLogManager: StatsLogManager = StatsLogManager.newInstance(context)
 
+        val isAfterRestore = get(context).get(LauncherPrefs.IS_FIRST_LOAD_AFTER_RESTORE)
         FileLog.d(
             TAG,
             "Begin grid migration. isAfterRestore: $isAfterRestore\nsrcDeviceState: " +
diff --git a/src/com/android/launcher3/model/ModelDbController.java b/src/com/android/launcher3/model/ModelDbController.java
index b674184..b80f1c9 100644
--- a/src/com/android/launcher3/model/ModelDbController.java
+++ b/src/com/android/launcher3/model/ModelDbController.java
@@ -351,27 +351,9 @@
             DeviceGridState destDeviceState = new DeviceGridState(mIdp);
 
             boolean isDestNewDb = !existingDBs.contains(destDeviceState.getDbFile());
-
-            boolean isAfterRestore =
-                    LauncherPrefs.get(mContext).get(LauncherPrefs.IS_FIRST_LOAD_AFTER_RESTORE);
             GridSizeMigrationLogic gridSizeMigrationLogic = new GridSizeMigrationLogic();
-
-            // Check if the migration path from source to destination is valid before migrating.
-            GridMigrationOption sourceGridMigrationOption =
-                    GridMigrationOption.Companion.from(
-                            srcDeviceState.getColumns(), srcDeviceState.getRows());
-            GridMigrationOption destinationGridMigrationOption =
-                    GridMigrationOption.Companion.from(
-                            destDeviceState.getColumns(), destDeviceState.getRows());
-            if (sourceGridMigrationOption != null && destinationGridMigrationOption != null
-                    && sourceGridMigrationOption.canMigrate(destinationGridMigrationOption,
-                    isAfterRestore)) {
-                gridSizeMigrationLogic.migrateGrid(mContext, srcDeviceState, destDeviceState,
-                        mOpenHelper, oldHelper.getWritableDatabase(), isDestNewDb, modelDelegate);
-            } else {
-                Log.e(TAG, "Cannot migrate from source: " + srcDeviceState
-                        + " to destination: " + destDeviceState);
-            }
+            gridSizeMigrationLogic.migrateGrid(mContext, srcDeviceState, destDeviceState,
+                    mOpenHelper, oldHelper.getWritableDatabase(), isDestNewDb, modelDelegate);
         } catch (Exception e) {
             resetLauncherDb(restoreEventLogger);
             throw new Exception("attemptMigrateDb: Failed to migrate grid", e);
diff --git a/tests/multivalentTests/src/com/android/launcher3/model/gridmigration/GridMigrationOptionUnitTest.kt b/tests/multivalentTests/src/com/android/launcher3/model/gridmigration/GridMigrationOptionUnitTest.kt
deleted file mode 100644
index f7b3315..0000000
--- a/tests/multivalentTests/src/com/android/launcher3/model/gridmigration/GridMigrationOptionUnitTest.kt
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright (C) 2025 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.launcher3.model.gridmigration
-
-import androidx.test.ext.junit.runners.AndroidJUnit4
-import androidx.test.filters.SmallTest
-import com.android.launcher3.model.GridMigrationOption
-import org.junit.Test
-import org.junit.runner.RunWith
-
-/** Unit test for [GridMigrationOption] */
-@SmallTest
-@RunWith(AndroidJUnit4::class)
-class GridMigrationOptionUnitTest {
-
-    /* Here we're going from a phone grid to another phone grid and isAfterRestore is false */
-    @Test
-    fun canMigrateFrom4x5To5x5NotAfterRestoreShouldReturnTrue() {
-        val sourceGridMigrationOption = GridMigrationOption.from(4, 5)
-        val destGridMigrationOption = GridMigrationOption.from(5, 5)
-        assert(
-            sourceGridMigrationOption != null &&
-                destGridMigrationOption != null &&
-                sourceGridMigrationOption.canMigrate(
-                    destGridMigrationOption, /* isAfterRestore */
-                    false,
-                )
-        ) {
-            "Going from 4x5 to 5x5 with isAfterRestore as false caused canMigrate() to return false"
-        }
-    }
-
-    /* Here we're going from a phone grid to another phone grid and isAfterRestore is false */
-    @Test
-    fun canMigrateFrom4x5To4x6NotAfterRestoreShouldReturnTrue() {
-        val sourceGridMigrationOption = GridMigrationOption.from(4, 5)
-        val destGridMigrationOption = GridMigrationOption.from(4, 6)
-        assert(
-            sourceGridMigrationOption != null &&
-                destGridMigrationOption != null &&
-                sourceGridMigrationOption.canMigrate(
-                    destGridMigrationOption, /* isAfterRestore */
-                    false,
-                )
-        ) {
-            "Going from 4x5 to 4x6 with isAfterRestore as false caused canMigrate() to return false"
-        }
-    }
-
-    /* Here we're going from a phone grid to a non-existent grid and isAfterRestore is false */
-    @Test
-    fun canMigrateFrom4x5To7x7NotAfterRestoreShouldReturnFalse() {
-        val sourceGridMigrationOption = GridMigrationOption.from(4, 5)
-        val destGridMigrationOption = GridMigrationOption.from(7, 7)
-        assert(destGridMigrationOption == null) {
-            "We create a GridMigrationOption for an invalid 7x7 grid"
-        }
-    }
-
-    /* Here we're going from a non-existent grid to a phone grid and isAfterRestore is false */
-    @Test
-    fun canMigrateFrom8x8To4x5NotAfterRestoreShouldReturnFalse() {
-        val sourceGridMigrationOption = GridMigrationOption.from(8, 8)
-        assert(sourceGridMigrationOption == null) {
-            "We create a GridMigrationOption for an invalid 8x8 grid"
-        }
-    }
-
-    /* Here we're going from a tablet grid to a phone grid and isAfterRestore is false */
-    @Test
-    fun canMigrateFrom6x5To2x2NotAfterRestoreShouldReturnFalse() {
-        val sourceGridMigrationOption = GridMigrationOption.from(6, 5)
-        val destGridMigrationOption = GridMigrationOption.from(2, 2)
-        assert(
-            sourceGridMigrationOption != null &&
-                destGridMigrationOption != null &&
-                !sourceGridMigrationOption.canMigrate(
-                    destGridMigrationOption, /* isAfterRestore */
-                    false,
-                )
-        ) {
-            "Going from 6x5 to 2x2 with isAfterRestore as false caused canMigrate() to return true"
-        }
-    }
-
-    /* Here we're going from a tablet grid to itself and isAfterRestore is false */
-    @Test
-    fun canMigrateFrom6x5To6x5NotAfterRestoreShouldReturnTrue() {
-        val sourceGridMigrationOption = GridMigrationOption.from(6, 5)
-        val destGridMigrationOption = GridMigrationOption.from(6, 5)
-
-        assert(
-            sourceGridMigrationOption != null &&
-                destGridMigrationOption != null &&
-                sourceGridMigrationOption.canMigrate(
-                    destGridMigrationOption, /* isAfterRestore */
-                    false,
-                )
-        ) {
-            "Going from 6x5 to 6x5 with isAfterRestore as false caused canMigrate() to return false"
-        }
-    }
-
-    /* Here we're going from a phone grid to another phone grid and isAfterRestore is true */
-    @Test
-    fun canMigrateFrom4x5To4x6AfterRestoreShouldReturnFalse() {
-        val sourceGridMigrationOption = GridMigrationOption.from(4, 5)
-        val destGridMigrationOption = GridMigrationOption.from(4, 6)
-        assert(
-            sourceGridMigrationOption != null &&
-                destGridMigrationOption != null &&
-                !sourceGridMigrationOption.canMigrate(
-                    destGridMigrationOption, /* isAfterRestore */
-                    true,
-                )
-        ) {
-            "Going from 4x5 to 4x6 with isAfterRestore as true caused canMigrate() to return true"
-        }
-    }
-}