From 6dadecacc2479995f63ea592fc25c65d1cd54650 Mon Sep 17 00:00:00 2001 From: Elise Richards Date: Tue, 22 Dec 2020 11:43:04 -0600 Subject: [PATCH] For #15703 and #17133: allow ETP redirect trackers setting to be customized (#17137) * Remove ETP redirect trackers feature flag. Add category to ETP panel view. * Add redirect tracker category to ETP custom settings --- .../java/org/mozilla/fenix/FeatureFlags.kt | 5 ----- .../TrackingProtectionPolicyFactory.kt | 10 ++++++---- .../settings/TrackingProtectionFragment.kt | 13 +++++++++++++ .../TrackingProtectionBlockingFragment.kt | 4 ++-- .../TrackingProtectionPanelView.kt | 15 +++++++++++++-- .../TrackingProtectionStore.kt | 14 ++++++++++++-- .../java/org/mozilla/fenix/utils/Settings.kt | 5 +++++ .../component_tracking_protection_panel.xml | 18 ++++++++++++++++++ .../fragment_tracking_protection_blocking.xml | 1 - app/src/main/res/values/preference_keys.xml | 1 + .../xml/tracking_protection_preferences.xml | 6 ++++++ .../TrackingProtectionPolicyFactoryTest.kt | 10 ++++++---- .../TrackingProtectionPanelInteractorTest.kt | 16 ++++++++++++++++ 13 files changed, 98 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt index 2386c31076..32d1d85d8e 100644 --- a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt +++ b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt @@ -26,11 +26,6 @@ object FeatureFlags { */ const val externalDownloadManager = true - /** - * Enables ETP cookie purging - */ - val etpCookiePurging = Config.channel.isNightlyOrDebug - /** * Enables the Nimbus experiments library, especially the settings toggle to opt-out of * all experiments. diff --git a/app/src/main/java/org/mozilla/fenix/components/TrackingProtectionPolicyFactory.kt b/app/src/main/java/org/mozilla/fenix/components/TrackingProtectionPolicyFactory.kt index bc614aef1a..4dd0a4b005 100644 --- a/app/src/main/java/org/mozilla/fenix/components/TrackingProtectionPolicyFactory.kt +++ b/app/src/main/java/org/mozilla/fenix/components/TrackingProtectionPolicyFactory.kt @@ -7,8 +7,6 @@ package org.mozilla.fenix.components import androidx.annotation.VisibleForTesting import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicyForSessionTypes -import org.mozilla.fenix.Config -import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.utils.Settings /** @@ -49,7 +47,7 @@ class TrackingProtectionPolicyFactory(private val settings: Settings) { return TrackingProtectionPolicy.select( cookiePolicy = getCustomCookiePolicy(), trackingCategories = getCustomTrackingCategories(), - cookiePurging = Config.channel.isNightlyOrDebug + cookiePurging = getCustomCookiePurgingPolicy() ).let { if (settings.blockTrackingContentSelectionInCustomTrackingProtection == "private") { it.forPrivateSessionsOnly() @@ -95,6 +93,10 @@ class TrackingProtectionPolicyFactory(private val settings: Settings) { return categories.toTypedArray() } + + private fun getCustomCookiePurgingPolicy(): Boolean { + return settings.blockRedirectTrackersInCustomTrackingProtection + } } @VisibleForTesting @@ -103,6 +105,6 @@ internal fun TrackingProtectionPolicyForSessionTypes.adaptPolicyToChannel(): Tra trackingCategories = trackingCategories, cookiePolicy = cookiePolicy, strictSocialTrackingProtection = strictSocialTrackingProtection, - cookiePurging = FeatureFlags.etpCookiePurging + cookiePurging = cookiePurging ) } diff --git a/app/src/main/java/org/mozilla/fenix/settings/TrackingProtectionFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/TrackingProtectionFragment.kt index 029183ac5b..66bb347cc4 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/TrackingProtectionFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/TrackingProtectionFragment.kt @@ -41,6 +41,7 @@ class TrackingProtectionFragment : PreferenceFragmentCompat() { private lateinit var customTrackingSelect: DropDownPreference private lateinit var customCryptominers: CheckBoxPreference private lateinit var customFingerprinters: CheckBoxPreference + private lateinit var customRedirectTrackers: CheckBoxPreference override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.tracking_protection_preferences, rootKey) @@ -145,6 +146,9 @@ class TrackingProtectionFragment : PreferenceFragmentCompat() { customFingerprinters = requirePreference(R.string.pref_key_tracking_protection_custom_fingerprinters) + customRedirectTrackers = + requirePreference(R.string.pref_key_tracking_protection_redirect_trackers) + customCookies.onPreferenceChangeListener = object : SharedPreferenceUpdater() { override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean { customCookiesSelect.isVisible = !customCookies.isChecked @@ -196,6 +200,14 @@ class TrackingProtectionFragment : PreferenceFragmentCompat() { } } + customRedirectTrackers.onPreferenceChangeListener = object : SharedPreferenceUpdater() { + override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean { + return super.onPreferenceChange(preference, newValue).also { + updateTrackingProtectionPolicy() + } + } + } + updateCustomOptionsVisibility() return radio @@ -218,5 +230,6 @@ class TrackingProtectionFragment : PreferenceFragmentCompat() { customTrackingSelect.isVisible = isCustomSelected && customTracking.isChecked customCryptominers.isVisible = isCustomSelected customFingerprinters.isVisible = isCustomSelected + customRedirectTrackers.isVisible = isCustomSelected } } diff --git a/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionBlockingFragment.kt b/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionBlockingFragment.kt index bbc8832f46..d071e887ab 100644 --- a/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionBlockingFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionBlockingFragment.kt @@ -10,7 +10,6 @@ import androidx.core.view.isVisible import androidx.fragment.app.Fragment import androidx.navigation.fragment.navArgs import kotlinx.android.synthetic.main.fragment_tracking_protection_blocking.* -import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.R import org.mozilla.fenix.ext.settings import org.mozilla.fenix.ext.showToolbar @@ -23,7 +22,6 @@ class TrackingProtectionBlockingFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - category_redirect_trackers.isVisible = FeatureFlags.etpCookiePurging when (args.protectionMode) { TrackingProtectionMode.STANDARD -> { @@ -41,6 +39,8 @@ class TrackingProtectionBlockingFragment : settings.blockCookiesInCustomTrackingProtection category_tracking_content.isVisible = settings.blockTrackingContentInCustomTrackingProtection + category_redirect_trackers.isVisible = + settings.blockRedirectTrackersInCustomTrackingProtection } } } diff --git a/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionPanelView.kt b/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionPanelView.kt index 624a76526e..ea9be12145 100644 --- a/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionPanelView.kt +++ b/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionPanelView.kt @@ -18,6 +18,7 @@ import androidx.core.view.isVisible import kotlinx.android.extensions.LayoutContainer import kotlinx.android.synthetic.main.component_tracking_protection_panel.* import kotlinx.android.synthetic.main.component_tracking_protection_panel.details_blocking_header +import kotlinx.android.synthetic.main.fragment_tracking_protection_blocking.* import kotlinx.android.synthetic.main.switch_with_description.view.* import mozilla.components.support.ktx.android.net.hostWithoutCommonPrefixes import org.mozilla.fenix.R @@ -28,6 +29,7 @@ import org.mozilla.fenix.trackingprotection.TrackingProtectionCategory.CRYPTOMIN import org.mozilla.fenix.trackingprotection.TrackingProtectionCategory.FINGERPRINTERS import org.mozilla.fenix.trackingprotection.TrackingProtectionCategory.SOCIAL_MEDIA_TRACKERS import org.mozilla.fenix.trackingprotection.TrackingProtectionCategory.TRACKING_CONTENT +import org.mozilla.fenix.trackingprotection.TrackingProtectionCategory.REDIRECT_TRACKERS /** * Interface for the TrackingProtectionPanelViewInteractor. This interface is implemented by objects that want @@ -170,6 +172,9 @@ class TrackingProtectionPanelView( CRYPTOMINERS.name -> { if (cryptominers.isGone) cryptominers_loaded else cryptominers } + REDIRECT_TRACKERS.name -> { + if (redirect_trackers.isGone) redirect_trackers_loaded else redirect_trackers + } else -> null } @@ -181,6 +186,7 @@ class TrackingProtectionPanelView( fingerprinters.isGone = bucketedTrackers.get(FINGERPRINTERS, true).isEmpty() tracking_content.isGone = bucketedTrackers.get(TRACKING_CONTENT, true).isEmpty() cryptominers.isGone = bucketedTrackers.get(CRYPTOMINERS, true).isEmpty() + redirect_trackers.isGone = bucketedTrackers.get(REDIRECT_TRACKERS, true).isEmpty() cross_site_tracking_loaded.isGone = bucketedTrackers.get(CROSS_SITE_TRACKING_COOKIES, false).isEmpty() @@ -189,6 +195,7 @@ class TrackingProtectionPanelView( fingerprinters_loaded.isGone = bucketedTrackers.get(FINGERPRINTERS, false).isEmpty() tracking_content_loaded.isGone = bucketedTrackers.get(TRACKING_CONTENT, false).isEmpty() cryptominers_loaded.isGone = bucketedTrackers.get(CRYPTOMINERS, false).isEmpty() + redirect_trackers_loaded.isGone = bucketedTrackers.get(REDIRECT_TRACKERS, false).isEmpty() } private fun setCategoryClickListeners() { @@ -202,6 +209,7 @@ class TrackingProtectionPanelView( fingerprinters_loaded.setOnClickListener(this) tracking_content_loaded.setOnClickListener(this) cryptominers_loaded.setOnClickListener(this) + redirect_trackers_loaded.setOnClickListener(this) } override fun onClick(v: View) { @@ -263,6 +271,7 @@ class TrackingProtectionPanelView( R.id.cross_site_tracking, R.id.cross_site_tracking_loaded -> CROSS_SITE_TRACKING_COOKIES R.id.tracking_content, R.id.tracking_content_loaded -> TRACKING_CONTENT R.id.cryptominers, R.id.cryptominers_loaded -> CRYPTOMINERS + R.id.redirect_trackers, R.id.redirect_trackers_loaded -> REDIRECT_TRACKERS else -> null } @@ -274,13 +283,15 @@ class TrackingProtectionPanelView( R.id.cross_site_tracking_loaded, R.id.fingerprinters_loaded, R.id.tracking_content_loaded, - R.id.cryptominers_loaded -> true + R.id.cryptominers_loaded, + R.id.redirect_trackers_loaded -> true R.id.social_media_trackers, R.id.fingerprinters, R.id.cross_site_tracking, R.id.tracking_content, - R.id.cryptominers -> false + R.id.cryptominers, + R.id.redirect_trackers -> false else -> false } } diff --git a/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionStore.kt b/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionStore.kt index f83a185327..8e957a5228 100644 --- a/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionStore.kt +++ b/app/src/main/java/org/mozilla/fenix/trackingprotection/TrackingProtectionStore.kt @@ -90,8 +90,18 @@ enum class TrackingProtectionCategory( R.string.etp_cryptominers_title, R.string.etp_cryptominers_description ), - FINGERPRINTERS(R.string.etp_fingerprinters_title, R.string.etp_fingerprinters_description), - TRACKING_CONTENT(R.string.etp_tracking_content_title, R.string.etp_tracking_content_description) + FINGERPRINTERS( + R.string.etp_fingerprinters_title, + R.string.etp_fingerprinters_description + ), + TRACKING_CONTENT( + R.string.etp_tracking_content_title, + R.string.etp_tracking_content_description + ), + REDIRECT_TRACKERS( + R.string.etp_redirect_trackers_title, + R.string.etp_redirect_trackers_description + ) } /** diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index 008f42687e..6ba49e7504 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -466,6 +466,11 @@ class Settings(private val appContext: Context) : PreferencesHolder { true ) + val blockRedirectTrackersInCustomTrackingProtection by booleanPreference( + appContext.getPreferenceKey(R.string.pref_key_tracking_protection_redirect_trackers), + true + ) + val shouldUseFixedTopToolbar: Boolean get() { return touchExplorationIsEnabled || switchServiceIsEnabled diff --git a/app/src/main/res/layout/component_tracking_protection_panel.xml b/app/src/main/res/layout/component_tracking_protection_panel.xml index e363deb9fe..b58da52d59 100644 --- a/app/src/main/res/layout/component_tracking_protection_panel.xml +++ b/app/src/main/res/layout/component_tracking_protection_panel.xml @@ -99,6 +99,15 @@ android:visibility="gone" app:layout_constraintTop_toBottomOf="@id/social_media_trackers" /> + + + + diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index b4cb114dfc..073b48bf5b 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -149,6 +149,7 @@ pref_key_tracking_protection_custom_tracking_content_select pref_key_tracking_protection_custom_cryptominers pref_key_tracking_protection_custom_fingerprinters + pref_key_tracking_protection_redirect_trackers pref_key_tracking_protection_onboarding diff --git a/app/src/main/res/xml/tracking_protection_preferences.xml b/app/src/main/res/xml/tracking_protection_preferences.xml index 226f213d15..f8742e6104 100644 --- a/app/src/main/res/xml/tracking_protection_preferences.xml +++ b/app/src/main/res/xml/tracking_protection_preferences.xml @@ -70,6 +70,12 @@ android:key="@string/pref_key_tracking_protection_custom_fingerprinters" android:layout="@layout/checkbox_left_preference_etp" android:title="@string/preference_enhanced_tracking_protection_custom_fingerprinters" /> +