Merge "Remove Lychee toggle from AOSP Contacts." into ub-contactsdialer-h-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e31f88f..1ef1bd5 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1573,12 +1573,6 @@
     <!--Label of the "default account" setting option to set default editor account. [CHAR LIMIT=80]-->
     <string name="default_editor_account">Default account for new contacts</string>
 
-    <!--Label of the "Sync contact metadata" setting option to set sync account for Lychee. [CHAR LIMIT=80]-->
-    <string name="sync_contact_metadata_title">Sync contact metadata [DOGFOOD]</string>
-
-    <!--Label of the "Sync contact metadata" setting dialog to set sync account for Lychee. [CHAR LIMIT=80]-->
-    <string name="sync_contact_metadata_dialog_title">Sync contact metadata</string>
-
     <!-- Title of my info preference, showing the name of user's personal profile [CHAR LIMIT=30]-->
     <string name="settings_my_info_title">My info</string>
 
diff --git a/src-bind/com/android/contactsbind/ObjectFactory.java b/src-bind/com/android/contactsbind/ObjectFactory.java
index c9539ee..d6799e2 100644
--- a/src-bind/com/android/contactsbind/ObjectFactory.java
+++ b/src-bind/com/android/contactsbind/ObjectFactory.java
@@ -14,7 +14,6 @@
 package com.android.contactsbind;
 
 import com.android.contacts.common.logging.Logger;
-import com.android.contacts.common.preference.PreferenceManager;
 import com.android.contactsbind.search.AutocompleteHelper;
 import com.android.contacts.common.util.DeviceLocalAccountTypeFactory;
 
@@ -32,8 +31,6 @@
         return null;
     }
 
-    public static PreferenceManager getPreferenceManager(Context context) { return null; }
-
     public static AutocompleteHelper getAutocompleteHelper(Context context) {
         return null;
     }
diff --git a/src/com/android/contacts/common/compat/MetadataSyncEnabledCompat.java b/src/com/android/contacts/common/compat/MetadataSyncEnabledCompat.java
deleted file mode 100644
index 4a9650f..0000000
--- a/src/com/android/contacts/common/compat/MetadataSyncEnabledCompat.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.contacts.common.compat;
-
-import android.content.Context;
-import android.provider.Settings;
-
-public class MetadataSyncEnabledCompat {
-    public static boolean isMetadataSyncEnabled(Context context) {
-        return CompatUtils.isNCompatible()
-                ? (Settings.Global.getInt(context.getContentResolver(),
-                        Settings.Global.CONTACT_METADATA_SYNC_ENABLED, 0) == 1)
-                : false;
-    }
-}
\ No newline at end of file
diff --git a/src/com/android/contacts/common/preference/ContactsPreferences.java b/src/com/android/contacts/common/preference/ContactsPreferences.java
index 26073f4..8865e91 100644
--- a/src/com/android/contacts/common/preference/ContactsPreferences.java
+++ b/src/com/android/contacts/common/preference/ContactsPreferences.java
@@ -16,7 +16,6 @@
 
 package com.android.contacts.common.preference;
 
-import android.accounts.Account;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.SharedPreferences;
@@ -27,7 +26,6 @@
 import android.os.Handler;
 import android.os.Looper;
 import android.preference.PreferenceManager;
-import android.provider.ContactsContract;
 import android.provider.Settings;
 import android.provider.Settings.SettingNotFoundException;
 import android.support.annotation.NonNull;
@@ -36,10 +34,7 @@
 
 import com.android.contacts.common.R;
 import com.android.contacts.common.model.account.AccountWithDataSet;
-import com.android.contacts.common.model.account.GoogleAccountType;
-import com.android.contacts.common.model.AccountTypeManager;
 
-import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -75,14 +70,6 @@
 
     public static final boolean PREF_DISPLAY_ONLY_PHONES_DEFAULT = false;
 
-    public static final String DO_NOT_SYNC_CONTACT_METADATA_MSG = "Do not sync metadata";
-
-    public static final String CONTACT_METADATA_AUTHORITY = "com.android.contacts.metadata";
-
-    public static final String SHOULD_CLEAR_METADATA_BEFORE_SYNCING =
-            "should_clear_metadata_before_syncing";
-
-    public static final String ONLY_CLEAR_DONOT_SYNC = "only_clear_donot_sync";
     /**
      * Value to use when a preference is unassigned and needs to be read from the shared preferences
      */
@@ -248,74 +235,6 @@
         return false;
     }
 
