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.

Live drones on the map and a drone-overhead alert

CIS-C0272f721d46f0
diff --git a/app/src/main/java/com/rfsentinel/app/MainActivity.kt b/app/src/main/java/com/rfsentinel/app/MainActivity.kt
index c1b1778..d8de36a 100644
--- a/app/src/main/java/com/rfsentinel/app/MainActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/MainActivity.kt
@@ -115,7 +115,13 @@ class MainActivity : AppCompatActivity() {
if (BuildConfig.DEBUG && intent.getBooleanExtra("demo", false)) {
demoMode = true
intent.getStringExtra("view")?.let { Prefs.setRadarView(this, it == "radar") }
- lifecycleScope.launch(kotlinx.coroutines.Dispatchers.Default) { com.rfsentinel.app.ui.DemoData.populate() }
+ val anchor = runCatching {
+ @Suppress("MissingPermission")
+ (getSystemService(LOCATION_SERVICE) as android.location.LocationManager)
+ .getLastKnownLocation(android.location.LocationManager.GPS_PROVIDER)
+ ?.let { it.latitude to it.longitude }
+ }.getOrNull()
+ lifecycleScope.launch(kotlinx.coroutines.Dispatchers.Default) { com.rfsentinel.app.ui.DemoData.populate(anchor) }
}
applyViewMode()
observeDevices()
diff --git a/app/src/main/java/com/rfsentinel/app/detect/DroneProximity.kt b/app/src/main/java/com/rfsentinel/app/detect/DroneProximity.kt
new file mode 100644
index 0000000..e164caf
--- /dev/null
+++ b/app/src/main/java/com/rfsentinel/app/detect/DroneProximity.kt
@@ -0,0 +1,30 @@
+package com.rfsentinel.app.detect
+
+import com.rfsentinel.app.service.DeviceRegistry
+import kotlin.math.roundToInt
+
+/**
+ * "Drone overhead": a drone whose Remote ID position is within [RADIUS_M] of
+ * you (horizontal distance). Remote ID broadcasts the aircraft's own GPS
+ * position, so unlike RSSI this is a real location.
+ */
+object DroneProximity {
+
+ const val RADIUS_M = 200.0
+
+ /** The alert hit, or null when the drone is farther away or its position is unknown. */
+ fun overheadHit(info: RemoteId.Info, myLat: Double, myLon: Double): Hit? {
+ val lat = info.latitude ?: return null
+ val lon = info.longitude ?: return null
+ val d = DeviceRegistry.metersBetween(myLat, myLon, lat, lon)
+ if (d > RADIUS_M) return null
+ val height = info.heightM ?: info.altitudeGeoM
+ val detail = buildString {
+ append("Remote ID position ~${d.roundToInt()} m from you")
+ height?.let { append(", ${it.roundToInt()} m up") }
+ info.speedMs?.let { append(", ${(it * 3.6).roundToInt()} km/h") }
+ info.uasId?.let { append(" (ID $it)") }
+ }
+ return Hit(Category.DRONE, "Drone overhead", 95, detail, "ASTM F3411 Remote ID (the drone's own GPS position)")
+ }
+}
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 84f4db6..656a763 100644
--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
@@ -33,6 +33,7 @@ import com.rfsentinel.app.data.WhitelistCache
import com.rfsentinel.app.detect.Advert
import com.rfsentinel.app.detect.Category
import com.rfsentinel.app.detect.DeviceIntel
+import com.rfsentinel.app.detect.DroneProximity
import com.rfsentinel.app.detect.EvidenceFusion
import com.rfsentinel.app.detect.Hit
import com.rfsentinel.app.detect.RemoteId
@@ -79,6 +80,7 @@ class ScanForegroundService : Service() {
/** Each periodic job holds a short wake lock only while it runs. */
private const val WAKE_SLICE_MS = 10_000L
private const val HISTORY_FLUSH_MS = 60_000L
+ private const val DRONE_OVERHEAD_REPEAT_MS = 5 * 60_000L
/** True while an instance is alive in this process. Source of truth for the UI. */
@Volatile
@@ -113,6 +115,7 @@ class ScanForegroundService : Service() {
private val classified = ConcurrentHashMap<String, Classified>()
private val lastAlerted = ConcurrentHashMap<String, Long>()
private val lastLogged = ConcurrentHashMap<String, Long>()
+ private val lastDroneOverhead = ConcurrentHashMap<String, Long>()
private var wifiPollJob: Job? = null
private var bleRestartJob: Job? = null
private var housekeepingJob: Job? = null
@@ -339,6 +342,8 @@ class ScanForegroundService : Service() {
)
}
+ remoteId?.let { info -> if (loc != null) maybeAlertDroneOverhead(a, info, loc, now) }
+
val best = c.hits.firstOrNull() ?: return
if (WhitelistCache.contains(mac)) return
@@ -409,6 +414,17 @@ class ScanForegroundService : Service() {
AlertPlayer.play(this, best.tier, "${best.label} nearby")
}
+ /** Remote ID puts the drone within ~200 m of you: alert once per drone per 5 minutes. */
+ private fun maybeAlertDroneOverhead(a: Advert, info: RemoteId.Info, loc: Location, now: Long) {
+ if (!Prefs.categoryEnabled(this, Category.DRONE) || WhitelistCache.contains(a.mac)) return
+ val hit = DroneProximity.overheadHit(info, loc.latitude, loc.longitude) ?: return
+ val last = lastDroneOverhead[a.mac] ?: 0L
+ if (now - last < DRONE_OVERHEAD_REPEAT_MS) return
+ lastDroneOverhead[a.mac] = now
+ NotificationHelper.sendAlert(this, a.mac, hit, a.rssi)
+ AlertPlayer.play(this, hit.tier, "Drone overhead")
+ }
+
// ---- History & housekeeping -----------------------------------------------
private suspend fun loadHistory(mac: String) {
diff --git a/app/src/main/java/com/rfsentinel/app/ui/DemoData.kt b/app/src/main/java/com/rfsentinel/app/ui/DemoData.kt
index cf93163..8ec995c 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/DemoData.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/DemoData.kt
@@ -4,6 +4,7 @@ import com.rfsentinel.app.detect.AddressType
import com.rfsentinel.app.detect.Advert
import com.rfsentinel.app.detect.DeviceIntel
import com.rfsentinel.app.detect.EvidenceFusion
+import com.rfsentinel.app.detect.RemoteId
import com.rfsentinel.app.detect.SignatureEngine
import com.rfsentinel.app.detect.VendorDb
import com.rfsentinel.app.oui.OuiWatchlist
@@ -19,6 +20,24 @@ import kotlin.math.sin
*/
object DemoData {
+ private const val DEMO_DRONE = "60:60:1F:A2:44:18"
+
+ /** A drone circling ~120 m from [anchor], with its operator ~80 m the other way. */
+ private fun demoRemoteId(anchor: Pair<Double, Double>, secondsAgo: Int): RemoteId.Info {
+ val angle = Math.toRadians(135.0 + secondsAgo * 2.0)
+ val dLat = 0.00108 * kotlin.math.cos(angle) // ~120 m
+ val dLon = 0.00108 * kotlin.math.sin(angle) / kotlin.math.cos(Math.toRadians(anchor.first))
+ return RemoteId.Info(
+ uasId = "1581F5FJDEMO00042", idType = "Serial number (ANSI/CTA-2063-A)",
+ uaType = "Helicopter / multirotor", status = "Airborne",
+ latitude = anchor.first + dLat, longitude = anchor.second + dLon,
+ heightM = 62.0, altitudeGeoM = 95.0, speedMs = 7.5, verticalSpeedMs = 0.0,
+ directionDeg = ((Math.toDegrees(angle) + 90) % 360).toInt(),
+ operatorLatitude = anchor.first - 0.0007, operatorLongitude = anchor.second - 0.0004,
+ operatorId = "DEMO-OP-0001"
+ )
+ }
+
private fun b(vararg v: Int) = ByteArray(v.size) { v[it].toByte() }
private fun ble(mac: String, name: String? = null, mfg: Map<Int, ByteArray> = emptyMap(), uuids: List<Int> = emptyList(),
@@ -51,7 +70,12 @@ object DemoData {
Triple(wifi("E4:5F:01:2B:3C:4D", "Cafe_Guest", 2437), -86, false)
)
- fun populate() {
+ /**
+ * @param anchor your phone's current position, if known: the demo drone's
+ * Remote ID position is placed relative to it at runtime, so no coordinates
+ * are stored in the code.
+ */
+ fun populate(anchor: Pair<Double, Double>? = null) {
if (!VendorDb.loaded) Thread.sleep(1500)
DeviceRegistry.startSession()
val now = System.currentTimeMillis()
@@ -66,7 +90,8 @@ object DemoData {
val raw = SignatureEngine.classify(a) +
OuiWatchlist.hits(a.mac, a.name, listOfNotNull(vendor)) +
listOfNotNull(DeviceRegistry.clusterHit(a.mac, t))
- DeviceRegistry.report(a, EvidenceFusion.fuse(raw), DeviceIntel.identify(a, VendorDb.macVendor(a.mac)), vendor, null, null, t)
+ val rid = if (a.mac == DEMO_DRONE && anchor != null) demoRemoteId(anchor, s) else null
+ DeviceRegistry.report(a, EvidenceFusion.fuse(raw), DeviceIntel.identify(a, VendorDb.macVendor(a.mac)), vendor, rid, null, t)
}
}
}
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 a0a03a3..74ac0c5 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/MapActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/MapActivity.kt
@@ -64,6 +64,7 @@ class MapActivity : AppCompatActivity() {
private const val ORDINARY_COLOR = 0xFF607D8B.toInt()
private const val TRACE_COLOR = 0xFFE0622D.toInt()
private const val PAST_TRACE_COLOR = 0xFF1F5FBF.toInt()
+ private const val DRONE_COLOR = 0xFF1F5FBF.toInt()
}
/** One device to draw, from the live registry or a saved trip. */
@@ -80,6 +81,8 @@ class MapActivity : AppCompatActivity() {
private val trace = Polyline()
private val pins = FolderOverlay()
+ /** Live drones from Remote ID: aircraft, operator and the line between them. */
+ private val drones = FolderOverlay()
private lateinit var myLocation: MyLocationNewOverlay
private val dateFmt = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT)
@@ -145,6 +148,7 @@ class MapActivity : AppCompatActivity() {
}
map.overlays.add(trace)
map.overlays.add(pins)
+ map.overlays.add(drones)
myLocation = MyLocationNewOverlay(GpsMyLocationProvider(this), map)
if (Permissions.granted(this, android.Manifest.permission.ACCESS_FINE_LOCATION)) {
@@ -192,7 +196,8 @@ class MapActivity : AppCompatActivity() {
trace.setPoints(TripRecorder.livePoints().map { GeoPoint(it.lat, it.lon) })
- val devices = if (ScanForegroundService.isRunning) DeviceRegistry.snapshot() else emptyList()
+ // Includes devices from a scan that just stopped: the registry drops them after 3 minutes.
+ val devices = DeviceRegistry.snapshot()
val drawn = devices.mapNotNull { s ->
val pos = s.bestPosition ?: return@mapNotNull null
val flagged = s.best != null && !WhitelistCache.contains(s.mac)
@@ -212,6 +217,7 @@ class MapActivity : AppCompatActivity() {
)
}
drawPins(drawn)
+ drawDrones(devices.filter { it.remoteId?.hasPosition == true })
val positioned = devices.count { it.bestPosition != null }
binding.statusText.text = when {
@@ -354,6 +360,90 @@ class MapActivity : AppCompatActivity() {
}
}
+ /**
+ * Drones place themselves: Remote ID broadcasts the aircraft's own GPS fix
+ * (and usually the operator's / take-off point), so these markers are real
+ * positions, unlike RSSI-based device pins.
+ */
+ private fun drawDrones(list: List<DeviceRegistry.Snapshot>) {
+ drones.items.clear()
+ val dp = resources.displayMetrics.density
+ for (s in list) {
+ val r = s.remoteId ?: continue
+ val aircraft = GeoPoint(r.latitude!!, r.longitude!!)
+ val details = droneDetails(s, r)
+ if (r.hasOperatorPosition) {
+ val operator = GeoPoint(r.operatorLatitude!!, r.operatorLongitude!!)
+ drones.add(Polyline().apply {
+ setPoints(listOf(operator, aircraft))
+ outlinePaint.apply {
+ color = DRONE_COLOR
+ strokeWidth = 2.5f * dp
+ pathEffect = android.graphics.DashPathEffect(floatArrayOf(10 * dp, 6 * dp), 0f)
+ }
+ })
+ drones.add(Marker(binding.map).apply {
+ position = operator
+ icon = GradientDrawable().apply {
+ shape = GradientDrawable.RECTANGLE
+ setColor(0xFFF5E100.toInt())
+ setStroke((2 * dp).toInt(), DRONE_COLOR)
+ setSize((14 * dp).toInt(), (14 * dp).toInt())
+ }
+ setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER)
+ title = "Drone operator / take-off point"
+ setOnMarkerClickListener { _, _ -> showDrone(s, "Operator of this drone (or its take-off point)\n\n$details"); true }
+ })
+ }
+ drones.add(Marker(binding.map).apply {
+ position = aircraft
+ icon = android.graphics.drawable.BitmapDrawable(resources, droneArrow(dp))
+ rotation = -(r.directionDeg ?: 0).toFloat() // osmdroid rotates counter-clockwise
+ isFlat = true
+ setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER)
+ title = "Drone"
+ setOnMarkerClickListener { _, _ -> showDrone(s, details); true }
+ })
+ }
+ }
+
+ private fun droneDetails(s: DeviceRegistry.Snapshot, r: com.rfsentinel.app.detect.RemoteId.Info) = buildString {
+ r.uasId?.let { append("ID: $it\n") }
+ r.uaType?.let { append("Type: $it\n") }
+ r.status?.let { append("Status: $it\n") }
+ r.heightM?.let { append(String.format(Locale.US, "Height: %.0f m\n", it)) }
+ r.altitudeGeoM?.let { append(String.format(Locale.US, "Altitude (GPS): %.0f m\n", it)) }
+ r.speedMs?.let { append(String.format(Locale.US, "Speed: %.0f km/h\n", it * 3.6)) }
+ r.directionDeg?.let { append("Heading: $it°\n") }
+ r.operatorId?.let { append("Operator ID: $it\n") }
+ r.selfIdDescription?.let { append("Description: $it\n") }
+ append("Radio: ${s.mac} · ${s.rssi} dBm")
+ }
+
+ private fun showDrone(s: DeviceRegistry.Snapshot, text: String) {
+ AlertDialog.Builder(this)
+ .setTitle("Drone (Remote ID)")
+ .setMessage(text + "\n\nPositions are broadcast by the drone itself (ASTM F3411 Remote ID).")
+ .setPositiveButton("Details") { _, _ -> DeviceActions.openDetails(this, s.mac) }
+ .setNegativeButton("Close", null)
+ .show()
+ }
+
+ /** A blue arrow pointing north; the marker rotation turns it to the drone's heading. */
+ private fun droneArrow(dp: Float): android.graphics.Bitmap {
+ val size = (30 * dp).toInt()
+ val bmp = android.graphics.Bitmap.createBitmap(size, size, android.graphics.Bitmap.Config.ARGB_8888)
+ val c = android.graphics.Canvas(bmp)
+ val path = android.graphics.Path().apply {
+ moveTo(size / 2f, 2 * dp); lineTo(size - 5 * dp, size - 4 * dp)
+ lineTo(size / 2f, size * 0.68f); lineTo(5 * dp, size - 4 * dp); close()
+ }
+ val paint = android.graphics.Paint(android.graphics.Paint.ANTI_ALIAS_FLAG)
+ c.drawPath(path, paint.apply { color = DRONE_COLOR; style = android.graphics.Paint.Style.FILL })
+ c.drawPath(path, paint.apply { color = Color.WHITE; style = android.graphics.Paint.Style.STROKE; strokeWidth = 2 * dp })
+ return bmp
+ }
+
private fun showPin(p: Pin) {
AlertDialog.Builder(this)
.setTitle(p.label)
diff --git a/app/src/test/java/com/rfsentinel/app/detect/DroneProximityTest.kt b/app/src/test/java/com/rfsentinel/app/detect/DroneProximityTest.kt
new file mode 100644
index 0000000..566b50b
--- /dev/null
+++ b/app/src/test/java/com/rfsentinel/app/detect/DroneProximityTest.kt
@@ -0,0 +1,32 @@
+package com.rfsentinel.app.detect
+
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertNotNull
+import org.junit.Assert.assertNull
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+class DroneProximityTest {
+
+ // Synthetic test position (not a real place of interest).
+ private val me = 10.5 to -20.5
+
+ private fun drone(dLat: Double, height: Double? = 60.0) =
+ RemoteId.Info(latitude = me.first + dLat, longitude = me.second, heightM = height, speedMs = 5.0, uasId = "TEST123")
+
+ @Test
+ fun droneWithin200mIsOverhead() {
+ val hit = DroneProximity.overheadHit(drone(0.001), me.first, me.second) // ~111 m north
+ assertNotNull(hit)
+ assertEquals(Category.DRONE, hit!!.category)
+ assertEquals(95, hit.confidence)
+ assertTrue(hit.evidence.contains("~111 m from you"))
+ assertTrue(hit.evidence.contains("60 m up"))
+ }
+
+ @Test
+ fun farOrUnpositionedDronesAreNot() {
+ assertNull(DroneProximity.overheadHit(drone(0.003), me.first, me.second)) // ~333 m
+ assertNull(DroneProximity.overheadHit(RemoteId.Info(uasId = "NOPOS"), me.first, me.second))
+ }
+}