Bug 1816186 - Use detect-only just when we can show the re-engagement dialog

fenix/112.0
Arturo Mejia 1 year ago committed by mergify[bot]
parent b275c973a8
commit 4d87860b2e

@ -132,6 +132,7 @@ import org.mozilla.fenix.settings.TrackingProtectionFragmentDirections
import org.mozilla.fenix.settings.about.AboutFragmentDirections
import org.mozilla.fenix.settings.logins.fragment.LoginDetailFragmentDirections
import org.mozilla.fenix.settings.logins.fragment.SavedLoginsAuthFragmentDirections
import org.mozilla.fenix.settings.quicksettings.protections.cookiebanners.dialog.CookieBannerReEngagementDialogUtils
import org.mozilla.fenix.settings.search.AddSearchEngineFragmentDirections
import org.mozilla.fenix.settings.search.EditCustomSearchEngineFragmentDirections
import org.mozilla.fenix.settings.studies.StudiesFragmentDirections
@ -445,6 +446,10 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
// and the user changes the system language
// More details here: https://github.com/mozilla-mobile/fenix/pull/27793#discussion_r1029892536
components.core.store.dispatch(SearchAction.RefreshSearchEnginesAction)
CookieBannerReEngagementDialogUtils.tryToEnableDetectOnlyModeIfNeeded(
components.settings,
components.core.engine.settings,
)
}
override fun onStart() {

@ -140,7 +140,7 @@ class Core(
cookieBannerHandlingModePrivateBrowsing = context.settings().getCookieBannerHandling(),
cookieBannerHandlingMode = context.settings().getCookieBannerHandling(),
cookieBannerHandlingDetectOnlyMode = context.settings()
.shouldEnabledCookieBannerDetectOnlyMode(),
.shouldShowCookieBannerReEngagementDialog(),
)
GeckoEngine(

@ -53,7 +53,7 @@ class CookieBannersFragment : PreferenceFragmentCompat() {
getEngineSettings().cookieBannerHandlingModePrivateBrowsing = mode
getEngineSettings().cookieBannerHandlingMode = mode
getEngineSettings().cookieBannerHandlingDetectOnlyMode =
requireContext().settings().shouldEnabledCookieBannerDetectOnlyMode()
requireContext().settings().shouldShowCookieBannerReEngagementDialog()
CookieBanners.settingChanged.record(CookieBanners.SettingChangedExtra(metricTag))
requireContext().components.useCases.sessionUseCases.reload()
return super.onPreferenceChange(preference, newValue)

@ -62,13 +62,12 @@ class CookieBannerReEngagementDialog : DialogFragment() {
dismiss()
},
onNotNowButtonClicked = {
disabledCookieBannerHandlingDetectOnlyMode()
CookieBanners.notNowReEngagementDialog.record(NoExtras())
dismiss()
},
onCloseButtonClicked = {
getEngineSettings().cookieBannerHandlingDetectOnlyMode = false
getEngineSettings().cookieBannerHandlingModePrivateBrowsing = DISABLED
getEngineSettings().cookieBannerHandlingMode = DISABLED
disabledCookieBannerHandlingDetectOnlyMode()
requireContext().settings().userOptOutOfReEngageCookieBannerDialog = true
CookieBanners.optOutReEngagementDialog.record(NoExtras())
dismiss()
@ -78,6 +77,12 @@ class CookieBannerReEngagementDialog : DialogFragment() {
}
}
private fun disabledCookieBannerHandlingDetectOnlyMode() {
getEngineSettings().cookieBannerHandlingDetectOnlyMode = false
getEngineSettings().cookieBannerHandlingModePrivateBrowsing = DISABLED
getEngineSettings().cookieBannerHandlingMode = DISABLED
}
private fun getEngineSettings(): Settings {
return requireContext().components.core.engine.settings
}

@ -6,6 +6,7 @@ package org.mozilla.fenix.settings.quicksettings.protections.cookiebanners.dialo
import android.content.Context
import androidx.navigation.NavController
import mozilla.components.concept.engine.EngineSession.CookieBannerHandlingMode.REJECT_ALL
import mozilla.components.concept.engine.EngineSession.CookieBannerHandlingStatus
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.BrowserFragmentDirections
@ -13,6 +14,7 @@ import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.nimbus.CookieBannersSection
import org.mozilla.fenix.nimbus.FxNimbus
import org.mozilla.fenix.utils.Settings
import mozilla.components.concept.engine.Settings as EngineSettings
private const val CONTROL_VARIANT = 0
private const val VARIANT_ONE = 1
@ -87,8 +89,13 @@ object CookieBannerReEngagementDialogUtils {
status: CookieBannerHandlingStatus,
navController: NavController,
) {
if (status == CookieBannerHandlingStatus.DETECTED &&
settings.shouldCookieBannerReEngagementDialog()
val tcpCFRAlreadyShown = if (settings.enabledTotalCookieProtectionCFR) {
!settings.shouldShowTotalCookieProtectionCFR
} else {
true
}
if (tcpCFRAlreadyShown && status == CookieBannerHandlingStatus.DETECTED &&
settings.shouldShowCookieBannerReEngagementDialog()
) {
settings.lastInteractionWithReEngageCookieBannerDialogInMs = System.currentTimeMillis()
settings.cookieBannerDetectedPreviously = true
@ -98,6 +105,21 @@ object CookieBannerReEngagementDialogUtils {
}
}
/**
* Tries to enable the detect only mode after the time limit for the cookie banner has been
* expired.
*/
fun tryToEnableDetectOnlyModeIfNeeded(
settings: Settings,
engineSettings: EngineSettings,
) {
if (settings.shouldShowCookieBannerReEngagementDialog()) {
engineSettings.cookieBannerHandlingDetectOnlyMode = true
engineSettings.cookieBannerHandlingModePrivateBrowsing = REJECT_ALL
engineSettings.cookieBannerHandlingMode = REJECT_ALL
}
}
/**
* Data class for cookie banner dialog variant
* @property title of the dialog

@ -586,10 +586,10 @@ class Settings(private val appContext: Context) : PreferencesHolder {
* Indicates if we should should show the cookie banner dialog that invites the user to turn-on
* the setting.
*/
fun shouldCookieBannerReEngagementDialog(): Boolean {
fun shouldShowCookieBannerReEngagementDialog(): Boolean {
val shouldShowDialog =
shouldShowCookieBannerUI && !userOptOutOfReEngageCookieBannerDialog && !shouldUseCookieBanner
return if (!shouldShowTotalCookieProtectionCFR && shouldShowDialog) {
return if (shouldShowDialog) {
!cookieBannerDetectedPreviously ||
timeNowInMillis() - lastInteractionWithReEngageCookieBannerDialogInMs >= timerForCookieBannerDialog
} else {
@ -704,7 +704,10 @@ class Settings(private val appContext: Context) : PreferencesHolder {
val enabledTotalCookieProtection: Boolean
get() = Config.channel.isNightlyOrDebug || mr2022Sections[Mr2022Section.TCP_FEATURE] == true
private val enabledTotalCookieProtectionCFR: Boolean
/**
* Indicates if the total cookie protection CRF feature is enabled.
*/
val enabledTotalCookieProtectionCFR: Boolean
get() = Config.channel.isNightlyOrDebug || mr2022Sections[Mr2022Section.TCP_CFR] == true
/**
@ -1557,7 +1560,7 @@ class Settings(private val appContext: Context) : PreferencesHolder {
fun getCookieBannerHandling(): CookieBannerHandlingMode {
return when (shouldUseCookieBanner) {
true -> CookieBannerHandlingMode.REJECT_ALL
false -> if (shouldEnabledCookieBannerDetectOnlyMode()) {
false -> if (shouldShowCookieBannerReEngagementDialog()) {
CookieBannerHandlingMode.REJECT_ALL
} else {
CookieBannerHandlingMode.DISABLED
@ -1565,18 +1568,6 @@ class Settings(private val appContext: Context) : PreferencesHolder {
}
}
/**
* Indicates if the cookie banner detect only mode should be enabled.
*/
fun shouldEnabledCookieBannerDetectOnlyMode(): Boolean {
val tcpCFRAlreadyShown = if (enabledTotalCookieProtectionCFR) {
!userOptOutOfReEngageCookieBannerDialog
} else {
true
}
return shouldShowCookieBannerUI && tcpCFRAlreadyShown && !shouldUseCookieBanner
}
var setAsDefaultGrowthSent by booleanPreference(
key = appContext.getPreferenceKey(R.string.pref_key_growth_set_as_default),
default = false,

Loading…
Cancel
Save