diff --git a/.gitignore b/.gitignore index 67426f7a1..24d282a79 100644 --- a/.gitignore +++ b/.gitignore @@ -84,6 +84,7 @@ gen-external-apklibs .adjust_token .sentry_token .digital_asset_links_token +.mls_token # Python Byte-compiled / optimized / DLL files diff --git a/app/build.gradle b/app/build.gradle index 2f45cb098..cde36dc15 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -356,6 +356,21 @@ android.applicationVariants.all { variant -> buildConfigField 'String', 'DIGITAL_ASSET_LINKS_TOKEN', 'null' println("X_X") } + +// ------------------------------------------------------------------------------------------------- +// MLS: Read token from local file if it exists +// ------------------------------------------------------------------------------------------------- + + print("MLS token: ") + + try { + def token = new File("${rootDir}/.mls_token").text.trim() + buildConfigField 'String', 'MLS_TOKEN', '"' + token + '"' + println "(Added from .mls_token file)" + } catch (FileNotFoundException ignored) { + buildConfigField 'String', 'MLS_TOKEN', '""' + println("X_X") + } } androidExtensions { @@ -429,6 +444,8 @@ dependencies { implementation Deps.mozilla_service_firefox_accounts implementation Deps.mozilla_service_glean implementation Deps.mozilla_service_experiments + implementation Deps.mozilla_service_location + implementation Deps.mozilla_support_base implementation Deps.mozilla_support_ktx diff --git a/app/src/main/java/org/mozilla/fenix/components/searchengine/FenixSearchEngineProvider.kt b/app/src/main/java/org/mozilla/fenix/components/searchengine/FenixSearchEngineProvider.kt index b78c1f6be..439cb28df 100644 --- a/app/src/main/java/org/mozilla/fenix/components/searchengine/FenixSearchEngineProvider.kt +++ b/app/src/main/java/org/mozilla/fenix/components/searchengine/FenixSearchEngineProvider.kt @@ -17,7 +17,10 @@ import mozilla.components.browser.search.provider.AssetsSearchEngineProvider import mozilla.components.browser.search.provider.SearchEngineList import mozilla.components.browser.search.provider.SearchEngineProvider import mozilla.components.browser.search.provider.filter.SearchEngineFilter -import mozilla.components.browser.search.provider.localization.LocaleSearchLocalizationProvider +import mozilla.components.service.location.MozillaLocationService +import mozilla.components.service.location.search.RegionSearchLocalizationProvider +import org.mozilla.fenix.BuildConfig +import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.settings import java.util.Locale @@ -26,15 +29,25 @@ open class FenixSearchEngineProvider( private val context: Context ) : SearchEngineProvider, CoroutineScope by CoroutineScope(Job() + Dispatchers.IO) { @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) + + private val localizationProvider = + RegionSearchLocalizationProvider( + MozillaLocationService( + context, + context.components.core.client, + BuildConfig.MLS_TOKEN + ) + ) + open val baseSearchEngines = async { - AssetsSearchEngineProvider(LocaleSearchLocalizationProvider()).loadSearchEngines(context) + AssetsSearchEngineProvider(localizationProvider).loadSearchEngines(context) } @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) open val bundledSearchEngines = async { val defaultEngineIdentifiers = baseSearchEngines.await().list.map { it.identifier }.toSet() AssetsSearchEngineProvider( - LocaleSearchLocalizationProvider(), + localizationProvider, filters = listOf(object : SearchEngineFilter { override fun filter(context: Context, searchEngine: SearchEngine): Boolean { return BUNDLED_SEARCH_ENGINES.contains(searchEngine.identifier) && diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt index 38be230c8..9456992c6 100644 --- a/buildSrc/src/main/java/Dependencies.kt +++ b/buildSrc/src/main/java/Dependencies.kt @@ -135,6 +135,7 @@ object Deps { const val mozilla_service_glean = "org.mozilla.components:service-glean:${Versions.mozilla_android_components}" const val mozilla_service_glean_forUnitTests = "org.mozilla.telemetry:glean-forUnitTests:${Versions.mozilla_glean}" const val mozilla_service_experiments = "org.mozilla.components:service-experiments:${Versions.mozilla_android_components}" + const val mozilla_service_location = "org.mozilla.components:service-location:${Versions.mozilla_android_components}" const val mozilla_ui_colors = "org.mozilla.components:ui-colors:${Versions.mozilla_android_components}" const val mozilla_ui_icons = "org.mozilla.components:ui-icons:${Versions.mozilla_android_components}" diff --git a/taskcluster/fenix_taskgraph/transforms/build.py b/taskcluster/fenix_taskgraph/transforms/build.py index 1973761be..a781c3253 100644 --- a/taskcluster/fenix_taskgraph/transforms/build.py +++ b/taskcluster/fenix_taskgraph/transforms/build.py @@ -47,6 +47,7 @@ def add_shippable_secrets(config, tasks): ('digital_asset_links', '.digital_asset_links_token'), ('leanplum', '.leanplum_token'), ('sentry_dsn', '.sentry_token'), + ('mls', '.mls_token'), )]) else: task["run"]["pre-gradlew"] = [[ @@ -55,6 +56,7 @@ def add_shippable_secrets(config, tasks): ("--", ".adjust_token"), ("", ".digital_asset_links_token"), ("-:-", ".leanplum_token"), + ("", ".mls_token"), ("https://fake@sentry.prod.mozaws.net/368", ".sentry_token"), )]