From: csagan5 <32685696+csagan5@users.noreply.github.com>
Date: Tue, 12 Jun 2018 14:23:07 +0200
Subject: Disable signin and data saver preferences

Never show the data saver promo snackbar
---
 chrome/android/java/res/xml/main_preferences.xml   | 20 -----
 .../android/java/res/xml/privacy_preferences.xml   |  7 --
 .../browser/preferences/MainPreferences.java       | 92 +---------------------
 .../preferences/privacy/PrivacyPreferences.java    | 17 ----
 .../java/strings/android_chrome_strings.grd        |  6 --
 5 files changed, 1 insertion(+), 141 deletions(-)

diff --git a/chrome/android/java/res/xml/main_preferences.xml b/chrome/android/java/res/xml/main_preferences.xml
--- a/chrome/android/java/res/xml/main_preferences.xml
+++ b/chrome/android/java/res/xml/main_preferences.xml
@@ -7,21 +7,6 @@
     android:orderingFromXml="false">
 
     <PreferenceCategory
-        android:key="account_section"
-        android:order="0"
-        android:title="@string/prefs_section_account"/>
-    <org.chromium.chrome.browser.preferences.SignInPreference
-        android:key="sign_in"
-        android:order="1"
-        android:title="@string/sign_in_to_chrome"/>
-    <org.chromium.chrome.browser.preferences.ChromeBasePreference
-        android:key="sync_and_services"
-        android:order="2"
-        android:layout="@layout/account_management_account_row"
-        android:title="@string/prefs_sync_and_services"
-        android:fragment="org.chromium.chrome.browser.preferences.SyncAndServicesPreferences"/>
-
-    <PreferenceCategory
         android:key="basics_section"
         android:order="3"
         android:title="@string/prefs_section_basics"/>
@@ -96,11 +81,6 @@
         android:key="languages"
         android:order="17"
         android:title="@string/prefs_languages"/>
-    <org.chromium.chrome.browser.preferences.datareduction.DataReductionPreference
-        android:fragment="org.chromium.chrome.browser.preferences.datareduction.DataReductionPreferenceFragment"
-        android:key="data_reduction"
-        android:order="18"
-        android:title="@string/data_reduction_title"/>
     <org.chromium.chrome.browser.preferences.ChromeBasePreference
         android:fragment="org.chromium.chrome.browser.preferences.download.DownloadPreferences"
         android:key="downloads"
diff --git a/chrome/android/java/res/xml/privacy_preferences.xml b/chrome/android/java/res/xml/privacy_preferences.xml
--- a/chrome/android/java/res/xml/privacy_preferences.xml
+++ b/chrome/android/java/res/xml/privacy_preferences.xml
@@ -55,11 +55,4 @@
         android:title="@string/clear_browsing_data_title"
         android:summary="@string/clear_browsing_data_summary"
         android:fragment="org.chromium.chrome.browser.preferences.privacy.ClearBrowsingDataTabsFragment" />
-    <Preference
-        android:key="sync_and_services_link_divider"
-        android:layout="@layout/divider_preference"
-        android:selectable="false"/>
-    <org.chromium.chrome.browser.preferences.TextMessagePreference
-        android:key="sync_and_services_link"
-        tools:summary="@string/privacy_sync_and_services_link"/>
 </PreferenceScreen>
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/MainPreferences.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/MainPreferences.java
--- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/MainPreferences.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/MainPreferences.java
@@ -17,16 +17,12 @@ import org.chromium.base.VisibleForTesting;
 import org.chromium.chrome.R;
 import org.chromium.chrome.browser.ChromeFeatureList;
 import org.chromium.chrome.browser.contextual_suggestions.ContextualSuggestionsEnabledStateUtils;
-import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings;
 import org.chromium.chrome.browser.partnercustomizations.HomepageManager;
 import org.chromium.chrome.browser.password_manager.ManagePasswordsReferrer;
 import org.chromium.chrome.browser.preferences.autofill_assistant.AutofillAssistantPreferences;
-import org.chromium.chrome.browser.preferences.datareduction.DataReductionPreferenceFragment;
 import org.chromium.chrome.browser.preferences.developer.DeveloperPreferences;
 import org.chromium.chrome.browser.search_engines.TemplateUrl;
 import org.chromium.chrome.browser.search_engines.TemplateUrlService;
