Verified Commit b019eb25 authored by Alex Catarineu's avatar Alex Catarineu Committed by ma1
Browse files

TB 40087 [android]: Implement a switch for spoof English.

parent 86144f34
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1446,6 +1446,15 @@ class GeckoEngine(
            get() = runtime.settings.userCharacteristicPingCurrentVersion
            set(value) { runtime.settings.setUserCharacteristicPingCurrentVersion(value) }

        override var spoofEnglish: Boolean
            get() = runtime.settings.spoofEnglish
            set(value) {
                value.let {
                    runtime.settings.spoofEnglish = it
                    localeUpdater.updateValue()
                }
            }

        override var webContentIsolationStrategy: WebContentIsolationStrategy?
            get() = runtime.settings.webContentIsolationStrategy?.intoWebContentIsolationStrategy()
            set(value) {
@@ -1518,6 +1527,7 @@ class GeckoEngine(
            this.fdlibmMathEnabled = it.fdlibmMathEnabled
            this.emailTrackerBlockingPrivateBrowsing = it.emailTrackerBlockingPrivateBrowsing
            this.userCharacteristicPingCurrentVersion = it.userCharacteristicPingCurrentVersion
            this.spoofEnglish = it.spoofEnglish
            this.webContentIsolationStrategy = it.webContentIsolationStrategy
            this.fetchPriorityEnabled = it.fetchPriorityEnabled
            this.parallelMarkingEnabled = it.parallelMarkingEnabled
+3 −0
Original line number Diff line number Diff line
@@ -300,6 +300,8 @@ abstract class Settings {
     */
    open var userCharacteristicPingCurrentVersion: Int by UnsupportedSetting()

    open var spoofEnglish: Boolean by UnsupportedSetting()

    /**
     * Setting to control whether the desktop user agent is used.
     */
@@ -409,6 +411,7 @@ data class DefaultSettings(
    override var queryParameterStrippingStripList: String = "",
    override var emailTrackerBlockingPrivateBrowsing: Boolean = false,
    override var userCharacteristicPingCurrentVersion: Int = 0,
    override var spoofEnglish: Boolean = false,
    override var webContentIsolationStrategy: WebContentIsolationStrategy? =
        WebContentIsolationStrategy.ISOLATE_HIGH_VALUE,
    override var fetchPriorityEnabled: Boolean = true,
+1 −0
Original line number Diff line number Diff line
@@ -186,6 +186,7 @@ class Core(
            cookieBannerHandlingGlobalRulesSubFrames = context.settings().shouldEnableCookieBannerGlobalRulesSubFrame,
            emailTrackerBlockingPrivateBrowsing = false,
            userCharacteristicPingCurrentVersion = FxNimbus.features.userCharacteristics.value().currentVersion,
            spoofEnglish = context.settings().spoofEnglish,
            getDesktopMode = {
                store.state.desktopMode
            },
+5 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.support.locale.LocaleManager
import mozilla.components.support.locale.LocaleUseCases
import org.mozilla.fenix.nimbus.FxNimbus
import org.mozilla.fenix.ext.components
import java.util.Locale

interface LocaleSettingsController {
@@ -83,5 +84,9 @@ class DefaultLocaleSettingsController(
        config.setLocale(locale)
        config.setLayoutDirection(locale)
        resources.updateConfiguration(config, resources.displayMetrics)
        // A slightly hacky way of triggering a `runtime.settings.locales` update,
        // so that the locales are updated in GeckoView.
        val spoofEnglish = context.components.core.engine.settings.spoofEnglish
        context.components.core.engine.settings.spoofEnglish = spoofEnglish
    }
}
+14 −1
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.components.StoreProvider
import org.mozilla.fenix.databinding.FragmentLocaleSettingsBinding
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.showToolbar

class LocaleSettingsFragment : Fragment(), MenuProvider {
@@ -46,6 +48,8 @@ class LocaleSettingsFragment : Fragment(), MenuProvider {
        _binding = FragmentLocaleSettingsBinding.inflate(inflater, container, false)
        val view = binding.root

        bindEnableSwitch()

        val browserStore = requireContext().components.core.store
        val localeUseCase = LocaleUseCases(browserStore)

@@ -62,10 +66,19 @@ class LocaleSettingsFragment : Fragment(), MenuProvider {
                localeUseCase = localeUseCase,
            ),
        )
        localeView = LocaleSettingsView(binding.root, interactor)
        localeView = LocaleSettingsView(binding.localeContainer, interactor)
        return view
    }

    private fun bindEnableSwitch() {
        val switch = binding.enableSwitch
        switch.isChecked = requireComponents.core.engine.settings.spoofEnglish
        switch.setOnCheckedChangeListener { _, isChecked ->
            context?.settings()?.spoofEnglish = isChecked
            requireComponents.core.engine.settings.spoofEnglish = isChecked
        }
    }

    override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
        inflater.inflate(R.menu.languages_list, menu)
        val searchItem = menu.findItem(R.id.search)
Loading