Commit 904425c3 authored by Matthew Finkel's avatar Matthew Finkel Committed by Pier Angelo Vendrame
Browse files

TB 40026 [android]: Implement Security Level settings on Android.

Originally, fenix#40026.
parent 7b11c84c
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -1863,6 +1863,12 @@ class GeckoEngine(
                value?.let { runtime.settings.setBaselineFingerprintingProtectionOverrides(it) }
            }

        override var torSecurityLevel: Int
            get() = runtime.settings.torSecurityLevel
            set(value) {
                runtime.settings.torSecurityLevel = value
            }

        override var spoofEnglish: Boolean
            get() = runtime.settings.spoofEnglish
            set(value) {
@@ -2028,6 +2034,7 @@ class GeckoEngine(
            this.userCharacteristicPingCurrentVersion = it.userCharacteristicPingCurrentVersion
            this.baselineFingerprintingProtection = it.baselineFingerprintingProtection
            this.baselineFingerprintingProtectionOverrides = it.baselineFingerprintingProtectionOverrides
            this.torSecurityLevel = it.torSecurityLevel
            this.spoofEnglish = it.spoofEnglish
            this.webContentIsolationStrategy = it.webContentIsolationStrategy
            this.fetchPriorityEnabled = it.fetchPriorityEnabled
+12 −0
Original line number Diff line number Diff line
@@ -318,6 +318,17 @@ abstract class Settings {
     */
    open var userCharacteristicPingCurrentVersion: Int by UnsupportedSetting()

    /**
     * Setting to control the current security level
     *
     * 4 -> STANDARD
     *
     * 2 -> SAFER
     *
     * 1 -> SAFEST
     */
    open var torSecurityLevel: Int by UnsupportedSetting()

    open var spoofEnglish: Boolean by UnsupportedSetting()

    /**
@@ -506,6 +517,7 @@ data class DefaultSettings(
    override var useContentBlockingDatabase: Boolean = false,
    override var emailTrackerBlockingPrivateBrowsing: Boolean = false,
    override var userCharacteristicPingCurrentVersion: Int = 0,
    override var torSecurityLevel: Int = 4,
    override var spoofEnglish: Boolean = false,
    override var webContentIsolationStrategy: WebContentIsolationStrategy? =
        WebContentIsolationStrategy.ISOLATE_HIGH_VALUE,
+1 −0
Original line number Diff line number Diff line
@@ -200,6 +200,7 @@ class Core(
            cookieBannerHandlingGlobalRulesSubFrames = context.settings().shouldEnableCookieBannerGlobalRulesSubFrame,
            emailTrackerBlockingPrivateBrowsing = false,
            userCharacteristicPingCurrentVersion = FxNimbus.features.userCharacteristics.value().currentVersion,
            torSecurityLevel = context.settings().torSecurityLevel,
            spoofEnglish = context.settings().spoofEnglish,
            getDesktopMode = {
                store.state.desktopMode
+20 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.Toast
@@ -82,6 +83,7 @@ import org.mozilla.fenix.perf.ProfilerViewModelFactory
import org.mozilla.fenix.settings.account.AccountUiView
import org.mozilla.fenix.snackbar.FenixSnackbarDelegate
import org.mozilla.fenix.snackbar.SnackbarBinding
import org.mozilla.fenix.tor.TorSecurityLevel
import org.mozilla.fenix.utils.Settings
import java.lang.ref.WeakReference
import kotlin.system.exitProcess
@@ -432,6 +434,10 @@ class SettingsFragment : PreferenceFragmentCompat(), SystemInsetsPaddedFragment
                SettingsFragmentDirections.actionSettingsFragmentToPrivateBrowsingFragment()
            }

            resources.getString(R.string.pref_key_tor_security_level) -> {
                SettingsFragmentDirections.actionSettingsFragmentToTorSecurityLevelFragment()
            }

            resources.getString(R.string.pref_key_https_only_settings) -> {
                SettingsFragmentDirections.actionSettingsFragmentToHttpsOnlyFragment()
            }
@@ -673,6 +679,7 @@ class SettingsFragment : PreferenceFragmentCompat(), SystemInsetsPaddedFragment
            FeatureFlags.customExtensionCollectionFeature,
        )
        setupGeckoLogsPreference(settings)
        setupSecurityLevelPreference()
        setupHttpsOnlyPreferences(settings)
        setupIPProtectionPreferences(settings)
        setupNotificationPreference(
@@ -914,6 +921,19 @@ class SettingsFragment : PreferenceFragmentCompat(), SystemInsetsPaddedFragment
        }
    }

    @VisibleForTesting
    internal fun setupSecurityLevelPreference() {
        val securityLevelPreference =
            requirePreference<Preference>(R.string.pref_key_tor_security_level)
        securityLevelPreference.summary =
            when (requireContext().settings().torSecurityLevel) {
                TorSecurityLevel.STANDARD.level -> getString(R.string.tor_security_level_standard)
                TorSecurityLevel.SAFER.level    -> getString(R.string.tor_security_level_safer)
                TorSecurityLevel.SAFEST.level   -> getString(R.string.tor_security_level_safest)
                else -> throw Exception("Unexpected TorSecurityLevel of ${requireContext().settings().torSecurityLevel}")
            }
    }

    private fun updateProfilerUI(profilerStatus: Boolean) {
        if (profilerStatus) {
            findPreference<Preference>(getPreferenceKey(R.string.pref_key_start_profiler))?.title =
+13 −0
Original line number Diff line number Diff line
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.fenix.tor

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
enum class TorSecurityLevel(val level: Int) : Parcelable {
    STANDARD(4), SAFER(2), SAFEST(1)
}
Loading