RF Sentinel (RFSentinel): free, open-source police detector app for Android. Spots police body cams, Flock ALPR cameras, AirTag trackers, Remote ID drones, smart glasses and fake cell towers from Bluetooth LE and WiFi. No root.
Kotlin airtagalprandroidandroid-autoanti-surveillancebluetooth-low-energybody-cameracounter-surveillancedrone-detectionflock-safetyimsi-catcher-detectorpolice-detectorpolice-scannerprivacyremote-idrtl-sdrsdrsurveillance-detectiontracker-detectionwifi
Pre-download cameras around you; sturdier Overpass downloads
CIS-C068026010467d
diff --git a/README.md b/README.mdindex 06c2121..7606e90 100644--- a/README.md+++ b/README.md@@ -77,7 +77,7 @@ publicly.- Patrol-vehicle detection: several kinds of police-type equipment whose signals move together are flagged as a possible police vehicle- Address-rotation linking: follows a device when its Bluetooth address changes- Follower alerts: a warning when a tracker or flagged device keeps moving with you-- **Known plate, speed and red-light cameras:** the cameras mapped in OpenStreetMap (plate readers e.g. by DeFlock, fixed speed and red-light cameras) appear on the map by themselves for the area you look at, and you're warned as you approach one - even the cellular-only cameras no radio scan can detect. Speed cameras warn about 30 seconds ahead, with the limit when it's mapped. Areas are kept offline and refreshed weekly+- **Known plate, speed and red-light cameras:** the cameras mapped in OpenStreetMap (plate readers e.g. by DeFlock, fixed speed and red-light cameras) appear on the map by themselves for the area you look at, and you're warned as you approach one - even the cellular-only cameras no radio scan can detect. Speed cameras warn about 30 seconds ahead, with the limit when it's mapped. Areas are kept offline and refreshed weekly; the setup wizard (and Settings) can pre-download everything within ~100 km of you- **Drones:** live map of each Remote ID drone with its heading, altitude, speed and operator, plus a "drone overhead" alert- **Fake cell tower signs (IMSI catchers):** warnings for test network codes, forced 2G downgrades, unexpected networks and other classic signs (heuristic, no root needed)- Editable watchlist with exact addresses, vendor prefixes, and name or vendor rules, plus regional presets (Global, Canada, US)diff --git a/app/src/main/java/com/rfsentinel/app/alpr/AlprStore.kt b/app/src/main/java/com/rfsentinel/app/alpr/AlprStore.ktindex f4e7278..d0b9308 100644--- a/app/src/main/java/com/rfsentinel/app/alpr/AlprStore.kt+++ b/app/src/main/java/com/rfsentinel/app/alpr/AlprStore.kt@@ -5,6 +5,10 @@ import com.google.gson.Gsonimport com.google.gson.reflect.TypeTokenimport com.rfsentinel.app.BuildConfigimport kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.cancel+import kotlinx.coroutines.flow.first+import kotlinx.coroutines.flow.updateAndGet+import kotlinx.coroutines.launchimport kotlinx.coroutines.withContextimport java.io.Fileimport java.net.HttpURLConnection@@ -93,6 +97,35 @@ object AlprStore {}}+ /**+ * Downloads every known camera within about [radiusKm] of a point, in up to+ * four tiles (small requests get through busy servers more easily). Tiles+ * that fail are skipped - the map fetches them later. Returns how many+ * cameras were found, or throws when no tile could be downloaded.+ */+ suspend fun downloadAround(+ context: Context, lat: Double, lon: Double, radiusKm: Double = 100.0,+ onProgress: (done: Int, total: Int) -> Unit = { _, _ -> }+ ): Int {+ val tiles = CameraArea.tilesAround(lat, lon, radiusKm, MAX_SPAN_DEG / 2)+ var found = 0+ var ok = 0+ var lastError: Exception? = null+ tiles.forEachIndexed { i, t ->+ try {+ found += download(context, t[0], t[1], t[2], t[3])+ ok+++ } catch (e: kotlinx.coroutines.CancellationException) {+ throw e+ } catch (e: Exception) {+ lastError = e+ }+ onProgress(i + 1, tiles.size)+ }+ if (ok == 0) throw lastError ?: java.io.IOException("No answer")+ return found+ }+/*** Downloads the cameras in a bounding box and merges them into the cache* (cameras deleted from OSM inside the box are dropped). Returns how many@@ -100,17 +133,17 @@ object AlprStore {*/suspend fun download(context: Context, south: Double, west: Double, north: Double, east: Double): Int =withContext(Dispatchers.IO) {- require(north - south <= MAX_SPAN_DEG && east - west <= MAX_SPAN_DEG) { "Area too large - zoom in" }+ require(north - south <= MAX_SPAN_DEG + 1e-9 && east - west <= MAX_SPAN_DEG + 1e-9) { "Area too large - zoom in" }val body = "data=" + URLEncoder.encode(KnownCameras.query(south, west, north, east), "UTF-8")- var lastError: Exception? = null- for (endpoint in ENDPOINTS) {- val json = try {- fetch(endpoint, body)- } catch (e: Exception) {- lastError = e- continue- }- val found = KnownCameras.parse(json)+ // Public servers often answer 429/504 under load: one more round after a pause.+ val json = try {+ fetchFirst(body)+ } catch (e: java.io.IOException) {+ kotlinx.coroutines.delay(RETRY_PAUSE_MS)+ fetchFirst(body)+ }+ val found = KnownCameras.parse(json)+ synchronized(this@AlprStore) {val inBox = { c: KnownCamera -> c.lat in south..north && c.lon in west..east }val merged = cameras.filterNot(inBox) + foundfile(context).writeText(gson.toJson(merged))@@ -118,21 +151,58 @@ object AlprStore {val area = CameraArea(south, west, north, east, System.currentTimeMillis())areas = areas.filterNot { area.contains(it) } + arearunCatching { areasFile(context).writeText(gson.toJson(areas)) }- return@withContext found.size}- error("OpenStreetMap servers busy (${lastError?.message ?: "no answer"}) - try again later")+ found.size}+ private const val STAGGER_MS = 4_000L+ private const val RETRY_PAUSE_MS = 5_000L++ /**+ * Asks the main server first and each mirror a few seconds later (at once+ * if the earlier ones already failed); the first JSON answer wins and the+ * others are abandoned. Throws an IOException when every server failed.+ */+ private suspend fun fetchFirst(body: String): String {+ val requests = kotlinx.coroutines.CoroutineScope(Dispatchers.IO + kotlinx.coroutines.SupervisorJob())+ val result = kotlinx.coroutines.CompletableDeferred<String>()+ val failures = kotlinx.coroutines.flow.MutableStateFlow(0)+ val errors = java.util.Collections.synchronizedList(mutableListOf<String>())+ val open = java.util.Collections.synchronizedList(mutableListOf<HttpURLConnection>())+ ENDPOINTS.forEachIndexed { i, endpoint ->+ requests.launch {+ if (i > 0) kotlinx.coroutines.withTimeoutOrNull(STAGGER_MS * i) { failures.first { it >= i } }+ if (result.isCompleted) return@launch+ try {+ result.complete(fetch(endpoint, body) { open += it })+ } catch (e: Exception) {+ errors += "${URL(endpoint).host}: ${e.message}"+ if (failures.updateAndGet { it + 1 } == ENDPOINTS.size) {+ result.completeExceptionally(java.io.IOException("OpenStreetMap servers busy - try again later"))+ }+ }+ }+ }+ return try {+ result.await()+ } finally {+ requests.cancel()+ synchronized(open) { open.forEach { runCatching { it.disconnect() } } }+ if (!result.isCompleted || errors.isNotEmpty()) android.util.Log.i("AlprStore", "Overpass: $errors")+ }+ }+/** One Overpass request; throws unless the answer is a JSON result. */- private fun fetch(endpoint: String, body: String): String {+ private fun fetch(endpoint: String, body: String, onOpen: (HttpURLConnection) -> Unit): String {val conn = (URL(endpoint).openConnection() as HttpURLConnection).apply {requestMethod = "POST"doOutput = true- connectTimeout = 15_000- readTimeout = 100_000+ connectTimeout = 10_000+ readTimeout = 60_000setRequestProperty("User-Agent", "${BuildConfig.APPLICATION_ID}/${BuildConfig.VERSION_NAME}")setRequestProperty("Content-Type", "application/x-www-form-urlencoded")}+ onOpen(conn)try {conn.outputStream.use { it.write(body.toByteArray()) }if (conn.responseCode != 200) error("HTTP ${conn.responseCode}")@@ -166,8 +236,36 @@ data class CameraArea(val south: Double, val west: Double, val north: Double, vas >= south && w >= west && n <= north && e <= eastcompanion object {- fun needsDownload(areas: List<CameraArea>, s: Double, w: Double, n: Double, e: Double, now: Long, maxAgeMs: Long) =- areas.none { now - it.time < maxAgeMs && it.contains(s, w, n, e) }+ /**+ * True unless the box is covered by fresh areas. Several areas together+ * count (e.g. the tiles downloaded around you at setup): a 3x3 grid of+ * points across the box must each fall inside one of them.+ */+ fun needsDownload(areas: List<CameraArea>, s: Double, w: Double, n: Double, e: Double, now: Long, maxAgeMs: Long): Boolean {+ val fresh = areas.filter { now - it.time < maxAgeMs }+ if (fresh.any { it.contains(s, w, n, e) }) return false+ for (i in 0..2) for (j in 0..2) {+ val lat = s + (n - s) * i / 2+ val lon = w + (e - w) * j / 2+ if (fresh.none { it.contains(lat, lon, lat, lon) }) return true+ }+ return false+ }++ /**+ * The box within [radiusKm] of a point, split into 2x2 tiles no larger+ * than [maxTileDeg] on a side: [[south, west, north, east], ...].+ */+ fun tilesAround(lat: Double, lon: Double, radiusKm: Double, maxTileDeg: Double): List<DoubleArray> {+ val dLat = (radiusKm / 111.0).coerceAtMost(maxTileDeg)+ val dLon = (radiusKm / (111.0 * kotlin.math.max(0.05, kotlin.math.cos(Math.toRadians(lat))))).coerceAtMost(maxTileDeg)+ val s = (lat - dLat).coerceAtLeast(-90.0); val n = (lat + dLat).coerceAtMost(90.0)+ val w = (lon - dLon).coerceAtLeast(-180.0); val e = (lon + dLon).coerceAtMost(180.0)+ return listOf(+ doubleArrayOf(s, w, lat, lon), doubleArrayOf(s, lon, lat, e),+ doubleArrayOf(lat, w, n, lon), doubleArrayOf(lat, lon, n, e)+ )+ }/** Smallest box one automatic download covers (degrees, ~40 km). */const val MIN_SPAN_DEG = 0.4diff --git a/app/src/main/java/com/rfsentinel/app/alpr/CameraPrefetch.kt b/app/src/main/java/com/rfsentinel/app/alpr/CameraPrefetch.ktnew file mode 100644index 0000000..9adffee--- /dev/null+++ b/app/src/main/java/com/rfsentinel/app/alpr/CameraPrefetch.kt@@ -0,0 +1,108 @@+package com.rfsentinel.app.alpr++import android.Manifest+import android.annotation.SuppressLint+import android.content.Context+import android.content.Intent+import android.location.Location+import android.location.LocationManager+import android.os.Handler+import android.os.Looper+import androidx.core.content.ContextCompat+import androidx.core.location.LocationManagerCompat+import com.rfsentinel.app.service.ScanForegroundService+import com.rfsentinel.app.util.Permissions+import kotlinx.coroutines.CoroutineScope+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.Job+import kotlinx.coroutines.SupervisorJob+import kotlinx.coroutines.launch+import kotlinx.coroutines.suspendCancellableCoroutine+import kotlinx.coroutines.withTimeoutOrNull+import kotlin.coroutines.resume++/**+ * "Download the cameras around me": finds where you are and fetches the known+ * plate, speed and red-light cameras within ~100 km, so they're on the map and+ * warn you offline from the start. Runs in the background - leaving the screen+ * that started it doesn't stop it. Only the area is sent, never your scans.+ */+object CameraPrefetch {++ sealed interface State {+ data object Idle : State+ data object Locating : State+ data class Downloading(val done: Int, val total: Int) : State+ data class Done(val cameras: Int) : State+ data class Failed(val reason: String) : State+ }++ private val scope = CoroutineScope(Dispatchers.Main + SupervisorJob())+ private val main = Handler(Looper.getMainLooper())+ private var job: Job? = null+ private val listeners = mutableSetOf<(State) -> Unit>()++ @Volatile var state: State = State.Idle+ private set++ fun canRun(context: Context) =+ Permissions.granted(context, Manifest.permission.ACCESS_FINE_LOCATION) ||+ Permissions.granted(context, Manifest.permission.ACCESS_COARSE_LOCATION)++ /** Called on the main thread with every state change (and once right away). */+ fun observe(listener: (State) -> Unit): () -> Unit {+ listeners += listener+ listener(state)+ return { listeners -= listener }+ }++ private fun set(s: State) = main.post { state = s; listeners.toList().forEach { it(s) } }++ fun start(context: Context) {+ if (job?.isActive == true) return+ val app = context.applicationContext+ job = scope.launch {+ set(State.Locating)+ val here = currentLocation(app)+ if (here == null) { set(State.Failed("No location yet - try again outdoors, or open the map later")); return@launch }+ set(State.Downloading(0, 4))+ try {+ val n = AlprStore.downloadAround(app, here.latitude, here.longitude) { done, total ->+ set(State.Downloading(done, total))+ }+ set(State.Done(n))+ // A running scan starts watching for the new cameras.+ if (ScanForegroundService.isRunning) runCatching {+ app.startService(Intent(app, ScanForegroundService::class.java).setAction(ScanForegroundService.ACTION_REFRESH_LOCATION))+ }+ } catch (e: kotlinx.coroutines.CancellationException) {+ throw e+ } catch (e: Exception) {+ set(State.Failed(e.message ?: "OpenStreetMap servers busy - try again later"))+ }+ }+ }++ /** A recent last-known position, or a fresh fix (up to 30 s); null without permission or fix. */+ @SuppressLint("MissingPermission") // checked by canRun()+ private suspend fun currentLocation(context: Context): Location? {+ if (!canRun(context)) return null+ val lm = context.getSystemService(LocationManager::class.java) ?: return null+ val last = listOf(LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER, LocationManager.PASSIVE_PROVIDER)+ .mapNotNull { p -> runCatching { lm.getLastKnownLocation(p) }.getOrNull() }+ .maxByOrNull { it.time }+ if (last != null && System.currentTimeMillis() - last.time < 6 * 3600_000L) return last+ val provider = listOf(LocationManager.NETWORK_PROVIDER, LocationManager.GPS_PROVIDER)+ .firstOrNull { runCatching { lm.isProviderEnabled(it) }.getOrDefault(false) } ?: return last+ val fresh = withTimeoutOrNull(30_000L) {+ suspendCancellableCoroutine { cont ->+ val cancel = androidx.core.os.CancellationSignal()+ cont.invokeOnCancellation { cancel.cancel() }+ LocationManagerCompat.getCurrentLocation(lm, provider, cancel, ContextCompat.getMainExecutor(context)) { loc ->+ if (cont.isActive) cont.resume(loc)+ }+ }+ }+ return fresh ?: last+ }+}diff --git a/app/src/main/java/com/rfsentinel/app/alpr/KnownCameras.kt b/app/src/main/java/com/rfsentinel/app/alpr/KnownCameras.ktindex 907da47..723ed00 100644--- a/app/src/main/java/com/rfsentinel/app/alpr/KnownCameras.kt+++ b/app/src/main/java/com/rfsentinel/app/alpr/KnownCameras.kt@@ -49,13 +49,20 @@ data class KnownCamera(object KnownCameras {- /** Overpass QL for every mapped plate reader, speed and red-light camera in a bounding box. */+ /**+ * Overpass QL for every mapped plate reader, speed and red-light camera in+ * a bounding box. Kept cheap on purpose - simple per-type key lookups and a+ * short declared timeout - because busy public servers turn away heavy or+ * long requests first (HTTP 429 / 504). [parse] sorts out the kinds.+ */fun query(south: Double, west: Double, north: Double, east: Double): String {val b = "($south,$west,$north,$east)"- return "[out:json][timeout:90];(" +- "nwr[\"surveillance:type\"=\"ALPR\"]$b;" ++ return "[out:json][timeout:25];(" ++ "node[\"surveillance:type\"=\"ALPR\"]$b;" ++ "way[\"surveillance:type\"=\"ALPR\"]$b;" +"node[\"highway\"=\"speed_camera\"]$b;" +- "nwr[\"enforcement\"~\"^(maxspeed|average_speed|traffic_signals)$\"]$b;" ++ "node[\"enforcement\"]$b;" ++ "relation[\"type\"=\"enforcement\"]$b;" +");out center tags;"}diff --git a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.ktindex aba1326..9886d3d 100644--- a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt+++ b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt@@ -24,6 +24,7 @@ import kotlinx.coroutines.launchclass SettingsActivity : AppCompatActivity() {private lateinit var binding: ActivitySettingsBinding+ private var stopObservingPrefetch: (() -> Unit)? = nullprivate val categorySwitches = mutableMapOf<Category, SwitchMaterial>()private val bannerPicker = registerForActivityResult(@@ -101,6 +102,11 @@ class SettingsActivity : AppCompatActivity() {binding.bannerClearButton.isEnabled = ThemeManager.hasBanner(this)}+ override fun onDestroy() {+ stopObservingPrefetch?.invoke()+ super.onDestroy()+ }+override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)binding = ActivitySettingsBinding.inflate(layoutInflater)@@ -229,6 +235,13 @@ class SettingsActivity : AppCompatActivity() {binding.knownAlprSwitch.isChecked = Prefs.knownAlprAlerts(this)binding.speedCameraSwitch.isChecked = Prefs.speedCameraAlerts(this)binding.autoCamerasSwitch.isChecked = Prefs.autoCameras(this)+ binding.prefetchCamerasButton.setOnClickListener { com.rfsentinel.app.alpr.CameraPrefetch.start(this) }+ stopObservingPrefetch = com.rfsentinel.app.alpr.CameraPrefetch.observe { s ->+ val located = com.rfsentinel.app.alpr.CameraPrefetch.canRun(this)+ binding.prefetchCamerasButton.isEnabled = located &&+ s !is com.rfsentinel.app.alpr.CameraPrefetch.State.Locating && s !is com.rfsentinel.app.alpr.CameraPrefetch.State.Downloading+ binding.prefetchCamerasText.text = com.rfsentinel.app.ui.cameraPrefetchText(s, located)+ }// Databinding.retentionInput.setText(Prefs.retentionDays(this).toString())diff --git a/app/src/main/java/com/rfsentinel/app/ui/CameraPrefetchText.kt b/app/src/main/java/com/rfsentinel/app/ui/CameraPrefetchText.ktnew file mode 100644index 0000000..da22868--- /dev/null+++ b/app/src/main/java/com/rfsentinel/app/ui/CameraPrefetchText.kt@@ -0,0 +1,12 @@+package com.rfsentinel.app.ui++import com.rfsentinel.app.alpr.CameraPrefetch++/** One line describing a camera pre-download, for the setup page and Settings. */+fun cameraPrefetchText(s: CameraPrefetch.State, located: Boolean): String = when (s) {+ CameraPrefetch.State.Idle -> if (located) "" else "Grant location access first (above)."+ CameraPrefetch.State.Locating -> "Finding your position..."+ is CameraPrefetch.State.Downloading -> "Downloading cameras around you... ${s.done}/${s.total}"+ is CameraPrefetch.State.Done -> "✓ ${s.cameras} known cameras saved within ~100 km of you."+ is CameraPrefetch.State.Failed -> "Couldn't download: ${s.reason}"+}diff --git a/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.kt b/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.ktindex 1488726..8d0e82d 100644--- a/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.kt+++ b/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.kt@@ -43,6 +43,7 @@ class SetupActivity : AppCompatActivity() {private lateinit var binding: ActivitySetupBindingprivate var step = 0private var startAfter = true+ private var stopObservingPrefetch: (() -> Unit)? = nullprivate val permissionLauncher = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()@@ -69,6 +70,11 @@ class SetupActivity : AppCompatActivity() {render()}+ override fun onDestroy() {+ stopObservingPrefetch?.invoke()+ super.onDestroy()+ }+override fun onSaveInstanceState(outState: Bundle) {super.onSaveInstanceState(outState)outState.putInt(KEY_STEP, step)@@ -84,6 +90,7 @@ class SetupActivity : AppCompatActivity() {else -> "Next"}binding.page.removeAllViews()+ stopObservingPrefetch?.invoke(); stopObservingPrefetch = nullwhen (step) {0 -> welcome()1 -> theme()@@ -199,9 +206,25 @@ class SetupActivity : AppCompatActivity() {button("Allow notifications") { permissionLauncher.launch(optionalMissing.toTypedArray()) }}para("Tip: in Android's battery settings, set RF Sentinel to \"Unrestricted\" so scanning keeps running in your pocket.", small = true)+ knownCamerasNearMe()check("Start scanning when I tap Finish", startAfter) { startAfter = it }}+ /** Pre-downloads the known cameras around you, so the map and warnings work offline from the start. */+ private fun knownCamerasNearMe() {+ label("Known cameras near you")+ para("Download the plate, speed and red-light cameras mapped in OpenStreetMap within about 100 km of you, " ++ "so they're on the map and warn you offline right away. Only that area is sent to the OpenStreetMap server.", small = true)+ val btn = button("Download cameras around me") { com.rfsentinel.app.alpr.CameraPrefetch.start(this) }+ val status = para("", small = true)+ stopObservingPrefetch = com.rfsentinel.app.alpr.CameraPrefetch.observe { s ->+ val located = com.rfsentinel.app.alpr.CameraPrefetch.canRun(this)+ btn.isEnabled = located && s !is com.rfsentinel.app.alpr.CameraPrefetch.State.Locating &&+ s !is com.rfsentinel.app.alpr.CameraPrefetch.State.Downloading+ status.text = cameraPrefetchText(s, located)+ }+ }+private fun finishSetup() {Prefs.setOnboardingDone(this)if (step == STEPS - 1 && startAfter && Permissions.missingRequired(this).isEmpty() && !ScanForegroundService.isRunning) {@@ -220,16 +243,15 @@ class SetupActivity : AppCompatActivity() {binding.subtitleText.text = subtitle}- private fun para(text: String, small: Boolean = false) {- binding.page.addView(TextView(this).apply {+ private fun para(text: String, small: Boolean = false): TextView =+ TextView(this).apply {this.text = textsetTextSize(TypedValue.COMPLEX_UNIT_SP, if (small) 12f else 15f)setPadding(0, (6 * dp).toInt(), 0, (6 * dp).toInt())if (small) alpha = 0.75f- })- }+ }.also { binding.page.addView(it) }- private fun bullet(text: String) = para("• $text")+ private fun bullet(text: String) { para("• $text") }private fun label(text: String) {binding.page.addView(TextView(this).apply {@@ -256,12 +278,11 @@ class SetupActivity : AppCompatActivity() {})}- private fun button(text: String, onClick: () -> Unit) {- binding.page.addView(com.google.android.material.button.MaterialButton(this).apply {+ private fun button(text: String, onClick: () -> Unit): android.widget.Button =+ com.google.android.material.button.MaterialButton(this).apply {this.text = textsetOnClickListener { onClick() }- })- }+ }.also { binding.page.addView(it) }private fun card(title: String, desc: String, selected: Boolean, onClick: () -> Unit) {val card = MaterialCardView(this).apply {diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xmlindex fb5081a..4b5de2e 100644--- a/app/src/main/res/layout/activity_settings.xml+++ b/app/src/main/res/layout/activity_settings.xml@@ -315,6 +315,19 @@android:layout_height="wrap_content"android:text="Show known cameras automatically: download them from OpenStreetMap for the map area you look at (the Overpass server sees that area, like map tiles)" />+ <Button+ android:id="@+id/prefetchCamerasButton"+ style="@style/Widget.MaterialComponents.Button.TextButton"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:text="Download cameras around me (~100 km)" />++ <TextView+ android:id="@+id/prefetchCamerasText"+ style="@style/SettingsLabel"+ android:paddingTop="0dp"+ android:textSize="12sp" />+<com.google.android.material.switchmaterial.SwitchMaterialandroid:id="@+id/speedCameraSwitch"android:layout_width="match_parent"diff --git a/app/src/test/java/com/rfsentinel/app/alpr/CameraAreaTest.kt b/app/src/test/java/com/rfsentinel/app/alpr/CameraAreaTest.ktindex 1449762..51619c8 100644--- a/app/src/test/java/com/rfsentinel/app/alpr/CameraAreaTest.kt+++ b/app/src/test/java/com/rfsentinel/app/alpr/CameraAreaTest.kt@@ -19,6 +19,18 @@ class CameraAreaTest {assertTrue(CameraArea.needsDownload(emptyList(), 10.2, -20.8, 10.8, -20.2, now = day, maxAgeMs = 7 * day))}+ @Test+ fun tilesTogetherCoverABox() {+ val tiles = CameraArea.tilesAround(10.5, -20.5, radiusKm = 100.0, maxTileDeg = 1.0)+ assertEquals(4, tiles.size)+ tiles.forEach { assertTrue(it[2] - it[0] <= 1.0 + 1e-9 && it[3] - it[1] <= 1.0 + 1e-9) }+ val areas = tiles.map { CameraArea(it[0], it[1], it[2], it[3], time = 0L) }+ // A view straddling all four tiles is covered by them together...+ assertFalse(CameraArea.needsDownload(areas, 10.3, -20.7, 10.7, -20.3, now = day, maxAgeMs = 7 * day))+ // ...but one reaching past them is not.+ assertTrue(CameraArea.needsDownload(areas, 10.3, -20.7, 11.9, -20.3, now = day, maxAgeMs = 7 * day))+ }+@Testfun expandDoublesWithinLimits() {// A small zoomed-in box grows to the minimum span.diff --git a/app/src/test/java/com/rfsentinel/app/alpr/KnownCamerasTest.kt b/app/src/test/java/com/rfsentinel/app/alpr/KnownCamerasTest.ktindex e3a0b2a..c037b5e 100644--- a/app/src/test/java/com/rfsentinel/app/alpr/KnownCamerasTest.kt+++ b/app/src/test/java/com/rfsentinel/app/alpr/KnownCamerasTest.kt@@ -75,7 +75,8 @@ class KnownCamerasTest {assertEquals(48, cams.first { it.osmId == "node/4" }.maxspeed) // 30 mphassertEquals("Red-light camera", cams.first { it.type == KnownCamera.Kind.RED_LIGHT }.label)val q = KnownCameras.query(1.0, 2.0, 3.0, 4.0)- assertTrue(q.contains("\"highway\"=\"speed_camera\"") && q.contains("traffic_signals"))+ assertTrue(q.contains("\"highway\"=\"speed_camera\"") && q.contains("relation[\"type\"=\"enforcement\"]"))+ assertTrue(q.startsWith("[out:json][timeout:25]")) // short timeout: busy servers refuse long ones first}@Test