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.
Kotlin airtagalprandroidandroid-autoanti-surveillancebluetooth-low-energybody-cameracounter-surveillancedrone-detectionflock-safetyimsi-catcher-detectorpolice-detectorpolice-scannerprivacyremote-idrtl-sdrsdrsurveillance-detectiontracker-detectionwifi
P25: wildcard talkgroups in Watch these talkgroups - 23* for 2300-2399 style groups, * for all; an exact line keeps its own name
CIS-C0acb22c8bfe3a
diff --git a/app/src/main/java/com/rfsentinel/app/sdr/P25Log.kt b/app/src/main/java/com/rfsentinel/app/sdr/P25Log.ktindex 8083d16..3db9bde 100644--- a/app/src/main/java/com/rfsentinel/app/sdr/P25Log.kt+++ b/app/src/main/java/com/rfsentinel/app/sdr/P25Log.kt@@ -80,13 +80,24 @@ class P25Log {/** A grant or update for a talkgroup heard within this long is the same call going on. */const val CALL_GAP_MS = 10_000L- private val LINE = Regex("""^\s*(\d{1,5})\b\s*[,;:\-]?\s*(.*)$""")-- /** "1234 Sheriff dispatch" lines (Settings): talkgroup to name ("" when unnamed). */- fun watched(text: String): Map<Int, String> = text.lines().mapNotNull { line ->- val m = LINE.find(line) ?: return@mapNotNull null- val tg = m.groupValues[1].toInt().takeIf { it in 1..0xFFFF } ?: return@mapNotNull null- tg to m.groupValues[2].trim()- }.toMap()+ private val LINE = Regex("""^\s*(\d{1,5}\*?|\*)(?!\d)\s*[,;:\-]?\s*(.*)$""")++ /** "1234 Sheriff dispatch" lines (Settings), and "23*" (2300, 2301, 2307...) or "*" (every talkgroup) ones. */+ fun watched(text: String): Watched {+ val exact = HashMap<Int, String>(); val prefixes = ArrayList<Pair<String, String>>()+ for (line in text.lines()) {+ val m = LINE.find(line) ?: continue+ val key = m.groupValues[1]; val name = m.groupValues[2].trim()+ if (key.endsWith("*")) prefixes += key.dropLast(1) to name+ else key.toInt().takeIf { it in 1..0xFFFF }?.let { exact[it] = name }+ }+ return Watched(exact, prefixes.sortedByDescending { it.first.length })+ }+ }++ /** Watched talkgroups: a number's name ("" when unnamed), or null when not watched. Its exact line wins over a wildcard, a longer wildcard over a shorter. */+ class Watched(private val exact: Map<Int, String> = emptyMap(), private val prefixes: List<Pair<String, String>> = emptyList()) {+ operator fun get(tg: Int?): String? = tg?.let { exact[it] ?: it.toString().let { s -> prefixes.firstOrNull { (p, _) -> s.startsWith(p) }?.second } }+ operator fun contains(tg: Int?) = get(tg) != null}}diff --git a/app/src/main/java/com/rfsentinel/app/sdr/SdrRadio.kt b/app/src/main/java/com/rfsentinel/app/sdr/SdrRadio.ktindex caf1ef6..7cbb025 100644--- a/app/src/main/java/com/rfsentinel/app/sdr/SdrRadio.kt+++ b/app/src/main/java/com/rfsentinel/app/sdr/SdrRadio.kt@@ -107,7 +107,7 @@ object SdrRadio {enum class Listen { OFF, WATCHED, ALL }@Volatile var p25Listen = Listen.OFF/** The watched talkgroups (Settings › Watch these talkgroups). */- @Volatile var p25Watched: Set<Int> = emptySet()+ @Volatile var p25Watched = P25Log.Watched()/** P25 talkgroups › Mute: no call is played, the SDR stays on the control channel. */@Volatile var p25Mute = false/**diff --git a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.ktindex d0fbf30..4affde2 100644--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt@@ -427,7 +427,7 @@ class ScanForegroundService : Service() {com.rfsentinel.app.sdr.SdrRadio.p25Inputs = Prefs.p25Inputs(this)com.rfsentinel.app.sdr.SdrRadio.p25Record = Prefs.p25Record(this)com.rfsentinel.app.sdr.SdrRadio.p25Listen = com.rfsentinel.app.sdr.SdrRadio.Listen.entries[Prefs.p25Listen(this)]- com.rfsentinel.app.sdr.SdrRadio.p25Watched = com.rfsentinel.app.sdr.P25Log.watched(Prefs.p25Talkgroups(this)).keys+ com.rfsentinel.app.sdr.SdrRadio.p25Watched = com.rfsentinel.app.sdr.P25Log.watched(Prefs.p25Talkgroups(this))com.rfsentinel.app.sdr.SdrRadio.p25Mute = Prefs.p25Mute(this)com.rfsentinel.app.sdr.SdrRadio.onP25Input = { call, hz, snr -> pipeline.post { onP25Input(call, hz, snr) } }com.rfsentinel.app.sdr.SdrRadio.location = { (lastLocation ?: lastFix)?.let { it.latitude to it.longitude } }diff --git a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.ktindex 0f060bb..dfa8312 100644--- a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt+++ b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt@@ -1491,7 +1491,8 @@ class SettingsActivity : AppCompatActivity() {val turnViews = listOf(box.getChildAt(box.childCount - 2), box.getChildAt(box.childCount - 1))lines("Watch these talkgroups", "1234 Sheriff dispatch\n2001", Prefs.p25Talkgroups(this),"P25: alerts when a call starts on one of them, and names them on the P25 talkgroups screen. One per line: the " +- "talkgroup number, with an optional name.") { Prefs.setP25Talkgroups(this, it) }+ "talkgroup number, with an optional name. 23* watches every talkgroup starting with 23 (2300, 2301, 2307...), and * every " ++ "talkgroup; a line with the exact number keeps its own name.") { Prefs.setP25Talkgroups(this, it) }slider(0, 60, Prefs.p25LogDays(this), { if (it == 0) "Keep the P25 call log: off" else "Keep the P25 call log: $it days" }) {Prefs.setP25LogDays(this, it)}diff --git a/app/src/main/java/com/rfsentinel/app/ui/P25Activity.kt b/app/src/main/java/com/rfsentinel/app/ui/P25Activity.ktindex 310b2b4..56bf61d 100644--- a/app/src/main/java/com/rfsentinel/app/ui/P25Activity.kt+++ b/app/src/main/java/com/rfsentinel/app/ui/P25Activity.kt@@ -39,7 +39,7 @@ class P25Activity : AppCompatActivity() {/** History mode: the kept log per talkgroup, read every [HISTORY_MS] (null: showing the live control channel). */private var history: List<P25History.Summary>? = nullprivate var historyAt = 0L- private var watched: Map<Int, String> = emptyMap()+ private var watched = P25Log.Watched()private val header by lazy {TextView(this).apply {textSize = 12f; alpha = 0.8fdiff --git a/app/src/test/java/com/rfsentinel/app/sdr/P25LogTest.kt b/app/src/test/java/com/rfsentinel/app/sdr/P25LogTest.ktindex 5f77e8b..bc7c40d 100644--- a/app/src/test/java/com/rfsentinel/app/sdr/P25LogTest.kt+++ b/app/src/test/java/com/rfsentinel/app/sdr/P25LogTest.kt@@ -42,7 +42,20 @@ class P25LogTest {@Testfun watchedTalkgroups() {- assertEquals(mapOf(1234 to "Sheriff dispatch", 2001 to "", 9 to "Fire"),- P25Log.watched("1234 Sheriff dispatch\n2001\n 9 - Fire\nnot a number\n70000 too big"))+ val w = P25Log.watched("1234 Sheriff dispatch\n2001\n 9 - Fire\nnot a number\n70000 too big\n123456 too long")+ assertEquals("Sheriff dispatch", w[1234]); assertEquals("", w[2001]); assertEquals("Fire", w[9])+ assertEquals(null, w[70000]); assertEquals(null, w[1235]); assertEquals(null, w[null])+ assertEquals(false, 123456 in w)+ }++ @Test+ fun wildcardTalkgroups() {+ val w = P25Log.watched("23* Town A\n2301 Police\n230* Town A north")+ assertEquals("Police", w[2301]) // the exact line wins+ assertEquals("Town A north", w[2307]) // the longer wildcard wins+ assertEquals("Town A", w[2350])+ assertEquals(null, w[2400])+ assertEquals("", P25Log.watched("*")[9999])+ assertEquals(true, 1 in P25Log.watched("* all"))}}