-
-
Notifications
You must be signed in to change notification settings - Fork 64
/
0060-Utility-class-for-modifying-preferences-at-Privacy-s.patch
159 lines (150 loc) · 6.99 KB
/
0060-Utility-class-for-modifying-preferences-at-Privacy-s.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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 9980a7c5f6d84..164ef483d5a44 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 b3a489f124aa8..d580fb6e83875 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 2429268892127..814bd064d67eb 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
@@ -90,6 +90,8 @@ public class PrivacySettings extends PreferenceFragmentCompat
SettingsUtils.addPreferencesFromResource(this, R.xml.privacy_preferences);
}
+ PrivacySettingsExt.initializePreferences(this, mProfile);
+
Preference sandboxPreference = findPreference(PREF_PRIVACY_SANDBOX);
if (PrivacySandboxBridge.isPrivacySandboxRestricted()
&& !PrivacySandboxBridge.isRestrictedNoticeEnabled()) {
@@ -186,6 +188,8 @@ public class PrivacySettings extends PreferenceFragmentCompat
SingleCategorySettings.EXTRA_TITLE, thirdPartyCookies.getTitle().toString());
}
+ PrivacySettingsExt.removeUnwantedPreferences(this);
+
updatePreferences();
}
@@ -300,6 +304,8 @@ public class PrivacySettings extends PreferenceFragmentCompat
UserPrefs.get(mProfile).getInteger(COOKIE_CONTROLS_MODE)));
}
+ PrivacySettingsExt.updatePreferences(this, mProfile);
+
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..a9acd9e82ee60
--- /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.chrome.R;
+import org.chromium.chrome.browser.flags.ChromeFeatureList;
+import org.chromium.chrome.browser.preferences.Pref;
+import org.chromium.chrome.browser.preferences.SharedPrefsUtils.SharedPrefsExt;
+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() {
+ @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);
+ }
+}