Add setting for adblock
Change-Id: Idde962722038742526c272e23fd52501be16010b
diff --git a/res/values/leaf_strings.xml b/res/values/leaf_strings.xml
index 01831c2..dd34818 100644
--- a/res/values/leaf_strings.xml
+++ b/res/values/leaf_strings.xml
@@ -20,6 +20,10 @@
<string name="leaf_version">LeafOS version</string>
<string name="leaf_vendor_security_patch">Vendor security patch level</string>
+ <!-- AdBlock -->
+ <string name="enable_adblock">Enable AdBlock</string>
+ <string name="enable_adblock_summary">Blocks various ads and trackers system-wide.</string>
+
<!-- Back gesture height -->
<string name="back_height_low_label">Full</string>
<string name="back_height_high_label">Bottom</string>
diff --git a/res/xml/more_security_privacy_settings.xml b/res/xml/more_security_privacy_settings.xml
index 5cd60f0..01b08d9 100644
--- a/res/xml/more_security_privacy_settings.xml
+++ b/res/xml/more_security_privacy_settings.xml
@@ -93,6 +93,13 @@
settings:controller=
"com.android.settings.sound.MediaControlsLockScreenPreferenceController" />
+ <!-- AdBlock -->
+ <SwitchPreference
+ android:key="adblock_enabled"
+ android:title="@string/enable_adblock"
+ android:summary="@string/enable_adblock_summary"
+ settings:controller="com.android.settings.privacy.AdBlockPreferenceController"/>
+
<!-- Content Capture -->
<!-- NOTE: content capture has a different preference, depending whether or not the
ContentCaptureService implementations defines a custom settings activitiy on its manifest.
diff --git a/res/xml/privacy_dashboard_settings.xml b/res/xml/privacy_dashboard_settings.xml
index 551501b..0eb6dcc 100644
--- a/res/xml/privacy_dashboard_settings.xml
+++ b/res/xml/privacy_dashboard_settings.xml
@@ -155,4 +155,11 @@
android:summary="@string/show_clip_access_notification_summary"
settings:controller="com.android.settings.privacy.ShowClipAccessNotificationPreferenceController"/>
+ <!-- AdBlock -->
+ <SwitchPreference
+ android:key="adblock_enabled"
+ android:title="@string/enable_adblock"
+ android:summary="@string/enable_adblock_summary"
+ settings:controller="com.android.settings.privacy.AdBlockPreferenceController"/>
+
</PreferenceScreen>
diff --git a/src/com/android/settings/privacy/AdBlockPreferenceController.java b/src/com/android/settings/privacy/AdBlockPreferenceController.java
new file mode 100644
index 0000000..0de5ab8
--- /dev/null
+++ b/src/com/android/settings/privacy/AdBlockPreferenceController.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2023 The LeafOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.privacy;
+
+import android.content.Context;
+import android.os.SystemProperties;
+
+import androidx.preference.Preference;
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.R;
+import com.android.settings.core.TogglePreferenceController;
+
+public class AdBlockPreferenceController extends TogglePreferenceController implements
+ Preference.OnPreferenceChangeListener {
+
+ private static final String PROP_ADBLOCK_ENABLED = "persist.sys.adblock_enabled";
+ private static final String PROP_ADBLOCK_STATUS = "sys.adblock_status";
+
+ private SwitchPreference mPreference;
+
+ public AdBlockPreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ mPreference = (SwitchPreference)preference;
+ super.updateState(preference);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public boolean isSliceable() {
+ return mPreference != null;
+ }
+
+ @Override
+ public boolean isPublicSlice() {
+ return true;
+ }
+
+ @Override
+ public int getSliceHighlightMenuRes() {
+ return R.string.menu_key_display;
+ }
+
+ @Override
+ public boolean isChecked() {
+ return SystemProperties.getBoolean(PROP_ADBLOCK_ENABLED, false);
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ if (!isChecked) {
+ SystemProperties.set(PROP_ADBLOCK_STATUS, "stopped");
+ }
+ SystemProperties.set(PROP_ADBLOCK_ENABLED, isChecked ? "true" : "false");
+ return true;
+ }
+}