1
0
Fork 0

For #5396: Adds "always launch in private mode" to settings

master
Sawyer Blatz 2019-09-18 09:47:30 -07:00 committed by Emily Kager
parent 13146c2b2a
commit 6f3d7b4ee8
8 changed files with 53 additions and 2 deletions

View File

@ -35,8 +35,8 @@ import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
import org.mozilla.fenix.browser.browsingmode.DefaultBrowsingModeManager
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.Event
import org.mozilla.fenix.exceptions.ExceptionsFragmentDirections
import org.mozilla.fenix.ext.alreadyOnDestination
import org.mozilla.fenix.ext.components

View File

@ -8,6 +8,7 @@ import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.speech.RecognizerIntent
import androidx.annotation.VisibleForTesting
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
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.metrics
import org.mozilla.fenix.home.intent.StartSearchIntentProcessor
import org.mozilla.fenix.utils.Settings
class IntentReceiverActivity : Activity() {
@ -25,6 +27,7 @@ class IntentReceiverActivity : Activity() {
private var previousIntent: Intent? = null
@Suppress("ComplexMethod")
@VisibleForTesting
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -39,9 +42,12 @@ class IntentReceiverActivity : Activity() {
// the HomeActivity.
val intent = intent?.let { Intent(intent) } ?: Intent()
val intentProcessor = if (Settings.getInstance(applicationContext).alwaysOpenInPrivateMode)
components.intentProcessors.privateIntentProcessor else components.intentProcessors.intentProcessor
val intentProcessors = listOf(
components.intentProcessors.customTabIntentProcessor,
components.intentProcessors.intentProcessor
intentProcessor
)
if (intent.getBooleanExtra(SPEECH_PROCESSING, false)) {

View File

@ -22,6 +22,7 @@ import androidx.preference.Preference
import androidx.preference.Preference.OnPreferenceClickListener
import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import kotlinx.coroutines.launch
import mozilla.components.concept.sync.AccountObserver
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_help
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_make_default_browser
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 leakKey = getPreferenceKey(pref_key_leakcanary)
val debuggingKey = getPreferenceKey(pref_key_remote_debugging)
val preferenceAlwaysOpenInPrivateModeKey = getPreferenceKey(
pref_key_launch_links_in_private_mode
)
val preferenceMakeDefaultBrowser = findPreference<Preference>(makeDefaultBrowserKey)
val preferenceLeakCanary = findPreference<Preference>(leakKey)
val preferenceRemoteDebugging = findPreference<Preference>(debuggingKey)
val preferenceAlwaysOpenInPrivateMode = findPreference<SwitchPreference>(preferenceAlwaysOpenInPrivateModeKey)
preferenceAlwaysOpenInPrivateMode?.setOnPreferenceClickListener {
requireContext().settings.alwaysOpenInPrivateMode = !requireContext().settings.alwaysOpenInPrivateMode
true
}
preferenceMakeDefaultBrowser?.onPreferenceClickListener =
getClickListenerForMakeDefaultBrowser()

View File

@ -80,6 +80,11 @@ class Settings private constructor(
default = false
)
var alwaysOpenInPrivateMode by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_launch_links_in_private_mode),
default = false
)
var defaultSearchEngineName by stringPreference(
appContext.getPreferenceKey(R.string.pref_key_search_engine),
default = ""

View File

@ -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_strict" translatable="false">pref_key_tracking_protection_strict</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 -->
<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>

View File

@ -142,6 +142,8 @@
<string name="preferences_category_privacy">Privacy</string>
<!-- Preference for advanced site permissions -->
<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 -->
<string name="preferences_add_private_browsing_shortcut">Add private browsing shortcut</string>
<!-- Preference for accessibility -->

View File

@ -58,6 +58,10 @@
android:icon="@drawable/ic_tracking_protection_enabled"
android:key="@string/pref_key_tracking_protection_settings"
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
android:icon="@drawable/ic_private_browsing"
android:key="@string/pref_key_add_private_browsing_shortcut"

View File

@ -55,6 +55,25 @@ class SettingsTest {
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
fun clearDataOnQuit() {
// When just created