diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index 4a4f8fd10e..574970ca6a 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -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() { diff --git a/app/src/main/java/org/mozilla/fenix/components/Core.kt b/app/src/main/java/org/mozilla/fenix/components/Core.kt index dcd3e8f571..53948d203d 100644 --- a/app/src/main/java/org/mozilla/fenix/components/Core.kt +++ b/app/src/main/java/org/mozilla/fenix/components/Core.kt @@ -140,7 +140,7 @@ class Core( cookieBannerHandlingModePrivateBrowsing = context.settings().getCookieBannerHandling(), cookieBannerHandlingMode = context.settings().getCookieBannerHandling(), cookieBannerHandlingDetectOnlyMode = context.settings() - .shouldEnabledCookieBannerDetectOnlyMode(), + .shouldShowCookieBannerReEngagementDialog(), ) GeckoEngine( diff --git a/app/src/main/java/org/mozilla/fenix/settings/CookieBannersFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/CookieBannersFragment.kt index 00461d2817..7b8853029b 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/CookieBannersFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/CookieBannersFragment.kt @@ -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) diff --git a/app/src/main/java/org/mozilla/fenix/settings/quicksettings/protections/cookiebanners/dialog/CookieBannerReEngagementDialog.kt b/app/src/main/java/org/mozilla/fenix/settings/quicksettings/protections/cookiebanners/dialog/CookieBannerReEngagementDialog.kt index 32639a9a66..ac32e6c5a1 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/quicksettings/protections/cookiebanners/dialog/CookieBannerReEngagementDialog.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/quicksettings/protections/cookiebanners/dialog/CookieBannerReEngagementDialog.kt @@ -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 } diff --git a/app/src/main/java/org/mozilla/fenix/settings/quicksettings/protections/cookiebanners/dialog/CookieBannerReEngagementDialogUtils.kt b/app/src/main/java/org/mozilla/fenix/settings/quicksettings/protections/cookiebanners/dialog/CookieBannerReEngagementDialogUtils.kt index 25cb29667f..9fabb22ef4 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/quicksettings/protections/cookiebanners/dialog/CookieBannerReEngagementDialogUtils.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/quicksettings/protections/cookiebanners/dialog/CookieBannerReEngagementDialogUtils.kt @@ -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 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 aa09c05496..ef87de482f 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -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,