@ -8,7 +8,6 @@ import android.content.Context
import mozilla.components.service.nimbus.NimbusApi
import mozilla.components.service.nimbus.NimbusAppInfo
import mozilla.components.service.nimbus.NimbusBuilder
import mozilla.components.service.nimbus.loggingErrorReporter
import mozilla.components.service.nimbus.messaging.FxNimbusMessaging
import mozilla.components.service.nimbus.messaging.NimbusSystem
import mozilla.components.support.base.log.logger.Logger
@ -30,6 +29,8 @@ import org.mozilla.fenix.utils.Settings
* /
private const val TIME _OUT _LOADING _EXPERIMENT _FROM _DISK _MS = 200L
private val logger = Logger ( " service/Nimbus " )
/ * *
* Create the Nimbus singleton object for the Fenix app .
* /
@ -59,35 +60,32 @@ fun createNimbus(context: Context, urlString: String?): NimbusApi {
return NimbusBuilder ( context ) . apply {
url = urlString
errorReporter = { message , e ->
if ( BuildConfig . BUILD _TYPE == " debug " ) {
Logger . error ( " Nimbus error: $message " , e )
}
if ( e !is NimbusException || e . isReportableError ( ) ) {
@Suppress ( " TooGenericExceptionCaught " )
try {
context . components . analytics . crashReporter . submitCaughtException ( e )
} catch ( e : Throwable ) {
loggingErrorReporter ( message , e )
}
}
}
errorReporter = context :: reportError
initialExperiments = R . raw . initial _experiments
timeoutLoadingExperiment = TIME _OUT _LOADING _EXPERIMENT _FROM _DISK _MS
usePreviewCollection = context . settings ( ) . nimbusUsePreview
isFirstRun = isAppFirstRun
onCreateCallback = { nimbus ->
FxNimbus . initialize { nimbus }
}
onApplyCallback = {
FxNimbus . invalidateCachedValues ( )
}
onFetchedCallback = {
featureManifest = FxNimbus
onFetchCallback = {
context . settings ( ) . nimbusExperimentsFetched = true
}
} . build ( appInfo )
}
private fun Context . reportError ( message : String , e : Throwable ) {
if ( BuildConfig . BUILD _TYPE == " debug " ) {
logger . error ( " Nimbus error: $message " , e )
}
if ( e !is NimbusException || e . isReportableError ( ) ) {
@Suppress ( " TooGenericExceptionCaught " )
try {
this . components . analytics . crashReporter . submitCaughtException ( e )
} catch ( e : Throwable ) {
logger . error ( message , e )
}
}
}
/ * *
* Classifies which errors we should forward to our crash reporter or not . We want to filter out the
* non - reportable ones if we know there is no reasonable action that we can perform .