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.

Blue ESP32 / green INTERNAL source badges; OUI-SPY reconnect fixes; README

CIS-C07ab62437a795
diff --git a/README.md b/README.md
index 05c21c4..1ace89e 100644
--- a/README.md
+++ b/README.md
@@ -140,13 +140,16 @@ permission is optional; without it, alerts still play and show in the app.
- **Threat banner:** shows all clear, weak, probable or strong, or *may be following you*.
- **Live list:** every device heard in the last 3 minutes, with vendor, type,
- radio, signal, rough distance, and NEW / ★ / FOLLOWING badges. Flagged
+ radio, signal, rough distance, and NEW / ★ / FOLLOWING badges. A green
+ **INTERNAL** badge means the phone's own Bluetooth or Wi-Fi chip heard the
+ device; a blue **ESP32** badge means a connected ESP32 board reported it
+ (both can show at once). Flagged
devices sort first and flash in their category colour. Matches above your
alert threshold play a sound and vibrate: one pulse for weak, two for
probable, three for strong.
- **Radar view:** closer to the centre means a stronger signal. The angle is
not a direction, because a phone can't measure one.
-- **Filters and search:** All, Flagged, Trackers, Drones, New, Favorites,
+- **Filters and search:** All, Flagged, Trackers, Drones, New, ESP32, Favorites,
Bluetooth, WiFi. Search matches name, address, vendor and type.
- **Tap** a device for details. **Long-press** for quick actions: watchlist,
whitelist, favorite, copy, and **Report unknown device** for devices with no
@@ -272,12 +275,28 @@ status.
Boards running the Bluetooth ("App-Controlled") OUI-SPY firmware
([lukeswitz/oui-spy-unified-blue](https://github.com/lukeswitz/oui-spy-unified-blue))
connect wirelessly: start scanning with the board powered on, then
-**Settings -> Pair OUI-SPY board** and pick its `OUI-SPY-xxxx` entry. While
-scanning, RF Sentinel switches on the board's Flock-BLE, Flock-WiFi, Sky Spy and
-Detector engines, adds what they find (Flock cameras and Raven sensors, Remote
-ID drones with position, trackers, Axon and smart-glasses signatures, the
-board's own watchlist), and switches them off again when scanning stops. It
-never uses the board's other engines.
+**Settings -> Pair OUI-SPY board** and pick its `OUI-SPY-xxxx` entry. Pair it
+only there - not in Android's Bluetooth settings: the board keeps no pairing
+keys, so a phone-side pairing breaks the link (the app tells you to tap
+*Forget* if it finds one).
+
+While scanning, RF Sentinel switches on the board's Flock-BLE, Flock-WiFi, Sky
+Spy and Detector engines, adds what they find (Flock cameras and Raven sensors,
+Remote ID drones with position, trackers, Axon and smart-glasses signatures,
+the board's own watchlist), and switches them off again when scanning stops.
+
+By default it also switches on the board's survey (Wardrive) engine, so the
+board relays **every** Wi-Fi network and Bluetooth device it hears. These
+arrive without a verdict and go through RF Sentinel's own watchlist, presets
+and rules, exactly like what the phone hears itself. In this mode the board
+also sends standard Wi-Fi scan probes (like any phone scanning for networks);
+turn **Settings -> OUI-SPY: relay every network and Bluetooth device** off to
+keep it listening only. It never uses the board's other engines (UniPwn, PCAP,
+Foxhunter).
+
+The status line under *Scanning* shows the board's state (`connecting…`,
+`live · N reports`), and the **ESP32** filter lists only what the board
+reported.
## Themes
diff --git a/app/src/main/java/com/rfsentinel/app/MainActivity.kt b/app/src/main/java/com/rfsentinel/app/MainActivity.kt
index 93de64c..8e90281 100644
--- a/app/src/main/java/com/rfsentinel/app/MainActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/MainActivity.kt
@@ -263,7 +263,7 @@ class MainActivity : AppCompatActivity() {
s.deviceType.contains("tracker", true) || s.deviceType.contains("Find My", true)
Filter.DRONES -> s.hits.any { it.category == Category.DRONE } || s.remoteId != null
Filter.NEW -> s.isNew
- Filter.ESP32 -> com.rfsentinel.app.esp.EspSeen.recent(s.mac)
+ Filter.ESP32 -> com.rfsentinel.app.esp.HeardBy.esp.recent(s.mac)
Filter.FAVORITES -> Favorites.contains(s.mac)
Filter.BLE -> Advert.Source.BLE in s.sources
Filter.WIFI -> Advert.Source.WIFI in s.sources
@@ -291,7 +291,6 @@ class MainActivity : AppCompatActivity() {
if (s.following) add("FOLLOWING")
if (Favorites.contains(s.mac)) add("★")
if (s.isNew) add("NEW")
- if (com.rfsentinel.app.esp.EspSeen.recent(s.mac)) add("ESP32")
}
val tag = when {
whitelisted -> "WHITELISTED"
@@ -314,7 +313,9 @@ class MainActivity : AppCompatActivity() {
highlight = if (alert) colorFor(s) else null,
flashing = alert && now - s.lastSeen < FLASH_WINDOW_MS &&
(s.following || (best!!.confidence >= threshold && best.category != Category.TRACKER)),
- bold = alert
+ bold = alert,
+ heardByEsp = com.rfsentinel.app.esp.HeardBy.esp.recent(s.mac, now),
+ heardByPhone = com.rfsentinel.app.esp.HeardBy.phone.recent(s.mac, now)
)
}
diff --git a/app/src/main/java/com/rfsentinel/app/esp/EspSeen.kt b/app/src/main/java/com/rfsentinel/app/esp/EspSeen.kt
deleted file mode 100644
index db4e943..0000000
--- a/app/src/main/java/com/rfsentinel/app/esp/EspSeen.kt
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.rfsentinel.app.esp
-
-import java.util.concurrent.ConcurrentHashMap
-
-/**
- * Which devices an ESP32 board (USB or OUI-SPY over Bluetooth) has reported,
- * and when, so the list can mark them and filter on them.
- */
-object EspSeen {
-
- /** How long a device keeps its ESP32 mark after the board last reported it. */
- const val WINDOW_MS = 5 * 60_000L
-
- private val last = ConcurrentHashMap<String, Long>()
-
- fun mark(mac: String, now: Long = System.currentTimeMillis()) {
- last[mac.uppercase()] = now
- }
-
- fun recent(mac: String, now: Long = System.currentTimeMillis()): Boolean {
- val t = last[mac.uppercase()] ?: return false
- if (now - t < WINDOW_MS) return true
- last.remove(mac.uppercase(), t)
- return false
- }
-
- fun clear() = last.clear()
-}
diff --git a/app/src/main/java/com/rfsentinel/app/esp/HeardBy.kt b/app/src/main/java/com/rfsentinel/app/esp/HeardBy.kt
new file mode 100644
index 0000000..651305a
--- /dev/null
+++ b/app/src/main/java/com/rfsentinel/app/esp/HeardBy.kt
@@ -0,0 +1,33 @@
+package com.rfsentinel.app.esp
+
+import java.util.concurrent.ConcurrentHashMap
+
+/**
+ * Which radio heard a device recently: an ESP32 board (USB or OUI-SPY over
+ * Bluetooth) and/or the phone's own chips, so the list can badge and filter them.
+ */
+class RecentMacs {
+ private val last = ConcurrentHashMap<String, Long>()
+
+ fun mark(mac: String, now: Long = System.currentTimeMillis()) {
+ last[mac.uppercase()] = now
+ }
+
+ fun recent(mac: String, now: Long = System.currentTimeMillis()): Boolean {
+ val key = mac.uppercase()
+ val t = last[key] ?: return false
+ if (now - t < HeardBy.WINDOW_MS) return true
+ last.remove(key, t)
+ return false
+ }
+
+ fun clear() = last.clear()
+}
+
+object HeardBy {
+ /** How long a device keeps its badge after that radio last heard it. */
+ const val WINDOW_MS = 5 * 60_000L
+
+ val esp = RecentMacs()
+ val phone = RecentMacs()
+}
diff --git a/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBle.kt b/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBle.kt
index 0b2918a..7756fd4 100644
--- a/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBle.kt
+++ b/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBle.kt
@@ -28,8 +28,13 @@ object OuiSpyBle {
private const val TAG = "OuiSpyBle"
private const val MTU = 247 // detections are up to 155 bytes
private const val RECONNECT_MS = 8_000L
+ private const val MTU_FALLBACK_MS = 2_500L
+ private const val SETUP_TIMEOUT_MS = 20_000L
+ /** Let a just-closed link go before reconnecting, or the new client shares (and inherits) it. */
+ private const val CLOSE_SETTLE_MS = 1_000L
private val main = Handler(Looper.getMainLooper())
+ private val closer = Handler(Looper.getMainLooper())
private var gatt: BluetoothGatt? = null
private var appContext: Context? = null
private var address: String? = null
@@ -37,6 +42,9 @@ object OuiSpyBle {
private var onSightings: ((List<EspSighting>) -> Unit)? = null
@Volatile private var active = false
private var inSpool = false
+ private var discovering = false
+ private var live = false
+ private var closingUntil = 0L
private var detections = 0
/** GATT writes must be sent one at a time. */
private val pending = ArrayDeque<ByteArray>()
@@ -72,7 +80,9 @@ object OuiSpyBle {
// Switch our engines off so the board goes quiet, then let go.
val ctl = g.getService(OuiSpyBleProtocol.SERVICE)?.getCharacteristic(OuiSpyBleProtocol.ENGINE_CONTROL)
if (ctl != null) runCatching { write(g, ctl, OuiSpyBleProtocol.disableAll()) }
- main.postDelayed({ runCatching { g.disconnect(); g.close() } }, 300)
+ // Own handler: a quick restart clears `main`, and must not cancel this close.
+ closer.postDelayed({ runCatching { g.disconnect(); g.close() } }, 300)
+ closingUntil = System.currentTimeMillis() + 300 + CLOSE_SETTLE_MS
gatt = null
setStatus("")
}
@@ -82,6 +92,8 @@ object OuiSpyBle {
val ctx = appContext ?: return
val addr = address ?: return
if (!active) return
+ val wait = closingUntil - System.currentTimeMillis()
+ if (wait > 0) { main.postDelayed({ connect() }, wait); return }
if (!canConnect(ctx)) { setStatus("OUI-SPY: allow \"Nearby devices\" to connect to the board"); return }
val adapter = ctx.getSystemService(BluetoothManager::class.java)?.adapter ?: return
if (!adapter.isEnabled) { setStatus("OUI-SPY: Bluetooth is off"); retry(); return }
@@ -119,6 +131,8 @@ object OuiSpyBle {
@SuppressLint("MissingPermission")
private fun writeNext(g: BluetoothGatt) {
val next = pending.removeFirstOrNull() ?: run {
+ live = true
+ Log.i(TAG, "live")
setStatus(if (relayAll) "OUI-SPY · live · relaying everything it hears"
else "OUI-SPY · live · Flock, Sky Spy and Detector engines on")
return
@@ -127,6 +141,13 @@ object OuiSpyBle {
write(g, ctl, next)
}
+ @SuppressLint("MissingPermission")
+ private fun discover(g: BluetoothGatt) {
+ if (discovering) return
+ discovering = true
+ g.discoverServices()
+ }
+
private fun handle(value: ByteArray) {
when {
OuiSpyBleProtocol.isSpoolHeader(value) -> { inSpool = true; return }
@@ -147,7 +168,21 @@ object OuiSpyBle {
if (g !== gatt) return@post
if (newState == BluetoothProfile.STATE_CONNECTED) {
setStatus("OUI-SPY: connected, setting up…")
- if (!g.requestMtu(MTU)) g.discoverServices()
+ live = false
+ discovering = false
+ // On a reused link Android may never answer the MTU request: go on anyway.
+ if (!g.requestMtu(MTU)) discover(g)
+ else main.postDelayed({ if (g === gatt) discover(g) }, MTU_FALLBACK_MS)
+ main.postDelayed({
+ if (g === gatt && !live && active) {
+ Log.w(TAG, "setup stalled, reconnecting")
+ runCatching { g.disconnect(); g.close() }
+ gatt = null
+ closingUntil = System.currentTimeMillis() + CLOSE_SETTLE_MS
+ setStatus("OUI-SPY: setup stalled - reconnecting…")
+ retry()
+ }
+ }, SETUP_TIMEOUT_MS)
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
runCatching { g.close() }
gatt = null
@@ -158,7 +193,8 @@ object OuiSpyBle {
@SuppressLint("MissingPermission")
override fun onMtuChanged(g: BluetoothGatt, mtu: Int, st: Int) {
- main.post { if (g === gatt) g.discoverServices() }
+ Log.i(TAG, "mtu $mtu (status $st)")
+ main.post { if (g === gatt) discover(g) }
}
@SuppressLint("MissingPermission")
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 58363ca..5849040 100644
--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
@@ -193,9 +193,9 @@ class ScanForegroundService : Service() {
pipelineThread = HandlerThread("rf-pipeline").apply { start() }
pipeline = Handler(pipelineThread.looper)
- bleEngine = BleScanEngine(this) { r -> pipeline.post { AdvertFactory.fromBle(r)?.let(::process) } }
+ bleEngine = BleScanEngine(this) { r -> pipeline.post { AdvertFactory.fromBle(r)?.let(::processPhone) } }
wifiEngine = WifiScanEngine(this) { results ->
- pipeline.post { results.forEach { r -> AdvertFactory.fromWifi(r)?.let(::process) } }
+ pipeline.post { results.forEach { r -> AdvertFactory.fromWifi(r)?.let(::processPhone) } }
}
val pm = getSystemService(POWER_SERVICE) as PowerManager
@@ -386,6 +386,12 @@ class ScanForegroundService : Service() {
// ---- Pipeline -------------------------------------------------------------
+ /** Something the phone's own Bluetooth or Wi-Fi chip heard. */
+ private fun processPhone(a: Advert) {
+ com.rfsentinel.app.esp.HeardBy.phone.mark(a.mac)
+ process(a)
+ }
+
private fun process(a: Advert, reportedRemoteId: RemoteId.Info? = null) {
val now = a.timestamp
val mac = a.mac
@@ -450,7 +456,7 @@ class ScanForegroundService : Service() {
/** One ESP32 report: becomes a normal observation, with the board's own matches added. */
private fun processEsp(e: com.rfsentinel.app.esp.EspSighting) {
val now = System.currentTimeMillis()
- com.rfsentinel.app.esp.EspSeen.mark(e.mac, now)
+ com.rfsentinel.app.esp.HeardBy.esp.mark(e.mac, now)
if (e.hits.isNotEmpty()) {
espHits[e.mac] = now to e.hits
classified.remove(e.mac) // re-classify with the new evidence
diff --git a/app/src/main/java/com/rfsentinel/app/ui/DeviceAdapter.kt b/app/src/main/java/com/rfsentinel/app/ui/DeviceAdapter.kt
index 636bf4c..4fe9042 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/DeviceAdapter.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/DeviceAdapter.kt
@@ -24,9 +24,33 @@ data class DeviceRow(
val highlight: Int?,
/** Pulse the tint (flagged, above the alert threshold, heard within the last minute). */
val flashing: Boolean,
- val bold: Boolean
+ val bold: Boolean,
+ /** Heard by an ESP32 board (blue badge) and/or the phone's own radios (green badge). */
+ val heardByEsp: Boolean = false,
+ val heardByPhone: Boolean = false
)
+private const val ESP_BADGE = 0xFF1E88E5.toInt()
+private const val PHONE_BADGE = 0xFF2E7D32.toInt()
+
+/** The meta line, followed by small coloured "ESP32" / "INTERNAL" badges. */
+private fun metaWithBadges(row: DeviceRow): CharSequence {
+ if (!row.heardByEsp && !row.heardByPhone) return row.meta
+ val sb = android.text.SpannableStringBuilder(row.meta)
+ fun badge(label: String, color: Int) {
+ sb.append(" ")
+ val start = sb.length
+ sb.append(" ").append(label).append(" ")
+ val end = sb.length
+ sb.setSpan(android.text.style.BackgroundColorSpan(color), start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
+ sb.setSpan(android.text.style.ForegroundColorSpan(Color.WHITE), start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
+ sb.setSpan(android.text.style.StyleSpan(Typeface.BOLD), start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
+ }
+ if (row.heardByEsp) badge("ESP32", ESP_BADGE)
+ if (row.heardByPhone) badge("INTERNAL", PHONE_BADGE)
+ return sb
+}
+
class DeviceAdapter(
private val onClick: (DeviceRow) -> Unit,
private val onLongPress: (DeviceRow) -> Unit
@@ -93,7 +117,7 @@ class DeviceAdapter(
b.titleText.text = row.title
b.titleText.setTypeface(null, if (row.bold) Typeface.BOLD else Typeface.NORMAL)
b.macText.text = row.subtitle
- b.metaText.text = row.meta
+ b.metaText.text = metaWithBadges(row)
holder.setHighlight(row.highlight, row.flashing)
holder.itemView.setOnClickListener { onClick(row) }
holder.itemView.setOnLongClickListener { onLongPress(row); true }
diff --git a/app/src/test/java/com/rfsentinel/app/esp/EspSeenTest.kt b/app/src/test/java/com/rfsentinel/app/esp/EspSeenTest.kt
deleted file mode 100644
index f9e45d1..0000000
--- a/app/src/test/java/com/rfsentinel/app/esp/EspSeenTest.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.rfsentinel.app.esp
-
-import org.junit.Assert.assertFalse
-import org.junit.Assert.assertTrue
-import org.junit.Test
-
-class EspSeenTest {
-
- @Test
- fun marksForAWhileThenForgets() {
- EspSeen.clear()
- EspSeen.mark("70:c9:4e:11:22:33", now = 1_000)
- assertTrue(EspSeen.recent("70:C9:4E:11:22:33", now = 1_000 + EspSeen.WINDOW_MS - 1))
- assertFalse(EspSeen.recent("70:C9:4E:11:22:33", now = 1_000 + EspSeen.WINDOW_MS))
- assertFalse(EspSeen.recent("00:11:22:33:44:55", now = 1_000))
- }
-}
diff --git a/app/src/test/java/com/rfsentinel/app/esp/HeardByTest.kt b/app/src/test/java/com/rfsentinel/app/esp/HeardByTest.kt
new file mode 100644
index 0000000..bb4a1d9
--- /dev/null
+++ b/app/src/test/java/com/rfsentinel/app/esp/HeardByTest.kt
@@ -0,0 +1,25 @@
+package com.rfsentinel.app.esp
+
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+class HeardByTest {
+
+ @Test
+ fun marksForAWhileThenForgets() {
+ val r = RecentMacs()
+ r.mark("70:c9:4e:11:22:33", now = 1_000)
+ assertTrue(r.recent("70:C9:4E:11:22:33", now = 1_000 + HeardBy.WINDOW_MS - 1))
+ assertFalse(r.recent("70:C9:4E:11:22:33", now = 1_000 + HeardBy.WINDOW_MS))
+ assertFalse(r.recent("00:11:22:33:44:55", now = 1_000))
+ }
+
+ @Test
+ fun boardAndPhoneAreTrackedSeparately() {
+ HeardBy.esp.clear(); HeardBy.phone.clear()
+ HeardBy.esp.mark("AA:BB:CC:00:00:01", now = 5_000)
+ assertTrue(HeardBy.esp.recent("AA:BB:CC:00:00:01", now = 5_000))
+ assertFalse(HeardBy.phone.recent("AA:BB:CC:00:00:01", now = 5_000))
+ }
+}