Unverified Commit d0abf58e authored by Jeff Boek's avatar Jeff Boek Committed by GitHub
Browse files

Uplifting mls revert (#15500)

* Revert "For #12544 - Prevent search engines mixup"

This reverts commit 0a4a170f.

* For mozilla-mobile/android-components#8429 - Dont initialize MLS if token is null
parent 1b2f43a6
Loading
Loading
Loading
Loading
+23 −16
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ package org.mozilla.fenix.components.searchengine
import android.content.Context
import androidx.annotation.VisibleForTesting
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.async
@@ -32,16 +33,15 @@ import java.util.Locale
open class FenixSearchEngineProvider(
    private val context: Context
) : SearchEngineProvider, CoroutineScope by CoroutineScope(Job() + Dispatchers.IO) {
    private val locationService = with(MozillaLocationService(
    private val shouldMockMLS = Config.channel.isDebug || BuildConfig.MLS_TOKEN.isNullOrEmpty()
    private val locationService: LocationService = if (shouldMockMLS) {
        LocationService.dummy()
    } else {
        MozillaLocationService(
            context,
            context.components.core.client,
            BuildConfig.MLS_TOKEN
    )) {
        if (Config.channel.isDebug || !this.hasRegionCached()) {
            LocationService.dummy()
        } else {
            this
        }
        )
    }

    // We have two search engine types: one based on MLS reported region, one based only on Locale.
@@ -94,6 +94,17 @@ open class FenixSearchEngineProvider(

    private var loadedSearchEngines = refreshAsync()

    // https://github.com/mozilla-mobile/fenix/issues/9935
    // Create new getter that will return the fallback SearchEngineList if
    // the main one hasn't completed yet
    private val searchEngines: Deferred<SearchEngineList>
        get() =
            if (isRegionCachedByLocationService) {
                loadedSearchEngines
            } else {
                fallbackEngines
            }

    fun getDefaultEngine(context: Context): SearchEngine {
        val engines = installedSearchEngines(context)
        val selectedName = context.settings().defaultSearchEngineName
@@ -107,7 +118,7 @@ open class FenixSearchEngineProvider(
     */
    fun installedSearchEngines(context: Context): SearchEngineList = runBlocking {
        val installedIdentifiers = installedSearchEngineIdentifiers(context)
        val engineList = loadedSearchEngines.await()
        val engineList = searchEngines.await()

        engineList.copy(
            list = engineList.list.filter {
@@ -178,11 +189,7 @@ open class FenixSearchEngineProvider(
    }

    private fun refreshAsync() = async {
        val engineList = if (isRegionCachedByLocationService) {
            baseSearchEngines.await()
        } else {
            fallbackEngines.await()
        }
        val engineList = baseSearchEngines.await()
        val bundledList = bundledSearchEngines.await().list
        val customList = customSearchEngines.await().list