Skip to content

Commit

Permalink
Gracefully handle SocketTimeout when MLS not available
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeRatcliffe authored and svillar committed Jul 6, 2023
1 parent 49900f5 commit 24e7eb4
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package com.igalia.wolvic.geolocation

import android.content.Context
import android.util.Log
import com.igalia.wolvic.browser.SettingsStore
import com.igalia.wolvic.browser.engine.EngineProvider
import com.igalia.wolvic.utils.SystemUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.future.future
import kotlinx.coroutines.launch
import mozilla.components.service.location.LocationService
import mozilla.components.service.location.MozillaLocationService
import java.net.SocketTimeoutException
import java.util.concurrent.CompletableFuture

object GeolocationWrapper {
private val LOGTAG = SystemUtils.createLogtag(GeolocationWrapper::class.java)

fun update(context: Context) {
val locationService = MozillaLocationService(
Expand All @@ -21,9 +25,13 @@ object GeolocationWrapper {
com.igalia.wolvic.BuildConfig.MLS_TOKEN
)
CoroutineScope(Dispatchers.IO).launch {
locationService.fetchRegion(true)?.run {
val data: GeolocationData = GeolocationData.create(countryCode, countryName)
SettingsStore.getInstance(context).geolocationData = data.toString()
try {
locationService.fetchRegion(true)?.run {
val data: GeolocationData = GeolocationData.create(countryCode, countryName)
SettingsStore.getInstance(context).geolocationData = data.toString()
}
} catch (e: SocketTimeoutException) {
Log.w(LOGTAG, "The Mozilla Location Service (MLS) is not available.")
}
}
}
Expand Down

0 comments on commit 24e7eb4

Please sign in to comment.