Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1604c1e9 authored by Tingting Wang's avatar Tingting Wang
Browse files

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
parent 6211694d
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.SharedPreferences;
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 @@ public final class ContactsPreferences implements OnSharedPreferenceChangeListen

    /**
     * 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 @@ public final class ContactsPreferences implements OnSharedPreferenceChangeListen
            }
            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);
            }
        }
    }
}