-    public String getContactMetadataSyncAccountName() {
-        final Account syncAccount = getContactMetadataSyncAccount();
-        return syncAccount == null ? DO_NOT_SYNC_CONTACT_METADATA_MSG : syncAccount.name;
-    }
-
-    public void setContactMetadataSyncAccount(AccountWithDataSet accountWithDataSet) {
-        final String mContactMetadataSyncAccount =
-                accountWithDataSet == null ? null : accountWithDataSet.name;
-        requestMetadataSyncForAccount(mContactMetadataSyncAccount);
-    }
-
-    private Account getContactMetadataSyncAccount() {
-        for (Account account : getFocusGoogleAccounts()) {
-            if (ContentResolver.getIsSyncable(account, CONTACT_METADATA_AUTHORITY) == 1
-                    && ContentResolver.getSyncAutomatically(account, CONTACT_METADATA_AUTHORITY)) {
-                return account;
-            }
-        }
-        return null;
-    }
-
-    /**
-     * Turn on contact metadata sync for this {@param accountName} and turn off automatic sync
-     * for other accounts. If accountName is null, then turn off automatic sync for all accounts.
-     */
-    private void requestMetadataSyncForAccount(String accountName) {
-        for (Account account : getFocusGoogleAccounts()) {
-            if (!TextUtils.isEmpty(accountName) && accountName.equals(account.name)) {
-                // Request sync.
-                final Bundle b = new Bundle();
-                b.putBoolean(SHOULD_CLEAR_METADATA_BEFORE_SYNCING, true);
-                b.putBoolean(ONLY_CLEAR_DONOT_SYNC, false);
-                b.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
-                b.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
-                ContentResolver.requestSync(account, CONTACT_METADATA_AUTHORITY, b);
-
-                ContentResolver.setSyncAutomatically(account, CONTACT_METADATA_AUTHORITY, true);
-            } else if (ContentResolver.getSyncAutomatically(account, CONTACT_METADATA_AUTHORITY)) {
-                // Turn off automatic sync for previous sync account.
-                ContentResolver.setSyncAutomatically(account, CONTACT_METADATA_AUTHORITY, false);
-                if (TextUtils.isEmpty(accountName)) {
-                    // Request sync to clear old data.
-                    final Bundle b = new Bundle();
-                    b.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
-                    b.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
-                    b.putBoolean(SHOULD_CLEAR_METADATA_BEFORE_SYNCING, true);
-                    b.putBoolean(ONLY_CLEAR_DONOT_SYNC, true);
-                    ContentResolver.requestSync(account, CONTACT_METADATA_AUTHORITY, b);
-                }
-            }
-        }
-    }
-
-    /**
-     * @return google accounts with "com.google" account type and null data set.
-     */
-    private List<Account> getFocusGoogleAccounts() {
-        List<Account> focusGoogleAccounts = new ArrayList<Account>();
-        final AccountTypeManager accountTypeManager = AccountTypeManager.getInstance(mContext);
-        List<AccountWithDataSet> accounts = accountTypeManager.getAccounts(true);
-        for (AccountWithDataSet account : accounts) {
-            if (GoogleAccountType.ACCOUNT_TYPE.equals(account.type) && account.dataSet == null) {
-                focusGoogleAccounts.add(account.getAccountOrNull());
-            }
-        }
-        return focusGoogleAccounts;
-    }
-
     public void registerChangeListener(ChangeListener listener) {
         if (mListener != null) unregisterChangeListener();
 
diff --git a/src/com/android/contacts/common/preference/DisplayOptionsPreferenceFragment.java b/src/com/android/contacts/common/preference/DisplayOptionsPreferenceFragment.java
index b3b2832..a6881ed 100644
--- a/src/com/android/contacts/common/preference/DisplayOptionsPreferenceFragment.java
+++ b/src/com/android/contacts/common/preference/DisplayOptionsPreferenceFragment.java
@@ -57,7 +57,6 @@
 import com.android.contacts.common.model.account.AccountWithDataSet;
 import com.android.contacts.common.util.AccountFilterUtil;
 import com.android.contacts.common.util.ImplicitIntentsUtil;
-import com.android.contactsbind.ObjectFactory;
 
 import java.util.List;
 
@@ -207,7 +206,6 @@
         mAreContactsAvailable = args.getBoolean(ARG_CONTACTS_AVAILABLE);
 
         removeUnsupportedPreferences();
-        addExtraPreferences();
 
         mMyInfoPreference = findPreference(KEY_MY_INFO);
 
@@ -291,16 +289,6 @@
         }
     }
 
-    private void addExtraPreferences() {
-        final PreferenceManager preferenceManager = ObjectFactory.getPreferenceManager(
-                getContext());
-        if (preferenceManager != null) {
-            for (Preference preference : preferenceManager.getPreferences()) {
-                getPreferenceScreen().addPreference(preference);
-            }
-        }
-    }
-
     @Override
     public Context getContext() {
         return getActivity();
diff --git a/src/com/android/contacts/common/preference/PreferenceManager.java b/src/com/android/contacts/common/preference/PreferenceManager.java
deleted file mode 100644
index 816f94e..0000000
--- a/src/com/android/contacts/common/preference/PreferenceManager.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.contacts.common.preference;
-
-import android.preference.Preference;
-
-import java.util.List;
-
-public interface PreferenceManager {
-    List<Preference> getPreferences();
-}