@ -21,6 +21,7 @@ import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.components.metrics.MozillaProductDetector.MozillaProducts
import org.mozilla.fenix.components.metrics.MozillaProductDetector.MozillaProducts
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.settings
import java.util.Locale
import java.util.Locale
import java.util.MissingResourceException
import java.util.UUID.randomUUID
import java.util.UUID.randomUUID
private val Event . name : String ?
private val Event . name : String ?
@ -83,12 +84,19 @@ class LeanplumMetricsService(private val application: Application) : MetricsServ
leanplumJob = scope . launch {
leanplumJob = scope . launch {
val applicationSetLocale = LocaleManager . getCurrentLocale ( application )
val applicationSetLocale = LocaleManager . getCurrentLocale ( application )
val currentLocale = when ( applicationSetLocale != null ) {
val currentLocale = applicationSetLocale ?: Locale . getDefault ( )
true -> applicationSetLocale . isO3Language
val languageCode =
false -> Locale . getDefault ( ) . isO3Language
currentLocale . iso3LanguageOrNull
}
?: currentLocale . language . let {
if ( !is LeanplumEnabled ( currentLocale ) ) {
if ( it . isNotBlank ( ) ) {
Log . i ( LOGTAG , " Leanplum is not available for this locale: $currentLocale " )
it
} else {
currentLocale . toString ( )
}
}
if ( !is LeanplumEnabled ( languageCode ) ) {
Log . i ( LOGTAG , " Leanplum is not available for this locale: $languageCode " )
return @launch
return @launch
}
}
@ -170,6 +178,12 @@ class LeanplumMetricsService(private val application: Application) : MetricsServ
return LEANPLUM_ENABLED_LOCALES . contains ( locale )
return LEANPLUM_ENABLED_LOCALES . contains ( locale )
}
}
private val Locale . iso3LanguageOrNull : String ?
get ( ) =
try {
this . isO3Language
} catch ( _ : MissingResourceException ) { null }
companion object {
companion object {
private const val LOGTAG = " LeanplumMetricsService "
private const val LOGTAG = " LeanplumMetricsService "
@ -181,7 +195,7 @@ class LeanplumMetricsService(private val application: Application) : MetricsServ
get ( ) = BuildConfig . LEANPLUM_TOKEN . orEmpty ( )
get ( ) = BuildConfig . LEANPLUM_TOKEN . orEmpty ( )
// Leanplum needs to be enabled for the following locales.
// Leanplum needs to be enabled for the following locales.
// Irrespective of the actual device location.
// Irrespective of the actual device location.
private val LEANPLUM _ENABLED _LOCALES = li stOf(
private val LEANPLUM _ENABLED _LOCALES = se tOf(
" eng " , // English
" eng " , // English
" zho " , // Chinese
" zho " , // Chinese
" deu " , // German
" deu " , // German