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.

Watch a probe shape; set the direction of an unmapped camera

CIS-C01a47f87a3ad5
diff --git a/app/src/main/java/com/rfsentinel/app/alpr/CameraDirections.kt b/app/src/main/java/com/rfsentinel/app/alpr/CameraDirections.kt
new file mode 100644
index 0000000..a1858a2
--- /dev/null
+++ b/app/src/main/java/com/rfsentinel/app/alpr/CameraDirections.kt
@@ -0,0 +1,47 @@
+package com.rfsentinel.app.alpr
+
+import android.content.Context
+
+/**
+ * Which way a known camera faces, as the user set it (tap a camera > Set direction) for cameras
+ * whose direction isn't mapped in OpenStreetMap. Kept on this phone only, by OSM id; a mapped
+ * direction always wins. Used for the map's cone and for the camera-ahead warnings.
+ */
+object CameraDirections {
+
+ private const val PREFS = "camera_directions"
+ private const val KEY = "dirs"
+
+ @Volatile private var dirs: Map<String, Int> = emptyMap()
+ @Volatile private var loaded = false
+
+ private fun ensure(context: Context) {
+ if (loaded) return
+ synchronized(this) {
+ if (loaded) return
+ dirs = parse(context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).getStringSet(KEY, null).orEmpty())
+ loaded = true
+ }
+ }
+
+ internal fun parse(set: Set<String>): Map<String, Int> = set.mapNotNull { e ->
+ val id = e.substringBeforeLast('=', "").ifEmpty { return@mapNotNull null }
+ val deg = e.substringAfterLast('=').toIntOrNull()?.takeIf { it in 0..359 } ?: return@mapNotNull null
+ id to deg
+ }.toMap()
+
+ /** The direction [cam] faces: mapped, else set by the user, else null. */
+ fun of(context: Context, cam: KnownCamera): Int? = cam.direction ?: run { ensure(context); dirs[cam.osmId] }
+
+ /** The user's own direction for [osmId], if any. */
+ fun userSet(context: Context, osmId: String): Int? { ensure(context); return dirs[osmId] }
+
+ /** Sets (0-359) or clears (null) the user's direction for [osmId]. */
+ @Synchronized
+ fun set(context: Context, osmId: String, deg: Int?) {
+ ensure(context)
+ dirs = if (deg == null) dirs - osmId else dirs + (osmId to ((deg % 360) + 360) % 360)
+ context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit()
+ .putStringSet(KEY, dirs.map { (k, v) -> "$k=$v" }.toSet()).apply()
+ }
+}
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 9408290..df8c9bc 100644
--- a/app/src/main/java/com/rfsentinel/app/alpr/KnownCameras.kt
+++ b/app/src/main/java/com/rfsentinel/app/alpr/KnownCameras.kt
@@ -208,11 +208,12 @@ object KnownCameras {
*/
fun ahead(
cameras: List<KnownCamera>, lat: Double, lon: Double, bearingDeg: Float?,
- maxM: Double = 3_000.0, coneDeg: Double = 45.0, skip: (KnownCamera) -> Boolean = { false }
+ maxM: Double = 3_000.0, coneDeg: Double = 45.0, directionOf: (KnownCamera) -> Int? = { it.direction },
+ skip: (KnownCamera) -> Boolean = { false }
): Pair<KnownCamera, Double>? {
if (bearingDeg == null) return near(cameras, lat, lon, maxM / 3).firstOrNull { !skip(it.first) }
return near(cameras, lat, lon, maxM).firstOrNull { (c, d) ->
- if (skip(c) || !watchesYourWay(c, bearingDeg.toDouble())) return@firstOrNull false
+ if (skip(c) || !watchesYourWay(c, bearingDeg.toDouble(), directionOf(c))) return@firstOrNull false
if (d < 30.0) return@firstOrNull true // right here
val diff = kotlin.math.abs(((bearingTo(lat, lon, c.lat, c.lon) - bearingDeg) % 360 + 540) % 360 - 180)
diff <= coneDeg
@@ -224,8 +225,8 @@ object KnownCameras {
* you (front plates) or away (rear plates, read once you've passed). One facing across your
* way - [SIDEWAYS_DEG] or more off - watches a cross street. True when either isn't known.
*/
- fun watchesYourWay(c: KnownCamera, bearingDeg: Double?): Boolean {
- val dir = c.direction ?: return true
+ fun watchesYourWay(c: KnownCamera, bearingDeg: Double?, direction: Int? = c.direction): Boolean {
+ val dir = direction ?: return true
if (bearingDeg == null) return true
val off = kotlin.math.abs(((dir - bearingDeg) % 180 + 270) % 180 - 90) // 0 = along your way, 90 = across
return off < SIDEWAYS_DEG
diff --git a/app/src/main/java/com/rfsentinel/app/car/CarUi.kt b/app/src/main/java/com/rfsentinel/app/car/CarUi.kt
index 6988852..b381e88 100644
--- a/app/src/main/java/com/rfsentinel/app/car/CarUi.kt
+++ b/app/src/main/java/com/rfsentinel/app/car/CarUi.kt
@@ -128,7 +128,8 @@ object CarUi {
val me = currentLocation(context) ?: return null
val moving = me.hasBearing() && me.hasSpeed() && me.speed > 2f
return com.rfsentinel.app.alpr.KnownCameras.ahead(
- cams, me.latitude, me.longitude, if (moving) me.bearing else null
+ cams, me.latitude, me.longitude, if (moving) me.bearing else null,
+ directionOf = { com.rfsentinel.app.alpr.CameraDirections.of(context, it) }
) { com.rfsentinel.app.alpr.IgnoredCameras.contains(context, it.osmId) }
}
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 b18803c..f6bf5cd 100644
--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
@@ -649,7 +649,8 @@ class ScanForegroundService : Service() {
com.rfsentinel.app.usb.ProbeIntel.note(mac, wps, fingerprint, ssids, hidden, skeleton)
// Kept in the requested-networks list when that's on, and always while a trace records.
if (ssids.isNotEmpty()) com.rfsentinel.app.data.ProbeLog.record(this, mac, ssids, rssi, now, force = TripRecorder.isRecording)
- val hits = OuiWatchlist.probeHits(ssids) + OuiWatchlist.fingerprintHits(fingerprint) + OuiWatchlist.wpsHits(wps)
+ val hits = OuiWatchlist.probeHits(ssids) + OuiWatchlist.fingerprintHits(fingerprint) + OuiWatchlist.wpsHits(wps) +
+ OuiWatchlist.fingerprintHits(skeleton?.let { com.rfsentinel.app.usb.ProbeIntel.shapeKey(it) })
if (hits.isEmpty()) return
val before = probeHits[mac]
probeHits[mac] = now to hits
@@ -792,7 +793,7 @@ class ScanForegroundService : Service() {
val heading = if (loc.hasBearing() && (speed ?: 0f) >= 2f) loc.bearing.toDouble() else null
val near = KnownCameras.near(AlprStore.cameras, loc.latitude, loc.longitude, radius)
.filter { (cam, d) ->
- wantsAlert(cam.type) && d <= KnownCameras.warnRadius(speed, cam.type) && KnownCameras.watchesYourWay(cam, heading) &&
+ wantsAlert(cam.type) && d <= KnownCameras.warnRadius(speed, cam.type) && KnownCameras.watchesYourWay(cam, heading, com.rfsentinel.app.alpr.CameraDirections.of(this, cam)) &&
!com.rfsentinel.app.alpr.IgnoredCameras.contains(this, cam.osmId) // silenced from the map
}
val nearIds = near.map { it.first.osmId }.toSet()
diff --git a/app/src/main/java/com/rfsentinel/app/ui/DeviceActions.kt b/app/src/main/java/com/rfsentinel/app/ui/DeviceActions.kt
index 707ee43..bfa2d71 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/DeviceActions.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/DeviceActions.kt
@@ -118,6 +118,13 @@ object DeviceActions {
}
// A probe fingerprint (USB adapter) marks the device model / OS, even across random addresses.
val fp = com.rfsentinel.app.usb.ProbeIntel.of(mac)?.fingerprint
+ // FlipDeFlock's coarser probe shape: also survives random addresses, but many phones share one.
+ val shape = com.rfsentinel.app.usb.ProbeIntel.of(mac)?.skeleton?.let { com.rfsentinel.app.usb.ProbeIntel.shapeKey(it) }
+ if (shape != null) {
+ b.scopeShape.visibility = View.VISIBLE
+ b.scopeShape.text = "Every device whose probe requests are built the same way (${shape.removePrefix("shape-")}; " +
+ "coarse: many phones share a shape)"
+ }
if (fp != null) {
b.scopeFingerprint.visibility = View.VISIBLE
b.scopeFingerprint.text = "Every device of this type (probe fingerprint $fp)"
@@ -131,9 +138,16 @@ object DeviceActions {
.setPositiveButton("Add") { _, _ ->
val wholePrefix = b.scopePrefix.isChecked
val byFingerprint = fp != null && b.scopeFingerprint.isChecked
- val key = when { byFingerprint -> OuiEntry.FINGERPRINT + fp; wholePrefix -> oui; else -> mac }
+ val byShape = shape != null && b.scopeShape.isChecked
+ val key = when {
+ byShape -> OuiEntry.FINGERPRINT + shape; byFingerprint -> OuiEntry.FINGERPRINT + fp
+ wholePrefix -> oui; else -> mac
+ }
val label = b.labelInput.text.toString().trim().ifEmpty {
- when { byFingerprint -> "Device type $fp"; wholePrefix -> "Custom prefix $oui"; else -> "Custom device $mac" }
+ when {
+ byShape -> "Probe shape ${shape!!.removePrefix("shape-")}"; byFingerprint -> "Device type $fp"
+ wholePrefix -> "Custom prefix $oui"; else -> "Custom device $mac"
+ }
}
OuiWatchlist.addCustomEntry(activity, OuiEntry(key, label, "user-added from live list", "custom"))
toast(activity, "Added $key to the watchlist")
diff --git a/app/src/main/java/com/rfsentinel/app/ui/DeviceDetailActivity.kt b/app/src/main/java/com/rfsentinel/app/ui/DeviceDetailActivity.kt
index 72a1121..218d4d0 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/DeviceDetailActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/DeviceDetailActivity.kt
@@ -256,7 +256,8 @@ class DeviceDetailActivity : AppCompatActivity() {
" (same for every device of this model / OS - Watchlist can watch it)"
}
r.skeleton?.let { sk ->
- id += "Probe shape" to "%08x".format(sk) + (com.rfsentinel.app.detect.SignatureEngine.probeShapeNote(sk)?.let { " · $it" } ?: "")
+ id += "Probe shape" to "%08x".format(sk) + (com.rfsentinel.app.detect.SignatureEngine.probeShapeNote(sk)?.let { " · $it" } ?: "") +
+ if (OuiWatchlist.isFingerprintWatched(com.rfsentinel.app.usb.ProbeIntel.shapeKey(sk))) " · on your watchlist" else ""
}
if (r.probed.isNotEmpty()) id += "Networks it asked for" to r.probed.reversed().joinToString(", ")
}
diff --git a/app/src/main/java/com/rfsentinel/app/ui/MapShared.kt b/app/src/main/java/com/rfsentinel/app/ui/MapShared.kt
index df5802a..2d90820 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/MapShared.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/MapShared.kt
@@ -165,6 +165,7 @@ internal object MapDialogs {
/** [onChanged] after its alerts were turned off or on again (redraw it faded / normal). */
fun showKnownCamera(a: AppCompatActivity, cam: com.rfsentinel.app.alpr.KnownCamera, onChanged: () -> Unit) {
val ignored = com.rfsentinel.app.alpr.IgnoredCameras.contains(a, cam.osmId)
+ val userDir = if (cam.direction == null) com.rfsentinel.app.alpr.CameraDirections.userSet(a, cam.osmId) else null
val text = buildString {
if (ignored) append("Alerts for this camera are off.\n\n")
append(when (cam.type) {
@@ -175,6 +176,7 @@ internal object MapDialogs {
cam.brand?.let { append("Maker: $it\n") }
cam.operator?.let { append("Operator: $it\n") }
cam.direction?.let { append("Faces: $it°\n") }
+ userDir?.let { append("Faces: ${compass(it).lowercase()} (set by you)\n") }
append("OSM: ${cam.osmId}\n\n")
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).")
}
@@ -188,13 +190,36 @@ internal object MapDialogs {
else "No more alerts for this camera (tap it again to undo)", Toast.LENGTH_SHORT).show()
onChanged()
}
- .setNegativeButton("Close", null)
+ .apply {
+ // No direction in OpenStreetMap: let the user say which way it faces (this phone only).
+ if (cam.direction == null) setNegativeButton("Set direction") { _, _ -> pickDirection(a, cam, userDir, onChanged) }
+ else setNegativeButton("Close", null)
+ }
.setNeutralButton("Open in OpenStreetMap") { _, _ ->
runCatching { a.startActivity(Intent(Intent.ACTION_VIEW, android.net.Uri.parse("https://www.openstreetmap.org/${cam.osmId}"))) }
}
.show()
}
+ private val COMPASS = listOf("North", "North-east", "East", "South-east", "South", "South-west", "West", "North-west")
+
+ private fun compass(deg: Int) = COMPASS[((deg + 22) % 360) / 45]
+
+ /** Which way the camera faces, from 8 compass points; saved on this phone, drawn as its cone. */
+ private fun pickDirection(a: AppCompatActivity, cam: com.rfsentinel.app.alpr.KnownCamera, current: Int?, onChanged: () -> Unit) {
+ val items = COMPASS.map { "Faces ${it.lowercase()}" } + "Not set"
+ val checked = current?.let { ((it + 22) % 360) / 45 } ?: COMPASS.size
+ AlertDialog.Builder(a)
+ .setTitle("Which way does it face?")
+ .setSingleChoiceItems(items.toTypedArray(), checked) { d, i ->
+ com.rfsentinel.app.alpr.CameraDirections.set(a, cam.osmId, if (i < COMPASS.size) i * 45 else null)
+ d.dismiss()
+ onChanged()
+ }
+ .setNegativeButton("Cancel", null)
+ .show()
+ }
+
fun showTower(a: AppCompatActivity, t: com.rfsentinel.app.service.CellTowerStore.Tower) {
val net = listOfNotNull(t.operator, "${t.mcc ?: "?"}-${t.mnc ?: "?"}").joinToString(" · ")
val dateFmt = java.text.DateFormat.getDateTimeInstance(java.text.DateFormat.MEDIUM, java.text.DateFormat.SHORT)
diff --git a/app/src/main/java/com/rfsentinel/app/ui/RfMap.kt b/app/src/main/java/com/rfsentinel/app/ui/RfMap.kt
index cbf361c..5ea26f4 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/RfMap.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/RfMap.kt
@@ -339,7 +339,7 @@ internal class RfMap(private val activity: AppCompatActivity, val map: MapEngine
"opacity" to if (com.rfsentinel.app.alpr.IgnoredCameras.contains(activity, c.osmId)) 0.35 else 1.0)
})
set(CAM_CONES, cams.mapNotNull { c ->
- val dir = c.direction ?: return@mapNotNull null
+ val dir = com.rfsentinel.app.alpr.CameraDirections.of(activity, c) ?: return@mapNotNull null
val faded = com.rfsentinel.app.alpr.IgnoredCameras.contains(activity, c.osmId)
GeoJson.feature(GeoJson.polygon(MapGeo.wedge(c.lat, c.lon, dir.toDouble(), CAMERA_CONE_DEG, CAMERA_CONE_M)),
"color" to hex(MapIcons.cameraColor(c.type)), "opacity" to if (faded) 0.08 else 0.25)
diff --git a/app/src/main/java/com/rfsentinel/app/usb/ProbeIntel.kt b/app/src/main/java/com/rfsentinel/app/usb/ProbeIntel.kt
index c826744..f45b6eb 100644
--- a/app/src/main/java/com/rfsentinel/app/usb/ProbeIntel.kt
+++ b/app/src/main/java/com/rfsentinel/app/usb/ProbeIntel.kt
@@ -102,6 +102,9 @@ object ProbeIntel {
return if (any) h else null
}
+ /** How a watched probe shape is written in the watchlist (after "fp:"), next to 8-digit fingerprints. */
+ fun shapeKey(shape: Long) = "shape-%08x".format(shape)
+
/** [end] without the 4-byte checksum some drivers keep on a frame starting at [d]. */
fun withoutFcs(b: ByteArray, d: Int, end: Int): Int {
if (end - d < 28) return end
diff --git a/app/src/main/res/layout/dialog_add_watchlist.xml b/app/src/main/res/layout/dialog_add_watchlist.xml
index f956b56..5d5ff83 100644
--- a/app/src/main/res/layout/dialog_add_watchlist.xml
+++ b/app/src/main/res/layout/dialog_add_watchlist.xml
@@ -28,6 +28,12 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
+
+ <RadioButton
+ android:id="@+id/scopeShape"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:visibility="gone" />
</RadioGroup>
<TextView
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 5bf0b38..c58c53a 100644
--- a/app/src/test/java/com/rfsentinel/app/alpr/KnownCamerasTest.kt
+++ b/app/src/test/java/com/rfsentinel/app/alpr/KnownCamerasTest.kt
@@ -126,4 +126,11 @@ class KnownCamerasTest {
assertTrue(KnownCameras.watchesYourWay(cam(null), 0.0))
assertTrue(KnownCameras.watchesYourWay(cam(90), null))
}
+
+ @Test
+ fun aDirectionYouSetCountsLikeAMappedOne() {
+ val cam = KnownCamera("n2", 10.5, -20.5, null, null, null)
+ assertFalse(KnownCameras.watchesYourWay(cam, 0.0, direction = 90))
+ assertEquals(mapOf("node/1" to 90, "way/2" to 315), CameraDirections.parse(setOf("node/1=90", "way/2=315", "bad", "node/3=400")))
+ }
}