Skip to content

Commit

Permalink
For mozilla-mobile#5396: Adds "always launch in private mode" to sett…
Browse files Browse the repository at this point in the history
…ings
  • Loading branch information
sblatz committed Sep 19, 2019
1 parent 2db2d9c commit e672e0f
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/org/mozilla/fenix/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {

Expand All @@ -25,6 +27,7 @@ class IntentReceiverActivity : Activity() {
private var previousIntent: Intent? = null

@Suppress("ComplexMethod")
@VisibleForTesting
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand All @@ -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)) {
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/org/mozilla/fenix/utils/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,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 = ""
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/preference_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,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>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 19 additions & 0 deletions app/src/test/java/org/mozilla/fenix/utils/SettingsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e672e0f

Please sign in to comment.