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.

Radar line turns in about 5 s and passes the top at each WiFi scan request; Watch this list adds an imported frequency list to the watched frequencies

CIS-C052f847a1b54e
diff --git a/app/src/main/java/com/rfsentinel/app/sdr/FreqNames.kt b/app/src/main/java/com/rfsentinel/app/sdr/FreqNames.kt
index f7832c2..0754a17 100644
--- a/app/src/main/java/com/rfsentinel/app/sdr/FreqNames.kt
+++ b/app/src/main/java/com/rfsentinel/app/sdr/FreqNames.kt
@@ -26,6 +26,7 @@ object FreqNames {
@Volatile var nearby: List<Name> = emptyList()
val importedCount: Int get() = imported.size
+ val importedNames: List<Name> get() = imported
@Synchronized
fun load(context: Context) {
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 5f32df2..71c3da5 100644
--- a/app/src/main/java/com/rfsentinel/app/sdr/RadioSettings.kt
+++ b/app/src/main/java/com/rfsentinel/app/sdr/RadioSettings.kt
@@ -20,7 +20,7 @@ object RadioSettings {
private const val MIN_HZ = 24_000_000L
private const val MAX_HZ = 1_766_000_000L
private const val MAX_CUSTOM_SPAN_HZ = 120_000_000L
- private const val MAX_TARGETS = 50
+ const val MAX_TARGETS = 50
fun config(context: Context): RadioWatch.Config {
val off = Prefs.radioBandsOff(context)
@@ -67,4 +67,14 @@ object RadioSettings {
val hz = mhzToHz(m.groupValues[1])?.takeIf { it in MIN_HZ..MAX_HZ } ?: return@mapNotNull null
RadioWatch.Target(hz, m.groupValues[2].trim().ifEmpty { "%.4f MHz".format(java.util.Locale.US, hz / 1e6) })
}.distinctBy { it.freqHz }.take(MAX_TARGETS)
+
+ /** [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 }
+ val fresh = names.filter { it.hz in MIN_HZ..MAX_HZ && it.hz !in have }.distinctBy { it.hz }
+ val added = fresh.take(MAX_TARGETS - have.size)
+ val lines = added.map { "${java.math.BigDecimal(it.hz).movePointLeft(6).stripTrailingZeros().toPlainString()} ${it.name}" }
+ val text = (listOf(current.trimEnd()).filter { it.isNotEmpty() } + lines).joinToString("\n")
+ return Triple(text, added.size, fresh.size - added.size)
+ }
}
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 f18d849..af84a87 100644
--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
@@ -601,9 +601,10 @@ class ScanForegroundService : Service() {
wifiPollJob = serviceScope.launch {
while (isActive) {
holdAwake()
- wifiEngine.requestScan()
val interval = Prefs.scanIntervalMs(this@ScanForegroundService)
com.rfsentinel.app.ui.LiveWindow.wifiScanMs = interval
+ com.rfsentinel.app.ui.LiveWindow.wifiScanAt = System.currentTimeMillis()
+ wifiEngine.requestScan()
delay(interval)
}
}
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 221d5f4..c4b8006 100644
--- a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
@@ -831,6 +831,7 @@ class SettingsActivity : AppCompatActivity() {
"that lines up with a device flagged over Wi-Fi / Bluetooth - is a useful sign; a phone alone is not. It adds time to " +
"each sweep while it's on.\n\n" +
"Frequency names: import a CSV (RadioReference's export, CHIRP, or any file with a frequency and a name column), " +
+ "then Watch this list to report its channels whenever they're active, " +
"or let RadioReference name the FCC licences near you (US): needs your own RadioReference Premium login and a " +
"RadioReference developer key; your position rounded to ~1 km is sent to RadioReference, at most once a day per area.\n\n" +
"Changes apply from the next sweep while scanning."),
@@ -1141,6 +1142,7 @@ class SettingsActivity : AppCompatActivity() {
info(binding.retentionLabel, "How long device history is kept. 0 keeps it forever.")
withUnit(binding.retentionInput, "days")
info(binding.exportAllButton, "CSV, JSON, KML, GPX or GeoJSON.")
+ info(binding.radarSweepSwitch, "One turn takes about 5 seconds. The line passes the top each time a WiFi scan is requested; Android may still hold back the scan.")
info(binding.forgetHistoryButton, "New / returning status, detect counts and the remembered cell towers start over. Favorites are kept.")
info(binding.openWhitelistButton, "Trusted devices: never flagged, and hidden from the list when you choose.")
info(binding.ignoredSsidsButton, "WiFi networks whose name contains one of these words are never flagged, " +
@@ -1435,15 +1437,15 @@ class SettingsActivity : AppCompatActivity() {
l.text = text(it)
})
}
- fun lines(title: String, hint: String, value: String, details: String? = null, save: (String) -> Unit) {
+ fun lines(title: String, hint: String, value: String, details: String? = null, save: (String) -> Unit): android.widget.EditText {
box.label(title).also { if (details != null) info(it, details) }
- box.addView(android.widget.EditText(this).apply {
+ return android.widget.EditText(this).apply {
setText(value); this.hint = hint
minLines = 2; maxLines = 8; gravity = android.view.Gravity.TOP
inputType = android.text.InputType.TYPE_CLASS_TEXT or android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE
importantForAutofill = View.IMPORTANT_FOR_AUTOFILL_NO
doAfterTextChanged { save(it?.toString().orEmpty()) }
- })
+ }.also { box.addView(it) }
}
info(box.label("Network SDR"), "Uses an RTL-SDR on another device over WiFi, such as an ESP32 board or a computer running " +
@@ -1566,7 +1568,7 @@ class SettingsActivity : AppCompatActivity() {
}
lines("Your own bands", "380-400 TETRA\n220-222", Prefs.radioCustomBands(this), "One per line, in MHz, with an optional name.") { Prefs.setRadioCustomBands(this, it) }
lines("Never report these ranges", "462-469 business band\n151.8-152.0", Prefs.radioExcluded(this), "One per line, in MHz.") { Prefs.setRadioExcluded(this, it) }
- lines("Watch these frequencies", "154.4300 County fire dispatch\n460.125", Prefs.radioTargets(this),
+ val watched = lines("Watch these frequencies", "154.4300 County fire dispatch\n460.125", Prefs.radioTargets(this),
"Always reported when active, whatever the sensitivity. One per line, in MHz, with an optional name.") { Prefs.setRadioTargets(this, it) }
box.toggle("Say the frequency", Prefs.radioSpeakFreq(this), "Says the frequency (and its name) instead of \"Radio transmitting nearby\".") { Prefs.setRadioSpeakFreq(this, it) }
box.toggle("Detect cellular transmitters", Prefs.radioCellOn(this),
@@ -1601,6 +1603,20 @@ class SettingsActivity : AppCompatActivity() {
setOnClickListener { com.rfsentinel.app.sdr.FreqNames.clearImported(this@SettingsActivity); updateFreqListText() }
})
})
+ // Its own row: three buttons side by side would be cut off on a narrow screen.
+ box.addView(com.google.android.material.button.MaterialButton(this, null, android.R.attr.borderlessButtonStyle).apply {
+ text = "Watch this list"
+ setOnClickListener {
+ val names = com.rfsentinel.app.sdr.FreqNames.importedNames
+ val (merged, added, left) = com.rfsentinel.app.sdr.RadioSettings.addTargets(watched.text.toString(), names)
+ if (added > 0) watched.setText(merged)
+ Toast.makeText(this@SettingsActivity, when {
+ names.isEmpty() -> "Import a frequency list first"
+ left > 0 -> "$added added, $left did not fit: the limit is ${com.rfsentinel.app.sdr.RadioSettings.MAX_TARGETS} watched frequencies"
+ else -> "$added added to Watch these frequencies"
+ }, Toast.LENGTH_LONG).show()
+ }
+ }, android.widget.LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT))
val rrSwitch = box.toggle("Name hits from RadioReference", Prefs.radioReferenceOn(this),
"Names a hit from RadioReference's database. Needs your own RadioReference Premium login and developer key, stored encrypted on this phone.") {
diff --git a/app/src/main/java/com/rfsentinel/app/ui/LiveWindow.kt b/app/src/main/java/com/rfsentinel/app/ui/LiveWindow.kt
index ac4e3e9..b0d4c8d 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/LiveWindow.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/LiveWindow.kt
@@ -17,6 +17,18 @@ object LiveWindow {
/** The WiFi scan interval in use (kept current by the scan service): WiFi devices only refresh once per scan. */
@Volatile var wifiScanMs = 30_000L
+ /** When the last WiFi scan was requested (kept current by the scan service): the radar line passes the top then. */
+ @Volatile var wifiScanAt = 0L
+
+ /**
+ * The radar line's angle for Canvas.rotate (-90 = top): turns of about 5 s that fit a whole number of times in
+ * the scan interval, so it passes the top at each scan request. It keeps turning when no scan is running.
+ */
+ fun sweepAngle(now: Long, scanAt: Long = wifiScanAt, scanMs: Long = wifiScanMs): Float {
+ val turnMs = scanMs.toDouble() / Math.round(scanMs / 5_000.0).coerceAtLeast(1L)
+ return (((now - scanAt) / turnMs).mod(1.0) * 360.0 - 90.0).toFloat()
+ }
+
/** Still being heard: Bluetooth within 8 s, WiFi within one scan round + 10 s. */
fun inRange(s: DeviceRegistry.Snapshot, now: Long = System.currentTimeMillis()): Boolean {
val wifi = Advert.Source.WIFI in s.sources || s.source == Advert.Source.WIFI
diff --git a/app/src/main/java/com/rfsentinel/app/ui/RadarView.kt b/app/src/main/java/com/rfsentinel/app/ui/RadarView.kt
index a91c5a7..94fea51 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/RadarView.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/RadarView.kt
@@ -91,7 +91,6 @@ class RadarView @JvmOverloads constructor(
/** Compass degrees at the top, null for north-up. */
private var heading: Float? = null
- private var sweep = 0f
private val density = resources.displayMetrics.density
private val scope = MaterialColors.getColor(context, R.attr.rfScopeColor, 0xFF0B5C63.toInt())
private val scopeText = MaterialColors.getColor(context, R.attr.rfScopeTextColor, 0xAA0B5C63.toInt())
@@ -238,7 +237,7 @@ class RadarView @JvmOverloads constructor(
if (sweepLine) {
canvas.save()
- canvas.rotate(sweep, cx, cy)
+ canvas.rotate(LiveWindow.sweepAngle(now), cx, cy)
canvas.drawCircle(cx, cy, rad, sweepPaint)
canvas.restore()
}
@@ -275,7 +274,6 @@ class RadarView @JvmOverloads constructor(
val footer = footer(width - 16 * density, now)
canvas.drawText(footer, 8 * density, height - 8 * density, textPaint)
- sweep = (sweep + 2.4f) % 360f
if (isShown) postInvalidateOnAnimation()
}
diff --git a/app/src/test/java/com/rfsentinel/app/sdr/RadioFeaturesTest.kt b/app/src/test/java/com/rfsentinel/app/sdr/RadioFeaturesTest.kt
index d8f1fdf..087ac42 100644
--- a/app/src/test/java/com/rfsentinel/app/sdr/RadioFeaturesTest.kt
+++ b/app/src/test/java/com/rfsentinel/app/sdr/RadioFeaturesTest.kt
@@ -20,6 +20,25 @@ class RadioFeaturesTest {
assertEquals(RadioWatch.Kind.CUSTOM, bands[0].kind)
}
+ @Test
+ fun importedListJoinsWatchedFrequencies() {
+ fun n(hz: Long, name: String) = FreqNames.Name(hz, name, "t")
+ val (text, added, left) = RadioSettings.addTargets("154.4300 County fire\n",
+ listOf(n(154_430_000L, "same"), n(851_006_250L, "Fine step"), n(155_000_000L, "Whole"), n(155_000_000L, "Twice"), n(1_790_000_000L, "Too high")))
+ assertEquals(2, added)
+ assertEquals(0, left)
+ val t = RadioSettings.targets(text)
+ assertEquals(listOf(154_430_000L, 851_006_250L, 155_000_000L), t.map { it.freqHz })
+ assertEquals(listOf("County fire", "Fine step", "Whole"), t.map { it.label })
+
+ val many = (0 until RadioSettings.MAX_TARGETS + 5).map { n(150_000_000L + it * 12_500L, "Ch $it") }
+ val (full, fit, over) = RadioSettings.addTargets("", many)
+ assertEquals(RadioSettings.MAX_TARGETS, fit)
+ assertEquals(5, over)
+ assertEquals(RadioSettings.MAX_TARGETS, RadioSettings.targets(full).size)
+ assertEquals(0, RadioSettings.addTargets(full, many).second)
+ }
+
@Test
fun trendIsCalledOnTheSetStep() {
RadioLog.clear()
diff --git a/app/src/test/java/com/rfsentinel/app/ui/RadarSweepTest.kt b/app/src/test/java/com/rfsentinel/app/ui/RadarSweepTest.kt
new file mode 100644
index 0000000..7a0c5a8
--- /dev/null
+++ b/app/src/test/java/com/rfsentinel/app/ui/RadarSweepTest.kt
@@ -0,0 +1,30 @@
+package com.rfsentinel.app.ui
+
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+class RadarSweepTest {
+
+ private fun angle(sinceScan: Long, scanMs: Long) = LiveWindow.sweepAngle(1_000_000L + sinceScan, 1_000_000L, scanMs)
+
+ @Test
+ fun passesTheTopAtEachScan() {
+ for (ms in listOf(5_000L, 7_000L, 12_000L, 30_000L, 47_000L)) assertEquals(-90f, angle(0, ms), 0.01f)
+ assertEquals(-90f, angle(30_000, 30_000), 0.01f)
+ }
+
+ @Test
+ fun turnsTakeAboutFiveSeconds() {
+ assertEquals(90f, angle(2_500, 5_000), 0.01f)
+ assertEquals(90f, angle(2_500, 30_000), 0.01f) // six turns per scan
+ assertEquals(-90f, angle(5_000, 30_000), 0.01f)
+ assertEquals(90f, angle(3_500, 7_000), 0.01f) // one turn: 7 s can't split
+ assertEquals(90f, angle(3_000, 12_000), 0.01f) // two 6 s turns
+ }
+
+ @Test
+ fun aClockSetBackStaysInRange() {
+ assertTrue(angle(-1_000, 30_000) in -90f..270f)
+ }
+}