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.

RTL-SDR: time per scan (radio sweep, ADS-B, P25), defaulting to the old shared time; Talkgroup alerts chips (Sound, Voice, Vibrate, Banner) for P25 alerts

CIS-C0f7ddf3bd2a7a
diff --git a/app/src/main/java/com/rfsentinel/app/sdr/SdrRadio.kt b/app/src/main/java/com/rfsentinel/app/sdr/SdrRadio.kt
index 3f29b9e..a46940f 100644
--- a/app/src/main/java/com/rfsentinel/app/sdr/SdrRadio.kt
+++ b/app/src/main/java/com/rfsentinel/app/sdr/SdrRadio.kt
@@ -18,7 +18,7 @@ import com.rfsentinel.app.usb.UsbWifi
*
* Or an ADS-B receiver on 1090 MHz ([ModeS], [AdsbTracker]): aircraft heard directly, no internet
* needed, handed to [onAircraft] every few seconds. Or it finds and follows a P25 trunked-radio
- * control channel ([P25Hunt]). Any mix of the three ([modes]): it takes turns of [turnMs].
+ * control channel ([P25Hunt]). Any mix of the three ([modes]): it takes turns, each of its own [turnMs].
*
* The radio waterfall screen ([SdrWaterfall]) gets a row per sweep, or, zoomed in with [tuneHz],
* holds one frequency for a fast live view (the sweep and ADS-B pause meanwhile).
@@ -68,9 +68,10 @@ object SdrRadio {
/** For the reading thread: stop now (scan stopped, unplugged, or a newer thread took over). */
private val halted get() = stop || Thread.currentThread() !== worker
enum class Mode(val label: String) { SWEEP("radio sweep"), ADSB("ADS-B"), P25("P25") }
- /** What the SDR does (Settings > RTL-SDR radio); with more than one it takes turns of [turnMs]. */
+ /** What the SDR does (Settings > RTL-SDR radio); with more than one it takes turns ([turnMs]). */
@Volatile var modes: Set<Mode> = setOf(Mode.SWEEP)
- @Volatile var turnMs = 60_000L
+ /** How long each scan's turn lasts (Settings › RTL-SDR radio); 60 s when not set. */
+ @Volatile var turnMs: Map<Mode, Long> = emptyMap()
/** The scan whose turn it is now; null when none is ticked. */
@Volatile var mode: Mode? = null; private set
@Volatile private var turnEnd = 0L
@@ -317,8 +318,9 @@ object SdrRadio {
status = "$deviceLabel · idle: no scan ticked in Settings › RTL-SDR radio"
Thread.sleep(500); continue
}
- if (active.size > 1) UsbWifi.log("$deviceLabel: turn: ${m.label} for ${turnMs / 1000} s")
- mode = m; turnEnd = System.currentTimeMillis() + turnMs
+ val turn = turnMs[m] ?: 60_000L
+ if (active.size > 1) UsbWifi.log("$deviceLabel: turn: ${m.label} for ${turn / 1000} s")
+ mode = m; turnEnd = System.currentTimeMillis() + turn
when (m) {
Mode.SWEEP -> runSweep(sdr, name)
Mode.ADSB -> runAdsb(sdr, name)
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 d0068fb..13d66e2 100644
--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
@@ -428,7 +428,7 @@ class ScanForegroundService : Service() {
com.rfsentinel.app.sdr.SdrRadio.Mode.P25.takeIf { radioOn && Prefs.sdrP25(this) }
).toSet()
com.rfsentinel.app.sdr.SdrRadio.modes = sdrModes
- com.rfsentinel.app.sdr.SdrRadio.turnMs = Prefs.sdrTurnS(this) * 1000L
+ com.rfsentinel.app.sdr.SdrRadio.turnMs = com.rfsentinel.app.sdr.SdrRadio.Mode.entries.associateWith { Prefs.sdrTurnS(this, it) * 1000L }
com.rfsentinel.app.sdr.SdrRadio.onP25Call = { tg -> pipeline.post { onP25Call(tg) } }
com.rfsentinel.app.sdr.SdrRadio.p25Inputs = Prefs.p25Inputs(this)
com.rfsentinel.app.sdr.SdrRadio.p25Record = Prefs.p25Record(this)
@@ -1591,15 +1591,16 @@ class ScanForegroundService : Service() {
radioDetection(hit, "RADIO " + e.mhz + " MHz", e.snrDb, now, "radio:" + e.freqHz, spoken, e.confidence >= threshold, via)
}
- /** A radio [hit] into the detection history (tagged with where you are), and alerted when [alert]. */
+ /** A radio [hit] into the detection history (tagged with where you are), and alerted when [alert]. [talkgroup]: a P25
+ * alert, which also follows Settings › RTL-SDR radio › Talkgroup alerts. */
private fun radioDetection(hit: Hit, mac: String, rssi: Int, now: Long, key: String, spoken: String, alert: Boolean,
- via: String? = null) {
+ via: String? = null, talkgroup: Boolean = false) {
val loc = lastLocation
if (via == null || Prefs.saveLinked(this))
logDetection(mac, "SDR", hit, now, loc?.latitude, loc?.longitude, rssi = rssi, heardBy = via?.let { "via $it" })
// Dismissed from the list (swiped left): logged, no alert.
if (!alert || com.rfsentinel.app.data.AlertMutes.isMuted(this, key, now)) return
- val off = alertsOff(hit.category)
+ val off = alertsOff(hit.category) + (if (talkgroup) Prefs.p25AlertsOff(this) else emptySet())
NotificationHelper.sendMapAlert(this, key, hit, com.rfsentinel.app.ui.DetectionLogActivity::class.java,
banner = AlertKind.BANNER !in off)
AlertPlayer.play(this, hit.tier, spoken, off = off)
@@ -1619,7 +1620,7 @@ class ScanForegroundService : Service() {
"Heard on the site's control channel: the radios may be anywhere the site covers, not necessarily near you."
val hit = Hit(Category.RADIO, "Talkgroup active: $called", P25_CONFIDENCE, detail, "P25 control channel (signalling only, no voice)")
radioDetection(hit, "P25 TG $tg", 0, System.currentTimeMillis(), "p25:$tg", "Talkgroup $called active",
- P25_CONFIDENCE >= Prefs.alertThreshold(this, Category.RADIO))
+ P25_CONFIDENCE >= Prefs.alertThreshold(this, Category.RADIO), talkgroup = true)
}
/** A call's radio heard strongly on the site's input: it is keying up close to you. */
@@ -1643,7 +1644,7 @@ class ScanForegroundService : Service() {
val hit = Hit(Category.RADIO, "P25 radio keyed up $near: $called", confidence, detail,
"P25 control channel grant + SDR signal strength on the input (no voice)")
radioDetection(hit, "P25 radio ${call.source}", snr, now, "p25in:${call.tg ?: call.target}",
- "Radio keyed up $near, $called", confidence >= Prefs.alertThreshold(this, Category.RADIO))
+ "Radio keyed up $near, $called", confidence >= Prefs.alertThreshold(this, Category.RADIO), talkgroup = true)
}
private var p25UnusualAt = 0L
@@ -1672,7 +1673,7 @@ class ScanForegroundService : Service() {
"the radios may be anywhere the site covers."
val hit = Hit(Category.RADIO, "Unusual activity: $called", P25_UNUSUAL_CONFIDENCE, detail, "P25 call log (signalling only, no voice)")
radioDetection(hit, "P25 TG ${u.tg}", 0, now, "p25u:${u.tg}", "Unusual activity on $called",
- P25_UNUSUAL_CONFIDENCE >= Prefs.alertThreshold(this, Category.RADIO))
+ P25_UNUSUAL_CONFIDENCE >= Prefs.alertThreshold(this, Category.RADIO), talkgroup = true)
}
/** "154.43" for 154.430 MHz: three decimals, trailing zeros dropped, read well by the voice. */
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 dfa8312..221d5f4 100644
--- a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
@@ -1485,14 +1485,23 @@ class SettingsActivity : AppCompatActivity() {
"Needs Two-way radio turned on. On by default when your region is the United States or Canada. Receiving radio " +
"signalling is legal in many places but not all, and some forbid it in a vehicle or passing on what you hear: " +
"check the law where you are.") { Prefs.setSdrP25(this, it) }
- slider(30, 300, Prefs.sdrTurnS(this), { "Time for each scan: $it s" }) { Prefs.setSdrTurnS(this, it) }
- info(box.getChildAt(box.childCount - 2), "With more than one scan ticked, the SDR spends this long on each in turn. Longer misses less " +
- "within a scan; shorter comes back to each sooner.", "Time for each scan")
- val turnViews = listOf(box.getChildAt(box.childCount - 2), box.getChildAt(box.childCount - 1))
+ // Each ticked scan's own turn length, shown while it shares the SDR.
+ val turnViews = listOf(sweepBox to com.rfsentinel.app.sdr.SdrRadio.Mode.SWEEP, adsbBox to com.rfsentinel.app.sdr.SdrRadio.Mode.ADSB,
+ p25Box to com.rfsentinel.app.sdr.SdrRadio.Mode.P25).map { (ticked, m) ->
+ slider(30, 300, Prefs.sdrTurnS(this, m), { "Time for ${m.label}: $it s" }) { Prefs.setSdrTurnS(this, m, it) }
+ info(box.getChildAt(box.childCount - 2), "With more than one scan ticked, the SDR gives ${m.label} this long before the next scan takes " +
+ "its turn. Longer misses less of it; shorter comes back to the other scans sooner.",
+ "Time for ${m.label}")
+ ticked to 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. 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) }
+ info(box.label("Talkgroup alerts"), "How P25 alerts reach you: a watched talkgroup's call starting, a radio keying up nearby and " +
+ "unusual talkgroup activity. Untick Voice or Sound so they don't talk or beep over P25 voice. Other radio alerts follow " +
+ "the Two-way radio category in What to detect.", "Talkgroup alerts")
+ box.addView(alertKindChips(Prefs.p25AlertsOff(this), false, "P25 talkgroups") { Prefs.setP25AlertsOff(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)
}
@@ -1527,11 +1536,11 @@ class SettingsActivity : AppCompatActivity() {
"2 minutes each. Watched talkgroups: only those in Watch these talkgroups. Mute on the P25 talkgroups screen pauses it; Hold there (or tapping a talkgroup) plays only that talkgroup and keeps the SDR on P25 until Release. " +
"Encrypted calls can't be played. Listening to radio calls is not allowed everywhere, and some places forbid it in " +
"a vehicle: check the law where you are.", "Listen to P25 voice"))
- val talkgroupViews = (box.childCount - 9 until box.childCount).map { box.getChildAt(it) }
+ val talkgroupViews = (box.childCount - 11 until box.childCount).map { box.getChildAt(it) }
var sweepViews = emptyList<View>() // the sweep's own settings, below
showSdrOptions = {
val ticked = listOf(sweepBox, adsbBox, p25Box).count { it.isChecked }
- turnViews.forEach { it.shownIf(ticked > 1) }
+ turnViews.forEach { (scan, views) -> views.forEach { it.shownIf(ticked > 1 && scan.isChecked) } }
talkgroupViews.forEach { it.shownIf(p25Box.isChecked) }
sweepViews.forEach { it.shownIf(sweepBox.isChecked) }
}
@@ -2086,28 +2095,34 @@ class SettingsActivity : AppCompatActivity() {
setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.text_caption))
setTextColor(com.google.android.material.color.MaterialColors.getColor(this, android.R.attr.textColorSecondary))
})
- val chips = com.google.android.material.chip.ChipGroup(this).apply {
- chipSpacingHorizontal = (6 * dp).toInt(); chipSpacingVertical = 0
- }
- var off = Prefs.categoryAlertsOff(this, c)
- com.rfsentinel.app.data.AlertKind.entries.forEach { kind ->
- if (kind == com.rfsentinel.app.data.AlertKind.BEEP && !Prefs.hasRadarTicks(c)) return@forEach
- chips.addView(com.rfsentinel.app.ui.FitChip(this).apply {
- text = kind.label; isCheckable = true
- com.rfsentinel.app.ui.ChipStyle.apply(this)
- isChecked = kind !in off
- contentDescription = "${kind.label} alerts for ${sw.contentDescription ?: sw.text}"
- setOnClickListener {
- off = if (isChecked) off - kind else off + kind
- Prefs.setCategoryAlertsOff(this@SettingsActivity, c, off)
- }
- })
- }
- box.addView(chips)
+ box.addView(alertKindChips(Prefs.categoryAlertsOff(this, c), Prefs.hasRadarTicks(c), "${sw.contentDescription ?: sw.text}") {
+ Prefs.setCategoryAlertsOff(this, c, it)
+ })
binding.categoryContainer.addView(box)
folds[sw] = Fold(sw, fold).also { it.add(box) }
}
+ /** A chip per way of alerting (Beep only with [beep]), ticked when it is on; [save] gets the ones turned off. */
+ private fun alertKindChips(off: Set<com.rfsentinel.app.data.AlertKind>, beep: Boolean, what: String,
+ save: (Set<com.rfsentinel.app.data.AlertKind>) -> Unit) =
+ com.google.android.material.chip.ChipGroup(this).apply {
+ chipSpacingHorizontal = dp(6); chipSpacingVertical = 0
+ var now = off
+ com.rfsentinel.app.data.AlertKind.entries.forEach { kind ->
+ if (kind == com.rfsentinel.app.data.AlertKind.BEEP && !beep) return@forEach
+ addView(com.rfsentinel.app.ui.FitChip(this@SettingsActivity).apply {
+ text = kind.label; isCheckable = true
+ com.rfsentinel.app.ui.ChipStyle.apply(this)
+ isChecked = kind !in now
+ contentDescription = "${kind.label} alerts for $what"
+ setOnClickListener {
+ now = if (isChecked) now - kind else now + kind
+ save(now)
+ }
+ })
+ }
+ }
+
private val folds = HashMap<SwitchMaterial, Fold>()
/** A category's ▾ and what it opens: its alert chips, then its own settings (aircraft, Waze). */
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 d556a3c..39ae914 100644
--- a/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
+++ b/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
@@ -672,9 +672,17 @@ object Prefs {
/** P25 talkgroups › Mute: listening paused. */
fun p25Mute(context: Context): Boolean = bool(context, "p25_mute", false)
fun setP25Mute(context: Context, v: Boolean) = setBool(context, "p25_mute", v)
- /** Seconds the SDR gives each ticked scan in turn, 30-300: a first P25 search takes up to about 15 s. */
- fun sdrTurnS(context: Context): Int = int(context, "sdr_turn_s", 60).coerceIn(30, 300)
- fun setSdrTurnS(context: Context, v: Int) = setInt(context, "sdr_turn_s", v.coerceIn(30, 300))
+ /** Seconds the SDR gives [mode] in turn, 30-300 (a first P25 search takes up to about 15 s); defaults to the old shared time. */
+ fun sdrTurnS(context: Context, mode: com.rfsentinel.app.sdr.SdrRadio.Mode): Int =
+ int(context, "sdr_turn_s_" + mode.name, int(context, "sdr_turn_s", 60)).coerceIn(30, 300)
+ fun setSdrTurnS(context: Context, mode: com.rfsentinel.app.sdr.SdrRadio.Mode, v: Int) =
+ setInt(context, "sdr_turn_s_" + mode.name, v.coerceIn(30, 300))
+ /** The ways P25 talkgroup alerts don't alert you (Settings › RTL-SDR radio › Talkgroup alerts); none by default. */
+ fun p25AlertsOff(context: Context): Set<com.rfsentinel.app.data.AlertKind> =
+ com.rfsentinel.app.data.AlertKind.parse(sp(context).getString("p25_alerts_off", null))
+ fun setP25AlertsOff(context: Context, off: Set<com.rfsentinel.app.data.AlertKind>) = sp(context).edit {
+ com.rfsentinel.app.data.AlertKind.format(off)?.let { putString("p25_alerts_off", it) } ?: remove("p25_alerts_off")
+ }
/** Name hits from RadioReference (needs the user's own Premium login and developer key; off by default). */
fun radioReferenceOn(context: Context): Boolean = bool(context, "radio_reference_on", false)
diff --git a/app/src/test/java/com/rfsentinel/app/util/SdrTurnPrefsTest.kt b/app/src/test/java/com/rfsentinel/app/util/SdrTurnPrefsTest.kt
new file mode 100644
index 0000000..84b5bab
--- /dev/null
+++ b/app/src/test/java/com/rfsentinel/app/util/SdrTurnPrefsTest.kt
@@ -0,0 +1,41 @@
+package com.rfsentinel.app.util
+
+import android.app.Application
+import android.content.Context
+import androidx.test.core.app.ApplicationProvider
+import com.rfsentinel.app.data.AlertKind
+import com.rfsentinel.app.sdr.SdrRadio.Mode
+import org.junit.Assert.assertEquals
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.RobolectricTestRunner
+import org.robolectric.annotation.Config
+
+/** Settings › RTL-SDR radio: each scan's own turn length, and the talkgroup alert chips. */
+@RunWith(RobolectricTestRunner::class)
+@Config(sdk = [35], application = Application::class)
+class SdrTurnPrefsTest {
+ private val ctx: Context = ApplicationProvider.getApplicationContext()
+
+ @Test
+ fun eachScanStartsFromTheOldSharedTime() {
+ Mode.entries.forEach { assertEquals(60, Prefs.sdrTurnS(ctx, it)) }
+ // Saved by an older version: one time for all.
+ ctx.getSharedPreferences("rf_sentinel_prefs", Context.MODE_PRIVATE).edit().putInt("sdr_turn_s", 120).commit()
+ Mode.entries.forEach { assertEquals(120, Prefs.sdrTurnS(ctx, it)) }
+ Prefs.setSdrTurnS(ctx, Mode.ADSB, 30)
+ Prefs.setSdrTurnS(ctx, Mode.P25, 999)
+ assertEquals(120, Prefs.sdrTurnS(ctx, Mode.SWEEP))
+ assertEquals(30, Prefs.sdrTurnS(ctx, Mode.ADSB))
+ assertEquals(300, Prefs.sdrTurnS(ctx, Mode.P25))
+ }
+
+ @Test
+ fun talkgroupAlertsOffRoundTrip() {
+ assertEquals(emptySet<AlertKind>(), Prefs.p25AlertsOff(ctx))
+ Prefs.setP25AlertsOff(ctx, setOf(AlertKind.VOICE, AlertKind.SOUND))
+ assertEquals(setOf(AlertKind.VOICE, AlertKind.SOUND), Prefs.p25AlertsOff(ctx))
+ Prefs.setP25AlertsOff(ctx, emptySet())
+ assertEquals(emptySet<AlertKind>(), Prefs.p25AlertsOff(ctx))
+ }
+}