2019-01-29 17:42:10 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
package org.mozilla.fenix.components
|
|
|
|
|
2019-03-12 21:09:04 +01:00
|
|
|
import android.app.Application
|
2019-03-20 18:47:22 +01:00
|
|
|
import android.app.PendingIntent
|
2019-01-29 17:42:10 +01:00
|
|
|
import android.content.Context
|
2019-03-20 18:47:22 +01:00
|
|
|
import android.content.Intent
|
2019-01-29 17:42:10 +01:00
|
|
|
import mozilla.components.lib.crash.CrashReporter
|
2019-03-27 19:04:00 +01:00
|
|
|
import mozilla.components.lib.crash.service.CrashReporterService
|
2019-09-24 03:29:33 +02:00
|
|
|
import mozilla.components.lib.crash.service.GleanCrashReporterService
|
2019-01-29 17:42:10 +01:00
|
|
|
import mozilla.components.lib.crash.service.MozillaSocorroService
|
|
|
|
import mozilla.components.lib.crash.service.SentryService
|
|
|
|
import org.mozilla.fenix.BuildConfig
|
2019-03-20 18:47:22 +01:00
|
|
|
import org.mozilla.fenix.HomeActivity
|
2019-01-29 17:42:10 +01:00
|
|
|
import org.mozilla.fenix.R
|
2019-04-17 22:42:46 +02:00
|
|
|
import org.mozilla.fenix.components.metrics.AdjustMetricsService
|
2019-03-12 21:09:04 +01:00
|
|
|
import org.mozilla.fenix.components.metrics.GleanMetricsService
|
|
|
|
import org.mozilla.fenix.components.metrics.LeanplumMetricsService
|
2019-04-09 19:29:09 +02:00
|
|
|
import org.mozilla.fenix.components.metrics.MetricController
|
2019-09-10 19:11:58 +02:00
|
|
|
import org.mozilla.fenix.ext.settings
|
2019-05-07 23:36:37 +02:00
|
|
|
import org.mozilla.fenix.test.Mockable
|
2019-01-29 17:42:10 +01:00
|
|
|
import org.mozilla.geckoview.BuildConfig.MOZ_APP_BUILDID
|
2019-12-18 00:54:22 +01:00
|
|
|
import org.mozilla.geckoview.BuildConfig.MOZ_APP_VENDOR
|
2019-01-29 17:42:10 +01:00
|
|
|
import org.mozilla.geckoview.BuildConfig.MOZ_APP_VERSION
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component group for all functionality related to analytics e.g. crash reporting and telemetry.
|
|
|
|
*/
|
2019-05-07 23:36:37 +02:00
|
|
|
@Mockable
|
2019-01-29 17:42:10 +01:00
|
|
|
class Analytics(
|
|
|
|
private val context: Context
|
|
|
|
) {
|
|
|
|
val crashReporter: CrashReporter by lazy {
|
2019-05-15 16:27:18 +02:00
|
|
|
val services = mutableListOf<CrashReporterService>()
|
2019-03-27 19:04:00 +01:00
|
|
|
|
2019-06-14 19:08:46 +02:00
|
|
|
if (isSentryEnabled()) {
|
2019-03-27 19:04:00 +01:00
|
|
|
val sentryService = SentryService(
|
|
|
|
context,
|
|
|
|
BuildConfig.SENTRY_TOKEN,
|
|
|
|
tags = mapOf("geckoview" to "$MOZ_APP_VERSION-$MOZ_APP_BUILDID"),
|
2019-06-10 17:55:39 +02:00
|
|
|
environment = BuildConfig.BUILD_TYPE,
|
2019-03-27 19:04:00 +01:00
|
|
|
sendEventForNativeCrashes = true
|
|
|
|
)
|
|
|
|
|
2019-05-15 16:27:18 +02:00
|
|
|
services.add(sentryService)
|
2019-03-27 19:04:00 +01:00
|
|
|
}
|
2019-01-29 17:42:10 +01:00
|
|
|
|
2019-09-24 03:29:33 +02:00
|
|
|
services.add(GleanCrashReporterService(context))
|
|
|
|
|
2019-05-15 16:27:18 +02:00
|
|
|
// The name "Fenix" here matches the product name on Socorro and is unrelated to the actual app name:
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1523284
|
2019-12-18 00:54:22 +01:00
|
|
|
val socorroService = MozillaSocorroService(context, appName = "Fenix",
|
|
|
|
version = MOZ_APP_VERSION, buildId = MOZ_APP_BUILDID, vendor = MOZ_APP_VENDOR)
|
2019-05-15 16:27:18 +02:00
|
|
|
services.add(socorroService)
|
2019-01-29 17:42:10 +01:00
|
|
|
|
2019-03-20 18:47:22 +01:00
|
|
|
val intent = Intent(context, HomeActivity::class.java).apply {
|
|
|
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
|
|
|
}
|
|
|
|
|
|
|
|
val pendingIntent = PendingIntent.getActivity(
|
|
|
|
context,
|
|
|
|
0,
|
|
|
|
intent,
|
|
|
|
0
|
|
|
|
)
|
|
|
|
|
2019-01-29 17:42:10 +01:00
|
|
|
CrashReporter(
|
2019-03-27 19:04:00 +01:00
|
|
|
services = services,
|
2019-01-29 17:42:10 +01:00
|
|
|
shouldPrompt = CrashReporter.Prompt.ALWAYS,
|
|
|
|
promptConfiguration = CrashReporter.PromptConfiguration(
|
|
|
|
appName = context.getString(R.string.app_name),
|
|
|
|
organizationName = "Mozilla"
|
|
|
|
),
|
2019-03-20 18:47:22 +01:00
|
|
|
enabled = true,
|
|
|
|
nonFatalCrashIntent = pendingIntent
|
2019-01-29 17:42:10 +01:00
|
|
|
)
|
|
|
|
}
|
2019-03-12 21:09:04 +01:00
|
|
|
|
2019-04-09 19:29:09 +02:00
|
|
|
val metrics: MetricController by lazy {
|
|
|
|
MetricController.create(
|
2019-03-12 21:09:04 +01:00
|
|
|
listOf(
|
|
|
|
GleanMetricsService(context),
|
2019-04-17 22:42:46 +02:00
|
|
|
LeanplumMetricsService(context as Application),
|
|
|
|
AdjustMetricsService(context)
|
2019-03-15 21:09:59 +01:00
|
|
|
),
|
2020-02-08 06:53:37 +01:00
|
|
|
isDataTelemetryEnabled = { context.settings().isTelemetryEnabled },
|
|
|
|
isMarketingDataTelemetryEnabled = { context.settings().isMarketingTelemetryEnabled }
|
2019-03-12 21:09:04 +01:00
|
|
|
)
|
|
|
|
}
|
2019-01-29 17:42:10 +01:00
|
|
|
}
|
2019-06-14 19:08:46 +02:00
|
|
|
|
|
|
|
fun isSentryEnabled() = !BuildConfig.SENTRY_TOKEN.isNullOrEmpty()
|