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.

Pager watch alerts, ignored capcodes, named channels, POCSAG speed choice

CIS-C061b4dea7ff2f
diff --git a/README.md b/README.md
index 0689027..1018afc 100644
--- a/README.md
+++ b/README.md
@@ -276,7 +276,7 @@ Everything the app does, grouped by area.
- The ALFA AWUS036ACS's light blinks with received traffic (Settings → External hardware switches it off, for the adapters whose light the app can control)
- RTL-SDR and HackRF transmissions show on the **radar** too, for a minute after they were last heard
- **P25 control channel** (experimental, RTL-SDR): finds the trunked-radio control channel and lists which talkgroups get a channel and when (Tools → P25 talkgroups), with alerts for talkgroups you watch. Signalling only, voice is never decoded. With more than one SDR scan ticked (radio sweep, ADS-B, P25) the dongle takes turns
-- **Pager messages** (experimental, RTL-SDR or HackRF, off by default): decodes POCSAG and FLEX pages (Tools → Pager messages), kept in memory only
+- **Pager messages** (experimental, RTL-SDR or HackRF, off by default): decodes POCSAG and FLEX pages (Tools → Pager messages), kept in memory only, with alerts for capcodes and words you watch, ignored capcodes and named channels
- **More from every frame:** WPS maker / model / device name, a **probe fingerprint** that survives MAC randomization (watchable: "every device of this type"), and the real name of **hidden networks** when a device joins them
</details>
@@ -783,7 +783,10 @@ the length you set.
paging channels and decodes POCSAG (512 / 1200 / 2400 baud) and FLEX pages into
**Tools → Pager messages**. Pages can hold private or medical details, so they stay in
the phone's memory: never saved, exported or sent, kept out of the logs, and gone when the
-app closes or you untick the setting. Canada, the United States and many other places
+app closes or you untick the setting. Settings can alert on the capcodes (RICs) and words
+you watch, with the page's text left out of the alert unless you turn it on, drop the
+capcodes you ignore, and pick the POCSAG speeds. Name your channels to switch between them
+in one tap on the messages screen, and import or export the list. Canada, the United States and many other places
restrict using or passing on messages you intercept, and some forbid listening at all:
check the law where you are.
diff --git a/app/src/main/java/com/rfsentinel/app/sdr/PagerDemod.kt b/app/src/main/java/com/rfsentinel/app/sdr/PagerDemod.kt
index 398a3fb..387af43 100644
--- a/app/src/main/java/com/rfsentinel/app/sdr/PagerDemod.kt
+++ b/app/src/main/java/com/rfsentinel/app/sdr/PagerDemod.kt
@@ -8,7 +8,7 @@ import kotlin.math.atan2
* cut to 48 kS/s as for P25), FM-demodulates it and hands it to POCSAG at its three speeds and to FLEX at once: a
* channel doesn't say which it is. Pure (no Android): unit-tested on a synthetic signal.
*/
-class PagerDemod(offsetHz: Long, onPage: (PagerLog.Page) -> Unit) {
+class PagerDemod(offsetHz: Long, speeds: Set<Int> = SPEEDS, onPage: (PagerLog.Page) -> Unit) {
private class PocsagRx(baud: Int, onPage: (PagerLog.Page) -> Unit) {
val decoder = Pocsag(baud, onPage)
@@ -21,7 +21,7 @@ class PagerDemod(offsetHz: Long, onPage: (PagerLog.Page) -> Unit) {
}
}
- private val pocsag = listOf(512, 1200, 2400).map { PocsagRx(it, onPage) }
+ private val pocsag = speeds.map { PocsagRx(it, onPage) }
private val flex = Flex(RATE, onPage)
private val baseband = P25Record.Baseband(offsetHz, onSample = ::channelSample)
@@ -53,6 +53,8 @@ class PagerDemod(offsetHz: Long, onPage: (PagerLog.Page) -> Unit) {
}
companion object {
+ /** The POCSAG speeds in use around the world. */
+ val SPEEDS = setOf(512, 1200, 2400)
private const val RATE = P25Demod.CHANNEL_RATE
private const val CLOCK_RATE = 0.05
private const val BOX = 6
diff --git a/app/src/main/java/com/rfsentinel/app/sdr/PagerHunt.kt b/app/src/main/java/com/rfsentinel/app/sdr/PagerHunt.kt
index 8f345f6..09c811b 100644
--- a/app/src/main/java/com/rfsentinel/app/sdr/PagerHunt.kt
+++ b/app/src/main/java/com/rfsentinel/app/sdr/PagerHunt.kt
@@ -6,7 +6,7 @@ package com.rfsentinel.app.sdr
* stays until nothing has decoded for [QUIET_S]. Paging transmitters can be silent between pages, so a channel missed now
* shows up on a later look. Frequencies, capcodes and text stay off the log: counts and levels only.
*/
-class PagerHunt(private val sdr: SdrDevice, private val log: (String) -> Unit = {}) {
+class PagerHunt(private val sdr: SdrDevice, private val speeds: () -> Set<Int> = { PagerDemod.SPEEDS }, private val log: (String) -> Unit = {}) {
/** Channels listened to in the last hunt, for the log. */
var tried = 0; private set
@@ -45,7 +45,7 @@ class PagerHunt(private val sdr: SdrDevice, private val log: (String) -> Unit =
if (!sdr.tune(hz - OFFSET_HZ)) { log("Pager: the tuner didn't lock"); return false }
sdr.resetBuffer()
repeat(sdr.settleReads) { sdr.read(buf) }
- val demod = PagerDemod(OFFSET_HZ) { onPage(it, hz) }
+ val demod = PagerDemod(OFFSET_HZ, speeds()) { onPage(it, hz) }
var samples = 0L; var lastGood = 0L; var seen = 0; var fails = 0
while (!stop()) {
val n = sdr.read(buf)
diff --git a/app/src/main/java/com/rfsentinel/app/sdr/PagerLog.kt b/app/src/main/java/com/rfsentinel/app/sdr/PagerLog.kt
index 4bfee79..12380ab 100644
--- a/app/src/main/java/com/rfsentinel/app/sdr/PagerLog.kt
+++ b/app/src/main/java/com/rfsentinel/app/sdr/PagerLog.kt
@@ -2,7 +2,8 @@ package com.rfsentinel.app.sdr
/**
* Pages heard this session (the Pager messages screen). In memory only, on purpose: pages can hold private or medical
- * details, so they are never saved, exported or sent, and go when the app closes or the setting is turned off.
+ * details, so they are never saved, exported or sent, and go when the app closes or the setting is turned off. The one
+ * exception is the user's: Show page text in alerts puts a watched page on its notification.
*/
class PagerLog {
diff --git a/app/src/main/java/com/rfsentinel/app/sdr/PagerRules.kt b/app/src/main/java/com/rfsentinel/app/sdr/PagerRules.kt
new file mode 100644
index 0000000..1985577
--- /dev/null
+++ b/app/src/main/java/com/rfsentinel/app/sdr/PagerRules.kt
@@ -0,0 +1,21 @@
+package com.rfsentinel.app.sdr
+
+/** Which pages to alert on or drop (Settings › RTL-SDR radio › Pagers). Pure: unit-tested. */
+object PagerRules {
+
+ /** A list line: a capcode with an optional name, or else words to find in a page. */
+ data class Watch(val capcode: Long?, val words: String?, val name: String)
+
+ // shortcut: a line starting with a number is always a capcode, so "2 alarm fire" can't be a keyword; add a prefix if asked.
+ private val CAPCODE = Regex("""^(\d{1,10})(?:\s+(.*))?$""")
+
+ fun watches(text: String): List<Watch> = text.lines().map { it.trim() }.filter { it.isNotEmpty() }.map { line ->
+ CAPCODE.find(line)?.let { Watch(it.groupValues[1].toLong(), null, it.groupValues[2].trim()) } ?: Watch(null, line, line)
+ }
+
+ fun ignored(text: String): Set<Long> = watches(text).mapNotNullTo(HashSet()) { it.capcode }
+
+ fun match(watches: List<Watch>, page: PagerLog.Page): Watch? = watches.firstOrNull { w ->
+ w.capcode == page.capcode || (w.words != null && page.text.contains(w.words, ignoreCase = true))
+ }
+}
diff --git a/app/src/main/java/com/rfsentinel/app/sdr/RadioReference.kt b/app/src/main/java/com/rfsentinel/app/sdr/RadioReference.kt
index 267fc2b..fa47837 100644
--- a/app/src/main/java/com/rfsentinel/app/sdr/RadioReference.kt
+++ b/app/src/main/java/com/rfsentinel/app/sdr/RadioReference.kt
@@ -74,7 +74,7 @@ object RadioReference {
else "RadioReference: ${calls.size} licences, ${names.size} frequencies near you"
}
} catch (e: Exception) {
- status = "RadioReference: " + (e.message ?: "lookup failed")
+ status = "RadioReference: " + (e.message ?: "lookup failed").removePrefix("RadioReference ")
} finally {
busy = false
}
diff --git a/app/src/main/java/com/rfsentinel/app/sdr/RadioSettings.kt b/app/src/main/java/com/rfsentinel/app/sdr/RadioSettings.kt
index 71c3da5..cda672f 100644
--- a/app/src/main/java/com/rfsentinel/app/sdr/RadioSettings.kt
+++ b/app/src/main/java/com/rfsentinel/app/sdr/RadioSettings.kt
@@ -35,6 +35,7 @@ object RadioSettings {
}
private val RANGE = Regex("""^\s*(\d{2,4}(?:[.,]\d+)?)\s*(?:-|–|to)\s*(\d{2,4}(?:[.,]\d+)?)\s*(?:mhz)?\s*(.*)$""", RegexOption.IGNORE_CASE)
+ private val PLAIN_LINE = Regex("""^\s*\d{2,4}(?:\.\d+)?(?:\s|$)""")
private val FREQ = Regex("""^\s*(\d{2,4}(?:[.,]\d+)?)\s*(?:mhz)?\s*[,;:\-]?\s*(.*)$""", RegexOption.IGNORE_CASE)
private fun mhzToHz(s: String): Long? = s.replace(',', '.').toDoubleOrNull()?.let { (it * 1_000_000).toLong() }
@@ -68,6 +69,12 @@ object RadioSettings {
RadioWatch.Target(hz, m.groupValues[2].trim().ifEmpty { "%.4f MHz".format(java.util.Locale.US, hz / 1e6) })
}.distinctBy { it.freqHz }.take(MAX_TARGETS)
+ /** [addTargets] from a file's text: a CSV, or plain "466.075 Fire dispatch" lines. */
+ fun addPagerFile(current: String, text: String): Triple<String, Int, Int> {
+ val plain = text.lines().filter { it.isNotBlank() }.all { PLAIN_LINE.containsMatchIn(it) }
+ return addTargets(current, if (plain) targets(text).map { FreqNames.Name(it.freqHz, it.label, "") } else FreqNames.parseCsv(text, ""))
+ }
+
/** [current] watched lines plus [names], up to the limit: the new text, how many were added, how many did not fit. */
fun addTargets(current: String, names: List<FreqNames.Name>): Triple<String, Int, Int> {
val have = targets(current).mapTo(HashSet()) { it.freqHz }
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 bbc8b10..e2b8948 100644
--- a/app/src/main/java/com/rfsentinel/app/sdr/SdrRadio.kt
+++ b/app/src/main/java/com/rfsentinel/app/sdr/SdrRadio.kt
@@ -102,6 +102,10 @@ object SdrRadio {
val pagerLog = PagerLog()
/** The paging channel to go back to on its next turn. */
private var pagerHz: Long? = null
+ /** The Pager messages screen's chosen channel in Hz; 0 for all of them. */
+ @Volatile var pagerChannel = 0L
+ /** A page that wasn't ignored, for the watch alerts. */
+ @Volatile var onPagerPage: ((PagerLog.Page) -> Unit)? = null
/** A call started on this talkgroup (the service alerts on watched ones). */
@Volatile var onP25Call: ((Int) -> Unit)? = null
/** Settings › RTL-SDR radio: after a call starts, briefly listen where its radio transmits (the site's input). */
@@ -664,23 +668,33 @@ object SdrRadio {
private fun runPager(sdr: SdrDevice, name: String) {
sdr.setGain(GAIN_TENTHS_DB)
sdr.resetBuffer()
- val hunt = PagerHunt(sdr) { UsbWifi.log("$deviceLabel: $it") }
+ val hunt = PagerHunt(sdr, { appContext?.let { com.rfsentinel.app.util.Prefs.pagerSpeeds(it) } ?: PagerDemod.SPEEDS }) {
+ UsbWifi.log("$deviceLabel: $it")
+ }
var lastCheck = System.currentTimeMillis(); var away = false
val stop = {
val now = System.currentTimeMillis()
if (now - lastCheck >= 2_000L) { lastCheck = now; away = gone(name) }
halted || sdr.lost || away || !keeps(Mode.PAGER)
}
- val onPage = { page: PagerLog.Page, hz: Long -> pagerLog.add(page, hz, System.currentTimeMillis()) }
+ val onPage = { page: PagerLog.Page, hz: Long ->
+ val ignored = appContext?.let { page.capcode in PagerRules.ignored(com.rfsentinel.app.util.Prefs.pagerIgnore(it)) } == true
+ if (!ignored) {
+ pagerLog.add(page, hz, System.currentTimeMillis())
+ onPagerPage?.invoke(page)
+ }
+ }
var next = 0
while (!stop()) {
// Frequencies typed in Settings: listen to those in turn, no scan.
- val mine = appContext?.let { c -> RadioSettings.targets(com.rfsentinel.app.util.Prefs.pagerFreqs(c)).map { it.freqHz } }.orEmpty()
+ val typed = appContext?.let { c -> RadioSettings.targets(com.rfsentinel.app.util.Prefs.pagerFreqs(c)).map { it.freqHz } }.orEmpty()
+ val picked = pagerChannel
+ val mine = typed.filter { it == picked }.ifEmpty { typed }
if (mine.isNotEmpty()) {
val hz = mine[next++ % mine.size]
status = "$deviceLabel · pagers · listening on %.4f MHz".format(java.util.Locale.US, hz / 1e6) + turnNote()
val from = System.currentTimeMillis()
- hunt.listen(hz, stop, onPage)
+ hunt.listen(hz, { stop() || pagerChannel != picked }, onPage)
if (System.currentTimeMillis() - from < 1_000L) Thread.sleep(1_000L) // the tuner didn't lock: don't spin
continue
}
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 84fa066..d97fe74 100644
--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
@@ -75,6 +75,7 @@ class ScanForegroundService : Service() {
private const val RADAR_HOLD_MS = 120_000L
/** A watched talkgroup's call: the user asked for it, like a watched frequency. */
const val P25_CONFIDENCE = 70
+ private const val PAGER_ALERT_GAP_MS = 60_000L
/** A talkgroup's radio heard on the site's input, [snr] dB above the noise ([min]: the radio threshold): near you. */
fun p25InputConfidence(snr: Int, min: Int) = if (snr >= min + 10) 75 else 60
/** A talkgroup much busier than usual: probable, not certain (an event, a shift change, a drill). */
@@ -449,6 +450,8 @@ class ScanForegroundService : Service() {
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))
com.rfsentinel.app.sdr.SdrRadio.p25Mute = Prefs.p25Mute(this)
+ com.rfsentinel.app.sdr.SdrRadio.pagerChannel = Prefs.pagerChannel(this)
+ com.rfsentinel.app.sdr.SdrRadio.onPagerPage = { page -> pipeline.post { onPagerPage(page) } }
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 } }
com.rfsentinel.app.sdr.SdrRadio.onAircraft = { planes, unlocated -> onlineWatch.localAircraft(planes, unlocated) }
@@ -1647,6 +1650,30 @@ class ScanForegroundService : Service() {
P25_CONFIDENCE >= Prefs.alertThreshold(this, Category.RADIO), talkgroup = true)
}
+ private val pagerAlertAt = HashMap<String, Long>()
+
+ /**
+ * A page matching the watch list (Settings > RTL-SDR radio). Stays out of the detection history, and its text out of
+ * the alert log: pages are memory only. Paging networks repeat a page, so one watch alerts once per [PAGER_ALERT_GAP_MS].
+ */
+ private fun onPagerPage(page: com.rfsentinel.app.sdr.PagerLog.Page) {
+ if (!Prefs.categoryEnabled(this, Category.RADIO)) return
+ val rules = com.rfsentinel.app.sdr.PagerRules
+ val watch = rules.match(rules.watches(Prefs.pagerWatch(this)), page) ?: return
+ val key = "pager:" + (watch.capcode ?: watch.words)
+ val now = System.currentTimeMillis()
+ if (now - (pagerAlertAt[key] ?: 0L) < PAGER_ALERT_GAP_MS) return
+ if (P25_CONFIDENCE < Prefs.alertThreshold(this, Category.RADIO) || com.rfsentinel.app.data.AlertMutes.isMuted(this, key, now)) return
+ pagerAlertAt[key] = now
+ val called = watch.name.ifEmpty { "capcode ${watch.capcode}" }
+ val hit = Hit(Category.RADIO, "Pager watch: $called", P25_CONFIDENCE,
+ "A page matched your watch. Read it in Tools › Pager messages.", "Pager messages")
+ val off = alertsOff(hit.category) + Prefs.pagerAlertsOff(this)
+ NotificationHelper.sendMapAlert(this, key, hit, com.rfsentinel.app.ui.PagerActivity::class.java, banner = AlertKind.BANNER !in off,
+ shown = page.text.takeIf { it.isNotEmpty() && Prefs.pagerAlertText(this) })
+ AlertPlayer.play(this, hit.tier, "Pager watch $called", off = off)
+ }
+
/** A call's radio heard strongly on the site's input: it is keying up close to you. */
private fun onP25Input(call: com.rfsentinel.app.sdr.P25History.Call, hz: Long, snr: Int) {
if (!Prefs.categoryEnabled(this, Category.RADIO)) return
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 1b7f788..c01c99b 100644
--- a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
@@ -1518,6 +1518,29 @@ class SettingsActivity : AppCompatActivity() {
}
}
+ private var pagerFreqField: android.widget.EditText? = null
+
+ /** Adds a file's frequencies to the Pager frequencies list: a CSV as for the frequency list, or the lines Export writes. */
+ private val pagerImport = registerForActivityResult(androidx.activity.result.contract.ActivityResultContracts.OpenDocument()) { uri ->
+ if (uri == null) return@registerForActivityResult
+ lifecycleScope.launch {
+ val text = kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) {
+ runCatching { contentResolver.openInputStream(uri)?.use { com.rfsentinel.app.sdr.FreqNames.readLimited(it) } }.getOrNull().orEmpty()
+ }
+ val (merged, added, _) = com.rfsentinel.app.sdr.RadioSettings.addPagerFile(Prefs.pagerFreqs(this@SettingsActivity), text)
+ if (added > 0) pagerFreqField?.setText(merged)
+ Toast.makeText(this@SettingsActivity, if (added > 0) "$added frequencies added" else "No new frequencies in that file", Toast.LENGTH_LONG).show()
+ }
+ }
+
+ private val pagerExport = registerForActivityResult(androidx.activity.result.contract.ActivityResultContracts.CreateDocument("text/plain")) { uri ->
+ if (uri == null) return@registerForActivityResult
+ val ok = runCatching {
+ contentResolver.openOutputStream(uri, "wt")!!.use { it.write(Prefs.pagerFreqs(this).toByteArray(Charsets.UTF_8)) }
+ }.isSuccess
+ Toast.makeText(this, if (ok) "Pager frequencies saved" else "Couldn't write the file", Toast.LENGTH_LONG).show()
+ }
+
private var freqListText: android.widget.TextView? = null
private fun updateFreqListText() {
@@ -1613,9 +1636,50 @@ class SettingsActivity : AppCompatActivity() {
}
val pagerFrom = box.childCount
heading("Pagers")
- lines("Pager frequencies", "466.075", Prefs.pagerFreqs(this),
- "Leave empty to scan for paging channels. If you know yours, enter it in MHz, one per line: the SDR listens there and " +
- "doesn't scan, so a quiet channel isn't missed.") { Prefs.setPagerFreqs(this, it) }
+ pagerFreqField = lines("Pager frequencies", "466.075 Fire dispatch", Prefs.pagerFreqs(this),
+ "Leave empty to scan for paging channels. If you know yours, enter it in MHz with an optional name, one per line: the SDR " +
+ "listens there and doesn't scan, so a quiet channel isn't missed. With two or more, the Pager messages screen gets a " +
+ "button for each, to stay on one.") { Prefs.setPagerFreqs(this, it) }
+ box.addView(android.widget.LinearLayout(this).apply {
+ orientation = android.widget.LinearLayout.HORIZONTAL
+ addView(com.google.android.material.button.MaterialButton(this@SettingsActivity, null,
+ android.R.attr.borderlessButtonStyle).apply {
+ text = "Import"
+ setOnClickListener { pagerImport.launch(arrayOf("text/*", "application/csv", "application/vnd.ms-excel", "*/*")) }
+ })
+ addView(com.google.android.material.button.MaterialButton(this@SettingsActivity, null,
+ android.R.attr.borderlessButtonStyle).apply {
+ text = "Export"
+ setOnClickListener { pagerExport.launch("pager-frequencies.txt") }
+ })
+ })
+ info(box.label("POCSAG speeds"), "Which POCSAG speeds to decode. Fewer use less battery. FLEX is always decoded.", "POCSAG speeds")
+ box.addView(com.google.android.material.chip.ChipGroup(this).apply {
+ chipSpacingHorizontal = dp(6); chipSpacingVertical = 0
+ var now = Prefs.pagerSpeeds(this@SettingsActivity)
+ com.rfsentinel.app.sdr.PagerDemod.SPEEDS.forEach { speed ->
+ addView(com.rfsentinel.app.ui.FitChip(this@SettingsActivity).apply {
+ text = "$speed"; isCheckable = true
+ com.rfsentinel.app.ui.ChipStyle.apply(this)
+ isChecked = speed in now
+ contentDescription = "POCSAG $speed baud"
+ setOnClickListener {
+ now = if (isChecked) now + speed else now - speed
+ Prefs.setPagerSpeeds(this@SettingsActivity, now)
+ }
+ })
+ }
+ })
+ lines("Watch these pagers", "1234567 Station 4\ncardiac arrest", Prefs.pagerWatch(this),
+ "Alerts when a page matches. One per line: a capcode, also called a RIC, with an optional name, or words to find in the " +
+ "page. A line starting with a number is a capcode. One alert a minute at most for each line.") { Prefs.setPagerWatch(this, it) }
+ lines("Ignore these pagers", "1234567", Prefs.pagerIgnore(this),
+ "Pages to these capcodes, one per line, are dropped: no list entry, no alert.") { Prefs.setPagerIgnore(this, it) }
+ info(box.label("Pager alerts"), "How a watched page reaches you. Untick Sound and Voice for silent alerts.", "Pager alerts")
+ box.addView(alertKindChips(Prefs.pagerAlertsOff(this), false, "pager watches") { Prefs.setPagerAlertsOff(this, it) })
+ scan("Show page text in alerts", Prefs.pagerAlertText(this),
+ "Off: the alert only says a page matched, and you read it in Tools › Pager messages. On: the page's text is also on the " +
+ "notification, and in Android Auto when connected. It is still never saved or spoken.") { Prefs.setPagerAlertText(this, it) }
val pagerViews = (pagerFrom until box.childCount).map { box.getChildAt(it) }
val p25From = box.childCount
heading("P25")
diff --git a/app/src/main/java/com/rfsentinel/app/ui/PagerActivity.kt b/app/src/main/java/com/rfsentinel/app/ui/PagerActivity.kt
index a5c3310..5af632d 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/PagerActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/PagerActivity.kt
@@ -7,9 +7,12 @@ import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.widget.doAfterTextChanged
+import com.google.android.material.chip.Chip
import com.rfsentinel.app.databinding.ActivityLogBinding
import com.rfsentinel.app.sdr.PagerLog
+import com.rfsentinel.app.sdr.RadioSettings
import com.rfsentinel.app.sdr.SdrRadio
+import com.rfsentinel.app.util.Prefs
import java.util.Locale
/**
@@ -20,6 +23,7 @@ class PagerActivity : AppCompatActivity() {
private lateinit var binding: ActivityLogBinding
private var rows: List<PagerLog.Row> = emptyList()
+ private var channels: Map<Long, String> = emptyMap()
private val header by lazy {
TextView(this).apply {
textSize = 12f; alpha = 0.8f
@@ -31,7 +35,7 @@ class PagerActivity : AppCompatActivity() {
labelText.text = "Capcode ${r.page.capcode} · ${r.page.protocol}"
macText.text = r.page.text.ifEmpty { "Tone only: no message" }
metaText.text = listOfNotNull(
- String.format(Locale.US, "%.4f MHz", r.hz / 1e6),
+ channels[r.hz] ?: String.format(Locale.US, "%.4f MHz", r.hz / 1e6),
"cut off".takeIf { r.page.partial },
DateUtils.getRelativeTimeSpanString(r.at, System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS)
).joinToString(" · ")
@@ -45,6 +49,30 @@ class PagerActivity : AppCompatActivity() {
refreshWhileStarted(1_000) { refresh() }
}
+ override fun onStart() {
+ super.onStart()
+ buildChips()
+ }
+
+ /** One tap to stay on a channel typed in Settings; All goes through them in turn. */
+ private fun buildChips() {
+ val list = RadioSettings.targets(Prefs.pagerFreqs(this))
+ channels = list.associate { it.freqHz to it.label }
+ binding.filterChips.removeAllViews()
+ if (list.size < 2) return
+ val on = Prefs.pagerChannel(this).takeIf { it in channels } ?: 0L
+ fun add(label: String, hz: Long) {
+ binding.filterChips.addView(Chip(this, null, com.google.android.material.R.attr.chipStyle).apply {
+ id = View.generateViewId(); text = label; isCheckable = true; isCheckedIconVisible = false
+ ChipStyle.apply(this)
+ isChecked = hz == on
+ setOnClickListener { Prefs.setPagerChannel(context, hz); SdrRadio.pagerChannel = hz }
+ })
+ }
+ add("All", 0L)
+ list.forEach { add(it.label, it.freqHz) }
+ }
+
override fun onSupportNavigateUp(): Boolean { finish(); return true }
@SuppressLint("NotifyDataSetChanged")
diff --git a/app/src/main/java/com/rfsentinel/app/util/NotificationHelper.kt b/app/src/main/java/com/rfsentinel/app/util/NotificationHelper.kt
index dbfc185..d006931 100644
--- a/app/src/main/java/com/rfsentinel/app/util/NotificationHelper.kt
+++ b/app/src/main/java/com/rfsentinel/app/util/NotificationHelper.kt
@@ -182,14 +182,17 @@ object NotificationHelper {
/** An internet alert's key ("air:..." aircraft, "waze:..." report): tapping opens the map on it ([lat] / [lon] where it was). */
online: String? = null,
/** False: only logged (its category's banner is turned off). */
- banner: Boolean = true
+ banner: Boolean = true,
+ /** Shown in place of the evidence on this notification only, never logged (a page's text). */
+ shown: String? = null
) {
recordAlert(context, key, null, hit, null, false, lat, lon, card = banner)
if (!banner) return
+ val evidence = shown ?: hit.evidence
val discreet = Prefs.discreetMode(context)
com.rfsentinel.app.ui.ThreatBubble.popup(context, if (discreet) "New alert" else hit.label,
if (discreet) null else hit.category.shortTag, hit.category.colorArgb)
- if (toCar(context, if (discreet) "New alert" else "${hit.label}. ${hit.evidence}", null)) return
+ if (toCar(context, if (discreet) "New alert" else "${hit.label}. $evidence", null)) return
val open = PendingIntent.getActivity(
context, key.hashCode(),
(online?.let { com.rfsentinel.app.ui.MapActivity.onlineIntent(context, it, lat, lon) } ?: Intent(context, target))
@@ -198,8 +201,8 @@ object NotificationHelper {
)
val builder = NotificationCompat.Builder(context, CHANNEL_ALERTS)
.setContentTitle(if (discreet) "RF Sentinel" else hit.label)
- .setContentText(if (discreet) "New alert - tap to view" else hit.evidence)
- .setStyle(if (discreet) null else NotificationCompat.BigTextStyle().bigText(hit.evidence))
+ .setContentText(if (discreet) "New alert - tap to view" else evidence)
+ .setStyle(if (discreet) null else NotificationCompat.BigTextStyle().bigText(evidence))
.setSmallIcon(R.drawable.ic_tile_scan)
.setColor(hit.category.colorArgb)
.setPriority(NotificationCompat.PRIORITY_HIGH)
@@ -213,7 +216,7 @@ object NotificationHelper {
.extend(
CarAppExtender.Builder()
.setContentTitle(if (discreet) "RF Sentinel" else hit.label)
- .setContentText(if (discreet) "New alert" else hit.evidence)
+ .setContentText(if (discreet) "New alert" else evidence)
.setSmallIcon(R.drawable.ic_tile_scan)
.setImportance(NotificationManagerCompat.IMPORTANCE_HIGH)
.addAction(R.drawable.ic_car_volume_off, "Mute ${Prefs.snoozeMinutes(context)} min",
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 64ae074..9c3f712 100644
--- a/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
+++ b/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
@@ -696,6 +696,28 @@ object Prefs {
/** Paging frequencies typed by the user, one per line in MHz: listened to instead of scanning for a channel. */
fun pagerFreqs(context: Context) = str(context, "pager_freqs")
fun setPagerFreqs(context: Context, v: String) = sp(context).edit { putString("pager_freqs", v) }
+ /** The channel picked on the Pager messages screen, in Hz; 0 listens to all of [pagerFreqs]. */
+ fun pagerChannel(context: Context): Long = sp(context).getLong("pager_channel", 0L)
+ fun setPagerChannel(context: Context, hz: Long) = sp(context).edit { putLong("pager_channel", hz) }
+ /** The POCSAG speeds to decode; all by default. */
+ fun pagerSpeeds(context: Context): Set<Int> = sp(context).getString("pager_speeds", null)
+ ?.split(",")?.mapNotNull { it.toIntOrNull() }?.toSet() ?: com.rfsentinel.app.sdr.PagerDemod.SPEEDS
+ fun setPagerSpeeds(context: Context, v: Set<Int>) = sp(context).edit { putString("pager_speeds", v.joinToString(",")) }
+ /** Capcodes and words that alert ([com.rfsentinel.app.sdr.PagerRules]). */
+ fun pagerWatch(context: Context) = str(context, "pager_watch")
+ fun setPagerWatch(context: Context, v: String) = sp(context).edit { putString("pager_watch", v) }
+ /** Capcodes whose pages are dropped. */
+ fun pagerIgnore(context: Context) = str(context, "pager_ignore")
+ fun setPagerIgnore(context: Context, v: String) = sp(context).edit { putString("pager_ignore", v) }
+ /** Page text in watch alerts: off by default, pages can hold private details. */
+ fun pagerAlertText(context: Context): Boolean = bool(context, "pager_alert_text", false)
+ fun setPagerAlertText(context: Context, v: Boolean) = setBool(context, "pager_alert_text", v)
+ /** The ways pager watch alerts don't alert you; none by default. */
+ fun pagerAlertsOff(context: Context): Set<com.rfsentinel.app.data.AlertKind> =
+ com.rfsentinel.app.data.AlertKind.parse(sp(context).getString("pager_alerts_off", null))
+ fun setPagerAlertsOff(context: Context, off: Set<com.rfsentinel.app.data.AlertKind>) = sp(context).edit {
+ com.rfsentinel.app.data.AlertKind.format(off)?.let { putString("pager_alerts_off", it) } ?: remove("pager_alerts_off")
+ }
/** The sweep's default follows the ADS-B and P25 settings: store it before they change, or ticking one would untick it. */
private fun keepSdrSweep(context: Context) { if (!sp(context).contains("sdr_sweep")) setSdrSweep(context, sdrSweep(context)) }
/** P25 talkgroups to alert on, "1234 Name" a line ([com.rfsentinel.app.sdr.P25Log.watched]). */
diff --git a/app/src/test/java/com/rfsentinel/app/sdr/PagerRulesTest.kt b/app/src/test/java/com/rfsentinel/app/sdr/PagerRulesTest.kt
new file mode 100644
index 0000000..0b2e3d3
--- /dev/null
+++ b/app/src/test/java/com/rfsentinel/app/sdr/PagerRulesTest.kt
@@ -0,0 +1,38 @@
+package com.rfsentinel.app.sdr
+
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertNull
+import org.junit.Test
+
+class PagerRulesTest {
+
+ private fun page(capcode: Long, text: String) = PagerLog.Page("POCSAG 1200", capcode, PagerLog.Kind.ALPHA, text)
+
+ @Test fun `a list line is a capcode with an optional name, or else words`() {
+ assertEquals(listOf(
+ PagerRules.Watch(1234567, null, "Station 4"),
+ PagerRules.Watch(42, null, ""),
+ PagerRules.Watch(null, "cardiac arrest", "cardiac arrest")
+ ), PagerRules.watches(" 1234567 Station 4\n\n42\ncardiac arrest\n"))
+ }
+
+ @Test fun `a page matches on its capcode or on words in any case, and tone pages only on the capcode`() {
+ val rules = PagerRules.watches("1234567 Station 4\ncardiac arrest")
+ assertEquals("Station 4", PagerRules.match(rules, page(1234567, ""))?.name)
+ assertEquals("cardiac arrest", PagerRules.match(rules, page(9, "CARDIAC ARREST, Main St"))?.name)
+ assertNull(PagerRules.match(rules, page(9, "")))
+ }
+
+ @Test fun `ignored keeps the capcodes and skips anything else`() {
+ assertEquals(setOf(5L, 6L), PagerRules.ignored("5 test pager\n6\nnot a number"))
+ }
+
+ @Test fun `a saved list comes back from its own file, and a CSV works too`() {
+ val (text, added, _) = RadioSettings.addPagerFile("", "466.075 Fire dispatch\n153.35")
+ assertEquals(2, added)
+ assertEquals(listOf(466_075_000L, 153_350_000L), RadioSettings.targets(text).map { it.freqHz })
+ assertEquals("Fire dispatch", RadioSettings.targets(text).first().label)
+ assertEquals(0, RadioSettings.addPagerFile(text, text).second)
+ assertEquals(1, RadioSettings.addPagerFile(text, "Frequency,Description\n929.5625,County EMS").second)
+ }
+}