-import org.chromium.chrome.browser.signin.SigninManager;
-import org.chromium.chrome.browser.sync.ProfileSyncService;
 import org.chromium.chrome.browser.util.FeatureUtilities;
 
 import java.util.HashMap;
@@ -36,11 +32,7 @@ import java.util.Map;
  * The main settings screen, shown when the user first opens Settings.
  */
 public class MainPreferences extends PreferenceFragment
-        implements TemplateUrlService.LoadListener, ProfileSyncService.SyncStateChangedListener,
-                   SigninManager.SignInStateObserver {
-    public static final String PREF_ACCOUNT_SECTION = "account_section";
-    public static final String PREF_SIGN_IN = "sign_in";
-    public static final String PREF_SYNC_AND_SERVICES = "sync_and_services";
+        implements TemplateUrlService.LoadListener {
     public static final String PREF_SEARCH_ENGINE = "search_engine";
     public static final String PREF_SAVED_PASSWORDS = "saved_passwords";
     public static final String PREF_CONTEXTUAL_SUGGESTIONS = "contextual_suggestions";
@@ -60,7 +52,6 @@ public class MainPreferences extends PreferenceFragment
 
     private final ManagedPreferenceDelegate mManagedPreferenceDelegate;
     private final Map<String, Preference> mAllPreferences = new HashMap<>();
-    private SignInPreference mSignInPreference;
 
     public MainPreferences() {
         setHasOptionsMenu(true);
@@ -76,33 +67,16 @@ public class MainPreferences extends PreferenceFragment
     @Override
     public void onDestroy() {
         super.onDestroy();
-        mSignInPreference.onPreferenceFragmentDestroyed();
     }
 
     @Override
     public void onStart() {
         super.onStart();
-        if (SigninManager.get().isSigninSupported()) {
-            SigninManager.get().addSignInStateObserver(this);
-            mSignInPreference.registerForUpdates();
-        }
-        ProfileSyncService syncService = ProfileSyncService.get();
-        if (syncService != null) {
-            syncService.addSyncStateChangedListener(this);
-        }
     }
 
     @Override
     public void onStop() {
         super.onStop();
-        if (SigninManager.get().isSigninSupported()) {
-            SigninManager.get().removeSignInStateObserver(this);
-            mSignInPreference.unregisterForUpdates();
-        }
-        ProfileSyncService syncService = ProfileSyncService.get();
-        if (syncService != null) {
-            syncService.removeSyncStateChangedListener(this);
-        }
     }
 
     @Override
@@ -115,17 +89,9 @@ public class MainPreferences extends PreferenceFragment
         PreferenceUtils.addPreferencesFromResource(this, R.xml.main_preferences);
         cachePreferences();
 
-        if (ChromeFeatureList.isEnabled(ChromeFeatureList.UNIFIED_CONSENT)) {
-            mSignInPreference.setOnStateChangedCallback(this::onSignInPreferenceStateChanged);
-        } else {
-            getPreferenceScreen().removePreference(findPreference(PREF_ACCOUNT_SECTION));
-            getPreferenceScreen().removePreference(findPreference(PREF_SYNC_AND_SERVICES));
-        }
-
         updatePasswordsPreference();
 
         setManagedPreferenceDelegateForPreference(PREF_SEARCH_ENGINE);
-        setManagedPreferenceDelegateForPreference(PREF_DATA_REDUCTION);
 
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
             // If we are on Android O+ the Notifications preference should lead to the Android
@@ -189,7 +155,6 @@ public class MainPreferences extends PreferenceFragment
             Preference preference = getPreferenceScreen().getPreference(index);
             mAllPreferences.put(preference.getKey(), preference);
         }
-        mSignInPreference = (SignInPreference) mAllPreferences.get(PREF_SIGN_IN);
     }
 
     private void setManagedPreferenceDelegateForPreference(String key) {
@@ -198,13 +163,6 @@ public class MainPreferences extends PreferenceFragment
     }
 
     private void updatePreferences() {
-        if (SigninManager.get().isSigninSupported()) {
-            addPreferenceIfAbsent(PREF_SIGN_IN);
-        } else {
-            removePreferenceIfPresent(PREF_SIGN_IN);
-        }
-
-        updateSyncAndServicesPreference();
         updateSearchEnginePreference();
 
         Preference homepagePref = addPreferenceIfAbsent(PREF_HOMEPAGE);
@@ -234,10 +192,6 @@ public class MainPreferences extends PreferenceFragment
         } else {
             removePreferenceIfPresent(PREF_DEVELOPER);
         }
-
-        ChromeBasePreference dataReduction =
-                (ChromeBasePreference) findPreference(PREF_DATA_REDUCTION);
-        dataReduction.setSummary(DataReductionPreferenceFragment.generateSummary(getResources()));
     }
 
     private Preference addPreferenceIfAbsent(String key) {
@@ -251,15 +205,6 @@ public class MainPreferences extends PreferenceFragment
         if (preference != null) getPreferenceScreen().removePreference(preference);
     }
 
