-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Location: Major rework of location provider
- Add Import/Export - Allow online source selection - Improve local data handling
- Loading branch information
Showing
35 changed files
with
1,876 additions
and
655 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...rvices-location/core/base/src/main/kotlin/org/microg/gms/location/network/OnlineSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.microg.gms.location.network | ||
|
||
import android.net.Uri | ||
import android.util.Log | ||
import org.json.JSONArray | ||
import org.json.JSONObject | ||
import org.microg.gms.location.LocationSettings | ||
import org.microg.gms.location.base.BuildConfig | ||
|
||
fun parseOnlineSources(string: String): List<OnlineSource> = JSONArray(string).let { array -> | ||
(0 until array.length()).map { parseOnlineSource(array.getJSONObject(it)) }.also { Log.d("Location", "parseOnlineSources: ${it.joinToString()}") } | ||
} | ||
|
||
fun parseOnlineSource(json: JSONObject): OnlineSource { | ||
val id = json.getString("id") | ||
val url = json.optString("url").takeIf { it.isNotBlank() } | ||
val host = json.optString("host").takeIf { it.isNotBlank() } ?: runCatching { Uri.parse(url).host }.getOrNull() | ||
val name = json.optString("name").takeIf { it.isNotBlank() } ?: host | ||
return OnlineSource( | ||
id = id, | ||
name = name, | ||
url = url, | ||
host = host, | ||
terms = json.optString("terms").takeIf { it.isNotBlank() }?.let { runCatching { Uri.parse(it) }.getOrNull() }, | ||
suggested = json.optBoolean("suggested", false), | ||
import = json.optBoolean("import", false), | ||
allowContribute = json.optBoolean("allowContribute", false), | ||
) | ||
} | ||
|
||
data class OnlineSource( | ||
val id: String, | ||
val name: String? = null, | ||
val url: String? = null, | ||
val host: String? = null, | ||
val terms: Uri? = null, | ||
/** | ||
* Show suggested flag | ||
*/ | ||
val suggested: Boolean = false, | ||
/** | ||
* If set, automatically import from custom URL if host matches (is the same domain suffix) | ||
*/ | ||
val import: Boolean = false, | ||
val allowContribute: Boolean = false, | ||
) { | ||
companion object { | ||
/** | ||
* Entry to allow configuring a custom URL | ||
*/ | ||
val ID_CUSTOM = "custom" | ||
|
||
/** | ||
* Legacy compatibility | ||
*/ | ||
val ID_DEFAULT = "default" | ||
|
||
val ALL: List<OnlineSource> = BuildConfig.ONLINE_SOURCES | ||
} | ||
} | ||
|
||
val LocationSettings.onlineSource: OnlineSource? | ||
get() { | ||
val id = onlineSourceId | ||
if (id != null) { | ||
val source = OnlineSource.ALL.firstOrNull { it.id == id } | ||
if (source != null) return source | ||
} | ||
val endpoint = customEndpoint | ||
if (endpoint != null) { | ||
val endpointHostSuffix = runCatching { "." + Uri.parse(endpoint).host }.getOrNull() | ||
if (endpointHostSuffix != null) { | ||
for (source in OnlineSource.ALL) { | ||
if (source.import && endpointHostSuffix.endsWith("." + source.host)) { | ||
return source | ||
} | ||
} | ||
} | ||
val customSource = OnlineSource.ALL.firstOrNull { it.id == OnlineSource.ID_CUSTOM } | ||
if (customSource != null && customSource.import) { | ||
return customSource | ||
} | ||
} | ||
if (OnlineSource.ALL.size == 1) return OnlineSource.ALL.single() | ||
return OnlineSource.ALL.firstOrNull { it.id == OnlineSource.ID_DEFAULT } | ||
} | ||
|
||
val LocationSettings.effectiveEndpoint: String? | ||
get() { | ||
val source = onlineSource ?: return null | ||
if (source.id == OnlineSource.ID_CUSTOM) return customEndpoint | ||
return source.url | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...re/provider/src/main/kotlin/org/microg/gms/location/network/DatabaseExportFileProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.microg.gms.location.network | ||
|
||
import android.net.Uri | ||
import androidx.core.content.FileProvider | ||
|
||
class DatabaseExportFileProvider : FileProvider() { | ||
override fun getType(uri: Uri): String? { | ||
try { | ||
if (uri.lastPathSegment?.startsWith("cell-") == true) { | ||
return "application/vnd.microg.location.cell+csv+gzip" | ||
} | ||
if (uri.lastPathSegment?.startsWith("wifi-") == true) { | ||
return "application/vnd.microg.location.wifi+csv+gzip" | ||
} | ||
} catch (ignored: Exception) {} | ||
return super.getType(uri) | ||
} | ||
} |
Oops, something went wrong.
44a9a4d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't support import OpenCellID database.
44a9a4d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There will be documentation about the format elsewhere, but I put this here as a start:
The file needs to be a csv file, optionally gzip compressed. Optional columns must be present, but the value can be left empty. The column order does not matter.
For all:
lat
: latitude as decimal number between -90 and 90.lon
: longitude as decimal number between -180 and 180.alt
: optional altitude in meters as decimal number.For Wi-Fi:
mac
: BSSID / MAC address in hexadecimal with leading zeros, in lower or upper case and with optional:
byte delimiterFor cell towers:
mcc
: MCC in decimal without leading zerosmnc
: MNC in decimal without leading zerostype
: Cell tower type0
orCDMA
for CDMA1
orGSM
for GSM2
orWCDMA
for UMTS3
orLTE
for LTE4
orTDSCDMA
for TD-SCDMA5
orNR
for 5G (New Radio 5G)lac
: LAC or TACcid
: CID, CI or NCIpsc
: optional PSC or PCIIt should be reasonably possible to convert all existing cell tower or wifi databases into this format. As you likely want to filter any existing database to only include data relevant for your region, conversion and filtering could happen at the same time.