From 349bb1786f4f50e16a94f7039beffe6d52db4441 Mon Sep 17 00:00:00 2001 From: Timo Wilken Date: Thu, 11 Sep 2025 09:24:02 +0200 Subject: [PATCH] Location: Implement TGV Lyria's new position provider The old position endpoint does not work anymore. I don't know if the other TGVs also run this new onboard system, so I have only moved the TGV Lyria provider over. --- .../location/network/wifi/MovingWifiHelper.kt | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/MovingWifiHelper.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/MovingWifiHelper.kt index a6cf861d54..e5d6640cb3 100644 --- a/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/MovingWifiHelper.kt +++ b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/MovingWifiHelper.kt @@ -381,9 +381,30 @@ class MovingWifiHelper(private val context: Context) { } private val SOURCE_SNCF = SncfLocationSource("https://wifi.sncf") private val SOURCE_SNCF_INTERCITES = SncfLocationSource("https://wifi.intercites.sncf") - private val SOURCE_LYRIA = SncfLocationSource("https://wifi.tgv-lyria.com") private val SOURCE_NORMANDIE = SncfLocationSource("https://wifi.normandie.fr") + private val SOURCE_LYRIA = object : MovingWifiLocationSource("https://wifi.tgv-lyria.com/api/train/gps/position/") { + /* If there is no location available (e.g. in a tunnel), the API + endpoint returns HTTP 500, though it may reuse a previous + location for a few seconds. The returned JSON has a + "satellites" integer field, but this always seems to be 0, even + when there is a valid location available. + */ + override fun parse(location: Location, data: ByteArray): Location { + val json = JSONObject(data.decodeToString()) + location.accuracy = 100f + location.latitude = json.getDouble("latitude") + location.longitude = json.getDouble("longitude") + json.optDouble("speed").takeIf { !it.isNaN() }?.let { + // Speed is returned in m/s. + location.speed = it.toFloat() + LocationCompat.setSpeedAccuracyMetersPerSecond(location, location.speed * 0.1f) + } + json.optDouble("altitude").takeIf { !it.isNaN() }?.let { location.altitude = it } + return location + } + } + private val SOURCE_OUIFI = object : MovingWifiLocationSource("https://ouifi.ouigo.com:8084/api/gps") { override fun parse(location: Location, data: ByteArray): Location { val json = JSONObject(data.decodeToString())