When we migrate Exchange folders, set the sync status to INITIAL_SYNC_NEEDED

b/17443087
When we migrate exchange accounts, we copy mailboxes over to the
new account (in order to preserve sync frequency and window).
The problem with this is, you may have many accounts/mailboxes.
After starting the app, it may take quite a long time before all
mailboxes are synced. If the user visits some mailbox near the
bottom, they'll see a misleading "folder is empty" view.
Now, when migrating, we'll set the uisyncstatus to INITIAL_SYNC_NEEDED.

The issue here is that when we start a fresh sync, we temporarily
store sync info needed in RAM, clear all of the folders, then
restore the sync. I needed to add uiSyncStatus to the list of
attributes copied over.

Change-Id: I223d2e000cfd48f62ce694365cbb8ec3850a50b3
diff --git a/src/com/android/exchange/adapter/FolderSyncParser.java b/src/com/android/exchange/adapter/FolderSyncParser.java
index c90be63..acd71d3 100644
--- a/src/com/android/exchange/adapter/FolderSyncParser.java
+++ b/src/com/android/exchange/adapter/FolderSyncParser.java
@@ -42,6 +42,7 @@
 import com.android.exchange.Eas;
 import com.android.exchange.eas.EasSyncContacts;
 import com.android.exchange.eas.EasSyncCalendar;
+import com.android.mail.providers.UIProvider;
 import com.android.mail.utils.LogUtils;
 import com.google.common.annotations.VisibleForTesting;
 
@@ -316,10 +317,12 @@
     private static class SyncOptions {
         private final int mInterval;
         private final int mLookback;
+        private final int mSyncState;
 
-        private SyncOptions(int interval, int lookback) {
+        private SyncOptions(int interval, int lookback, int syncState) {
             mInterval = interval;
             mLookback = lookback;
+            mSyncState = syncState;
         }
     }
 
@@ -329,10 +332,12 @@
             SyncWindow.SYNC_WINDOW_ACCOUNT + ")";
 
     private static final String[] MAILBOX_STATE_PROJECTION = new String[] {
-        MailboxColumns.SERVER_ID, MailboxColumns.SYNC_INTERVAL, MailboxColumns.SYNC_LOOKBACK};
+        MailboxColumns.SERVER_ID, MailboxColumns.SYNC_INTERVAL, MailboxColumns.SYNC_LOOKBACK,
+            MailboxColumns.UI_SYNC_STATUS};
     private static final int MAILBOX_STATE_SERVER_ID = 0;
     private static final int MAILBOX_STATE_INTERVAL = 1;
     private static final int MAILBOX_STATE_LOOKBACK = 2;
+    private static final int MAILBOX_STATE_SYNC_STATUS = 3;
     @VisibleForTesting
     final HashMap<String, SyncOptions> mSyncOptionsMap = new HashMap<String, SyncOptions>();
 
@@ -349,9 +354,17 @@
         if (c != null) {
             try {
                 while (c.moveToNext()) {
+                    int syncStatus = c.getInt(MAILBOX_STATE_SYNC_STATUS);
+                    // The only sync status I would ever want to propagate is INITIAL_SYNC_NEEDED.
+                    // This is so that after a migration from the old Email to Unified Gmail
+                    // won't appear to be empty, but not syncing.
+                    if (syncStatus != UIProvider.SyncStatus.INITIAL_SYNC_NEEDED) {
+                        syncStatus = UIProvider.SyncStatus.NO_SYNC;
+                    }
                     mSyncOptionsMap.put(c.getString(MAILBOX_STATE_SERVER_ID),
                             new SyncOptions(c.getInt(MAILBOX_STATE_INTERVAL),
-                                    c.getInt(MAILBOX_STATE_LOOKBACK)));
+                                    c.getInt(MAILBOX_STATE_LOOKBACK),
+                                    syncStatus));
                 }
             } finally {
                 c.close();