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.

Known cameras appear on the map automatically

CIS-C065f0364a9979
diff --git a/README.md b/README.md
index f0d2bed..06c2121 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:** 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
+- **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
- **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)
@@ -246,11 +246,14 @@ Pick a theme in the setup wizard or under **Settings → Appearance**.
- **Receive-only.** Nothing is transmitted, jammed, spoofed or connected to.
- **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 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
+- **Network use is limited to OpenStreetMap:** map tiles while the map is open,
+ and the known-camera list for the area you look at on the map (or around you on
+ the Android Auto camera map), fetched once per area and refreshed weekly, 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 - like the map tiles - never your scans. Turn off *Show known cameras
+ automatically* in Settings to fetch only when you tap *Download known cameras*.
+ 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 496eef6..f4e7278 100644
--- a/app/src/main/java/com/rfsentinel/app/alpr/AlprStore.kt
+++ b/app/src/main/java/com/rfsentinel/app/alpr/AlprStore.kt
@@ -12,8 +12,8 @@ import java.net.URL
import java.net.URLEncoder
/**
- * Offline cache of known plate-reader cameras, downloaded only when the user
- * asks for a map area. The download tells the OpenStreetMap Overpass server
+ * Offline cache of known plate, speed and red-light cameras, downloaded for the
+ * map area you look at (automatically, unless turned off). The download tells the Overpass server
* which area you're looking at (like map tiles do) - nothing else is sent.
*/
object AlprStore {
@@ -31,18 +31,66 @@ object AlprStore {
/** Largest area one download may cover (degrees of latitude / longitude). */
const val MAX_SPAN_DEG = 2.0
+ private const val AREAS_FILE = "known_alpr_areas.json"
+ /** Downloaded areas are fetched again after this long. */
+ const val REFRESH_MS = 7 * 24 * 3600_000L
+ /** After a failed automatic download, wait this long before trying again. */
+ private const val RETRY_MS = 60_000L
+
private val gson = Gson()
private val listType = object : TypeToken<List<KnownCamera>>() {}.type
+ private val areaListType = object : TypeToken<List<CameraArea>>() {}.type
@Volatile var cameras: List<KnownCamera> = emptyList()
private set
+ /** Areas already downloaded, so the map doesn't fetch them again. */
+ @Volatile var areas: List<CameraArea> = emptyList()
+ private set
+
+ private val busy = java.util.concurrent.atomic.AtomicBoolean(false)
+ @Volatile private var lastFailedArea: CameraArea? = null
+ val isBusy: Boolean get() = busy.get()
private fun file(context: Context) = File(context.filesDir, FILE)
+ private fun areasFile(context: Context) = File(context.filesDir, AREAS_FILE)
fun load(context: Context) {
cameras = runCatching {
file(context).takeIf { it.exists() }?.readText()?.let { gson.fromJson<List<KnownCamera>>(it, listType) }
}.getOrNull().orEmpty()
+ areas = runCatching {
+ areasFile(context).takeIf { it.exists() }?.readText()?.let { gson.fromJson<List<CameraArea>>(it, areaListType) }
+ }.getOrNull().orEmpty()
+ }
+
+ /** True when the box isn't inside an area downloaded in the last [REFRESH_MS]. */
+ fun needsDownload(south: Double, west: Double, north: Double, east: Double, now: Long = System.currentTimeMillis()) =
+ CameraArea.needsDownload(areas, south, west, north, east, now, REFRESH_MS)
+
+ /**
+ * Fetches the cameras around a box in the background when that area isn't
+ * cached yet (one download at a time; quiet back-off after a failure).
+ * Returns true when a download ran and changed the cache.
+ */
+ suspend fun autoDownload(context: Context, south: Double, west: Double, north: Double, east: Double): Boolean {
+ val now = System.currentTimeMillis()
+ if (!needsDownload(south, west, north, east, now)) return false
+ // After a failure, leave that same area alone for a minute (other areas may go ahead).
+ if (lastFailedArea?.let { now - it.time < RETRY_MS && it.contains(south, west, north, east) } == true) return false
+ if (!busy.compareAndSet(false, true)) return false
+ val (s, w, n, e) = CameraArea.expand(south, west, north, east, MAX_SPAN_DEG)
+ return try {
+ download(context, s, w, n, e)
+ true
+ } catch (ex: kotlinx.coroutines.CancellationException) {
+ throw ex // the screen closed: not a failure, try again next time
+ } catch (ex: Exception) {
+ android.util.Log.w("AlprStore", "Automatic camera download failed: ${ex.message}")
+ lastFailedArea = CameraArea(s, w, n, e, System.currentTimeMillis())
+ false
+ } finally {
+ busy.set(false)
+ }
}
/**
@@ -67,6 +115,9 @@ object AlprStore {
val merged = cameras.filterNot(inBox) + found
file(context).writeText(gson.toJson(merged))
cameras = merged
+ val area = CameraArea(south, west, north, east, System.currentTimeMillis())
+ areas = areas.filterNot { area.contains(it) } + area
+ runCatching { areasFile(context).writeText(gson.toJson(areas)) }
return@withContext found.size
}
error("OpenStreetMap servers busy (${lastError?.message ?: "no answer"}) - try again later")
@@ -100,6 +151,40 @@ object AlprStore {
fun clear(context: Context) {
file(context).delete()
+ areasFile(context).delete()
cameras = emptyList()
+ areas = emptyList()
+ }
+}
+
+/** A downloaded bounding box and when it was fetched (pure; unit-tested). */
+data class CameraArea(val south: Double, val west: Double, val north: Double, val east: Double, val time: Long) {
+
+ fun contains(o: CameraArea) = contains(o.south, o.west, o.north, o.east)
+
+ fun contains(s: Double, w: Double, n: Double, e: Double) =
+ s >= south && w >= west && n <= north && e <= east
+
+ companion 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) }
+
+ /** Smallest box one automatic download covers (degrees, ~40 km). */
+ const val MIN_SPAN_DEG = 0.4
+
+ /**
+ * Grows the visible box to twice its size, and at least [MIN_SPAN_DEG],
+ * so panning around doesn't fetch again right away - without exceeding
+ * [maxSpan] degrees.
+ */
+ fun expand(s: Double, w: Double, n: Double, e: Double, maxSpan: Double): List<Double> {
+ fun pad(span: Double) = (((span * 2).coerceIn(MIN_SPAN_DEG, maxSpan) - span) / 2).coerceAtLeast(0.0)
+ val latPad = pad(n - s)
+ val lonPad = pad(e - w)
+ return listOf(
+ (s - latPad).coerceAtLeast(-90.0), (w - lonPad).coerceAtLeast(-180.0),
+ (n + latPad).coerceAtMost(90.0), (e + lonPad).coerceAtMost(180.0)
+ )
+ }
}
}
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 9c2beeb..8347311 100644
--- a/app/src/main/java/com/rfsentinel/app/car/NearbyMapScreen.kt
+++ b/app/src/main/java/com/rfsentinel/app/car/NearbyMapScreen.kt
@@ -20,6 +20,8 @@ import com.rfsentinel.app.alpr.KnownCameras
import com.rfsentinel.app.service.DeviceRegistry
import com.rfsentinel.app.service.ScanForegroundService
import com.rfsentinel.app.util.Permissions
+import androidx.lifecycle.lifecycleScope
+import kotlinx.coroutines.launch
import kotlin.math.roundToInt
/**
@@ -35,6 +37,7 @@ class NearbyMapScreen(carContext: CarContext) : LiveScreen(carContext, periodMs
override fun onGetTemplate(): Template {
val me = myLocation()
+ if (me != null) autoDownloadAround(me)
val limit = CarUi.listLimit(carContext).coerceAtMost(6)
val items = if (me == null) emptyList() else nearby(me.latitude, me.longitude, limit)
@@ -83,6 +86,18 @@ class NearbyMapScreen(carContext: CarContext) : LiveScreen(carContext, periodMs
.build()
}
+ /** Fetches the cameras within ~20 km when that area isn't cached yet, then refreshes. */
+ private fun autoDownloadAround(me: Location) {
+ if (!com.rfsentinel.app.util.Prefs.autoCameras(carContext)) return
+ val dLat = 0.18
+ val dLon = 0.18 / kotlin.math.max(0.1, kotlin.math.cos(Math.toRadians(me.latitude)))
+ val (s, w, n, e) = listOf(me.latitude - dLat, me.longitude - dLon, me.latitude + dLat, me.longitude + dLon)
+ if (!AlprStore.needsDownload(s, w, n, e)) return
+ lifecycleScope.launch {
+ if (AlprStore.autoDownload(carContext, s, w, n, e)) invalidate()
+ }
+ }
+
@SuppressLint("MissingPermission") // checked via Permissions
private fun myLocation(): Location? {
ScanForegroundService.lastFix?.let { return it }
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 2a2eee7..aba1326 100644
--- a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
@@ -228,6 +228,7 @@ class SettingsActivity : AppCompatActivity() {
binding.autoRecordSwitch.isChecked = Prefs.autoRecordTrace(this)
binding.knownAlprSwitch.isChecked = Prefs.knownAlprAlerts(this)
binding.speedCameraSwitch.isChecked = Prefs.speedCameraAlerts(this)
+ binding.autoCamerasSwitch.isChecked = Prefs.autoCameras(this)
// Data
binding.retentionInput.setText(Prefs.retentionDays(this).toString())
@@ -359,6 +360,7 @@ class SettingsActivity : AppCompatActivity() {
Prefs.setAutoRecordTrace(this, binding.autoRecordSwitch.isChecked)
Prefs.setKnownAlprAlerts(this, binding.knownAlprSwitch.isChecked)
Prefs.setSpeedCameraAlerts(this, binding.speedCameraSwitch.isChecked)
+ Prefs.setAutoCameras(this, binding.autoCamerasSwitch.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 4cb48f1..43a7edc 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, speed and red-light cameras for the area on
+ open, and the list of known plate, speed and red-light cameras for the area you look at 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 ac7d491..dba6169 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/MapActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/MapActivity.kt
@@ -465,11 +465,41 @@ class MapActivity : AppCompatActivity() {
binding.map.postDelayed(redrawKnownAlpr, 250)
}
+ private val autoDownloadCameras = Runnable { maybeAutoDownloadCameras() }
+
+ /**
+ * Fetches the cameras for the area on screen when it isn't cached yet, so
+ * they're always on the map without a manual download. Runs once the map
+ * has stopped moving for a moment.
+ */
+ private fun maybeAutoDownloadCameras() {
+ val prefs = com.rfsentinel.app.util.Prefs
+ if (!prefs.autoCameras(this) || !prefs.showKnownAlpr(this) || tripId != null) return
+ // Still gliding to your position (or another target): wait until it stops.
+ if (binding.map.isAnimating) { binding.map.postDelayed(autoDownloadCameras, 1_000); return }
+ val box = binding.map.boundingBox
+ val span = com.rfsentinel.app.alpr.AlprStore.MAX_SPAN_DEG
+ if (box.latNorth - box.latSouth > span || box.lonEast - box.lonWest > span) return
+ // The map starts at 0°,0° until it's moved to your position: don't fetch the ocean.
+ if (kotlin.math.abs(box.centerLatitude) < 0.5 && kotlin.math.abs(box.centerLongitude) < 0.5) return
+ // Another download (e.g. the car screen's) is running: look again shortly.
+ if (com.rfsentinel.app.alpr.AlprStore.isBusy) { binding.map.postDelayed(autoDownloadCameras, 3_000); return }
+ lifecycleScope.launch {
+ val changed = com.rfsentinel.app.alpr.AlprStore.autoDownload(
+ this@MapActivity, box.latSouth, box.lonWest, box.latNorth, box.lonEast
+ )
+ // Redrawing also re-checks the area now on screen, in case the map moved meanwhile.
+ if (changed) { drawKnownAlpr(); refreshServiceLocation() }
+ }
+ }
+
/** Draws the cameras in (and just around) the visible area; skipped when zoomed far out. */
private fun drawKnownAlpr() {
val map = binding.map
knownAlpr.items.clear()
- if (!com.rfsentinel.app.util.Prefs.showKnownAlpr(this) || map.zoomLevelDouble < 10.0) {
+ map.removeCallbacks(autoDownloadCameras)
+ map.postDelayed(autoDownloadCameras, 1_200)
+ if (!com.rfsentinel.app.util.Prefs.showKnownAlpr(this) || map.zoomLevelDouble < 9.0) {
map.invalidate(); return
}
val box = map.boundingBox.increaseByScale(1.5f)
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 5eeec1e..1488726 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, speed and red-light camera locations).")
+ bullet("Scans, detections and history stay on this phone. Internet is only used for OpenStreetMap maps (including known plate, speed and red-light camera locations for the area you look at - can be turned off in Settings).")
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 d64a493..4bbb0fb 100644
--- a/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
+++ b/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
@@ -95,6 +95,9 @@ object Prefs {
/** 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)
+ /** Fetch known cameras for the map area on screen (and around you in the car) automatically. */
+ fun autoCameras(context: Context): Boolean = bool(context, "auto_cameras", true)
+ fun setAutoCameras(context: Context, value: Boolean) = setBool(context, "auto_cameras", 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 7aa5dbf..fb5081a 100644
--- a/app/src/main/res/layout/activity_settings.xml
+++ b/app/src/main/res/layout/activity_settings.xml
@@ -309,6 +309,12 @@
android:layout_height="wrap_content"
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/autoCamerasSwitch"
+ android:layout_width="match_parent"
+ 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)" />
+
<com.google.android.material.switchmaterial.SwitchMaterial
android: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.kt
new file mode 100644
index 0000000..1449762
--- /dev/null
+++ b/app/src/test/java/com/rfsentinel/app/alpr/CameraAreaTest.kt
@@ -0,0 +1,36 @@
+package com.rfsentinel.app.alpr
+
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+class CameraAreaTest {
+
+ // Synthetic boxes (not real places).
+ private val day = 24 * 3600_000L
+ private val area = CameraArea(10.0, -21.0, 11.0, -20.0, time = 0L)
+
+ @Test
+ fun coveredOnlyInsideAFreshArea() {
+ assertFalse(CameraArea.needsDownload(listOf(area), 10.2, -20.8, 10.8, -20.2, now = day, maxAgeMs = 7 * day))
+ assertTrue(CameraArea.needsDownload(listOf(area), 10.2, -20.8, 11.2, -20.2, now = day, maxAgeMs = 7 * day)) // sticks out
+ assertTrue(CameraArea.needsDownload(listOf(area), 10.2, -20.8, 10.8, -20.2, now = 8 * day, maxAgeMs = 7 * day)) // stale
+ assertTrue(CameraArea.needsDownload(emptyList(), 10.2, -20.8, 10.8, -20.2, now = day, maxAgeMs = 7 * day))
+ }
+
+ @Test
+ fun expandDoublesWithinLimits() {
+ // A small zoomed-in box grows to the minimum span.
+ val (s, w, n, e) = CameraArea.expand(10.0, -20.05, 10.1, -19.95, maxSpan = 2.0)
+ assertEquals(CameraArea.MIN_SPAN_DEG, n - s, 1e-9)
+ assertEquals(CameraArea.MIN_SPAN_DEG, e - w, 1e-9)
+ assertEquals(10.05, (s + n) / 2, 1e-9) // still centred
+ // A large box doubles but never exceeds the maximum.
+ val big = CameraArea.expand(10.0, -21.0, 11.5, -19.5, maxSpan = 2.0)
+ assertEquals(2.0, big[2] - big[0], 1e-9)
+ // A box already at the maximum is left as is.
+ val max = CameraArea.expand(10.0, -21.0, 12.0, -19.0, maxSpan = 2.0)
+ assertEquals(listOf(10.0, -21.0, 12.0, -19.0), max)
+ }
+}