Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / networklocation / src / main / java / com / vayunmathur / networklocation / PositioningData.kt
PositioningData.kt76 lines · 2.6 KiBRaw
| 1 | package com.vayunmathur.networklocation |
| 2 | |
| 3 | /** |
| 4 | * Plain domain types shared across the network-location pipeline (scan → offline |
| 5 | * store lookup → cache → position estimate). Kept free of Android types so the |
| 6 | * pieces compose cleanly. |
| 7 | */ |
| 8 | |
| 9 | /** |
| 10 | * Cellular access technology. Part of a cell's identity, not decoration: an LTE ECI and a GSM |
| 11 | * CID are different numbers in the same range, so without this two unrelated towers in the same |
| 12 | * network and area code alias onto one key. |
| 13 | * |
| 14 | * The wire values are baked into the `cells-v2.wpsdb` key and MUST match `wps_harvest`'s |
| 15 | * `RadioType`. Append only. |
| 16 | */ |
| 17 | @Suppress("MagicNumber") // Wire values are the protocol spec; see doc above. |
| 18 | /** |
| 19 | * Wire values are baked into the `cells-v2.wpsdb` key and MUST match `wps_harvest`'s |
| 20 | * `RadioType`. File level (not in the companion): enum entries are initialised |
| 21 | * before the companion object, so entries cannot read companion constants — |
| 22 | * but file-level `const` is inlined at compile time and has no init order. |
| 23 | */ |
| 24 | private const val WIRE_GSM = 1 |
| 25 | private const val WIRE_UMTS = 2 |
| 26 | private const val WIRE_LTE = 3 |
| 27 | private const val WIRE_NR = 4 |
| 28 | |
| 29 | enum class RadioType(val wire: Int) { |
| 30 | GSM(WIRE_GSM), |
| 31 | UMTS(WIRE_UMTS), |
| 32 | LTE(WIRE_LTE), |
| 33 | NR(WIRE_NR), |
| 34 | ; |
| 35 | } |
| 36 | |
| 37 | /** A radio beacon we can resolve to a location: a WiFi access point or a cell tower. */ |
| 38 | sealed interface BeaconId { |
| 39 | data class Wifi(val bssid: String) : BeaconId |
| 40 | |
| 41 | /** |
| 42 | * [cellId] is a [Long] because 5G's NCI is 36 bits; truncating it to an [Int] aliases |
| 43 | * distinct gNB cells onto one another. [tacOrLac] holds a 5G 24-bit TAC as well as the |
| 44 | * 16-bit LTE TAC and GSM/UMTS LAC. |
| 45 | */ |
| 46 | data class Cell( |
| 47 | val mcc: Int, |
| 48 | val mnc: Int, |
| 49 | val radio: RadioType, |
| 50 | val cellId: Long, |
| 51 | val tacOrLac: Int, |
| 52 | ) : BeaconId |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * A beacon whose coordinates are known (from the offline stores or the local cache). |
| 57 | * [accuracyMeters] is the beacon's own horizontal accuracy radius. |
| 58 | * |
| 59 | * [altitudeMeters] is the beacon's altitude when the source reported one (kind-2 WiFi |
| 60 | * records; Apple's `location.5`), or null when it did not — always the case for cells and |
| 61 | * for kind-1 stores. The solver is 2D and does not consume it yet. |
| 62 | */ |
| 63 | data class BeaconFix( |
| 64 | val id: BeaconId, |
| 65 | val latitude: Double, |
| 66 | val longitude: Double, |
| 67 | val accuracyMeters: Double, |
| 68 | val altitudeMeters: Double? = null, |
| 69 | ) |
| 70 | |
| 71 | /** An estimated device position: the output of the Rust weighted-centroid solver. */ |
| 72 | data class DevicePosition( |
| 73 | val latitude: Double, |
| 74 | val longitude: Double, |
| 75 | val accuracyMeters: Double, |
| 76 | ) |