LeOSium_old/patches/0001-Vanadium/0061-Utility-class-for-modi...

155 lines
6.8 KiB
Diff

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 | 67 +++++++++++++++++++
5 files changed, 84 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 f97d64c38274d..3e137357b40c6 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
@@ -93,6 +93,8 @@ public class PrivacySettings extends PreferenceFragmentCompat
SettingsUtils.addPreferencesFromResource(this, R.xml.privacy_preferences);
}
+ PrivacySettingsExt.initializePreferences(this);
+
Preference sandboxPreference = findPreference(PREF_PRIVACY_SANDBOX);
if (PrivacySandboxBridge.isPrivacySandboxRestricted()
&& !PrivacySandboxBridge.isRestrictedNoticeEnabled()) {
@@ -191,6 +193,8 @@ public class PrivacySettings extends PreferenceFragmentCompat
SingleCategorySettings.EXTRA_TITLE, thirdPartyCookies.getTitle().toString());
}
+ PrivacySettingsExt.removeUnwantedPreferences(this);
+
updatePreferences();
}
@@ -305,6 +309,8 @@ public class PrivacySettings extends PreferenceFragmentCompat
UserPrefs.get(mProfile).getInteger(COOKIE_CONTROLS_MODE)));
}
+ PrivacySettingsExt.updatePreferences(this);
+
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..00a65cf922353
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/privacy/settings/PrivacySettingsExt.java
@@ -0,0 +1,67 @@
+// 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 LISTENER =
+ (pref, val) -> {
+ PrefService prefService = UserPrefs.get(Profile.getLastUsedRegularProfile());
+ if (pref == null) {
+ return false;
+ }
+ String key = pref.getKey();
+ return true;
+ };
+
+ private static final ChromeManagedPreferenceDelegate DELEGATE =
+ pref -> {
+ PrefService prefService = UserPrefs.get(Profile.getLastUsedRegularProfile());
+ 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) {
+ 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) {
+ ThreadUtils.checkUiThread();
+ PrefService prefService = UserPrefs.get(Profile.getLastUsedRegularProfile());
+ }
+}