Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit ac9387ca authored by Marvin W.'s avatar Marvin W. 🐿️
Browse files

Location: Add support for Hotsplots API in agilis trains

parent fe60c2a6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -8,5 +8,6 @@
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">portal.mav.hu</domain>
        <domain includeSubdomains="true">cdwifi.cz</domain>
        <domain includeSubdomains="true">hsp.hotsplots.net</domain>
    </domain-config>
</network-security-config>
 No newline at end of file
+32 −16
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ private val MOVING_WIFI_HOTSPOTS = setOf(
    "FlyNet",
    "Telekom_FlyNet",
    "Vestische WLAN",
    "agilis-Wifi",
    // Greece
    "AegeanWiFi",
    // Hong Kong
@@ -275,6 +276,19 @@ class MovingWifiHelper(private val context: Context) {
        return location
    }

    private fun parseHotsplots(location: Location, data: ByteArray): Location {
        val json = JSONObject(data.decodeToString())
        location.accuracy = 100f
        location.latitude = json.getDouble("lat")
        location.longitude = json.getDouble("lng")
        json.optLong("ts").takeIf { it != 0L }?.let { location.time = it * 1000 }
        json.optDouble("speed").takeIf { !it.isNaN() }?.let {
            location.speed = it.toFloat()
            LocationCompat.setSpeedAccuracyMetersPerSecond(location, location.speed * 0.1f)
        }
        return location
    }

    private fun parseInput(ssid: String, data: ByteArray): Location {
        val location = Location(ssid)
        return when (ssid) {
@@ -291,6 +305,7 @@ class MovingWifiHelper(private val context: Context) {
            "_SNCF_WIFI_INTERCITES" -> parseSncf(location, data)
            "_WIFI_LYRIA" -> parseSncf(location, data)
            "NormandieTrainConnecte" -> parseSncf(location, data)
            "agilis-Wifi" -> parseHotsplots(location, data)
            else -> throw UnsupportedOperationException()
        }
    }
@@ -319,7 +334,8 @@ class MovingWifiHelper(private val context: Context) {
            "_SNCF_WIFI_INOUI" to "https://wifi.sncf/router/api/train/gps",
            "_SNCF_WIFI_INTERCITES" to "https://wifi.intercites.sncf/router/api/train/gps",
            "_WIFI_LYRIA" to "https://wifi.tgv-lyria.com/router/api/train/gps",
            "NormandieTrainConnecte" to "https://wifi.normandie.fr/router/api/train/gps"
            "NormandieTrainConnecte" to "https://wifi.normandie.fr/router/api/train/gps",
            "agilis-Wifi" to "http://hsp.hotsplots.net/status.json",
        )
    }
}