Save default account setting from previous preferences.

Default account was saved in another preferences before
adding "Default account" setting. Read it if Contacts apps was
upgraded from the old version.

BUG 25341224

Change-Id: I5ff8abf03af43360a71c74a35001f492d4989028
diff --git a/src/com/android/contacts/common/preference/ContactsPreferences.java b/src/com/android/contacts/common/preference/ContactsPreferences.java
index 1d7b120..ca38af7 100644
--- a/src/com/android/contacts/common/preference/ContactsPreferences.java
+++ b/src/com/android/contacts/common/preference/ContactsPreferences.java
@@ -21,6 +21,7 @@
 import android.content.SharedPreferences.Editor;
 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
 import android.os.Handler;
+import android.preference.PreferenceManager;
 import android.provider.Settings;
 import android.provider.Settings.SettingNotFoundException;
 import android.text.TextUtils;
@@ -238,8 +239,10 @@
 
     /**
      * If there are currently no preferences (which means this is the first time we are run),
-     * check to see if there are any preferences stored in system settings (pre-L) which can be
-     * copied into our own SharedPreferences.
+     * For sort order and display order, check to see if there are any preferences stored in
+     * system settings (pre-L) which can be copied into our own SharedPreferences.
+     * For default account setting, check to see if there are any preferences stored in the previous
+     * SharedPreferences which can be copied into current SharedPreferences.
      */
     private void maybeMigrateSystemSettings() {
         if (!mPreferences.contains(SORT_ORDER_KEY)) {
@@ -261,5 +264,16 @@
             }
             setDisplayOrder(displayOrder);
         }
+
+        if (!mPreferences.contains(mDefaultAccountKey)) {
+            final SharedPreferences previousPrefs =
+                    PreferenceManager.getDefaultSharedPreferences(mContext);
+            final String defaultAccount = previousPrefs.getString(mDefaultAccountKey, null);
+            if (!TextUtils.isEmpty(defaultAccount)) {
+                final AccountWithDataSet accountWithDataSet = AccountWithDataSet.unstringify(
+                        defaultAccount);
+                setDefaultAccount(accountWithDataSet);
+            }
+        }
     }
 }