From: csagan5 <32685696+csagan5@users.noreply.github.com>
Date: Sun, 4 Oct 2020 12:58:17 +0200
Subject: Move some account settings back to privacy settings

Search suggestions, autofill assistant and contextual search

License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
---
 .../java/res/xml/privacy_preferences.xml      | 13 ++++++++
 .../privacy/settings/PrivacySettings.java     | 31 ++++++++++++++++++-
 .../strings/android_chrome_strings.grd        |  4 +++
 3 files changed, 47 insertions(+), 1 deletion(-)

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
@@ -48,6 +48,19 @@ found in the LICENSE file.
         android:key="privacy_sandbox"
         android:title="@string/prefs_privacy_sandbox"
         android:fragment="org.chromium.chrome.browser.privacy_sandbox.PrivacySandboxSettingsFragment"/>
+    <PreferenceCategory
+        android:key="services_category"
+        android:title="@string/services_category_title">
+      <org.chromium.components.browser_ui.settings.ChromeSwitchPreference
+          android:key="search_suggestions"
+          android:title="@string/autocomplete_searches_and_urls_title"
+          android:summary="@string/autocomplete_searches_and_urls_summary"
+          android:persistent="false"/>
+      <org.chromium.components.browser_ui.settings.ChromeBasePreference
+          android:key="contextual_search"
+          android:title="@string/contextual_search_title"
+          android:fragment="org.chromium.chrome.browser.contextualsearch.ContextualSearchPreferenceFragment"/>
+    </PreferenceCategory>
     <Preference
         android:key="phone_as_a_security_key"
         android:title="@string/cablev2_paask_title"
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettings.java b/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettings.java
--- a/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettings.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettings.java
@@ -39,6 +39,12 @@ import org.chromium.components.user_prefs.UserPrefs;
 import org.chromium.ui.text.NoUnderlineClickableSpan;
 import org.chromium.ui.text.SpanApplier;
 
+import androidx.annotation.Nullable;
+import androidx.preference.PreferenceCategory;
+import org.chromium.chrome.browser.contextualsearch.ContextualSearchManager;
+import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
+import org.chromium.components.browser_ui.settings.ChromeSwitchPreference;
+
 /**
  * Fragment to keep track of the all the privacy related preferences.
  */
@@ -54,6 +60,16 @@ public class PrivacySettings
     private static final String PREF_PRIVACY_GUIDE = "privacy_guide";
     private static final String PREF_INCOGNITO_LOCK = "incognito_lock";
 
+    // moved from SyncAndServicesSettings.java
+    private static final String PREF_SERVICES_CATEGORY = "services_category";
+    private static final String PREF_SEARCH_SUGGESTIONS = "search_suggestions";
+    private static final String PREF_CONTEXTUAL_SEARCH = "contextual_search";
+    private ChromeSwitchPreference mSearchSuggestions;
+    private @Nullable Preference mContextualSearch;
+    private final SharedPreferencesManager mSharedPreferencesManager =
+            SharedPreferencesManager.getInstance();
+    private final PrefService prefService = UserPrefs.get(Profile.getLastUsedRegularProfile());
+
     private ManagedPreferenceDelegate mManagedPreferenceDelegate;
     private IncognitoLockSettings mIncognitoLockSettings;
 
@@ -93,6 +109,16 @@ public class PrivacySettings
 
         mManagedPreferenceDelegate = createManagedPreferenceDelegate();
 
+        mSearchSuggestions = (ChromeSwitchPreference) findPreference(PREF_SEARCH_SUGGESTIONS);
+        mSearchSuggestions.setOnPreferenceChangeListener(this);
+        mSearchSuggestions.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
+
+        mContextualSearch = findPreference(PREF_CONTEXTUAL_SEARCH);
+        boolean isContextualSearchEnabled =
+                !ContextualSearchManager.isContextualSearchDisabled();
+        mContextualSearch.setSummary(
+                isContextualSearchEnabled ? R.string.text_on : R.string.text_off);
+
         ChromeSwitchPreference canMakePaymentPref =
                 (ChromeSwitchPreference) findPreference(PREF_CAN_MAKE_PAYMENT);
         canMakePaymentPref.setOnPreferenceChangeListener(this);
@@ -121,6 +147,9 @@ public class PrivacySettings
         } else if (PREF_HTTPS_FIRST_MODE.equals(key)) {
             UserPrefs.get(Profile.getLastUsedRegularProfile())
                     .setBoolean(Pref.HTTPS_ONLY_MODE_ENABLED, (boolean) newValue);
+        } else if (PREF_SEARCH_SUGGESTIONS.equals(key)) {
+            UserPrefs.get(Profile.getLastUsedRegularProfile())
+                    .setBoolean(Pref.SEARCH_SUGGEST_ENABLED, (boolean) newValue);
         }
         return true;
     }
@@ -135,7 +164,7 @@ public class PrivacySettings
      * Updates the preferences.
      */
     public void updatePreferences() {
-        PrefService prefService = UserPrefs.get(Profile.getLastUsedRegularProfile());
+        mSearchSuggestions.setChecked(prefService.getBoolean(Pref.SEARCH_SUGGEST_ENABLED));
 
         ChromeSwitchPreference canMakePaymentPref =
                 (ChromeSwitchPreference) findPreference(PREF_CAN_MAKE_PAYMENT);
diff --git a/chrome/browser/ui/android/strings/android_chrome_strings.grd b/chrome/browser/ui/android/strings/android_chrome_strings.grd
--- a/chrome/browser/ui/android/strings/android_chrome_strings.grd
+++ b/chrome/browser/ui/android/strings/android_chrome_strings.grd
@@ -423,6 +423,10 @@ CHAR_LIMIT guidelines:
         No statistics or crash reports are sent to Google
       </message>
 
+      <message name="IDS_SERVICES_CATEGORY_TITLE" desc="Title for the group of preferences that control non-personalized Google services. This group contains preferences for data that is not tied to user's Google Account.">
+        Other services
+      </message>
+
       <!-- Search engine settings -->
       <message name="IDS_SEARCH_ENGINE_SETTINGS" desc="Title for Search Engine settings. [CHAR_LIMIT=32]">
         Search engine
--
2.25.1
