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: Hold a talkgroup - only its calls play, no length limit, the SDR stays on P25 (sweep / ADS-B / recordings paused, input check kept for its calls) until Release
CIS-C0bb2e2a83dca4
diff --git a/app/src/main/java/com/rfsentinel/app/sdr/SdrRadio.kt b/app/src/main/java/com/rfsentinel/app/sdr/SdrRadio.ktindex 322a49b..caf1ef6 100644--- a/app/src/main/java/com/rfsentinel/app/sdr/SdrRadio.kt+++ b/app/src/main/java/com/rfsentinel/app/sdr/SdrRadio.kt@@ -74,12 +74,15 @@ object SdrRadio {/** The scan whose turn it is now; null when none is ticked. */@Volatile var mode: Mode? = null; private set@Volatile private var turnEnd = 0L+ /** The scans that get turns: P25 alone while a talkgroup is held ([p25Hold]). */+ private val active get() = if (p25Hold != null) setOf(Mode.P25) else modes/** [m] keeps the SDR: its turn, still ticked, and the waterfall not zoomed in. */- private fun keeps(m: Mode) = mode == m && m in modes && tuneHz == null && (modes.size == 1 || System.currentTimeMillis() < turnEnd)+ private fun keeps(m: Mode) = mode == m && m in active && tuneHz == null && (active.size == 1 || System.currentTimeMillis() < turnEnd)/** The scan after the current one, round the ticked ones. */- private fun next(): Mode? = Mode.entries.filter { it in modes }.let { l -> l.firstOrNull { it.ordinal > (mode?.ordinal ?: -1) } ?: l.firstOrNull() }- /** " · ADS-B in 40 s" while taking turns, for the status line. */+ private fun next(): Mode? = Mode.entries.filter { it in active }.let { l -> l.firstOrNull { it.ordinal > (mode?.ordinal ?: -1) } ?: l.firstOrNull() }+ /** " · ADS-B in 40 s" while taking turns, or " · holding talkgroup 1234", for the status line. */private fun turnNote(): String {+ p25Hold?.let { return " · holding talkgroup $it" }if (modes.size < 2) return ""val left = ((turnEnd - System.currentTimeMillis()) / 1000).coerceAtLeast(0)return " · ${next()?.label} in $left s"@@ -107,6 +110,16 @@ object SdrRadio {@Volatile var p25Watched: Set<Int> = emptySet()/** P25 talkgroups › Mute: no call is played, the SDR stays on the control channel. */@Volatile var p25Mute = false+ /**+ * P25 talkgroups › Hold: only this talkgroup's clear calls play (whatever Listen is set to, with no length limit),+ * the SDR stays on P25 (no sweep or ADS-B turns), and recordings pause; the input check stays on for its calls.+ * Until released (null) or scanning stops.+ */+ @Volatile var p25Hold: Int? = null+ set(tg) {+ field = tg+ if (tg != null) onAircraft?.invoke(emptyList(), emptyList()) // no ADS-B while held+ }/** The call playing now (the P25 screen marks it), or null. */@Volatile var p25Playing: P25History.Call? = null; private setprivate var speaker: android.media.AudioTrack? = null@@ -167,6 +180,7 @@ object SdrRadio {halt("")onEvent = nulltuneHz = null+ p25Hold = null}@Synchronized@@ -296,14 +310,14 @@ object SdrRadio {while (!halted && !sdr.lost && !gone(name)) {if (tuneHz != null) { runTuned(sdr, name); tuned = true; continue }// Back from the waterfall: the scan it interrupted gets its turn again, not the next one.- val m = mode?.takeIf { tuned && it in modes } ?: next()+ val m = mode?.takeIf { tuned && it in active } ?: next()tuned = falseif (m == null) {mode = nullstatus = "$deviceLabel · idle: no scan ticked in Settings › RTL-SDR radio"Thread.sleep(500); continue}- if (modes.size > 1) UsbWifi.log("$deviceLabel: turn: ${m.label} for ${turnMs / 1000} s")+ if (active.size > 1) UsbWifi.log("$deviceLabel: turn: ${m.label} for ${turnMs / 1000} s")mode = m; turnEnd = System.currentTimeMillis() + turnMswhen (m) {Mode.SWEEP -> runSweep(sdr, name)@@ -379,7 +393,7 @@ object SdrRadio {}}// Only its turn ended: the aircraft stay listed until they go stale, and come back on the next turn.- if (Mode.ADSB !in modes) onAircraft?.invoke(emptyList(), emptyList())+ if (Mode.ADSB !in active) onAircraft?.invoke(emptyList(), emptyList())UsbWifi.log("$deviceLabel: ADS-B receiver stopped after $messages messages")}@@ -515,16 +529,18 @@ object SdrRadio {for (tg in p25Log.add(it, now)) onP25Call?.invoke(tg)val calls = p25Log.takeCalls()appContext?.let { c -> P25History.append(c, calls) }+ val hold = p25Holdif (p25Inputs && pending == null && now - lastInput >= INPUT_GAP_MS) {- calls.lastOrNull { it.source != null && it.channel != null }?.let { c ->+ calls.lastOrNull { it.source != null && it.channel != null && (hold == null || it.tg == hold) }?.let { c ->p25Log.inputHz(c.channel!!)?.let { hz -> pending = c to hz; lastInput = now }}}val listen = p25Listen- if (listen != Listen.OFF && !p25Mute && toFollow == null) {- calls.lastOrNull { !it.encrypted && it.hz != null && (listen == Listen.ALL || it.tg in p25Watched) }?.let { toFollow = it }+ if ((listen != Listen.OFF || hold != null) && !p25Mute && toFollow == null) {+ calls.lastOrNull { !it.encrypted && it.hz != null && (if (hold != null) it.tg == hold else listen == Listen.ALL || it.tg in p25Watched) }+ ?.let { toFollow = it }}- if (p25Record && toRecord == null && now - lastRecord >= RECORD_GAP_MS) {+ if (p25Record && hold == null && toRecord == null && now - lastRecord >= RECORD_GAP_MS) {calls.lastOrNull { !it.encrypted && it.hz != null && it !== toFollow }?.let { toRecord = it; lastRecord = now }}if (now - lastStatus >= 2_000L && !halted) { lastStatus = now; status = "$deviceLabel · P25 · control channel $where · $messages messages" + turnNote() }@@ -540,7 +556,8 @@ object SdrRadio {}/**- * Plays [call] live from its voice channel until it ends, goes quiet, or listening stops ([FOLLOW_MAX_MS] at most);+ * Plays [call] live from its voice channel until it ends, goes quiet, or listening stops ([FOLLOW_MAX_MS] at most,+ * unless its talkgroup is held);* false when no voice was heard. Frequency kept off the log.*/private fun followCall(sdr: SdrDevice, call: P25History.Call, stop: () -> Boolean): Boolean {@@ -563,8 +580,10 @@ object SdrRadio {val start = System.currentTimeMillis()var fails = 0try {- while (!stop() && !p25Mute && p25Listen != Listen.OFF && !follow.ended && fails < STALL_CHUNKS &&- follow.quietS < (if (follow.frames == 0) FOLLOW_START_S else FOLLOW_QUIET_S) && System.currentTimeMillis() - start < FOLLOW_MAX_MS) {+ while (!stop() && !p25Mute && !follow.ended && fails < STALL_CHUNKS &&+ follow.quietS < (if (follow.frames == 0) FOLLOW_START_S else FOLLOW_QUIET_S)) {+ val hold = p25Hold+ if (if (hold != null) hold != call.tg else p25Listen == Listen.OFF || System.currentTimeMillis() - start >= FOLLOW_MAX_MS) breakval n = sdr.read(buf)if (n <= 0) { fails++; continue }fails = 0 // stalls in a row end it, not stalls over a long calldiff --git a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.ktindex 2991cc1..d0fbf30 100644--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt@@ -1289,7 +1289,8 @@ class ScanForegroundService : Service() {val devices = DeviceRegistry.snapshot()val flagged = devices.count { d -> com.rfsentinel.app.ui.LiveWindow.alerting(d) }val text = "${devices.size} device${if (devices.size == 1) "" else "s"} nearby" +- if (flagged > 0) " · $flagged flagged" else ""+ (if (flagged > 0) " · $flagged flagged" else "") ++ (com.rfsentinel.app.sdr.SdrRadio.p25Hold?.let { " · holding P25 talkgroup $it" } ?: "")NotificationHelper.updateServiceNotification(this@ScanForegroundService, text)StatusWidget.updateAll(this@ScanForegroundService, devices.size, flagged)runCatching { TripRecorder.flush(this@ScanForegroundService) }diff --git a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.ktindex 2a8555f..0f060bb 100644--- a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt+++ b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt@@ -1523,7 +1523,7 @@ class SettingsActivity : AppCompatActivity() {Prefs.setP25Listen(this, it)}, "Experimental. Plays clear (not encrypted) P25 calls as they happen, through the speaker, headphones or car like other audio. " +"The SDR leaves the control channel for the call and misses its messages meanwhile: one call at a time, at most " +- "2 minutes each. Watched talkgroups: only those in Watch these talkgroups. Mute on the P25 talkgroups screen pauses it. " ++ "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) }diff --git a/app/src/main/java/com/rfsentinel/app/ui/P25Activity.kt b/app/src/main/java/com/rfsentinel/app/ui/P25Activity.ktindex c8623eb..310b2b4 100644--- a/app/src/main/java/com/rfsentinel/app/ui/P25Activity.kt+++ b/app/src/main/java/com/rfsentinel/app/ui/P25Activity.kt@@ -30,6 +30,7 @@ import java.util.Locale* talkgroups and private calls granted a channel there, most recent first. Watched talkgroups are named and* marked. History: the kept call log ([P25History]) per talkgroup over the last day and week, and its busiest hour.* With Settings › Listen to P25 voice on, the call playing is marked, and Mute pauses listening.+ * Hold (or tapping a talkgroup) keeps the SDR on that talkgroup's calls alone until Release ([SdrRadio.p25Hold]).*/class P25Activity : AppCompatActivity() {@@ -52,12 +53,14 @@ class P25Activity : AppCompatActivity() {object : RecyclerView.ViewHolder(ItemDetectionBinding.inflate(LayoutInflater.from(parent.context), parent, false).root) {}override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {+ holder.itemView.setOnClickListener(null)history?.let { bindHistory(ItemDetectionBinding.bind(holder.itemView), it[position]); return }val r = rows[position]ItemDetectionBinding.bind(holder.itemView).apply {val name = r.tg?.let { watched[it] }val playing = SdrRadio.p25Playing?.let { if (r.tg != null) it.tg == r.tg else it.tg == null && it.target == r.target } == true- labelText.text = listOfNotNull(title(r), "playing".takeIf { playing }, name?.ifEmpty { "watched" }, "EMERGENCY".takeIf { r.emergency },+ r.tg?.let { tg -> root.setOnClickListener { askHold(tg, r.encrypted) } }+ labelText.text = listOfNotNull(title(r), "playing".takeIf { playing }, "held".takeIf { r.tg != null && r.tg == SdrRadio.p25Hold }, name?.ifEmpty { "watched" }, "EMERGENCY".takeIf { r.emergency },"encrypted".takeIf { r.encrypted }).joinToString(" · ")labelText.setTextColor(when {r.emergency -> EMERGENCY@@ -93,9 +96,40 @@ class P25Activity : AppCompatActivity() {menu.add(0, MENU_EXPORT, 1, "Export call log")if (Prefs.p25Listen(this) != 0) menu.add(0, MENU_MUTE, 0, if (Prefs.p25Mute(this)) "Unmute" else "Mute").setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM)+ heldInMenu = SdrRadio.p25Hold+ if (Prefs.p25Listen(this) != 0 || heldInMenu != null) menu.add(0, MENU_HOLD, 0, if (heldInMenu != null) "Release" else "Hold")+ .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM)return true}+ /** The talkgroup held when the menu was built: the menu is rebuilt when that changes (Release, or scanning stopped). */+ private var heldInMenu: Int? = null++ private fun hold(tg: Int?) {+ SdrRadio.p25Hold = tg+ invalidateOptionsMenu(); refresh()+ }++ /** A talkgroup tapped: hold it, or release it when it is the one held. */+ private fun askHold(tg: Int, encrypted: Boolean) {+ if (SdrRadio.p25Hold == tg) {+ com.google.android.material.dialog.MaterialAlertDialogBuilder(this)+ .setTitle("Release talkgroup $tg?")+ .setMessage("The SDR goes back to all its scans in Settings › RTL-SDR radio.")+ .setPositiveButton("Release") { _, _ -> hold(null) }+ .setNegativeButton("Cancel", null).show()+ return+ }+ com.google.android.material.dialog.MaterialAlertDialogBuilder(this)+ .setTitle("Hold talkgroup $tg?")+ .setMessage("Plays only this talkgroup's clear calls, with no time limit, and keeps the SDR on P25: the radio sweep, " ++ "cellular check and ADS-B pause, and so do recordings. Listening for radios keying up nearby stays on for its calls. " ++ "Until you tap Release or scanning stops." ++ (if (encrypted) "\n\nIts last call was encrypted: encrypted calls can't be played." else ""))+ .setPositiveButton("Hold") { _, _ -> hold(tg) }+ .setNegativeButton("Cancel", null).show()+ }+override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {MENU_HISTORY -> {history = if (history == null) emptyList() else null@@ -104,6 +138,15 @@ class P25Activity : AppCompatActivity() {invalidateOptionsMenu(); refresh(); true}MENU_EXPORT -> { exportLog(); true }+ MENU_HOLD -> {+ val tg = SdrRadio.p25Playing?.tg+ when {+ SdrRadio.p25Hold != null -> hold(null)+ tg != null -> hold(tg)+ else -> android.widget.Toast.makeText(this, "Tap a talkgroup to hold it, or tap Hold while a call plays", android.widget.Toast.LENGTH_LONG).show()+ }+ true+ }MENU_MUTE -> {val mute = !Prefs.p25Mute(this)Prefs.setP25Mute(this, mute); SdrRadio.p25Mute = mute@@ -141,6 +184,7 @@ class P25Activity : AppCompatActivity() {@SuppressLint("NotifyDataSetChanged")private fun refresh() {+ if (SdrRadio.p25Hold != heldInMenu) invalidateOptionsMenu()watched = P25Log.watched(Prefs.p25Talkgroups(this))val q = binding.searchInput.text?.toString()?.trim().orEmpty()if (history != null) { refreshHistory(q); return }@@ -149,6 +193,7 @@ class P25Activity : AppCompatActivity() {}val s = SdrRadio.p25Log.summary()header.text = listOfNotNull(+ SdrRadio.p25Hold?.let { "Holding talkgroup $it · other radio uses paused" },SdrRadio.status.ifBlank { "No SDR running" },s.site?.let { site ->listOfNotNull(site.wacn?.let { "WACN %05X".format(it) }, "system %03X".format(site.sysId),@@ -201,6 +246,7 @@ class P25Activity : AppCompatActivity() {private const val MENU_HISTORY = 1private const val MENU_EXPORT = 2private const val MENU_MUTE = 3+ private const val MENU_HOLD = 4private const val HISTORY_MS = 30_000Lprivate val EMERGENCY = 0xFFD0503C.toInt()