Merge "Add logging to catch rare launcher wipe issue" into sc-v2-dev am: 25e84690b3

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/15839769

Change-Id: Ifb26c8168e31336f4591cfcbde66c5376b69dafc
diff --git a/src/com/android/launcher3/model/DeviceGridState.java b/src/com/android/launcher3/model/DeviceGridState.java
index e2df16d..0fc4c2d 100644
--- a/src/com/android/launcher3/model/DeviceGridState.java
+++ b/src/com/android/launcher3/model/DeviceGridState.java
@@ -119,12 +119,23 @@
     }
 
     @Override
-    public boolean equals(Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
-        DeviceGridState that = (DeviceGridState) o;
-        return mNumHotseat == that.mNumHotseat
-                && deviceTypeCompatible(mDeviceType, that.mDeviceType)
-                && Objects.equals(mGridSizeString, that.mGridSizeString);
+    public String toString() {
+        return "DeviceGridState{"
+                + "mGridSizeString='" + mGridSizeString + '\''
+                + ", mNumHotseat=" + mNumHotseat
+                + ", mDeviceType=" + mDeviceType
+                + '}';
+    }
+
+    /**
+     * Returns true if the database from another DeviceGridState can be loaded into the current
+     * DeviceGridState without migration, or false otherwise.
+     */
+    public boolean isCompatible(DeviceGridState other) {
+        if (this == other) return true;
+        if (other == null) return false;
+        return mNumHotseat == other.mNumHotseat
+                && deviceTypeCompatible(mDeviceType, other.mDeviceType)
+                && Objects.equals(mGridSizeString, other.mGridSizeString);
     }
 }
diff --git a/src/com/android/launcher3/model/GridSizeMigrationTaskV2.java b/src/com/android/launcher3/model/GridSizeMigrationTaskV2.java
index e7d0749..fc86cf8 100644
--- a/src/com/android/launcher3/model/GridSizeMigrationTaskV2.java
+++ b/src/com/android/launcher3/model/GridSizeMigrationTaskV2.java
@@ -103,7 +103,13 @@
      * Check given a new IDP, if migration is necessary.
      */
     public static boolean needsToMigrate(Context context, InvariantDeviceProfile idp) {
-        return !new DeviceGridState(idp).equals(new DeviceGridState(context));
+        DeviceGridState idpGridState = new DeviceGridState(idp);
+        DeviceGridState contextGridState = new DeviceGridState(context);
+        boolean needsToMigrate = !idpGridState.isCompatible(contextGridState);
+        // TODO: Revert this change after b/200010396 is fixed
+        Log.d(TAG, "Migration is needed. idpGridState: " + idpGridState
+                + ", contextGridState: " + contextGridState);
+        return needsToMigrate;
     }
 
     /** See {@link #migrateGridIfNeeded(Context, InvariantDeviceProfile)} */