bromite/build/patches/Move-some-account-settings-back-to-privacy-settings.patch
2021-01-26 01:12:38 +01:00

162 lines
8.3 KiB
Diff

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
---
.../java/res/xml/privacy_preferences.xml | 19 ++++++
.../privacy/settings/PrivacySettings.java | 63 ++++++++++++++++++-
2 files changed, 79 insertions(+), 3 deletions(-)
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
@@ -58,4 +58,23 @@
android:summary="@string/clear_browsing_data_summary"
android:fragment="org.chromium.chrome.browser.browsing_data.ClearBrowsingDataTabsFragment"
android:order="5"/>
+
+ <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.ChromeSwitchPreference
+ android:key="autofill_assistant"
+ android:title="@string/prefs_autofill_assistant_title"
+ android:summary="@string/prefs_autofill_assistant_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>
</PreferenceScreen>
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
@@ -24,7 +24,6 @@ import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.privacy.secure_dns.SecureDnsSettings;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.safe_browsing.metrics.SettingsAccessPoint;
-import org.chromium.chrome.browser.safe_browsing.settings.SafeBrowsingSettingsFragment;
import org.chromium.chrome.browser.settings.ChromeManagedPreferenceDelegate;
import org.chromium.chrome.browser.settings.SettingsLauncher;
import org.chromium.chrome.browser.settings.SettingsLauncherImpl;
@@ -40,6 +39,13 @@ import org.chromium.ui.text.SpanApplier;
import org.chromium.base.Log;
+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;
+import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
+
/**
* Fragment to keep track of the all the privacy related preferences.
*/
@@ -56,6 +62,18 @@ public class PrivacySettings
private static final String PREF_PROXY_OPTIONS = "proxy";
public static final String PREF_INCOGNITO_TAB_HISTORY_ENABLED = "incognito_history_enabled";
+ // 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";
+ public static final String PREF_AUTOFILL_ASSISTANT = "autofill_assistant";
+ private ChromeSwitchPreference mSearchSuggestions;
+ private @Nullable ChromeSwitchPreference mAutofillAssistant;
+ private @Nullable Preference mContextualSearch;
+ private final SharedPreferencesManager mSharedPreferencesManager =
+ SharedPreferencesManager.getInstance();
+ private final PrefService prefService = UserPrefs.get(Profile.getLastUsedRegularProfile());
+
private static final String[] NEW_PRIVACY_PREFERENCE_ORDER = {PREF_CLEAR_BROWSING_DATA,
PREF_CAN_MAKE_PAYMENT, PREF_NETWORK_PREDICTIONS,
PREF_SECURE_DNS, PREF_DO_NOT_TRACK,
@@ -63,7 +81,8 @@ public class PrivacySettings
PREF_INCOGNITO_TAB_HISTORY_ENABLED,
PREF_ALLOW_CUSTOM_TAB_INTENTS,
PREF_CLOSE_TABS_ON_EXIT,
- PREF_PROXY_OPTIONS
+ PREF_PROXY_OPTIONS,
+ PREF_SERVICES_CATEGORY
};
private ManagedPreferenceDelegate mManagedPreferenceDelegate;
@@ -89,6 +108,29 @@ public class PrivacySettings
mManagedPreferenceDelegate = createManagedPreferenceDelegate();
+ mSearchSuggestions = (ChromeSwitchPreference) findPreference(PREF_SEARCH_SUGGESTIONS);
+ mSearchSuggestions.setOnPreferenceChangeListener(this);
+ mSearchSuggestions.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
+
+ mAutofillAssistant = (ChromeSwitchPreference) findPreference(PREF_AUTOFILL_ASSISTANT);
+ if (shouldShowAutofillAssistantPreference()) {
+ mAutofillAssistant.setOnPreferenceChangeListener(this);
+ mAutofillAssistant.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
+ mAutofillAssistant.setChecked(mSharedPreferencesManager.readBoolean(
+ ChromePreferenceKeys.AUTOFILL_ASSISTANT_ENABLED, false));
+ } else {
+ PreferenceCategory servicesCategory =
+ (PreferenceCategory) findPreference(PREF_SERVICES_CATEGORY);
+ servicesCategory.removePreference(mAutofillAssistant);
+ mAutofillAssistant = null;
+ }
+
+ 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 +163,11 @@ public class PrivacySettings
} else if (PREF_CAN_MAKE_PAYMENT.equals(key)) {
UserPrefs.get(Profile.getLastUsedRegularProfile())
.setBoolean(Pref.CAN_MAKE_PAYMENT_ENABLED, (boolean) newValue);
+ } else if (PREF_SEARCH_SUGGESTIONS.equals(key)) {
+ prefService.setBoolean(Pref.SEARCH_SUGGEST_ENABLED, (boolean) newValue);
+ } else if (PREF_AUTOFILL_ASSISTANT.equals(key)) {
+ mSharedPreferencesManager.writeBoolean(
+ ChromePreferenceKeys.AUTOFILL_ASSISTANT_ENABLED, (boolean) newValue);
} else if (PREF_NETWORK_PREDICTIONS.equals(key)) {
PrivacyPreferencesManager.getInstance().setNetworkPredictionEnabled((boolean) newValue);
} else if (PREF_ALLOW_CUSTOM_TAB_INTENTS.equals(key)) {
@@ -135,6 +182,16 @@ public class PrivacySettings
return true;
}
+ /**
+ * This checks whether Autofill Assistant is enabled and was shown at least once (only then
+ * will the AA switch be assigned a value).
+ */
+ private boolean shouldShowAutofillAssistantPreference() {
+ return ChromeFeatureList.isEnabled(ChromeFeatureList.AUTOFILL_ASSISTANT)
+ && mSharedPreferencesManager.contains(
+ ChromePreferenceKeys.AUTOFILL_ASSISTANT_ENABLED);
+ }
+
@Override
public void onResume() {
super.onResume();
@@ -145,7 +202,7 @@ public class PrivacySettings
* Updates the summaries for several preferences.
*/
public void updateSummaries() {
- PrefService prefService = UserPrefs.get(Profile.getLastUsedRegularProfile());
+ mSearchSuggestions.setChecked(prefService.getBoolean(Pref.SEARCH_SUGGEST_ENABLED));
ChromeSwitchPreference canMakePaymentPref =
(ChromeSwitchPreference) findPreference(PREF_CAN_MAKE_PAYMENT);
--
2.17.1