For #12103: Add ChangedDefaultBrowser event for leanplum
parent
2b1122bc77
commit
8bfc493568
|
@ -31,6 +31,7 @@ import androidx.navigation.ui.NavigationUI
|
||||||
import kotlinx.android.synthetic.main.activity_home.*
|
import kotlinx.android.synthetic.main.activity_home.*
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.delay
|
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.components.metrics.Event
|
||||||
import org.mozilla.fenix.ext.alreadyOnDestination
|
import org.mozilla.fenix.ext.alreadyOnDestination
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
|
import org.mozilla.fenix.ext.metrics
|
||||||
import org.mozilla.fenix.ext.nav
|
import org.mozilla.fenix.ext.nav
|
||||||
import org.mozilla.fenix.ext.resetPoliciesAfter
|
import org.mozilla.fenix.ext.resetPoliciesAfter
|
||||||
import org.mozilla.fenix.ext.settings
|
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() {
|
final override fun onPause() {
|
||||||
if (settings().lastKnownMode.isPrivate) {
|
if (settings().lastKnownMode.isPrivate) {
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
|
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (settings().wasDefaultBrowserOnLastPause != settings().isDefaultBrowser()) {
|
||||||
|
settings().wasDefaultBrowserOnLastPause = settings().isDefaultBrowser()
|
||||||
|
}
|
||||||
|
|
||||||
super.onPause()
|
super.onPause()
|
||||||
|
|
||||||
// Every time the application goes into the background, it is possible that the user
|
// 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.FennecToFenixMigrated -> null
|
||||||
is Event.AddonInstalled -> null
|
is Event.AddonInstalled -> null
|
||||||
is Event.SearchWidgetInstalled -> null
|
is Event.SearchWidgetInstalled -> null
|
||||||
|
is Event.ChangedToDefaultBrowser -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
class GleanMetricsService(private val context: Context) : MetricsService {
|
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.FennecToFenixMigrated -> "E_Fennec_To_Fenix_Migrated"
|
||||||
is Event.AddonInstalled -> "E_Addon_Installed"
|
is Event.AddonInstalled -> "E_Addon_Installed"
|
||||||
is Event.SearchWidgetInstalled -> "E_Search_Widget_Added"
|
is Event.SearchWidgetInstalled -> "E_Search_Widget_Added"
|
||||||
|
is Event.ChangedToDefaultBrowser -> "E_Changed_Default_To_Fenix"
|
||||||
|
|
||||||
// Do not track other events in Leanplum
|
// Do not track other events in Leanplum
|
||||||
else -> null
|
else -> null
|
||||||
|
|
|
@ -183,6 +183,7 @@ sealed class Event {
|
||||||
object OnboardingPrivateBrowsing : Event()
|
object OnboardingPrivateBrowsing : Event()
|
||||||
object OnboardingWhatsNew : Event()
|
object OnboardingWhatsNew : Event()
|
||||||
object OnboardingFinish : Event()
|
object OnboardingFinish : Event()
|
||||||
|
object ChangedToDefaultBrowser : Event()
|
||||||
|
|
||||||
object ContextualHintETPDisplayed : Event()
|
object ContextualHintETPDisplayed : Event()
|
||||||
object ContextualHintETPDismissed : Event()
|
object ContextualHintETPDismissed : Event()
|
||||||
|
|
|
@ -10,6 +10,8 @@ import android.widget.Switch
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import androidx.preference.PreferenceViewHolder
|
import androidx.preference.PreferenceViewHolder
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
|
import org.mozilla.fenix.components.metrics.Event
|
||||||
|
import org.mozilla.fenix.ext.metrics
|
||||||
import org.mozilla.fenix.utils.BrowsersCache
|
import org.mozilla.fenix.utils.BrowsersCache
|
||||||
|
|
||||||
class DefaultBrowserPreference @JvmOverloads constructor(
|
class DefaultBrowserPreference @JvmOverloads constructor(
|
||||||
|
|
|
@ -324,6 +324,15 @@ class Settings(private val appContext: Context) : PreferencesHolder {
|
||||||
default = true
|
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 {
|
fun isDefaultBrowser(): Boolean {
|
||||||
val browsers = BrowsersCache.all(appContext)
|
val browsers = BrowsersCache.all(appContext)
|
||||||
return browsers.isDefaultBrowser
|
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_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_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>
|
<string name="pref_key_login_exceptions" translatable="false">pref_key_login_exceptions</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue