For issue 7192: move unsetOpenLinksInAPrivateTabIfNecessary off main thread. (#7246)
Move method to Settings. There are two instances when we want to call this method: either processing an intent, or within DefaultBrowserPreference
This commit is contained in:
parent
cf143489e1
commit
13f73c2d2c
|
@ -113,7 +113,7 @@ events:
|
|||
preference_key:
|
||||
description: "The preference key for the boolean (true/false) preference the user toggled. We currently track:
|
||||
show_search_suggestions, remote_debugging, telemetry, tracking_protection, search_bookmarks,
|
||||
search_browsing_history, show_clipboard_suggestions, show_search_shortcuts, open_links_in_a_private_tab,
|
||||
search_browsing_history, show_clipboard_suggestions, show_search_shortcuts, open_links_in_a_private_tab (bug in implementation https://github.com/mozilla-mobile/fenix/issues/7384),
|
||||
pref_key_sync_logins, pref_key_sync_bookmarks, pref_key_sync_history
|
||||
and pref_key_show_search_suggestions_in_private"
|
||||
enabled:
|
||||
|
|
|
@ -30,7 +30,6 @@ import mozilla.components.service.fxa.sync.SyncReason
|
|||
import mozilla.components.support.base.feature.UserInteractionHandler
|
||||
import mozilla.components.support.ktx.kotlin.isUrl
|
||||
import mozilla.components.support.ktx.kotlin.toNormalizedUrl
|
||||
import mozilla.components.support.utils.Browsers
|
||||
import mozilla.components.support.utils.SafeIntent
|
||||
import mozilla.components.support.utils.toSafeIntent
|
||||
import org.mozilla.fenix.browser.UriOpenedObserver
|
||||
|
@ -61,7 +60,6 @@ import org.mozilla.fenix.settings.SettingsFragmentDirections
|
|||
import org.mozilla.fenix.settings.TrackingProtectionFragmentDirections
|
||||
import org.mozilla.fenix.theme.DefaultThemeManager
|
||||
import org.mozilla.fenix.theme.ThemeManager
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
@SuppressWarnings("TooManyFunctions", "LargeClass")
|
||||
open class HomeActivity : AppCompatActivity() {
|
||||
|
@ -118,8 +116,6 @@ open class HomeActivity : AppCompatActivity() {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
unsetOpenLinksInAPrivateTabIfNecessary()
|
||||
|
||||
lifecycleScope.launch {
|
||||
with(components.backgroundServices) {
|
||||
// Make sure accountManager is initialized.
|
||||
|
@ -143,21 +139,6 @@ open class HomeActivity : AppCompatActivity() {
|
|||
hotStartMonitor.onPostResumeFinalMethodCall()
|
||||
}
|
||||
|
||||
private fun unsetOpenLinksInAPrivateTabIfNecessary() {
|
||||
// Toggle off the open_link_in_private_tab pref if we are no longer set as the default browser
|
||||
// We do this on a separate thread to alleviate performance issues
|
||||
val weakReferenceContext = WeakReference(this)
|
||||
lifecycleScope.launch {
|
||||
val context = weakReferenceContext.get() ?: return@launch
|
||||
if (!Browsers.all(context).isDefaultBrowser) {
|
||||
context.settings().preferences
|
||||
.edit()
|
||||
.putBoolean(context.getString(R.string.pref_key_open_links_in_a_private_tab), false)
|
||||
.apply()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles intents received when the activity is open.
|
||||
*/
|
||||
|
|
|
@ -10,7 +10,6 @@ import android.os.Bundle
|
|||
import androidx.annotation.VisibleForTesting
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.launch
|
||||
import mozilla.components.support.utils.Browsers
|
||||
import org.mozilla.fenix.components.getType
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.ext.components
|
||||
|
@ -36,17 +35,10 @@ class IntentReceiverActivity : Activity() {
|
|||
}
|
||||
|
||||
suspend fun processIntent(intent: Intent) {
|
||||
if (!Browsers.all(this).isDefaultBrowser) {
|
||||
/* If the user has unset us as the default browser, unset openLinksInAPrivateTab */
|
||||
this.settings().openLinksInAPrivateTab = false
|
||||
components.analytics.metrics.track(Event.PreferenceToggled(
|
||||
preferenceKey = getString(R.string.pref_key_open_links_in_a_private_tab),
|
||||
enabled = false,
|
||||
context = applicationContext
|
||||
))
|
||||
}
|
||||
val settings = settings()
|
||||
settings.unsetOpenLinksInAPrivateTabIfNecessary()
|
||||
|
||||
val modeDependentProcessors = if (settings().openLinksInAPrivateTab) {
|
||||
val modeDependentProcessors = if (settings.openLinksInAPrivateTab) {
|
||||
components.analytics.metrics.track(Event.OpenedLink(Event.OpenedLink.Mode.PRIVATE))
|
||||
listOf(
|
||||
components.intentProcessors.privateCustomTabIntentProcessor,
|
||||
|
|
|
@ -51,9 +51,12 @@ class DefaultBrowserSettingsFragment : PreferenceFragmentCompat() {
|
|||
findPreference<DefaultBrowserPreference>(getPreferenceKey(R.string.pref_key_make_default_browser))
|
||||
?.updateSwitch()
|
||||
|
||||
val settings = context!!.settings()
|
||||
settings.unsetOpenLinksInAPrivateTabIfNecessary()
|
||||
|
||||
findPreference<CheckBoxPreference>(getPreferenceKey(R.string.pref_key_open_links_in_a_private_tab))?.apply {
|
||||
isEnabled = Browsers.all(requireContext()).isDefaultBrowser
|
||||
isChecked = context.settings().openLinksInAPrivateTab
|
||||
isChecked = settings.openLinksInAPrivateTab
|
||||
onPreferenceChangeListener = SharedPreferenceUpdater()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,16 @@ import mozilla.components.support.ktx.android.content.floatPreference
|
|||
import mozilla.components.support.ktx.android.content.intPreference
|
||||
import mozilla.components.support.ktx.android.content.longPreference
|
||||
import mozilla.components.support.ktx.android.content.stringPreference
|
||||
import mozilla.components.support.utils.Browsers
|
||||
import org.mozilla.fenix.BuildConfig
|
||||
import org.mozilla.fenix.Config
|
||||
import org.mozilla.fenix.FeatureFlags
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.components.metrics.MozillaProductDetector
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.getPreferenceKey
|
||||
import org.mozilla.fenix.ext.settings
|
||||
import org.mozilla.fenix.settings.PhoneFeature
|
||||
import org.mozilla.fenix.settings.deletebrowsingdata.DeleteBrowsingDataOnQuitType
|
||||
import java.security.InvalidParameterException
|
||||
|
@ -370,6 +374,21 @@ class Settings private constructor(
|
|||
).apply()
|
||||
}
|
||||
|
||||
fun unsetOpenLinksInAPrivateTabIfNecessary() {
|
||||
if (Browsers.all(appContext).isDefaultBrowser) {
|
||||
return
|
||||
}
|
||||
|
||||
appContext.settings().openLinksInAPrivateTab = false
|
||||
appContext.components.analytics.metrics.track(
|
||||
Event.PreferenceToggled(
|
||||
preferenceKey = appContext.getString(R.string.pref_key_open_links_in_a_private_tab),
|
||||
enabled = false,
|
||||
context = appContext
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private var showedPrivateModeContextualFeatureRecommender by booleanPreference(
|
||||
appContext.getPreferenceKey(R.string.pref_key_showed_private_mode_cfr),
|
||||
default = false
|
||||
|
|
|
@ -84,7 +84,7 @@ The following metrics are added to the ping:
|
|||
| events.entered_url |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user entered a url |[1](https://github.com/mozilla-mobile/fenix/pull/1067#issuecomment-474598673)|<ul><li>autocomplete: A boolean that tells us whether the URL was autofilled by an Autocomplete suggestion</li></ul>|2020-03-01 |
|
||||
| events.opened_link |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened a link with Fenix |[1](https://github.com/mozilla-mobile/fenix/pull/5975)|<ul><li>mode: The mode the link was opened in. Either 'PRIVATE' or 'NORMAL'</li></ul>|2020-03-01 |
|
||||
| events.performed_search |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user performed a search |[1](https://github.com/mozilla-mobile/fenix/pull/1067#issuecomment-474598673), [2](https://github.com/mozilla-mobile/fenix/pull/1677)|<ul><li>source: A string that tells us how the user performed the search. Possible values are: * default.action * default.suggestion * shortcut.action * shortcut.suggestion </li></ul>|2020-03-01 |
|
||||
| events.preference_toggled |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user toggled a boolean preference in settings |[1](https://github.com/mozilla-mobile/fenix/pull/1896), [2](https://github.com/mozilla-mobile/fenix/pull/5704), [3](https://github.com/mozilla-mobile/fenix/pull/5886), [4](https://github.com/mozilla-mobile/fenix/pull/5975), [5](https://github.com/mozilla-mobile/fenix/pull/6352), [6](https://github.com/mozilla-mobile/fenix/pull/6601), [7](https://github.com/mozilla-mobile/fenix/pull/6746)|<ul><li>enabled: Whether or not the preference is *now* enabled</li><li>preference_key: The preference key for the boolean (true/false) preference the user toggled. We currently track: show_search_suggestions, remote_debugging, telemetry, tracking_protection, search_bookmarks, search_browsing_history, show_clipboard_suggestions, show_search_shortcuts, open_links_in_a_private_tab, pref_key_sync_logins, pref_key_sync_bookmarks, pref_key_sync_history and pref_key_show_search_suggestions_in_private</li></ul>|2020-03-01 |
|
||||
| events.preference_toggled |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user toggled a boolean preference in settings |[1](https://github.com/mozilla-mobile/fenix/pull/1896), [2](https://github.com/mozilla-mobile/fenix/pull/5704), [3](https://github.com/mozilla-mobile/fenix/pull/5886), [4](https://github.com/mozilla-mobile/fenix/pull/5975), [5](https://github.com/mozilla-mobile/fenix/pull/6352), [6](https://github.com/mozilla-mobile/fenix/pull/6601), [7](https://github.com/mozilla-mobile/fenix/pull/6746)|<ul><li>enabled: Whether or not the preference is *now* enabled</li><li>preference_key: The preference key for the boolean (true/false) preference the user toggled. We currently track: show_search_suggestions, remote_debugging, telemetry, tracking_protection, search_bookmarks, search_browsing_history, show_clipboard_suggestions, show_search_shortcuts, open_links_in_a_private_tab (bug in implementation https://github.com/mozilla-mobile/fenix/issues/7384), pref_key_sync_logins, pref_key_sync_bookmarks, pref_key_sync_history and pref_key_show_search_suggestions_in_private</li></ul>|2020-03-01 |
|
||||
| events.search_bar_tapped |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user tapped the search bar |[1](https://github.com/mozilla-mobile/fenix/pull/1067#issuecomment-474598673)|<ul><li>source: The view the user was on when they initiated the search (For example: `Home` or `Browser`)</li></ul>|2020-03-01 |
|
||||
| events.whats_new_tapped |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user opened the "what's new" page button |[1](https://github.com/mozilla-mobile/fenix/pull/5090)|<ul><li>source: The location from which the user selected the what's new button. Either 'about' or 'home'</li></ul>|2020-03-01 |
|
||||
| find_in_page.closed |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user closed the find in page UI |[1](https://github.com/mozilla-mobile/fenix/pull/1344#issuecomment-479285010)||2020-03-01 |
|
||||
|
|
Loading…
Reference in New Issue