Skip to content

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.

Speed and red-light camera warnings from OpenStreetMap

CIS-C0c0a02c7c7082
diff --git a/README.md b/README.md
index 788ad21..f0d2bed 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 cameras:** download the license-plate readers mapped in OpenStreetMap (e.g. by DeFlock) and get warned as you approach one - even the cellular-only cameras no radio scan can detect
+- **Known plate, speed and red-light cameras:** download the cameras mapped in OpenStreetMap (plate readers e.g. by DeFlock, fixed speed and red-light cameras) and get 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
- **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)
@@ -95,7 +95,7 @@ publicly.
- Alerts with sound, vibration patterns and spoken announcements, plus a discreet mode
- **Floating threat bubble** over Waze, Google Maps or any other app while scanning
- **Starts by itself in the car** (your car's Bluetooth or Android Auto) and stops when you leave
-- Android Auto app with a map of nearby plate cameras and drones, Quick Settings tile and home-screen widget
+- Android Auto app with a map of nearby cameras and drones, Quick Settings tile and home-screen widget
- **Report unknown device:** share a privacy-safe signature (no full address, serials, location or times) so new equipment can be added
- 12 themes, each styled theme with its own animated header
@@ -188,7 +188,7 @@ RF Sentinel runs in Android Auto as a driver-safe, template-based app:
- **Device lists** (flagged, drones & trackers, all nearby) and **device details**
with Whitelist, Watch and Favorite actions. **Navigate** opens your car's
navigation app for drones with a known position.
-- **Plate cameras & drones map:** the closest known plate cameras (downloaded
+- **Cameras & drones map:** the closest known plate, speed and red-light cameras (downloaded
on the phone from OpenStreetMap) and Remote ID drones, on the car's map
with distances.
- **Alerts** appear as a heads-up on the car screen. While connected, they play
@@ -247,8 +247,10 @@ Pick a theme in the setup wizard or under **Settings → Appearance**.
- **No accounts, no cloud, no analytics.** Detections are stored in a local
database and excluded from cloud backup.
- **Network use is limited to OpenStreetMap:** map tiles while the map is open, and,
- only when you tap *Download known plate cameras*, the camera list for the area on
- screen. Those servers see your IP address and that area, never your scans. Map data
+ only when you tap *Download known cameras*, the camera list for the area on
+ screen (from overpass-api.de, or the public mirrors overpass.kumi.systems and
+ overpass.private.coffee when it's busy). Those servers see your IP address and
+ that area, never your scans. Map data
© OpenStreetMap contributors (ODbL).
- **Data leaves the phone only when you export or share it.**
- **Optional permissions:** *Nearby devices → connect* is asked only to read the
diff --git a/app/src/main/java/com/rfsentinel/app/alpr/AlprStore.kt b/app/src/main/java/com/rfsentinel/app/alpr/AlprStore.kt
index e252c10..496eef6 100644
--- a/app/src/main/java/com/rfsentinel/app/alpr/AlprStore.kt
+++ b/app/src/main/java/com/rfsentinel/app/alpr/AlprStore.kt
@@ -19,7 +19,15 @@ import java.net.URLEncoder
object AlprStore {
private const val FILE = "known_alpr.json"
- private const val ENDPOINT = "https://overpass-api.de/api/interpreter"
+ /**
+ * The main Overpass server, then public mirrors for when it's overloaded
+ * (it answers with a runtime error under load). Mirrors may lag a few months.
+ */
+ val ENDPOINTS = listOf(
+ "https://overpass-api.de/api/interpreter",
+ "https://overpass.kumi.systems/api/interpreter",
+ "https://overpass.private.coffee/api/interpreter"
+ )
/** Largest area one download may cover (degrees of latitude / longitude). */
const val MAX_SPAN_DEG = 2.0
@@ -46,28 +54,46 @@ object AlprStore {
withContext(Dispatchers.IO) {
require(north - south <= MAX_SPAN_DEG && east - west <= MAX_SPAN_DEG) { "Area too large - zoom in" }
val body = "data=" + URLEncoder.encode(KnownCameras.query(south, west, north, east), "UTF-8")
- val conn = (URL(ENDPOINT).openConnection() as HttpURLConnection).apply {
- requestMethod = "POST"
- doOutput = true
- connectTimeout = 20_000
- readTimeout = 120_000
- setRequestProperty("User-Agent", "${BuildConfig.APPLICATION_ID}/${BuildConfig.VERSION_NAME}")
- setRequestProperty("Content-Type", "application/x-www-form-urlencoded")
- }
- try {
- conn.outputStream.use { it.write(body.toByteArray()) }
- if (conn.responseCode != 200) error("OpenStreetMap server busy (HTTP ${conn.responseCode}) - try again later")
- val found = KnownCameras.parse(conn.inputStream.bufferedReader().use { it.readText() })
+ 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)
val inBox = { c: KnownCamera -> c.lat in south..north && c.lon in west..east }
val merged = cameras.filterNot(inBox) + found
file(context).writeText(gson.toJson(merged))
cameras = merged
- found.size
- } finally {
- conn.disconnect()
+ return@withContext found.size
}
+ error("OpenStreetMap servers busy (${lastError?.message ?: "no answer"}) - try again later")
}
+ /** One Overpass request; throws unless the answer is a JSON result. */
+ private fun fetch(endpoint: String, body: String): String {
+ val conn = (URL(endpoint).openConnection() as HttpURLConnection).apply {
+ requestMethod = "POST"
+ doOutput = true
+ connectTimeout = 15_000
+ readTimeout = 100_000
+ setRequestProperty("User-Agent", "${BuildConfig.APPLICATION_ID}/${BuildConfig.VERSION_NAME}")
+ setRequestProperty("Content-Type", "application/x-www-form-urlencoded")
+ }
+ try {
+ conn.outputStream.use { it.write(body.toByteArray()) }
+ if (conn.responseCode != 200) error("HTTP ${conn.responseCode}")
+ val text = conn.inputStream.bufferedReader().use { it.readText() }
+ // An overloaded server can answer 200 with an HTML error page.
+ if (!text.trimStart().startsWith("{")) error("server error")
+ return text
+ } finally {
+ conn.disconnect()
+ }
+ }
+
/** Tests only: set the cache without files or network. */
@androidx.annotation.VisibleForTesting
fun setForTest(list: List<KnownCamera>) { cameras = list }
diff --git a/app/src/main/java/com/rfsentinel/app/alpr/KnownCameras.kt b/app/src/main/java/com/rfsentinel/app/alpr/KnownCameras.kt
index c60005b..907da47 100644
--- a/app/src/main/java/com/rfsentinel/app/alpr/KnownCameras.kt
+++ b/app/src/main/java/com/rfsentinel/app/alpr/KnownCameras.kt
@@ -6,10 +6,12 @@ import kotlin.math.cos
import kotlin.math.max
/**
- * Plate-reader (ALPR) cameras mapped in OpenStreetMap - most famously by the
- * DeFlock project - with the tag `surveillance:type=ALPR`. Most plate readers
- * send their data over cellular and have no radio signature a phone can hear,
- * so a map of known locations is the only way to warn about them.
+ * Enforcement cameras mapped in OpenStreetMap: plate readers (ALPR, tagged
+ * `surveillance:type=ALPR`, most famously by the DeFlock project), speed
+ * cameras (`highway=speed_camera`, `enforcement=maxspeed|average_speed`) and
+ * red-light cameras (`enforcement=traffic_signals`). They send their data over
+ * cellular or wire and have no radio signature a phone can hear, so a map of
+ * known locations is the only way to warn about them.
*
* Pure Kotlin (parsing and geometry), so it's unit-tested on the JVM.
* Data © OpenStreetMap contributors, ODbL.
@@ -21,17 +23,80 @@ data class KnownCamera(
val brand: String?,
val operator: String?,
/** Direction the camera faces, degrees from north, when mapped. */
- val direction: Int?
+ val direction: Int?,
+ /** Null in caches saved before speed cameras were added: those are all plate readers. */
+ val kind: Kind? = null,
+ /** Enforced speed limit (km/h) for speed cameras, when mapped. */
+ val maxspeed: Int? = null
) {
- val label: String get() = (brand ?: "Plate reader") + " (ALPR)"
+ enum class Kind { ALPR, SPEED, RED_LIGHT }
+
+ val type: Kind get() = kind ?: Kind.ALPR
+
+ val label: String get() = when (type) {
+ Kind.ALPR -> (brand ?: "Plate reader") + " (ALPR)"
+ Kind.SPEED -> "Speed camera" + (maxspeed?.let { " ($it km/h)" } ?: "")
+ Kind.RED_LIGHT -> "Red-light camera"
+ }
+
+ /** Short phrase for spoken alerts. */
+ val spoken: String get() = when (type) {
+ Kind.ALPR -> "Plate camera ahead"
+ Kind.SPEED -> "Speed camera ahead" + (maxspeed?.let { ", $it" } ?: "")
+ Kind.RED_LIGHT -> "Red-light camera ahead"
+ }
}
object KnownCameras {
- /** Overpass QL for every mapped plate reader in a bounding box. */
- fun query(south: Double, west: Double, north: Double, east: Double): String =
- "[out:json][timeout:90];nwr[\"surveillance:type\"=\"ALPR\"]" +
- "($south,$west,$north,$east);out center tags;"
+ /** Overpass QL for every mapped plate reader, speed and red-light camera in a bounding box. */
+ 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;" +
+ "node[\"highway\"=\"speed_camera\"]$b;" +
+ "nwr[\"enforcement\"~\"^(maxspeed|average_speed|traffic_signals)$\"]$b;" +
+ ");out center tags;"
+ }
+
+ /** What an OSM element is, from its tags; null when it's none of ours. */
+ fun kindOf(tag: (String) -> String?): KnownCamera.Kind? = when {
+ tag("surveillance:type").equals("ALPR", ignoreCase = true) -> KnownCamera.Kind.ALPR
+ tag("enforcement") == "traffic_signals" -> KnownCamera.Kind.RED_LIGHT
+ tag("highway") == "speed_camera" || tag("enforcement") in setOf("maxspeed", "average_speed") -> KnownCamera.Kind.SPEED
+ else -> null
+ }
+
+ /** "50", "50 km/h" or "30 mph" -> km/h; null otherwise. */
+ fun parseMaxspeed(v: String?): Int? {
+ val m = Regex("""^\s*(\d{1,3})\s*(mph|km/h|kmh)?\s*$""", RegexOption.IGNORE_CASE).find(v ?: return null) ?: return null
+ val n = m.groupValues[1].toInt()
+ return if (m.groupValues[2].equals("mph", ignoreCase = true)) Math.round(n * 1.609).toInt() else n
+ }
+
+ /**
+ * A speed camera is often mapped twice: the camera node and an enforcement
+ * relation whose centre sits somewhere along the enforced stretch. Keep one
+ * per kind - within 40 m for two nodes, 150 m when one is a relation - and
+ * prefer the copy that has the speed limit, then the node (exact position).
+ */
+ fun dedupe(cameras: List<KnownCamera>): List<KnownCamera> {
+ val kept = ArrayList<KnownCamera>()
+ fun isNode(c: KnownCamera) = c.osmId.startsWith("node")
+ for (c in cameras.sortedByDescending { (if (it.maxspeed != null) 2 else 0) + (if (isNode(it)) 1 else 0) }) {
+ val dup = c.type != KnownCamera.Kind.ALPR && kept.any {
+ it.type == c.type &&
+ DeviceRegistry.metersBetween(it.lat, it.lon, c.lat, c.lon) < (if (isNode(it) && isNode(c)) 40.0 else 150.0)
+ }
+ if (!dup) kept += c
+ }
+ // Keep the exact node position when a relation won only because it had the limit.
+ return kept.map { k ->
+ if (isNode(k) || k.type == KnownCamera.Kind.ALPR) k
+ else cameras.firstOrNull { isNode(it) && it.type == k.type && DeviceRegistry.metersBetween(it.lat, it.lon, k.lat, k.lon) < 150.0 }
+ ?.let { n -> k.copy(lat = n.lat, lon = n.lon) } ?: k
+ }
+ }
/** Parses an Overpass JSON response (nodes, and ways/relations via their centre). */
fun parse(json: String): List<KnownCamera> {
@@ -46,13 +111,16 @@ object KnownCameras {
val lon = pos.get("lon")?.asDouble ?: return@mapNotNull null
val tags = o.getAsJsonObject("tags")
fun tag(vararg keys: String) = keys.firstNotNullOfOrNull { k -> tags?.get(k)?.asString?.takeIf { it.isNotBlank() } }
+ val kind = kindOf { tag(it) } ?: return@mapNotNull null
KnownCamera(
osmId = "$type/$id", lat = lat, lon = lon,
brand = tag("manufacturer", "brand"),
operator = tag("operator"),
- direction = parseDirection(tag("camera:direction", "direction"))
+ direction = parseDirection(tag("camera:direction", "direction")),
+ kind = kind,
+ maxspeed = if (kind == KnownCamera.Kind.SPEED) parseMaxspeed(tag("maxspeed")) else null
)
- }
+ }.let(::dedupe)
}
private val CARDINAL = mapOf(
@@ -69,9 +137,14 @@ object KnownCameras {
/**
* Warning distance: at least 150 m, or ~20 s of travel at your speed
- * (capped at 600 m), so there's time to notice on a highway.
+ * (capped at 600 m), so there's time to notice on a highway. Speed cameras
+ * get ~30 s (300-900 m) so there's time to slow down.
*/
- fun warnRadius(speedMs: Float?): Double = max(150.0, minOf(600.0, (speedMs ?: 0f) * 20.0))
+ fun warnRadius(speedMs: Float?, kind: KnownCamera.Kind = KnownCamera.Kind.ALPR): Double {
+ val v = (speedMs ?: 0f).toDouble()
+ return if (kind == KnownCamera.Kind.ALPR) max(150.0, minOf(600.0, v * 20.0))
+ else max(300.0, minOf(900.0, v * 30.0))
+ }
/** Cameras within [radiusM] of a point, nearest first. Cheap bounding-box prefilter. */
fun near(cameras: List<KnownCamera>, lat: Double, lon: Double, radiusM: Double): List<Pair<KnownCamera, Double>> {
diff --git a/app/src/main/java/com/rfsentinel/app/car/HomeScreen.kt b/app/src/main/java/com/rfsentinel/app/car/HomeScreen.kt
index 6c65aba..625522e 100644
--- a/app/src/main/java/com/rfsentinel/app/car/HomeScreen.kt
+++ b/app/src/main/java/com/rfsentinel/app/car/HomeScreen.kt
@@ -58,7 +58,7 @@ class HomeScreen(carContext: CarContext) : LiveScreen(carContext) {
items.addItem(navRow("All nearby devices", devices.size, R.drawable.ic_car_list, DeviceListScreen.Filter.ALL))
items.addItem(
Row.Builder()
- .setTitle("Plate cameras & drones on the map")
+ .setTitle("Cameras & drones on the map")
.setImage(CarUi.icon(carContext, R.drawable.ic_car_navigate))
.setBrowsable(true)
.setOnClickListener { screenManager.push(NearbyMapScreen(carContext)) }
diff --git a/app/src/main/java/com/rfsentinel/app/car/NearbyMapScreen.kt b/app/src/main/java/com/rfsentinel/app/car/NearbyMapScreen.kt
index 119067e..9c2beeb 100644
--- a/app/src/main/java/com/rfsentinel/app/car/NearbyMapScreen.kt
+++ b/app/src/main/java/com/rfsentinel/app/car/NearbyMapScreen.kt
@@ -23,7 +23,7 @@ import com.rfsentinel.app.util.Permissions
import kotlin.math.roundToInt
/**
- * Android Auto: the closest known plate cameras (OpenStreetMap, downloaded on
+ * Android Auto: the closest known plate, speed and red-light cameras (OpenStreetMap, downloaded on
* the phone) and the drones broadcasting a Remote ID position, on the car's own
* map with distances. The car host draws the map; we only supply places.
*/
@@ -31,7 +31,7 @@ class NearbyMapScreen(carContext: CarContext) : LiveScreen(carContext, periodMs
/** One row: a camera or a drone. */
data class Item(val title: String, val detail: String, val lat: Double, val lon: Double, val distanceM: Double,
- val drone: Boolean, val mac: String?)
+ val drone: Boolean, val mac: String?, val kind: com.rfsentinel.app.alpr.KnownCamera.Kind? = null)
override fun onGetTemplate(): Template {
val me = myLocation()
@@ -43,14 +43,14 @@ class NearbyMapScreen(carContext: CarContext) : LiveScreen(carContext, periodMs
list.setNoItemsMessage("Waiting for your location...")
} else if (items.isEmpty()) {
list.setNoItemsMessage(
- if (AlprStore.cameras.isEmpty()) "No known cameras downloaded - on your phone: Map > menu > Download known plate cameras"
- else "No known plate cameras or drones within ${SEARCH_RADIUS_M / 1000} km"
+ if (AlprStore.cameras.isEmpty()) "No known cameras downloaded - on your phone: Map > menu > Download known cameras"
+ else "No known cameras or drones within ${(SEARCH_RADIUS_M / 1000).toInt()} km"
)
}
items.forEach { it -> list.addItem(row(it)) }
val template = PlaceListMapTemplate.Builder()
- .setTitle("Plate cameras & drones")
+ .setTitle("Cameras & drones")
.setHeaderAction(Action.BACK)
.setCurrentLocationEnabled(me != null)
.setItemList(list.build())
@@ -63,8 +63,13 @@ class NearbyMapScreen(carContext: CarContext) : LiveScreen(carContext, periodMs
val place = Place.Builder(CarLocation.create(it.lat, it.lon))
.setMarker(
PlaceMarker.Builder()
- .setColor(if (it.drone) CarColor.BLUE else CarColor.RED)
- .setLabel(if (it.drone) "D" else "P")
+ .setColor(if (it.drone) CarColor.BLUE else if (it.kind == com.rfsentinel.app.alpr.KnownCamera.Kind.ALPR) CarColor.RED else CarColor.YELLOW)
+ .setLabel(when (it.kind) {
+ null -> "D"
+ com.rfsentinel.app.alpr.KnownCamera.Kind.SPEED -> "S"
+ com.rfsentinel.app.alpr.KnownCamera.Kind.RED_LIGHT -> "R"
+ com.rfsentinel.app.alpr.KnownCamera.Kind.ALPR -> "P"
+ })
.build()
).build()
return Row.Builder()
@@ -95,7 +100,7 @@ class NearbyMapScreen(carContext: CarContext) : LiveScreen(carContext, periodMs
fun nearby(lat: Double, lon: Double, limit: Int): List<Item> {
val cams = KnownCameras.near(AlprStore.cameras, lat, lon, SEARCH_RADIUS_M).map { (c, d) ->
Item(c.label, c.operator ?: (c.direction?.let { "faces $it°" } ?: "mapped in OpenStreetMap"),
- c.lat, c.lon, d, drone = false, mac = null)
+ c.lat, c.lon, d, drone = false, mac = null, kind = c.type)
}
val drones = DeviceRegistry.snapshot().mapNotNull { s ->
val r = s.remoteId ?: return@mapNotNull null
diff --git a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
index 69a8d32..6b55215 100644
--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
@@ -305,7 +305,7 @@ class ScanForegroundService : Service() {
fun updateLocationUpdates() {
val wanted = hasFineLocation() &&
(Prefs.gpsTaggingEnabled(this) || Prefs.followerAlerts(this) || TripRecorder.isRecording || knownAlprActive())
- // Frequent fixes while recording a trace or watching for known plate cameras
+ // Frequent fixes while recording a trace or watching for known cameras
// (at highway speed a 20 s interval could skip right past one).
val fast = TripRecorder.isRecording || knownAlprActive()
val lm = getSystemService(LOCATION_SERVICE) as LocationManager
@@ -441,20 +441,27 @@ class ScanForegroundService : Service() {
AlertPlayer.play(this, best.tier, "${best.label} nearby")
}
- private fun knownAlprActive() = Prefs.knownAlprAlerts(this) &&
+ private fun knownAlprActive() = (Prefs.knownAlprAlerts(this) || Prefs.speedCameraAlerts(this)) &&
Prefs.categoryEnabled(this, Category.ALPR) && AlprStore.cameras.isNotEmpty()
+ private fun wantsAlert(kind: com.rfsentinel.app.alpr.KnownCamera.Kind) =
+ if (kind == com.rfsentinel.app.alpr.KnownCamera.Kind.ALPR) Prefs.knownAlprAlerts(this) else Prefs.speedCameraAlerts(this)
+
/**
* Warns once (per camera, per 30 minutes) when you're approaching a plate
- * reader mapped in OpenStreetMap: within ~20 s of travel and getting closer.
+ * reader (~20 s of travel) or a speed / red-light camera (~30 s) mapped in
+ * OpenStreetMap, and getting closer.
* Runs on the main thread with each location fix; the lookup is a cheap
* bounding-box filter.
*/
private fun checkKnownAlpr(loc: Location) {
if (!knownAlprActive()) return
val now = System.currentTimeMillis()
- val radius = KnownCameras.warnRadius(if (loc.hasSpeed()) loc.speed else null)
+ val speed = if (loc.hasSpeed()) loc.speed else null
+ // Search out to the larger (speed camera) radius, then apply each kind's own.
+ val radius = KnownCameras.warnRadius(speed, com.rfsentinel.app.alpr.KnownCamera.Kind.SPEED)
val near = KnownCameras.near(AlprStore.cameras, loc.latitude, loc.longitude, radius)
+ .filter { (cam, d) -> wantsAlert(cam.type) && d <= KnownCameras.warnRadius(speed, cam.type) }
val nearIds = near.map { it.first.osmId }.toSet()
alprLastDistance.keys.retainAll(nearIds)
for ((cam, d) in near) {
@@ -462,14 +469,15 @@ class ScanForegroundService : Service() {
val approaching = prev == null || d < prev - 3
if (!approaching || now - (alprLastAlert[cam.osmId] ?: 0L) < KNOWN_ALPR_REPEAT_MS) continue
alprLastAlert[cam.osmId] = now
+ val alpr = cam.type == com.rfsentinel.app.alpr.KnownCamera.Kind.ALPR
val hit = Hit(
- Category.ALPR, "Known plate camera ahead", 80,
+ Category.ALPR, if (alpr) "Known plate camera ahead" else "${cam.label} ahead", 80,
"${cam.label}, ~${d.toInt()} m away" + (cam.operator?.let { ", operated by $it" } ?: "") +
- ". Mapped in OpenStreetMap - it may not broadcast any signal.",
- "OpenStreetMap (surveillance:type=ALPR), ODbL"
+ ". Mapped in OpenStreetMap" + (if (alpr) " - it may not broadcast any signal." else "."),
+ "OpenStreetMap (" + (if (alpr) "surveillance:type=ALPR" else "highway=speed_camera / enforcement") + "), ODbL"
)
NotificationHelper.sendMapAlert(this, "alpr:" + cam.osmId, hit)
- AlertPlayer.play(this, hit.tier, "Plate camera ahead")
+ AlertPlayer.play(this, hit.tier, cam.spoken)
break // one warning per fix is enough
}
}
diff --git a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
index fd96982..2a2eee7 100644
--- a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
@@ -227,6 +227,7 @@ class SettingsActivity : AppCompatActivity() {
binding.gpsSwitch.isChecked = Prefs.gpsTaggingEnabled(this)
binding.autoRecordSwitch.isChecked = Prefs.autoRecordTrace(this)
binding.knownAlprSwitch.isChecked = Prefs.knownAlprAlerts(this)
+ binding.speedCameraSwitch.isChecked = Prefs.speedCameraAlerts(this)
// Data
binding.retentionInput.setText(Prefs.retentionDays(this).toString())
@@ -357,6 +358,7 @@ class SettingsActivity : AppCompatActivity() {
Prefs.setGpsTaggingEnabled(this, binding.gpsSwitch.isChecked)
Prefs.setAutoRecordTrace(this, binding.autoRecordSwitch.isChecked)
Prefs.setKnownAlprAlerts(this, binding.knownAlprSwitch.isChecked)
+ Prefs.setSpeedCameraAlerts(this, binding.speedCameraSwitch.isChecked)
Prefs.setRetentionDays(this, (binding.retentionInput.text.toString().toIntOrNull() ?: 90).coerceAtLeast(0))
diff --git a/app/src/main/java/com/rfsentinel/app/ui/AboutDialog.kt b/app/src/main/java/com/rfsentinel/app/ui/AboutDialog.kt
index 24523d4..4cb48f1 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/AboutDialog.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/AboutDialog.kt
@@ -18,7 +18,7 @@ object AboutDialog {
Passive, receive-only Bluetooth LE and WiFi scanner. It never transmits to,
connects to, jams or spoofs any device. Scans, detections, history and traces stay
on this phone. Internet is used only for OpenStreetMap: map tiles while the map is
- open, and - only when you ask - the list of known plate cameras for the area on
+ open, and - only when you ask - the list of known plate, speed and red-light cameras for the area on
screen. Those servers see your IP and that area, never your scans or detections.
Map data &copy; OpenStreetMap contributors (ODbL).<br/><br/>
diff --git a/app/src/main/java/com/rfsentinel/app/ui/MapActivity.kt b/app/src/main/java/com/rfsentinel/app/ui/MapActivity.kt
index 1db2f8f..ac7d491 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/MapActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/MapActivity.kt
@@ -456,7 +456,7 @@ class MapActivity : AppCompatActivity() {
return bmp
}
- // ---- Known plate cameras (OpenStreetMap) --------------------------------------------
+ // ---- Known plate, speed and red-light cameras (OpenStreetMap) --------------------------------------------
private val redrawKnownAlpr = Runnable { drawKnownAlpr() }
@@ -477,11 +477,13 @@ class MapActivity : AppCompatActivity() {
it.lat in box.latSouth..box.latNorth && it.lon in box.lonWest..box.lonEast
}.take(1500)
val dp = resources.displayMetrics.density
- val icon = android.graphics.drawable.BitmapDrawable(resources, cameraIcon(dp))
+ val icons = com.rfsentinel.app.alpr.KnownCamera.Kind.entries.associateWith {
+ android.graphics.drawable.BitmapDrawable(resources, cameraIcon(dp, it))
+ }
for (cam in inView) {
knownAlpr.add(Marker(map).apply {
position = GeoPoint(cam.lat, cam.lon)
- this.icon = icon
+ this.icon = icons.getValue(cam.type)
setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER)
title = cam.label
setOnMarkerClickListener { _, _ -> showKnownCamera(cam); true }
@@ -491,14 +493,19 @@ class MapActivity : AppCompatActivity() {
map.invalidate()
}
- /** A small red camera glyph, distinct from the round device dots. */
- private fun cameraIcon(dp: Float): android.graphics.Bitmap {
+ /** A small camera glyph, distinct from the round device dots: red plate reader, amber speed, purple red-light. */
+ private fun cameraIcon(dp: Float, kind: com.rfsentinel.app.alpr.KnownCamera.Kind): android.graphics.Bitmap {
val w = (22 * dp).toInt(); val h = (16 * dp).toInt()
val bmp = android.graphics.Bitmap.createBitmap(w, h, android.graphics.Bitmap.Config.ARGB_8888)
val c = android.graphics.Canvas(bmp)
val p = android.graphics.Paint(android.graphics.Paint.ANTI_ALIAS_FLAG)
val body = android.graphics.RectF(1 * dp, 3 * dp, w - 1 * dp, h - 1 * dp)
- p.color = 0xFFB3261E.toInt(); c.drawRoundRect(body, 3 * dp, 3 * dp, p)
+ p.color = when (kind) {
+ com.rfsentinel.app.alpr.KnownCamera.Kind.ALPR -> 0xFFB3261E.toInt()
+ com.rfsentinel.app.alpr.KnownCamera.Kind.SPEED -> 0xFFE08A00.toInt()
+ com.rfsentinel.app.alpr.KnownCamera.Kind.RED_LIGHT -> 0xFF7B1FA2.toInt()
+ }
+ c.drawRoundRect(body, 3 * dp, 3 * dp, p)
p.style = android.graphics.Paint.Style.STROKE; p.strokeWidth = 1.5f * dp; p.color = Color.WHITE
c.drawRoundRect(body, 3 * dp, 3 * dp, p)
c.drawCircle(w / 2f, (h + 2 * dp) / 2f, 3.5f * dp, p)
@@ -507,12 +514,16 @@ class MapActivity : AppCompatActivity() {
private fun showKnownCamera(cam: com.rfsentinel.app.alpr.KnownCamera) {
val text = buildString {
- append("A license-plate reader mapped in OpenStreetMap.\n\n")
+ append(when (cam.type) {
+ com.rfsentinel.app.alpr.KnownCamera.Kind.ALPR -> "A license-plate reader mapped in OpenStreetMap.\n\n"
+ com.rfsentinel.app.alpr.KnownCamera.Kind.SPEED -> "A speed camera mapped in OpenStreetMap.\n\n"
+ com.rfsentinel.app.alpr.KnownCamera.Kind.RED_LIGHT -> "A red-light camera mapped in OpenStreetMap.\n\n"
+ })
cam.brand?.let { append("Maker: $it\n") }
cam.operator?.let { append("Operator: $it\n") }
cam.direction?.let { append("Faces: $it°\n") }
append("OSM: ${cam.osmId}\n\n")
- append("Most plate readers send their data over cellular and have no Bluetooth/WiFi signature, so they can't be detected by radio - this map is the only warning.\n\nMap data © OpenStreetMap contributors (ODbL).")
+ append("These cameras send their data over cellular or wire and have no Bluetooth/WiFi signature, so they can't be detected by radio - this map is the only warning. Mobile speed cameras move and are rarely mapped.\n\nMap data © OpenStreetMap contributors (ODbL).")
}
AlertDialog.Builder(this)
.setTitle(cam.label)
@@ -533,22 +544,23 @@ class MapActivity : AppCompatActivity() {
return
}
AlertDialog.Builder(this)
- .setTitle("Download known plate cameras?")
+ .setTitle("Download known cameras?")
.setMessage(
- "Fetches the license-plate readers mapped in OpenStreetMap for the area on screen, " +
+ "Fetches the license-plate readers, speed cameras and red-light cameras mapped in " +
+ "OpenStreetMap for the area on screen, " +
"then keeps them on this phone for offline warnings.\n\n" +
- "Privacy: the OpenStreetMap server (overpass-api.de) sees this area and your IP address, " +
+ "Privacy: the OpenStreetMap Overpass server (overpass-api.de, or a public mirror when it is busy: overpass.kumi.systems, overpass.private.coffee) sees this area and your IP address, " +
"like when loading map tiles. Nothing about your scans is sent."
)
.setPositiveButton("Download") { _, _ ->
- binding.statusText.text = "Downloading known plate cameras..."
+ binding.statusText.text = "Downloading known cameras..."
lifecycleScope.launch {
val result = runCatching {
com.rfsentinel.app.alpr.AlprStore.download(this@MapActivity, box.latSouth, box.lonWest, box.latNorth, box.lonEast)
}
result.onSuccess { n ->
val total = com.rfsentinel.app.alpr.AlprStore.cameras.size
- Toast.makeText(this@MapActivity, "$n plate cameras in this area ($total saved in total)", Toast.LENGTH_LONG).show()
+ Toast.makeText(this@MapActivity, "$n cameras in this area ($total saved in total)", Toast.LENGTH_LONG).show()
com.rfsentinel.app.util.Prefs.setShowKnownAlpr(this@MapActivity, true)
drawKnownAlpr()
refreshServiceLocation() // start watching for them while scanning
@@ -579,11 +591,11 @@ class MapActivity : AppCompatActivity() {
menu.add(0, 3, 2, "Delete")
} else {
menu.add(0, 4, 0, "Recorded traces")
- menu.add(0, 5, 1, "Download known plate cameras here")
- menu.add(0, 6, 2, "Show known plate cameras").apply {
+ menu.add(0, 5, 1, "Download known cameras here")
+ menu.add(0, 6, 2, "Show known cameras").apply {
isCheckable = true; isChecked = com.rfsentinel.app.util.Prefs.showKnownAlpr(this@MapActivity)
}
- menu.add(0, 7, 3, "Delete downloaded plate cameras")
+ menu.add(0, 7, 3, "Delete downloaded cameras")
}
return true
}
@@ -605,7 +617,7 @@ class MapActivity : AppCompatActivity() {
7 -> {
com.rfsentinel.app.alpr.AlprStore.clear(this)
drawKnownAlpr(); refreshServiceLocation()
- Toast.makeText(this, "Downloaded plate cameras deleted", Toast.LENGTH_SHORT).show(); true
+ Toast.makeText(this, "Downloaded cameras deleted", Toast.LENGTH_SHORT).show(); true
}
android.R.id.home -> { finish(); true }
else -> super.onOptionsItemSelected(item)
diff --git a/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.kt b/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.kt
index 445d103..5eeec1e 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.kt
@@ -100,7 +100,7 @@ class SetupActivity : AppCompatActivity() {
header("Welcome to RF Sentinel", "A quick setup - about a minute. You can change everything later in Settings.")
para("RF Sentinel listens - passively - to the Bluetooth and WiFi signals devices around you already broadcast, and flags equipment such as body cameras, license-plate cameras, drones, trackers following you and camera glasses.")
bullet("It never transmits to, connects to or interferes with any device.")
- bullet("Scans, detections and history stay on this phone. Internet is only used for OpenStreetMap maps (and, if you ask, known plate-camera locations).")
+ bullet("Scans, detections and history stay on this phone. Internet is only used for OpenStreetMap maps (and, if you ask, known plate, speed and red-light camera locations).")
bullet("A match means a device with that signature is nearby - not proof of who is there.")
para("Check your local laws before use. This is not legal advice.", small = true)
}
diff --git a/app/src/main/java/com/rfsentinel/app/util/Prefs.kt b/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
index ea5aa6b..d64a493 100644
--- a/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
+++ b/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
@@ -92,6 +92,9 @@ object Prefs {
/** Warn when approaching a plate reader mapped in OpenStreetMap (needs downloaded data). */
fun knownAlprAlerts(context: Context): Boolean = bool(context, "known_alpr_alerts", true)
fun setKnownAlprAlerts(context: Context, value: Boolean) = setBool(context, "known_alpr_alerts", value)
+ /** Warn when approaching a speed or red-light camera mapped in OpenStreetMap. */
+ fun speedCameraAlerts(context: Context): Boolean = bool(context, "speed_camera_alerts", true)
+ fun setSpeedCameraAlerts(context: Context, value: Boolean) = setBool(context, "speed_camera_alerts", value)
fun showKnownAlpr(context: Context): Boolean = bool(context, "show_known_alpr", true)
fun setShowKnownAlpr(context: Context, value: Boolean) = setBool(context, "show_known_alpr", value)
diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml
index 9d40963..7aa5dbf 100644
--- a/app/src/main/res/layout/activity_settings.xml
+++ b/app/src/main/res/layout/activity_settings.xml
@@ -307,7 +307,13 @@
android:id="@+id/knownAlprSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:text="Warn when approaching a known plate-reader camera (download them on the map: menu, Known plate cameras)" />
+ android:text="Warn when approaching a known plate-reader camera (download them on the map: menu, Download known cameras)" />
+
+ <com.google.android.material.switchmaterial.SwitchMaterial
+ android:id="@+id/speedCameraSwitch"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Warn when approaching a known speed or red-light camera (same download)" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/autoRecordSwitch"
diff --git a/app/src/test/java/com/rfsentinel/app/alpr/KnownCamerasTest.kt b/app/src/test/java/com/rfsentinel/app/alpr/KnownCamerasTest.kt
index d0efc9b..e3a0b2a 100644
--- a/app/src/test/java/com/rfsentinel/app/alpr/KnownCamerasTest.kt
+++ b/app/src/test/java/com/rfsentinel/app/alpr/KnownCamerasTest.kt
@@ -49,6 +49,50 @@ class KnownCamerasTest {
assertEquals(600.0, KnownCameras.warnRadius(40f), 0.0) // capped
}
+ // Synthetic: a speed camera mapped twice (node + enforcement relation), a red-light
+ // relation, an mph camera elsewhere, and an unrelated element.
+ private val enforcement = """
+ {"elements":[
+ {"type":"node","id":1,"lat":10.5000,"lon":-20.5000,"tags":{"highway":"speed_camera"}},
+ {"type":"relation","id":2,"center":{"lat":10.5009,"lon":-20.5000},
+ "tags":{"type":"enforcement","enforcement":"maxspeed","maxspeed":"50"}},
+ {"type":"relation","id":3,"center":{"lat":10.5000,"lon":-20.5000},
+ "tags":{"type":"enforcement","enforcement":"traffic_signals"}},
+ {"type":"node","id":4,"lat":11.0,"lon":-21.0,"tags":{"highway":"speed_camera","maxspeed":"30 mph"}},
+ {"type":"node","id":5,"lat":11.5,"lon":-21.5,"tags":{"highway":"traffic_signals"}}
+ ]}
+ """.trimIndent()
+
+ @Test
+ fun speedAndRedLightCameras() {
+ val cams = KnownCameras.parse(enforcement)
+ assertEquals(3, cams.size) // duplicate speed camera merged, traffic light ignored
+ val speed = cams.first { it.type == KnownCamera.Kind.SPEED && it.lat < 10.6 }
+ assertEquals(50, speed.maxspeed) // kept the copy that has the limit (relation ~100 m away)
+ assertEquals(10.5000, speed.lat, 1e-9) // ...at the camera node's exact position
+ assertEquals("Speed camera (50 km/h)", speed.label)
+ assertEquals("Speed camera ahead, 50", speed.spoken)
+ assertEquals(48, cams.first { it.osmId == "node/4" }.maxspeed) // 30 mph
+ assertEquals("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"))
+ }
+
+ @Test
+ fun oldCacheEntriesArePlateReaders() {
+ val old = com.google.gson.Gson().fromJson(
+ """{"osmId":"node/9","lat":1.0,"lon":2.0}""", KnownCamera::class.java
+ )
+ assertEquals(KnownCamera.Kind.ALPR, old.type)
+ }
+
+ @Test
+ fun speedCamerasWarnEarlier() {
+ assertEquals(300.0, KnownCameras.warnRadius(null, KnownCamera.Kind.SPEED), 0.0)
+ assertEquals(840.0, KnownCameras.warnRadius(28f, KnownCamera.Kind.SPEED), 0.01) // ~100 km/h
+ assertEquals(900.0, KnownCameras.warnRadius(40f, KnownCamera.Kind.RED_LIGHT), 0.0)
+ }
+
@Test
fun nearFindsCamerasInRadiusNearestFirst() {
val cams = KnownCameras.parse(sample)
diff --git a/app/src/test/java/com/rfsentinel/app/car/CarScreensTest.kt b/app/src/test/java/com/rfsentinel/app/car/CarScreensTest.kt
index 22de063..7656f09 100644
--- a/app/src/test/java/com/rfsentinel/app/car/CarScreensTest.kt
+++ b/app/src/test/java/com/rfsentinel/app/car/CarScreensTest.kt
@@ -79,7 +79,7 @@ class CarScreensTest {
assertTrue(rows[1].title.toString().startsWith("Flagged nearby (2)"))
assertTrue(rows[2].title.toString().startsWith("Drones & trackers (1)"))
assertTrue(rows[3].title.toString().startsWith("All nearby devices (14)"))
- assertEquals("Plate cameras & drones on the map", rows[4].title.toString())
+ assertEquals("Cameras & drones on the map", rows[4].title.toString())
val actions = t.actionStrip!!.actions
assertEquals(2, actions.size)
assertEquals("Stop", actions[0].title.toString())