For #5396: Adds "always launch in private mode" to settings
parent
13146c2b2a
commit
6f3d7b4ee8
|
@ -35,8 +35,8 @@ import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
||||||
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
|
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
|
||||||
import org.mozilla.fenix.browser.browsingmode.DefaultBrowsingModeManager
|
import org.mozilla.fenix.browser.browsingmode.DefaultBrowsingModeManager
|
||||||
import org.mozilla.fenix.components.FenixSnackbar
|
import org.mozilla.fenix.components.FenixSnackbar
|
||||||
import org.mozilla.fenix.components.metrics.Event
|
|
||||||
import org.mozilla.fenix.components.metrics.BreadcrumbsRecorder
|
import org.mozilla.fenix.components.metrics.BreadcrumbsRecorder
|
||||||
|
import org.mozilla.fenix.components.metrics.Event
|
||||||
import org.mozilla.fenix.exceptions.ExceptionsFragmentDirections
|
import org.mozilla.fenix.exceptions.ExceptionsFragmentDirections
|
||||||
import org.mozilla.fenix.ext.alreadyOnDestination
|
import org.mozilla.fenix.ext.alreadyOnDestination
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.speech.RecognizerIntent
|
import android.speech.RecognizerIntent
|
||||||
|
import androidx.annotation.VisibleForTesting
|
||||||
import kotlinx.coroutines.MainScope
|
import kotlinx.coroutines.MainScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.mozilla.fenix.components.metrics.Event
|
import org.mozilla.fenix.components.metrics.Event
|
||||||
|
@ -17,6 +18,7 @@ import org.mozilla.fenix.customtabs.CustomTabActivity
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.ext.metrics
|
import org.mozilla.fenix.ext.metrics
|
||||||
import org.mozilla.fenix.home.intent.StartSearchIntentProcessor
|
import org.mozilla.fenix.home.intent.StartSearchIntentProcessor
|
||||||
|
import org.mozilla.fenix.utils.Settings
|
||||||
|
|
||||||
class IntentReceiverActivity : Activity() {
|
class IntentReceiverActivity : Activity() {
|
||||||
|
|
||||||
|
@ -25,6 +27,7 @@ class IntentReceiverActivity : Activity() {
|
||||||
private var previousIntent: Intent? = null
|
private var previousIntent: Intent? = null
|
||||||
|
|
||||||
@Suppress("ComplexMethod")
|
@Suppress("ComplexMethod")
|
||||||
|
@VisibleForTesting
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
@ -39,9 +42,12 @@ class IntentReceiverActivity : Activity() {
|
||||||
// the HomeActivity.
|
// the HomeActivity.
|
||||||
val intent = intent?.let { Intent(intent) } ?: Intent()
|
val intent = intent?.let { Intent(intent) } ?: Intent()
|
||||||
|
|
||||||
|
val intentProcessor = if (Settings.getInstance(applicationContext).alwaysOpenInPrivateMode)
|
||||||
|
components.intentProcessors.privateIntentProcessor else components.intentProcessors.intentProcessor
|
||||||
|
|
||||||
val intentProcessors = listOf(
|
val intentProcessors = listOf(
|
||||||
components.intentProcessors.customTabIntentProcessor,
|
components.intentProcessors.customTabIntentProcessor,
|
||||||
components.intentProcessors.intentProcessor
|
intentProcessor
|
||||||
)
|
)
|
||||||
|
|
||||||
if (intent.getBooleanExtra(SPEECH_PROCESSING, false)) {
|
if (intent.getBooleanExtra(SPEECH_PROCESSING, false)) {
|
||||||
|
|
|
@ -22,6 +22,7 @@ import androidx.preference.Preference
|
||||||
import androidx.preference.Preference.OnPreferenceClickListener
|
import androidx.preference.Preference.OnPreferenceClickListener
|
||||||
import androidx.preference.PreferenceCategory
|
import androidx.preference.PreferenceCategory
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
|
import androidx.preference.SwitchPreference
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import mozilla.components.concept.sync.AccountObserver
|
import mozilla.components.concept.sync.AccountObserver
|
||||||
import mozilla.components.concept.sync.AuthType
|
import mozilla.components.concept.sync.AuthType
|
||||||
|
@ -44,6 +45,7 @@ import org.mozilla.fenix.R.string.pref_key_delete_browsing_data
|
||||||
import org.mozilla.fenix.R.string.pref_key_delete_browsing_data_on_quit_preference
|
import org.mozilla.fenix.R.string.pref_key_delete_browsing_data_on_quit_preference
|
||||||
import org.mozilla.fenix.R.string.pref_key_help
|
import org.mozilla.fenix.R.string.pref_key_help
|
||||||
import org.mozilla.fenix.R.string.pref_key_language
|
import org.mozilla.fenix.R.string.pref_key_language
|
||||||
|
import org.mozilla.fenix.R.string.pref_key_launch_links_in_private_mode
|
||||||
import org.mozilla.fenix.R.string.pref_key_leakcanary
|
import org.mozilla.fenix.R.string.pref_key_leakcanary
|
||||||
import org.mozilla.fenix.R.string.pref_key_make_default_browser
|
import org.mozilla.fenix.R.string.pref_key_make_default_browser
|
||||||
import org.mozilla.fenix.R.string.pref_key_privacy_link
|
import org.mozilla.fenix.R.string.pref_key_privacy_link
|
||||||
|
@ -248,10 +250,19 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
|
||||||
val makeDefaultBrowserKey = getPreferenceKey(pref_key_make_default_browser)
|
val makeDefaultBrowserKey = getPreferenceKey(pref_key_make_default_browser)
|
||||||
val leakKey = getPreferenceKey(pref_key_leakcanary)
|
val leakKey = getPreferenceKey(pref_key_leakcanary)
|
||||||
val debuggingKey = getPreferenceKey(pref_key_remote_debugging)
|
val debuggingKey = getPreferenceKey(pref_key_remote_debugging)
|
||||||
|
val preferenceAlwaysOpenInPrivateModeKey = getPreferenceKey(
|
||||||
|
pref_key_launch_links_in_private_mode
|
||||||
|
)
|
||||||
|
|
||||||
val preferenceMakeDefaultBrowser = findPreference<Preference>(makeDefaultBrowserKey)
|
val preferenceMakeDefaultBrowser = findPreference<Preference>(makeDefaultBrowserKey)
|
||||||
val preferenceLeakCanary = findPreference<Preference>(leakKey)
|
val preferenceLeakCanary = findPreference<Preference>(leakKey)
|
||||||
val preferenceRemoteDebugging = findPreference<Preference>(debuggingKey)
|
val preferenceRemoteDebugging = findPreference<Preference>(debuggingKey)
|
||||||
|
val preferenceAlwaysOpenInPrivateMode = findPreference<SwitchPreference>(preferenceAlwaysOpenInPrivateModeKey)
|
||||||
|
|
||||||
|
preferenceAlwaysOpenInPrivateMode?.setOnPreferenceClickListener {
|
||||||
|
requireContext().settings.alwaysOpenInPrivateMode = !requireContext().settings.alwaysOpenInPrivateMode
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
preferenceMakeDefaultBrowser?.onPreferenceClickListener =
|
preferenceMakeDefaultBrowser?.onPreferenceClickListener =
|
||||||
getClickListenerForMakeDefaultBrowser()
|
getClickListenerForMakeDefaultBrowser()
|
||||||
|
|
|
@ -80,6 +80,11 @@ class Settings private constructor(
|
||||||
default = false
|
default = false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var alwaysOpenInPrivateMode by booleanPreference(
|
||||||
|
appContext.getPreferenceKey(R.string.pref_key_launch_links_in_private_mode),
|
||||||
|
default = false
|
||||||
|
)
|
||||||
|
|
||||||
var defaultSearchEngineName by stringPreference(
|
var defaultSearchEngineName by stringPreference(
|
||||||
appContext.getPreferenceKey(R.string.pref_key_search_engine),
|
appContext.getPreferenceKey(R.string.pref_key_search_engine),
|
||||||
default = ""
|
default = ""
|
||||||
|
|
|
@ -96,6 +96,10 @@
|
||||||
<string name="pref_key_tracking_protection_standard" translatable="false">pref_key_tracking_protection_standard</string>
|
<string name="pref_key_tracking_protection_standard" translatable="false">pref_key_tracking_protection_standard</string>
|
||||||
<string name="pref_key_tracking_protection_strict" translatable="false">pref_key_tracking_protection_strict</string>
|
<string name="pref_key_tracking_protection_strict" translatable="false">pref_key_tracking_protection_strict</string>
|
||||||
<string name="pref_key_tracking_protection_onboarding" translatable="false">pref_key_tracking_protection_onboarding</string>
|
<string name="pref_key_tracking_protection_onboarding" translatable="false">pref_key_tracking_protection_onboarding</string>
|
||||||
|
|
||||||
|
<!-- Privacy Settings -->
|
||||||
|
<string name="pref_key_launch_links_in_private_mode" translatable="false">pref_key_launch_links_in_private_mode</string>
|
||||||
|
|
||||||
<!-- Quick Action Sheet -->
|
<!-- Quick Action Sheet -->
|
||||||
<string name="pref_key_bounce_quick_action" translatable="false">pref_key_bounce_quick_action</string>
|
<string name="pref_key_bounce_quick_action" translatable="false">pref_key_bounce_quick_action</string>
|
||||||
<string name="pref_key_reader_mode_notification" translatable="false">pref_key_reader_mode_notification</string>
|
<string name="pref_key_reader_mode_notification" translatable="false">pref_key_reader_mode_notification</string>
|
||||||
|
|
|
@ -142,6 +142,8 @@
|
||||||
<string name="preferences_category_privacy">Privacy</string>
|
<string name="preferences_category_privacy">Privacy</string>
|
||||||
<!-- Preference for advanced site permissions -->
|
<!-- Preference for advanced site permissions -->
|
||||||
<string name="preferences_site_permissions">Site permissions</string>
|
<string name="preferences_site_permissions">Site permissions</string>
|
||||||
|
<!-- Preference for launching links in a private tab-->
|
||||||
|
<string name="preferences_launch_links_in_private_mode">Launch links in a private tab</string>
|
||||||
<!-- Preference for adding private browsing shortcut -->
|
<!-- Preference for adding private browsing shortcut -->
|
||||||
<string name="preferences_add_private_browsing_shortcut">Add private browsing shortcut</string>
|
<string name="preferences_add_private_browsing_shortcut">Add private browsing shortcut</string>
|
||||||
<!-- Preference for accessibility -->
|
<!-- Preference for accessibility -->
|
||||||
|
|
|
@ -58,6 +58,10 @@
|
||||||
android:icon="@drawable/ic_tracking_protection_enabled"
|
android:icon="@drawable/ic_tracking_protection_enabled"
|
||||||
android:key="@string/pref_key_tracking_protection_settings"
|
android:key="@string/pref_key_tracking_protection_settings"
|
||||||
android:title="@string/preference_enhanced_tracking_protection" />
|
android:title="@string/preference_enhanced_tracking_protection" />
|
||||||
|
<androidx.preference.SwitchPreference
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="@string/pref_key_launch_links_in_private_mode"
|
||||||
|
android:title="@string/preferences_launch_links_in_private_mode" />
|
||||||
<androidx.preference.Preference
|
<androidx.preference.Preference
|
||||||
android:icon="@drawable/ic_private_browsing"
|
android:icon="@drawable/ic_private_browsing"
|
||||||
android:key="@string/pref_key_add_private_browsing_shortcut"
|
android:key="@string/pref_key_add_private_browsing_shortcut"
|
||||||
|
|
|
@ -55,6 +55,25 @@ class SettingsTest {
|
||||||
assertFalse(settings.usePrivateMode)
|
assertFalse(settings.usePrivateMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun alwaysOpenInPrivateMode() {
|
||||||
|
// When just created
|
||||||
|
// Then
|
||||||
|
assertFalse(settings.alwaysOpenInPrivateMode)
|
||||||
|
|
||||||
|
// When
|
||||||
|
settings.alwaysOpenInPrivateMode = true
|
||||||
|
|
||||||
|
// Then
|
||||||
|
assertTrue(settings.alwaysOpenInPrivateMode)
|
||||||
|
|
||||||
|
// When
|
||||||
|
settings.alwaysOpenInPrivateMode = false
|
||||||
|
|
||||||
|
// Then
|
||||||
|
assertFalse(settings.usePrivateMode)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun clearDataOnQuit() {
|
fun clearDataOnQuit() {
|
||||||
// When just created
|
// When just created
|
||||||
|
|
Loading…
Reference in New Issue