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.

Held P25 talkgroup stays listed and pinned to the top; aircraft alert distance setting, 5 km by default

CIS-C01403e540ce8d
diff --git a/app/src/main/java/com/rfsentinel/app/MainActivity.kt b/app/src/main/java/com/rfsentinel/app/MainActivity.kt
index e176441..f21ddad 100644
--- a/app/src/main/java/com/rfsentinel/app/MainActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/MainActivity.kt
@@ -814,7 +814,7 @@ class MainActivity : AppCompatActivity() {
// the rest follow the devices.
val (urgent, quiet) = waze.partition { it.flashing }
val (radioLive, radioOld) = radio.partition { it.flashing }
- val (tgLive, tgOld) = talkgroups.partition { it.flashing }
+ val (tgLive, tgOld) = talkgroups.partition { it.flashing || it.mac == TG_ROW + com.rfsentinel.app.sdr.SdrRadio.p25Hold }
val (airUrgent, airQuiet) = air.partition { it.flashing }
// Alerting devices from your own watchlist entries go above all of them.
fun mine(s: DeviceRegistry.Snapshot) = com.rfsentinel.app.ui.LiveWindow.alerting(s, now) &&
@@ -986,16 +986,18 @@ class MainActivity : AppCompatActivity() {
}
}
- /** P25 talkgroups (and private calls) of the last few minutes that you watch, or whose radio was heard close by on the site's input. */
+ /** The held P25 talkgroup, plus talkgroups (and private calls) of the last few minutes that you watch, or whose radio was heard close by on the site's input. */
private fun currentTalkgroups(now: Long): List<com.rfsentinel.app.sdr.P25Log.Row> =
if (!ScanForegroundService.isRunning) emptyList()
else com.rfsentinel.app.sdr.SdrRadio.p25Log.rows().filter {
- now - it.lastAt <= TG_LIST_MS && (it.tg in com.rfsentinel.app.sdr.SdrRadio.p25Watched || now - it.inputAt <= TG_LIST_MS)
+ (it.tg != null && it.tg == com.rfsentinel.app.sdr.SdrRadio.p25Hold) ||
+ now - it.lastAt <= TG_LIST_MS && (it.tg in com.rfsentinel.app.sdr.SdrRadio.p25Watched || now - it.inputAt <= TG_LIST_MS)
}
/**
- * The Talkgroups filter's rows (under All, only the NEAR ones): a talkgroup whose radio keyed up on the input in the
- * last 2 minutes gets the NEAR box and, at or above the alert threshold, is tinted, flashes and is pinned to the top.
+ * The Talkgroups filter's rows (under All, only the NEAR and held ones): a talkgroup whose radio keyed up on the input in
+ * the last 2 minutes gets the NEAR box and, at or above the alert threshold, is tinted, flashes and is pinned to the top.
+ * A held talkgroup is pinned there too, without the tint.
*/
private fun talkgroupRows(now: Long, threshold: Int): List<DeviceRow> {
if (filter != com.rfsentinel.app.ui.DeviceFilter.ALL && filter != com.rfsentinel.app.ui.DeviceFilter.TALKGROUPS) return emptyList()
@@ -1005,7 +1007,8 @@ class MainActivity : AppCompatActivity() {
val playing = sdr.p25Playing
return currentTalkgroups(now).mapNotNull { r ->
val near = now - r.inputAt <= TG_NEAR_MS
- if (filter == com.rfsentinel.app.ui.DeviceFilter.ALL && !near) return@mapNotNull null
+ val held = r.tg != null && r.tg == sdr.p25Hold
+ if (filter == com.rfsentinel.app.ui.DeviceFilter.ALL && !near && !held) return@mapNotNull null
val title = com.rfsentinel.app.ui.P25Activity.title(r) + (sdr.p25Watched[r.tg]?.ifEmpty { null }?.let { " · $it" } ?: "")
if (query.isNotBlank() && !title.contains(query.trim(), ignoreCase = true)) return@mapNotNull null
val key = TG_ROW + (r.tg ?: "r${r.target}")
@@ -1028,7 +1031,7 @@ class MainActivity : AppCompatActivity() {
badges = listOfNotNull(
("NEAR ${r.inputSnr} dB" to com.rfsentinel.app.ui.NEAR_BADGE).takeIf { near },
("PLAYING" to com.rfsentinel.app.ui.PEER_BADGE).takeIf { playing != null && playing.tg == r.tg && playing.target == r.target },
- ("HELD" to com.rfsentinel.app.ui.PEER_BADGE).takeIf { r.tg != null && r.tg == sdr.p25Hold })
+ ("HELD" to com.rfsentinel.app.ui.PEER_BADGE).takeIf { held })
)
}
}
diff --git a/app/src/main/java/com/rfsentinel/app/online/OnlineWatch.kt b/app/src/main/java/com/rfsentinel/app/online/OnlineWatch.kt
index 3669a29..9a77ef4 100644
--- a/app/src/main/java/com/rfsentinel/app/online/OnlineWatch.kt
+++ b/app/src/main/java/com/rfsentinel/app/online/OnlineWatch.kt
@@ -93,7 +93,7 @@ class OnlineWatch(
val hit = PoliceAircraft.classify(p, registry, circling, distanceM)
seen += PoliceAircraft.Seen(p, hit)
if (hit == null) continue
- val loud = PoliceAircraft.alerts(hit, distanceM, Prefs.aircraftCircling(context))
+ val loud = PoliceAircraft.alerts(hit, distanceM, Prefs.aircraftCircling(context), Prefs.aircraftAlertKm(context) * 1000.0)
if (loud && (best == null || hit.confidence > best!!.confidence)) best = hit
reportAircraft(hit, p.hex, p.lat, p.lon, loud, now, said(hit, distanceM, me, p))
}
@@ -126,7 +126,7 @@ class OnlineWatch(
val hit = PoliceAircraft.classify(p, registry, circling, distanceM, PoliceAircraft.VIA_LOCAL)
seen += PoliceAircraft.Seen(p, hit)
if (hit == null) continue
- val loud = PoliceAircraft.alerts(hit, distanceM, Prefs.aircraftCircling(context))
+ val loud = PoliceAircraft.alerts(hit, distanceM, Prefs.aircraftCircling(context), Prefs.aircraftAlertKm(context) * 1000.0)
if (loud && (best == null || hit.confidence > best!!.confidence)) best = hit
reportAircraft(hit, p.hex, p.lat, p.lon, loud, now, said(hit, distanceM, me, p))
}
diff --git a/app/src/main/java/com/rfsentinel/app/online/PoliceAircraft.kt b/app/src/main/java/com/rfsentinel/app/online/PoliceAircraft.kt
index fab807f..2ec3615 100644
--- a/app/src/main/java/com/rfsentinel/app/online/PoliceAircraft.kt
+++ b/app/src/main/java/com/rfsentinel/app/online/PoliceAircraft.kt
@@ -149,15 +149,15 @@ object PoliceAircraft {
"FAA / Transport Canada aircraft registry; $VIA_LOCAL")
}
- /** Closer than this (ground distance) a strong match alerts; farther, or weaker, it's only logged and listed. */
+ /** The default alert distance (ground distance, Settings): closer, a strong match alerts; farther, or weaker, it's only logged and listed. */
const val ALERT_M = 5_000.0
/**
- * Whether a hit alerts (sound, voice, notification): a strong match (police, government) within [ALERT_M], or with
+ * Whether a hit alerts (sound, voice, notification): a strong match (police, government) within [alertM], or with
* [circlingOn] (Settings) any aircraft circling within it; otherwise it's only logged.
*/
- fun alerts(hit: Hit, distanceM: Double?, circlingOn: Boolean = false): Boolean =
- distanceM != null && distanceM <= ALERT_M &&
+ fun alerts(hit: Hit, distanceM: Double?, circlingOn: Boolean = false, alertM: Double = ALERT_M): Boolean =
+ distanceM != null && distanceM <= alertM &&
(hit.confidence >= com.rfsentinel.app.detect.Tier.STRONG.min || (circlingOn && hit.label == CIRCLING))
const val VIA_ONLINE = "ADS-B (adsb.fi / adsb.lol)"
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 c4b8006..39f165b 100644
--- a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
@@ -655,7 +655,7 @@ class SettingsActivity : AppCompatActivity() {
"Police aircraft and Waze reports are online sources, off by default. Aircraft: every minute, a position " +
"rounded to about 1 km goes to the community ADS-B feeds adsb.fi / adsb.lol; matched against a list of " +
"about 1,400 US and Canadian law-enforcement aircraft, plus unlisted aircraft circling low overhead. Only a strong match " +
- "within 5 km alerts; the rest are listed and logged. With an RTL-SDR " +
+ "within the alert distance alerts; the rest are listed and logged. With an RTL-SDR " +
"set up as an ADS-B receiver, aircraft are also heard directly, and the online feeds can be turned off. " +
"Waze: crowd reports (police, and any other kind you tick), at your own risk. Either through your own OpenWeb Ninja key " +
"(Waze never sees you), or Waze direct: no key, free, but an anonymous Waze account on this phone sends Waze (Google) your " +
@@ -2162,7 +2162,7 @@ class SettingsActivity : AppCompatActivity() {
}
}
- /** Aircraft search radius (10-50 km) and the feed status, under the aircraft switch. */
+ /** Aircraft alert distance (1-20 km), search radius (10-50 km) and the feed status, under the aircraft switch. */
private fun addAircraftControls(sw: SwitchMaterial) {
val dp = resources.displayMetrics.density
val box = android.widget.LinearLayout(this).apply {
@@ -2177,24 +2177,31 @@ class SettingsActivity : AppCompatActivity() {
box.addView(detectRow(SwitchMaterial(this).apply {
text = "Alert for circling aircraft"; isChecked = Prefs.aircraftCircling(this@SettingsActivity)
setOnCheckedChangeListener { _, v -> Prefs.setAircraftCircling(this@SettingsActivity, v) }
- }, "Police and government aircraft within 5 km always alert. Turn this on to also hear about any other aircraft " +
- "circling within 5 km (news, training, survey and unlisted police flights orbit too). Off: they're only listed and logged."))
- val radiusText = android.widget.TextView(this).apply { textSize = 12f; alpha = 0.75f }
- fun showRadius(km: Int) { radiusText.text = "Look for aircraft within ${com.rfsentinel.app.util.Units.km(km)}" }
- val km = Prefs.aircraftRadiusKm(this)
- showRadius(km)
- box.addView(radiusText)
- box.addView(com.google.android.material.slider.Slider(this).apply {
- valueFrom = 10f; valueTo = 50f; stepSize = 5f
- value = (km - km % 5).coerceIn(10, 50).toFloat()
- contentDescription = "Aircraft search radius in kilometres"
- setLabelFormatter { com.rfsentinel.app.util.Units.km(it.toInt()) }
- addOnChangeListener { _, v, fromUser ->
- if (!fromUser) return@addOnChangeListener
- Prefs.setAircraftRadiusKm(this@SettingsActivity, v.toInt())
- showRadius(v.toInt())
- }
- })
+ }, "Police and government aircraft within the alert distance always alert. Turn this on to also hear about any other aircraft " +
+ "circling within it (news, training, survey and unlisted police flights orbit too). Off: they're only listed and logged."))
+ fun kmSlider(label: String, about: String, km: Int, from: Int, to: Int, step: Int, save: (Int) -> Unit) {
+ val text = android.widget.TextView(this).apply { textSize = 12f; alpha = 0.75f }
+ fun show(v: Int) { text.text = "$label ${com.rfsentinel.app.util.Units.km(v)}" }
+ show(km)
+ box.addView(text)
+ box.addView(com.google.android.material.slider.Slider(this).apply {
+ valueFrom = from.toFloat(); valueTo = to.toFloat(); stepSize = step.toFloat()
+ value = (km - km % step).coerceIn(from, to).toFloat()
+ contentDescription = about
+ setLabelFormatter { com.rfsentinel.app.util.Units.km(it.toInt()) }
+ addOnChangeListener { _, v, fromUser ->
+ if (!fromUser) return@addOnChangeListener
+ save(v.toInt())
+ show(v.toInt())
+ }
+ })
+ }
+ kmSlider("Alert for aircraft within", "Aircraft alert distance in kilometres", Prefs.aircraftAlertKm(this), 1, 20, 1) {
+ Prefs.setAircraftAlertKm(this, it)
+ }
+ kmSlider("Look for aircraft within", "Aircraft search radius in kilometres", Prefs.aircraftRadiusKm(this), 10, 50, 5) {
+ Prefs.setAircraftRadiusKm(this, it)
+ }
aircraftStatusText = android.widget.TextView(this).apply { textSize = 12f; alpha = 0.75f }
box.addView(aircraftStatusText)
showNote(aircraftStatusText, com.rfsentinel.app.online.OnlineWatch.aircraftStatus)
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 15e378c..71fa9d9 100644
--- a/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
+++ b/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
@@ -331,6 +331,10 @@ object Prefs {
fun aircraftCircling(context: Context): Boolean = bool(context, "aircraft_circling", false)
fun setAircraftCircling(context: Context, v: Boolean) = setBool(context, "aircraft_circling", v)
+ /** How close a police or government aircraft has to be to alert. */
+ fun aircraftAlertKm(context: Context): Int = int(context, "aircraft_alert_km", 5).coerceIn(1, 20)
+ fun setAircraftAlertKm(context: Context, km: Int) = setInt(context, "aircraft_alert_km", km.coerceIn(1, 20))
+
fun aircraftRadiusKm(context: Context): Int = int(context, "aircraft_radius_km", 30).coerceIn(10, 50)
fun setAircraftRadiusKm(context: Context, km: Int) = setInt(context, "aircraft_radius_km", km.coerceIn(10, 50))
diff --git a/app/src/test/java/com/rfsentinel/app/online/OnlineSourcesTest.kt b/app/src/test/java/com/rfsentinel/app/online/OnlineSourcesTest.kt
index 9477858..bca6751 100644
--- a/app/src/test/java/com/rfsentinel/app/online/OnlineSourcesTest.kt
+++ b/app/src/test/java/com/rfsentinel/app/online/OnlineSourcesTest.kt
@@ -44,6 +44,8 @@ class OnlineSourcesTest {
assertTrue(!PoliceAircraft.alerts(circling, 9000.0, circlingOn = true))
val gov = PoliceAircraft.classify(airline.copy(owner = "STATE OF MINNESOTA DEPT OF NATURAL RESOURCES"), registry, circling = false, distanceM = 900.0)!!
assertTrue(gov.label.startsWith("Government aircraft") && PoliceAircraft.alerts(gov, 900.0))
+ assertTrue(!PoliceAircraft.alerts(gov, 9000.0) && PoliceAircraft.alerts(gov, 9000.0, alertM = 10_000.0))
+ assertTrue(!PoliceAircraft.alerts(gov, 3000.0, alertM = 2_000.0))
assertEquals("Police aircraft overhead", com.rfsentinel.app.util.Spoken.aircraft(h1, 300.0, 0.0))
assertEquals("Police aircraft, 2 kilometers northeast", com.rfsentinel.app.util.Spoken.aircraft(h1, 2000.0, 50.0))
}