Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle SocketTimeout when MLS not available #794

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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