Skip to content

Commit

Permalink
for mozilla-mobile#11830 collecting startup metric inaside onNewInten…
Browse files Browse the repository at this point in the history
…t in HomeActivity
  • Loading branch information
sraturi committed Jun 25, 2020
1 parent 18b1bb6 commit 4630ea8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
28 changes: 24 additions & 4 deletions app/src/main/java/org/mozilla/fenix/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity() {
StrictMode.allowThreadDiskReads().resetPoliciesAfter {
super.onCreate(savedInstanceState)
}

components.publicSuffixList.prefetch()

setupThemeAndBrowsingMode(getModeFromIntentOrLastKnown(intent))
Expand Down Expand Up @@ -164,10 +163,16 @@ open class HomeActivity : LocaleAwareAppCompatActivity() {
lifecycle.addObserver(BreadcrumbsRecorder(components.analytics.crashReporter,
navHost.navController, ::getBreadcrumbMessage))

intent
?.toSafeIntent()
val safeIntent = intent?.toSafeIntent()
safeIntent
?.let(::getIntentSource)
?.also { components.analytics.metrics.track(Event.OpenedApp(it)) }
// report cold startup
safeIntent
?.let(::getIntentStartSource)
?.also {
components.analytics.metrics.track(Event.OpenedAppAllStart(it))
}
}
supportActionBar?.hide()

Expand Down Expand Up @@ -218,7 +223,13 @@ open class HomeActivity : LocaleAwareAppCompatActivity() {
val intentProcessors = listOf(CrashReporterIntentProcessor()) + externalSourceIntentProcessors
val intentHandled = intentProcessors.any { it.process(intent, navHost.navController, this.intent) }
browsingModeManager.mode = getModeFromIntentOrLastKnown(intent)

if (settings().isTelemetryEnabled) {
intent.toSafeIntent()
.let(::getIntentStartSource)
?.also {
components.analytics.metrics.track(Event.OpenedAppAllStart(it))
}
}
if (intentHandled) {
supportFragmentManager
.primaryNavigationFragment
Expand Down Expand Up @@ -298,6 +309,15 @@ open class HomeActivity : LocaleAwareAppCompatActivity() {
}
}

@VisibleForTesting(otherwise = PROTECTED)
internal open fun getIntentStartSource(intent: SafeIntent): Event.OpenedAppAllStart.Source? {
return when {
intent.isLauncherIntent -> Event.OpenedAppAllStart.Source.APP_ICON
intent.action == Intent.ACTION_VIEW -> Event.OpenedAppAllStart.Source.LINK
else -> null
}
}

/**
* External sources such as 3rd party links and shortcuts use this function to enter
* private mode directly before the content view is created. Returns the mode set by the intent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ private val Event.wrapper: EventWrapper<*>?
{ Events.appOpened.record(it) },
{ Events.appOpenedKeys.valueOf(it) }
)
is Event.OpenedAppAllStart -> EventWrapper(
{ Events.appOpenedAllStartup.record(it) },
{ Events.appOpenedAllStartupKeys.valueOf(it) }
)
is Event.SearchBarTapped -> EventWrapper(
{ Events.searchBarTapped.record(it) },
{ Events.searchBarTappedKeys.valueOf(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ sealed class Event {
override val extras: Map<Events.appOpenedKeys, String>?
get() = hashMapOf(Events.appOpenedKeys.source to source.name)
}
data class OpenedAppAllStart(val source: Source) : Event() {
enum class Source { APP_ICON, LINK, CUSTOM_TAB }

override val extras: Map<Events.appOpenedKeys, String>?
get() = hashMapOf(Events.appOpenedKeys.source to source.name)
}

data class CollectionSaveButtonPressed(val fromScreen: String) : Event() {
override val extras: Map<Collections.saveButtonKeys, String>?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ open class ExternalAppBrowserActivity : HomeActivity() {

final override fun getIntentSource(intent: SafeIntent) = Event.OpenedApp.Source.CUSTOM_TAB

final override fun getIntentStartSource(intent: SafeIntent) = Event.OpenedAppAllStart.Source.CUSTOM_TAB

final override fun getIntentSessionId(intent: SafeIntent) = intent.getSessionId()

override fun getNavDirections(
Expand Down

0 comments on commit 4630ea8

Please sign in to comment.