[DO NOT MERGE] Adding minSpanX and minSpanY for all the launcher widgets

Bug: 22353460
Change-Id: Id4450dee42a83e4603dcd56e1c4dec2b0e405858
diff --git a/protos/backup.proto b/protos/backup.proto
index 44c4b09..f3ad0b6 100644
--- a/protos/backup.proto
+++ b/protos/backup.proto
@@ -90,17 +90,17 @@
   optional string iconPackage = 16;
   optional string iconResource = 17;
   optional bytes icon = 18;
- }
+}
 
 message Screen {
   required int64 id = 1;
   optional int32 rank = 2;
- }
+}
 
 message Resource {
   required int32 dpi = 1;
   required bytes data = 2;
- }
+}
 
 message Widget {
   required string provider = 1;
@@ -108,4 +108,8 @@
   optional bool configure = 3;
   optional Resource icon = 4;
   optional Resource preview = 5;
- }
+
+  // Assume that a widget is resizable upto 2x2 if no data is available
+  optional int32 minSpanX = 6 [default = 2];
+  optional int32 minSpanY = 7 [default = 2];
+}
diff --git a/src/com/android/launcher3/LauncherBackupAgentHelper.java b/src/com/android/launcher3/LauncherBackupAgentHelper.java
index ddfd70d..5760578 100644
--- a/src/com/android/launcher3/LauncherBackupAgentHelper.java
+++ b/src/com/android/launcher3/LauncherBackupAgentHelper.java
@@ -92,7 +92,7 @@
             LauncherClings.synchonouslyMarkFirstRunClingDismissed(this);
 
             // TODO: Update the backup set to include rank.
-            if (mHelper.restoredBackupVersion <= 2) {
+            if (mHelper.restoredBackupVersion <= 3) {
                 LauncherAppState.getLauncherProvider().updateFolderItemsRank();
             }
         } else {
diff --git a/src/com/android/launcher3/LauncherBackupHelper.java b/src/com/android/launcher3/LauncherBackupHelper.java
index 31b434c..11768b8 100644
--- a/src/com/android/launcher3/LauncherBackupHelper.java
+++ b/src/com/android/launcher3/LauncherBackupHelper.java
@@ -19,7 +19,6 @@
 import android.app.backup.BackupDataOutput;
 import android.app.backup.BackupHelper;
 import android.app.backup.BackupManager;
-import android.appwidget.AppWidgetProviderInfo;
 import android.content.ComponentName;
 import android.content.ContentResolver;
 import android.content.ContentValues;
@@ -58,7 +57,6 @@
 import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.zip.CRC32;
 
@@ -70,7 +68,7 @@
     private static final boolean VERBOSE = LauncherBackupAgentHelper.VERBOSE;
     private static final boolean DEBUG = LauncherBackupAgentHelper.DEBUG;
 
-    private static final int BACKUP_VERSION = 2;
+    private static final int BACKUP_VERSION = 3;
     private static final int MAX_JOURNAL_SIZE = 1000000;
 
     // Journal key is such that it is always smaller than any dynamically generated
@@ -171,6 +169,7 @@
                 mExistingKeys.add(keyToBackupKey(key));
             }
         }
+        restoredBackupVersion = journal.backupVersion;
     }
 
     /**
@@ -313,7 +312,6 @@
                 MessageNano.mergeFrom(journal, readCheckedBytes(mBuffer, dataSize));
                 applyJournal(journal);
                 restoreSuccessful = isBackupCompatible(journal);
-                restoredBackupVersion = journal.backupVersion;
                 return;
             }
 
@@ -639,7 +637,7 @@
                 } else {
                     Log.w(TAG, "empty intent on appwidget: " + id);
                 }
-                if (mExistingKeys.contains(backupKey)) {
+                if (mExistingKeys.contains(backupKey) && restoredBackupVersion >= BACKUP_VERSION) {
                     if (DEBUG) Log.d(TAG, "already saved widget " + backupKey);
 
                     // remember that we already backed this up previously
@@ -942,6 +940,11 @@
                 widget.preview.dpi = dpi;
             }
         }
+
+        widget.minSpanX = (info.resizeMode & LauncherAppWidgetProviderInfo.RESIZE_HORIZONTAL) != 0
+                ? info.minSpanX : -1;
+        widget.minSpanY = (info.resizeMode & LauncherAppWidgetProviderInfo.RESIZE_VERTICAL) != 0
+                ? info.minSpanY : -1;
         return widget;
     }