blob: 654afeb8fad64f61cad4ee1b1daa2aad4a09ee41 [file] [log] [blame]
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: fgei <fgei@gmail.com>
Date: Tue, 11 Apr 2023 07:55:52 +0000
Subject: [PATCH] Utility class for modifying preferences at Privacy section
---
chrome/android/chrome_ext_java_resources.gni | 1 +
chrome/android/chrome_ext_java_sources.gni | 1 +
.../java/res/xml/privacy_preferences_ext.xml | 9 +++
.../privacy/settings/PrivacySettings.java | 6 ++
.../privacy/settings/PrivacySettingsExt.java | 72 +++++++++++++++++++
5 files changed, 89 insertions(+)
create mode 100644 chrome/android/java/res/xml/privacy_preferences_ext.xml
create mode 100644 chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettingsExt.java
diff --git a/chrome/android/chrome_ext_java_resources.gni b/chrome/android/chrome_ext_java_resources.gni
index 4ce3232392871..99618ae9ac2f1 100644
--- a/chrome/android/chrome_ext_java_resources.gni
+++ b/chrome/android/chrome_ext_java_resources.gni
@@ -3,4 +3,5 @@
# found in the LICENSE file.
chrome_ext_java_resources = [
+ "java/res/xml/privacy_preferences_ext.xml",
]
diff --git a/chrome/android/chrome_ext_java_sources.gni b/chrome/android/chrome_ext_java_sources.gni
index b3fe144daf2d6..598bfaf9cb860 100644
--- a/chrome/android/chrome_ext_java_sources.gni
+++ b/chrome/android/chrome_ext_java_sources.gni
@@ -4,4 +4,5 @@
chrome_ext_java_sources = [
"java/src/org/chromium/chrome/browser/settings/SettingsExtUtils.java",
+ "java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettingsExt.java",
]
diff --git a/chrome/android/java/res/xml/privacy_preferences_ext.xml b/chrome/android/java/res/xml/privacy_preferences_ext.xml
new file mode 100644
index 0000000000000..a352cd657b1b9
--- /dev/null
+++ b/chrome/android/java/res/xml/privacy_preferences_ext.xml
@@ -0,0 +1,9 @@
+<!--
+Copyright 2023 GrapheneOS
+Use of this source code is governed by a GPLv2 only-style license
+that can be found in the LICENSE file.
+-->
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto">
+</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
index 88c5241c0c93c..96bf04332e1c6 100644
--- 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
@@ -85,6 +85,8 @@ public class PrivacySettings extends ChromeBaseSettingsFragment
SettingsUtils.addPreferencesFromResource(this, R.xml.privacy_preferences);
+ PrivacySettingsExt.initializePreferences(this, getProfile());
+
Preference ipProtectionPreference = findPreference(PREF_IP_PROTECTION);
ipProtectionPreference.setVisible(shouldShowIpProtectionUI());
ipProtectionPreference.setOnPreferenceClickListener(
@@ -227,6 +229,8 @@ public class PrivacySettings extends ChromeBaseSettingsFragment
clearBrowsingDataAdvancedPreference.setVisible(true);
}
+ PrivacySettingsExt.removeUnwantedPreferences(this);
+
updatePreferences();
}
@@ -358,6 +362,8 @@ public class PrivacySettings extends ChromeBaseSettingsFragment
UserPrefs.get(getProfile()).getInteger(COOKIE_CONTROLS_MODE)));
}
+ PrivacySettingsExt.updatePreferences(this, getProfile());
+
updatePrivacyGuidePreferenceTitle();
}
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettingsExt.java b/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettingsExt.java
new file mode 100644
index 0000000000000..fa6ef4589d6e9
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettingsExt.java
@@ -0,0 +1,72 @@
+// Copyright 2023 GrapheneOS
+// Use of this source code is governed by a GPLv2-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.privacy.settings;
+
+import androidx.annotation.NonNull;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceFragmentCompat;
+import androidx.preference.SwitchPreferenceCompat;
+
+import org.chromium.base.ThreadUtils;
+import org.chromium.base.shared_preferences.SharedPrefsUtils.SharedPrefsExt;
+import org.chromium.chrome.R;
+import org.chromium.chrome.browser.flags.ChromeFeatureList;
+import org.chromium.chrome.browser.preferences.Pref;
+import org.chromium.chrome.browser.profiles.Profile;
+import org.chromium.chrome.browser.settings.ChromeManagedPreferenceDelegate;
+import org.chromium.chrome.browser.settings.SettingsExtUtils;
+import org.chromium.components.browser_ui.settings.ChromeBasePreference;
+import org.chromium.components.browser_ui.settings.ChromeSwitchPreference;
+import org.chromium.components.browser_ui.settings.SettingsUtils;
+import org.chromium.components.prefs.PrefService;
+import org.chromium.components.user_prefs.UserPrefs;
+
+final class PrivacySettingsExt {
+
+ private static final Preference.OnPreferenceChangeListener getListener(@NonNull Profile profile) {
+ return (pref, val) -> {
+ PrefService prefService = UserPrefs.get(profile);
+ if (pref == null) {
+ return false;
+ }
+ String key = pref.getKey();
+ return true;
+ };
+ }
+
+ private static final ChromeManagedPreferenceDelegate getDelegate(@NonNull Profile profile) {
+ return new ChromeManagedPreferenceDelegate(profile) {
+ @Override
+ public boolean isPreferenceControlledByPolicy(Preference pref) {
+ PrefService prefService = UserPrefs.get(profile);
+ if (pref == null) {
+ return false;
+ }
+ String key = pref.getKey();
+ return false;
+ }
+ };
+ }
+
+ static void removeUnwantedPreferences(@NonNull PreferenceFragmentCompat prefFragment) {
+ ThreadUtils.checkUiThread();
+ }
+
+ static void initializePreferences(@NonNull PreferenceFragmentCompat prefFragment, @NonNull Profile profile) {
+ ThreadUtils.checkUiThread();
+ // This is such that privacy preferences are added at Privacy Section in newer UI,
+ // and mostly kept on previous order at older UI.
+ int PRIVACY_PREFERENCES_ORDER =
+ ChromeFeatureList.isEnabled(ChromeFeatureList.PRIVACY_SANDBOX_SETTINGS_4) ? 2 : 6;
+ int SECURITY_PREFERENCES_ORDER =
+ ChromeFeatureList.isEnabled(ChromeFeatureList.PRIVACY_SANDBOX_SETTINGS_4) ? 2 : 9999;
+ SettingsUtils.addPreferencesFromResource(prefFragment, R.xml.privacy_preferences_ext);
+ }
+
+ static void updatePreferences(@NonNull PreferenceFragmentCompat prefFragment, @NonNull Profile profile) {
+ ThreadUtils.checkUiThread();
+ PrefService prefService = UserPrefs.get(profile);
+ }
+}