-    private void updateSyncAndServicesPreference() {
-        if (!ChromeFeatureList.isEnabled(ChromeFeatureList.UNIFIED_CONSENT)) return;
-
-        ChromeBasePreference syncAndServices =
-                (ChromeBasePreference) findPreference(PREF_SYNC_AND_SERVICES);
-        syncAndServices.setIcon(SyncPreferenceUtils.getSyncStatusIcon(getActivity()));
-        syncAndServices.setSummary(SyncPreferenceUtils.getSyncStatusSummary(getActivity()));
-    }
-
     private void updateSearchEnginePreference() {
         if (!TemplateUrlService.getInstance().isLoaded()) {
             ChromeBasePreference searchEnginePref =
@@ -291,28 +236,6 @@ public class MainPreferences extends PreferenceFragment
         pref.setSummary(getResources().getString(isOn ? R.string.text_on : R.string.text_off));
     }
 
-    // SigninManager.SignInStateObserver implementation.
-    @Override
-    public void onSignedIn() {
-        // After signing in or out of a managed account, preferences may change or become enabled
-        // or disabled.
-        new Handler().post(() -> updatePreferences());
-    }
-
-    @Override
-    public void onSignedOut() {
-        updatePreferences();
-    }
-
-    private void onSignInPreferenceStateChanged() {
-        // Remove "Account" section header if the personalized sign-in promo is shown.
-        if (mSignInPreference.getState() == SignInPreference.State.PERSONALIZED_PROMO) {
-            removePreferenceIfPresent(PREF_ACCOUNT_SECTION);
-        } else {
-            addPreferenceIfAbsent(PREF_ACCOUNT_SECTION);
-        }
-    }
-
     // TemplateUrlService.LoadListener implementation.
     @Override
     public void onTemplateUrlServiceLoaded() {
@@ -320,11 +243,6 @@ public class MainPreferences extends PreferenceFragment
         updateSearchEnginePreference();
     }
 
-    @Override
-    public void syncStateChanged() {
-        updateSyncAndServicesPreference();
-    }
-
     @VisibleForTesting
     ManagedPreferenceDelegate getManagedPreferenceDelegateForTest() {
         return mManagedPreferenceDelegate;
@@ -334,9 +252,6 @@ public class MainPreferences extends PreferenceFragment
         return new ManagedPreferenceDelegate() {
             @Override
             public boolean isPreferenceControlledByPolicy(Preference preference) {
-                if (PREF_DATA_REDUCTION.equals(preference.getKey())) {
-                    return DataReductionProxySettings.getInstance().isDataReductionProxyManaged();
-                }
                 if (PREF_SEARCH_ENGINE.equals(preference.getKey())) {
                     return TemplateUrlService.getInstance().isDefaultSearchManaged();
                 }
@@ -345,11 +260,6 @@ public class MainPreferences extends PreferenceFragment
 
             @Override
             public boolean isPreferenceClickDisabledByPolicy(Preference preference) {
-                if (PREF_DATA_REDUCTION.equals(preference.getKey())) {
-                    DataReductionProxySettings settings = DataReductionProxySettings.getInstance();
-                    return settings.isDataReductionProxyManaged()
-                            && !settings.isDataReductionProxyEnabled();
-                }
                 if (PREF_SEARCH_ENGINE.equals(preference.getKey())) {
                     return TemplateUrlService.getInstance().isDefaultSearchManaged();
                 }
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PrivacyPreferences.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PrivacyPreferences.java
--- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PrivacyPreferences.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PrivacyPreferences.java
@@ -27,7 +27,6 @@ import org.chromium.chrome.browser.preferences.Pref;
 import org.chromium.chrome.browser.preferences.PrefServiceBridge;
 import org.chromium.chrome.browser.preferences.PreferenceUtils;
 import org.chromium.chrome.browser.preferences.PreferencesLauncher;
-import org.chromium.chrome.browser.preferences.SyncAndServicesPreferences;
 import org.chromium.chrome.browser.profiles.Profile;
 import org.chromium.chrome.browser.usage_stats.UsageStatsConsentDialog;
 import org.chromium.ui.text.NoUnderlineClickableSpan;
@@ -49,9 +48,6 @@ public class PrivacyPreferences extends PreferenceFragment
     private static final String PREF_DO_NOT_TRACK = "do_not_track";
     private static final String PREF_USAGE_AND_CRASH_REPORTING = "usage_and_crash_reports";
     private static final String PREF_CLEAR_BROWSING_DATA = "clear_browsing_data";
-    private static final String PREF_SYNC_AND_SERVICES_LINK_DIVIDER =
-            "sync_and_services_link_divider";
-    private static final String PREF_SYNC_AND_SERVICES_LINK = "sync_and_services_link";
     private static final String PREF_USAGE_STATS = "usage_stats_reporting";
 
     private ManagedPreferenceDelegate mManagedPreferenceDelegate;
@@ -100,22 +96,9 @@ public class PrivacyPreferences extends PreferenceFragment
             networkPredictionPref.setOrder(canMakePaymentPref.getOrder());
             preferenceScreen.addPreference(networkPredictionPref);
 
-            Preference syncAndServicesLink = findPreference(PREF_SYNC_AND_SERVICES_LINK);
-            NoUnderlineClickableSpan linkSpan =
-                    new NoUnderlineClickableSpan(getResources(), view -> {
-                        PreferencesLauncher.launchSettingsPage(getActivity(),
-                                SyncAndServicesPreferences.class,
-                                SyncAndServicesPreferences.createArguments(false));
-                    });
-            syncAndServicesLink.setSummary(
-                    SpanApplier.applySpans(getString(R.string.privacy_sync_and_services_link),
-                            new SpanApplier.SpanInfo("<link>", "</link>", linkSpan)));
-
             updateSummaries();
             return;
         }
-        preferenceScreen.removePreference(findPreference(PREF_SYNC_AND_SERVICES_LINK_DIVIDER));
-        preferenceScreen.removePreference(findPreference(PREF_SYNC_AND_SERVICES_LINK));
 
         ChromeBaseCheckBoxPreference navigationErrorPref =
                 (ChromeBaseCheckBoxPreference) findPreference(PREF_NAVIGATION_ERROR);
diff --git a/chrome/android/java/strings/android_chrome_strings.grd b/chrome/android/java/strings/android_chrome_strings.grd
--- a/chrome/android/java/strings/android_chrome_strings.grd
+++ b/chrome/android/java/strings/android_chrome_strings.grd
@@ -315,9 +315,6 @@ CHAR-LIMIT guidelines:
       </message>
 
       <!-- Sign-in, sync and personalization preferences -->
-      <message name="IDS_PREFS_SECTION_ACCOUNT" desc="Title for the group of account-related entries in Settings. [CHAR-LIMIT=32]">
-        Account
-      </message>
       <message name="IDS_SIGN_IN_TO_CHROME" desc="Title for the button to sign in to Chrome using one's Google account. [CHAR-LIMIT=27]">
         Sign in to Chrome
       </message>
@@ -400,9 +397,6 @@ CHAR-LIMIT guidelines:
       <message name="IDS_URL_KEYED_ANONYMIZED_DATA_SUMMARY" desc="Summary for a checkbox in Settings that controls non-personalized URL collection and informs the user about the data shared by this feature.">
         Sends URLs of pages you visit to Google
       </message>
-      <message name="IDS_PRIVACY_SYNC_AND_SERVICES_LINK" desc="The text for Privacy preferences that is shown after all preference rows.">
-        For more settings that relate to privacy, security, and data collection, see <ph name="BEGIN_LINK">&lt;link&gt;</ph>Sync and Google services<ph name="END_LINK">&lt;/link&gt;</ph>
-      </message>
       <message name="IDS_USAGE_AND_CRASH_REPORTS_TITLE" desc="Title for a preference that enables sending usage statistics and crash reports.">
         Help improve Chrome's features and performance
       </message>
-- 
2.11.0

