GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit 8bfc4935 authored by Sawyer Blatz's avatar Sawyer Blatz Committed by Emily Kager
Browse files

For #12103: Add ChangedDefaultBrowser event for leanplum

parent 2b1122bc
......@@ -31,6 +31,7 @@ import androidx.navigation.ui.NavigationUI
import kotlinx.android.synthetic.main.activity_home.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
......@@ -68,6 +69,7 @@ import org.mozilla.fenix.components.metrics.BreadcrumbsRecorder
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.alreadyOnDestination
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.resetPoliciesAfter
import org.mozilla.fenix.ext.settings
......@@ -243,12 +245,24 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
}
}
}
// Launch this on a background thread so as not to affect startup performance
lifecycleScope.launch(IO) {
if (settings().wasDefaultBrowserOnLastPause != settings().isDefaultBrowser()) {
metrics.track(Event.ChangedToDefaultBrowser)
}
}
}
final override fun onPause() {
if (settings().lastKnownMode.isPrivate) {
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
if (settings().wasDefaultBrowserOnLastPause != settings().isDefaultBrowser()) {
settings().wasDefaultBrowserOnLastPause = settings().isDefaultBrowser()
}
super.onPause()
// Every time the application goes into the background, it is possible that the user
......
......@@ -666,6 +666,7 @@ private val Event.wrapper: EventWrapper<*>?
is Event.FennecToFenixMigrated -> null
is Event.AddonInstalled -> null
is Event.SearchWidgetInstalled -> null
is Event.ChangedToDefaultBrowser -> null
}
class GleanMetricsService(private val context: Context) : MetricsService {
......
......@@ -40,6 +40,7 @@ private val Event.name: String?
is Event.FennecToFenixMigrated -> "E_Fennec_To_Fenix_Migrated"
is Event.AddonInstalled -> "E_Addon_Installed"
is Event.SearchWidgetInstalled -> "E_Search_Widget_Added"
is Event.ChangedToDefaultBrowser -> "E_Changed_Default_To_Fenix"
// Do not track other events in Leanplum
else -> null
......
......@@ -183,6 +183,7 @@ sealed class Event {
object OnboardingPrivateBrowsing : Event()
object OnboardingWhatsNew : Event()
object OnboardingFinish : Event()
object ChangedToDefaultBrowser : Event()
object ContextualHintETPDisplayed : Event()
object ContextualHintETPDismissed : Event()
......
......@@ -10,6 +10,8 @@ import android.widget.Switch
import androidx.preference.Preference
import androidx.preference.PreferenceViewHolder
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.utils.BrowsersCache
class DefaultBrowserPreference @JvmOverloads constructor(
......
......@@ -324,6 +324,15 @@ class Settings(private val appContext: Context) : PreferencesHolder {
default = true
)
/**
* Caches the last known "is default browser" state when the app was paused.
* For an up to do date state use `isDefaultBrowser` instead.
*/
var wasDefaultBrowserOnLastPause by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_default_browser),
default = isDefaultBrowser()
)
fun isDefaultBrowser(): Boolean {
val browsers = BrowsersCache.all(appContext)
return browsers.isDefaultBrowser
......
......@@ -186,5 +186,7 @@
<string name="pref_key_is_in_search_widget_experiment" translatable="false">pref_key_is_in_search_widget_experiment</string>
<string name="pref_key_show_search_widget_cfr" translatable="false">pref_key_show_search_widget_cfr</string>
<string name="pref_key_default_browser" translatable="false">pref_key_default_browser</string>
<string name="pref_key_login_exceptions" translatable="false">pref_key_login_exceptions</string>
</resources>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment