Use "gmail-ls" as default sync authority

In case account's syncAuthority is not set during app upgrade, use a
default "gmail-ls" value.

Bug 11064918

Change-Id: Iabec20d58c261bd4d87af43a6265ffc172941dc1
diff --git a/src/com/android/mail/ui/TurnAutoSyncOnDialog.java b/src/com/android/mail/ui/TurnAutoSyncOnDialog.java
index 4eca7ec..237159f 100644
--- a/src/com/android/mail/ui/TurnAutoSyncOnDialog.java
+++ b/src/com/android/mail/ui/TurnAutoSyncOnDialog.java
@@ -24,6 +24,7 @@
 import android.content.DialogInterface;
 import android.content.res.Resources;
 import android.os.Bundle;
+import android.text.TextUtils;
 
 import com.android.mail.R;
 import com.android.mail.utils.Utils;
@@ -38,6 +39,13 @@
 
     public static final String DIALOG_TAG = "auto sync";
 
+    private static String sDefaultSyncAuthority;
+
+    // Should be called once per app.
+    static public void setDefaultSyncAuthority(String defaultSyncAuthority) {
+        sDefaultSyncAuthority = defaultSyncAuthority;
+    }
+
     public interface TurnAutoSyncOnDialogListener {
         void onEnableAutoSync();
         void onCancelAutoSync();
@@ -76,14 +84,21 @@
                             public void onClick(DialogInterface dialog, int whichButton) {
                                 // Turn on auto-sync
                                 ContentResolver.setMasterSyncAutomatically(true);
-                                // Since we're enabling auto-sync from within Gmail, should
-                                // almost always enable sync for Gmail as well:
-                                ContentResolver.setSyncAutomatically(
-                                        account,
-                                        syncAuthority,
-                                        true);
-                                if (mListener != null) {
-                                    mListener.onEnableAutoSync();
+                                // Also enable auto-sync for Gmail.
+                                // Note it's possible for syncAuthority to be empty on the
+                                // account (used for constructing this dialog) was
+                                // cached from shared prefs.  This can happen during app upgrade.
+                                // As work around use default value set by app.
+                                final String authority = TextUtils.isEmpty(syncAuthority) ?
+                                        sDefaultSyncAuthority : syncAuthority;
+                                if (!TextUtils.isEmpty(authority)) {
+                                    ContentResolver.setSyncAutomatically(
+                                            account,
+                                            authority,
+                                            true);
+                                    if (mListener != null) {
+                                        mListener.onEnableAutoSync();
+                                    }
                                 }
                             }
                         })