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.

Snapshots and recorded traces use the main screen's filter chips

CIS-C0bcd0ce6844c7
diff --git a/app/src/main/java/com/rfsentinel/app/ui/DeviceFilter.kt b/app/src/main/java/com/rfsentinel/app/ui/DeviceFilter.kt
index d107cf5..9364981 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/DeviceFilter.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/DeviceFilter.kt
@@ -1,35 +1,39 @@
package com.rfsentinel.app.ui
+import android.content.Context
import com.rfsentinel.app.data.Favorites
+import com.rfsentinel.app.data.TripDeviceEntity
import com.rfsentinel.app.data.WhitelistCache
import com.rfsentinel.app.detect.Advert
import com.rfsentinel.app.detect.Category
import com.rfsentinel.app.detect.DeviceIntel
+import com.rfsentinel.app.detect.Hit
import com.rfsentinel.app.service.DeviceRegistry
+import com.rfsentinel.app.util.Prefs
/** The device filters shared by the list and the map, so both pick the same devices. */
-enum class DeviceFilter(val label: String) {
+enum class DeviceFilter(val label: String, val liveOnly: Boolean = false) {
// Chip order: most useful first.
ALL("All"),
FLAGGED("Flagged"),
TRACKERS("Trackers"),
DRONES("Drones"),
FAVORITES("Favorites"),
- NEW("New"),
+ NEW("New", liveOnly = true),
BLE("Bluetooth"),
WIFI("WiFi"),
/** Cell towers: not devices, listed from the cell snapshot (list only, not the map). */
- CELLS("Cells"),
+ CELLS("Cells", liveOnly = true),
/** RTL-SDR radio hits: not devices, listed from the radio log (list only). */
- RADIO("Radio"),
+ RADIO("Radio", liveOnly = true),
/** Waze reports: not devices, drawn on the map from the Waze poll (map only). */
- WAZE("Waze"),
+ WAZE("Waze", liveOnly = true),
/** Aircraft from the RTL-SDR's ADS-B receiver and the online feeds: not devices (list and map). */
- AIRCRAFT("Aircraft"),
+ AIRCRAFT("Aircraft", liveOnly = true),
/** Heard by external hardware: an ESP32 board (USB or OUI-SPY over Bluetooth) or a USB WiFi adapter. */
- EXTERNAL("External"),
+ EXTERNAL("External", liveOnly = true),
/** Heard by a linked Sentinel (Sentinel Link). */
- SENTINELS("Sentinels"),
+ SENTINELS("Sentinels", liveOnly = true),
// Kinds of device, from what identified them (see DeviceIntel).
VEHICLES("Vehicles"),
PHONES("Phones"),
@@ -40,12 +44,40 @@ enum class DeviceFilter(val label: String) {
TVS("TVs & consoles"),
SMART_HOME("Smart home");
- fun matches(s: DeviceRegistry.Snapshot): Boolean = when (this) {
+ /**
+ * What a filter looks at, the same for a device heard now and one saved in a snapshot or a trace,
+ * so every filter (and any added later) works on both.
+ */
+ class Seen(
+ val mac: String,
+ val type: String,
+ val name: String?,
+ val hits: List<Hit>,
+ val sources: Set<Advert.Source>,
+ val flagged: Boolean,
+ val facts: List<Pair<String, String>> = emptyList(),
+ val isNew: Boolean = false,
+ val remoteId: Boolean = false
+ )
+
+ fun matches(s: DeviceRegistry.Snapshot): Boolean = matches(Seen(
+ s.mac, s.deviceType, s.name, s.hits, s.sources, s.best != null && !WhitelistCache.contains(s.mac),
+ s.facts, s.isNew, s.remoteId != null
+ ))
+
+ /** A device saved in a snapshot or a trace (its type read with today's names, see [DeviceIntel.savedType]). */
+ fun matches(d: TripDeviceEntity): Boolean = !liveOnly && matches(Seen(
+ d.mac, DeviceIntel.savedType(d.deviceType, d.vendor, d.mac).orEmpty(), d.name,
+ listOfNotNull(Category.parse(d.category)?.let { Hit(it, d.label, d.confidence, d.evidence.orEmpty(), "") }),
+ setOfNotNull(Advert.Source.entries.firstOrNull { it.name == d.source }), d.flagged
+ ))
+
+ fun matches(s: Seen): Boolean = when (this) {
ALL -> true
- FLAGGED -> s.best != null && !WhitelistCache.contains(s.mac)
+ FLAGGED -> s.flagged
TRACKERS -> !(excludeAirTags && isAppleFindMy(s)) && (s.hits.any { it.category == Category.TRACKER } ||
- s.deviceType.contains("tracker", true) || s.deviceType.contains("Find My", true))
- DRONES -> s.hits.any { it.category == Category.DRONE } || s.remoteId != null || s.deviceType.startsWith("Drone")
+ s.type.contains("tracker", true) || s.type.contains("Find My", true))
+ DRONES -> s.hits.any { it.category == Category.DRONE } || s.remoteId || s.type.startsWith("Drone")
NEW -> s.isNew
CELLS, WAZE, RADIO, AIRCRAFT -> false
EXTERNAL -> com.rfsentinel.app.esp.HeardBy.esp.recent(s.mac) || com.rfsentinel.app.esp.HeardBy.usb.recent(s.mac)
@@ -53,14 +85,14 @@ enum class DeviceFilter(val label: String) {
FAVORITES -> Favorites.contains(s.mac)
BLE -> Advert.Source.BLE in s.sources
WIFI -> Advert.Source.WIFI in s.sources
- VEHICLES -> s.deviceType.startsWith("Vehicle")
- PHONES -> DeviceIntel.isPhone(s.deviceType, s.name)
- AUDIO -> AUDIO_TYPE.containsMatchIn(s.deviceType) || s.facts.contains("Identified by" to "Fast Pair model ID")
- CAMERAS -> CAMERA_TYPE.containsMatchIn(s.deviceType)
- ROUTERS -> s.deviceType.startsWith("Home router")
- HOTSPOTS -> HOTSPOT_TYPE.containsMatchIn(s.deviceType)
- TVS -> TV_TYPE.containsMatchIn(s.deviceType)
- SMART_HOME -> SMART_HOME_TYPE.containsMatchIn(s.deviceType)
+ VEHICLES -> s.type.startsWith("Vehicle")
+ PHONES -> DeviceIntel.isPhone(s.type, s.name)
+ AUDIO -> AUDIO_TYPE.containsMatchIn(s.type) || s.facts.contains("Identified by" to "Fast Pair model ID")
+ CAMERAS -> CAMERA_TYPE.containsMatchIn(s.type)
+ ROUTERS -> s.type.startsWith("Home router")
+ HOTSPOTS -> HOTSPOT_TYPE.containsMatchIn(s.type)
+ TVS -> TV_TYPE.containsMatchIn(s.type)
+ SMART_HOME -> SMART_HOME_TYPE.containsMatchIn(s.type)
}
companion object {
@@ -70,14 +102,14 @@ enum class DeviceFilter(val label: String) {
/** The device-kind filters (from the device's type), after the main ones. */
val KINDS = listOf(VEHICLES, PHONES, AUDIO, CAMERAS, ROUTERS, HOTSPOTS, TVS, SMART_HOME)
- private val AUDIO_TYPE = Regex("headphone|earbud|airpods|beats|speaker|soundbar|\\bbuds\\b|audio", RegexOption.IGNORE_CASE)
+ private val AUDIO_TYPE = Regex("headphone|earbud|airpods|beats|speaker|soundbar|\\bbuds\\b|audio|bose|jbl|jabra|sennheiser|soundcore|skullcandy|sonos", RegexOption.IGNORE_CASE)
private val CAMERA_TYPE = Regex("^(dashcam|action camera|security camera|smart-home / camera)", RegexOption.IGNORE_CASE)
private val HOTSPOT_TYPE = Regex("^(public wifi hotspot|mobile hotspot box|phone hotspot)", RegexOption.IGNORE_CASE)
private val TV_TYPE = Regex("^(smart tv|tv / streaming|game console|apple tv)", RegexOption.IGNORE_CASE)
private val SMART_HOME_TYPE = Regex("^(iot board|iot / smart-home|smart plug|smart-home device)", RegexOption.IGNORE_CASE)
- private fun isAppleFindMy(s: DeviceRegistry.Snapshot) =
- s.deviceType.contains("Find My", true) || s.deviceType.contains("AirTag", true) ||
+ private fun isAppleFindMy(s: Seen) =
+ s.type.contains("Find My", true) || s.type.contains("AirTag", true) ||
s.hits.any { com.rfsentinel.app.detect.SignatureEngine.isAppleFindMy(it) }
fun parse(name: String?) = entries.firstOrNull { it.name == name } ?: ALL
@@ -87,5 +119,11 @@ enum class DeviceFilter(val label: String) {
* radio), so they fit without scrolling; the narrower filters after them.
*/
val MAIN_ORDER = listOf(ALL, FLAGGED, BLE, WIFI, CELLS, TRACKERS, DRONES, AIRCRAFT, RADIO, WAZE, EXTERNAL, SENTINELS, FAVORITES, NEW) + KINDS
+
+ /** The chips of a saved snapshot or trace: the main screen's, less those that only mean something live. */
+ val SAVED_ORDER = MAIN_ORDER.filterNot { it.liveOnly }
+
+ /** The main screen's chosen filter, when a saved snapshot or trace can use it (else All). */
+ fun savedStart(context: Context) = parse(Prefs.mapFilter(context)).takeIf { it in SAVED_ORDER } ?: ALL
}
}
diff --git a/app/src/main/java/com/rfsentinel/app/ui/MapFragment.kt b/app/src/main/java/com/rfsentinel/app/ui/MapFragment.kt
index 4ff0215..6a51587 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/MapFragment.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/MapFragment.kt
@@ -157,7 +157,7 @@ class MapFragment : Fragment() {
private val alive get() = _binding != null && isAdded && activity != null
private var tripId: Long? = null
private var trip: TripEntity? = null
- /** Which devices the map shows (live: every filter; a saved trace: all or flagged). */
+ /** Which devices the map shows (live: every filter; a saved trace: those that work on saved devices). */
private var filter = DeviceFilter.ALL
private val filterChips = HashMap<DeviceFilter, com.google.android.material.chip.Chip>()
private var centeredOnce = false
@@ -1277,8 +1277,8 @@ class MapFragment : Fragment() {
filter = DeviceFilter.ALL
return
}
- // The main screen's order; the choice is shared with it (a trace's own map keeps its own).
- val options = if (tripId == null) DeviceFilter.MAIN_ORDER.filter { it != DeviceFilter.RADIO } else listOf(DeviceFilter.ALL, DeviceFilter.FLAGGED)
+ // The main screen's order; the choice is shared with it (a trace starts on it, then keeps its own).
+ val options = if (tripId == null) DeviceFilter.MAIN_ORDER.filter { it != DeviceFilter.RADIO } else DeviceFilter.SAVED_ORDER
filter = DeviceFilter.parse(Prefs.mapFilter(act)).takeIf { it in options } ?: DeviceFilter.ALL
val group = binding.mapFilterChips
for (f in options) {
@@ -1462,7 +1462,12 @@ class MapFragment : Fragment() {
val r = rf
r?.safe("trip") {
r.drawTrace(points, RfMap.PAST_TRACE_COLOR)
- r.drawPins(devices.filter { it.lat != null && (it.flagged || filter == DeviceFilter.ALL) }.map { it.toPin() })
+ r.drawPins(devices.filter { it.lat != null && filter.matches(it) }.map { it.toPin() })
+ }
+ val placed = devices.filter { it.lat != null }
+ for ((f, chip) in filterChips) {
+ val n = placed.count { f.matches(it) }
+ chip.text = if (f == DeviceFilter.ALL || n > 0) "${f.label} $n" else f.label
}
val mins = ((t.endTime ?: System.currentTimeMillis()) - t.startTime) / 60000
// A snapshot has no route: where its devices were, and how many.
diff --git a/app/src/main/java/com/rfsentinel/app/ui/SnapshotActivity.kt b/app/src/main/java/com/rfsentinel/app/ui/SnapshotActivity.kt
index a589b47..e18e59d 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/SnapshotActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/SnapshotActivity.kt
@@ -41,7 +41,9 @@ class SnapshotActivity : AppCompatActivity() {
private var tripId = 0L
private var trip: TripEntity? = null
private var devices: List<TripDeviceEntity> = emptyList()
- private var onlyFlagged = false
+ /** The main screen's filters (those that work on saved devices), starting on its choice. */
+ private var filter = DeviceFilter.ALL
+ private val filterChips = LinkedHashMap<DeviceFilter, Chip>()
private val fmt = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT)
private val timeFmt = DateFormat.getTimeInstance(DateFormat.SHORT)
@@ -87,22 +89,31 @@ class SnapshotActivity : AppCompatActivity() {
binding.recyclerView.layoutManager = LinearLayoutManager(this)
binding.recyclerView.adapter = adapter
binding.searchInput.doAfterTextChanged { show() }
- onlyFlagged = savedInstanceState?.getBoolean("only_flagged") ?: false
- fun chip(label: String, flagged: Boolean) = binding.filterChips.addView(
- Chip(this, null, com.google.android.material.R.attr.chipStyle).apply {
- id = View.generateViewId(); text = label; isCheckable = true; isCheckedIconVisible = false
+ filter = savedInstanceState?.getString("filter")?.let(DeviceFilter::parse) ?: DeviceFilter.savedStart(this)
+ for (f in DeviceFilter.SAVED_ORDER) {
+ val chip = Chip(this, null, com.google.android.material.R.attr.chipStyle).apply {
+ id = View.generateViewId(); text = f.label; isCheckable = true; isCheckedIconVisible = false
ChipStyle.apply(this)
- isChecked = flagged == onlyFlagged
- setOnClickListener { onlyFlagged = flagged; show() }
- })
- chip("All", false)
- chip("Flagged", true)
+ }
+ filterChips[f] = chip
+ binding.filterChips.addView(chip)
+ if (f == filter) chip.isChecked = true
+ }
+ binding.filterChips.setOnCheckedStateChangeListener { _, ids ->
+ filter = filterChips.entries.firstOrNull { it.value.id == ids.firstOrNull() }?.key ?: return@setOnCheckedStateChangeListener
+ show()
+ }
+ // The main screen's choice may sit off screen: bring it into view.
+ filterChips[filter]?.let { chip ->
+ val row = binding.filterChips.parent as? android.widget.HorizontalScrollView
+ row?.post { if (chip.right > row.width) row.scrollTo((chip.left - row.width / 4).coerceAtLeast(0), 0) }
+ }
load()
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
- outState.putBoolean("only_flagged", onlyFlagged)
+ outState.putString("filter", filter.name)
}
private fun load() = lifecycleScope.launch {
@@ -118,10 +129,14 @@ class SnapshotActivity : AppCompatActivity() {
val t = trip ?: return
val q = binding.searchInput.text?.toString()?.trim().orEmpty()
val list = devices.filter { d ->
- (!onlyFlagged || d.flagged) && (q.isEmpty() ||
+ filter.matches(d) && (q.isEmpty() ||
listOfNotNull(d.mac, d.label, d.name, d.vendor, d.deviceType, DeviceIntel.savedType(d.deviceType, d.vendor, d.mac), d.evidence).any { it.contains(q, ignoreCase = true) })
}
adapter.items = list
+ for ((f, chip) in filterChips) {
+ val n = devices.count { f.matches(it) }
+ chip.text = if (f == DeviceFilter.ALL || n > 0) "${f.label} $n" else f.label
+ }
@Suppress("NotifyDataSetChanged") adapter.notifyDataSetChanged()
binding.emptyText.visibility = if (list.isEmpty()) View.VISIBLE else View.GONE
binding.emptyText.text = if (devices.isEmpty()) "This snapshot has no devices." else "Nothing matches."
diff --git a/app/src/test/java/com/rfsentinel/app/detect/IdentifyMoreTest.kt b/app/src/test/java/com/rfsentinel/app/detect/IdentifyMoreTest.kt
index 96a0a4c..d4ecf17 100644
--- a/app/src/test/java/com/rfsentinel/app/detect/IdentifyMoreTest.kt
+++ b/app/src/test/java/com/rfsentinel/app/detect/IdentifyMoreTest.kt
@@ -2,6 +2,7 @@ package com.rfsentinel.app.detect
import com.rfsentinel.app.service.DeviceRegistry
import com.rfsentinel.app.service.DeviceRegistry.GeoSample
+import com.rfsentinel.app.ui.DeviceFilter
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
@@ -118,9 +119,9 @@ class IdentifyMoreTest {
fun kindFiltersPickTheirDevices() {
DeviceRegistry.clear(); DeviceRegistry.startSession()
val kinds = mapOf(
- "BELL123" to com.rfsentinel.app.ui.DeviceFilter.ROUTERS, "xfinitywifi" to com.rfsentinel.app.ui.DeviceFilter.HOTSPOTS,
- "70mai_D06_1234" to com.rfsentinel.app.ui.DeviceFilter.CAMERAS, "TELLO-5A1B2C" to com.rfsentinel.app.ui.DeviceFilter.DRONES,
- "DIRECT-1F-[TV] Samsung Q60" to com.rfsentinel.app.ui.DeviceFilter.TVS, "ESP_1A2B3C" to com.rfsentinel.app.ui.DeviceFilter.SMART_HOME
+ "BELL123" to DeviceFilter.ROUTERS, "xfinitywifi" to DeviceFilter.HOTSPOTS,
+ "70mai_D06_1234" to DeviceFilter.CAMERAS, "TELLO-5A1B2C" to DeviceFilter.DRONES,
+ "DIRECT-1F-[TV] Samsung Q60" to DeviceFilter.TVS, "ESP_1A2B3C" to DeviceFilter.SMART_HOME
)
kinds.keys.forEachIndexed { i, ssid ->
val a = Advert("02:00:00:00:00:1$i", Advert.Source.WIFI, -60, ssid, wifi = Advert.WifiInfo(2437, "[WPA2-PSK-CCMP]", null, emptyList()))
@@ -130,11 +131,30 @@ class IdentifyMoreTest {
DeviceRegistry.report(buds, emptyList(), DeviceIntel.identify(buds), null, null, null)
val snaps = DeviceRegistry.snapshot()
kinds.forEach { (ssid, f) -> assertEquals(ssid, listOf(ssid), snaps.filter { f.matches(it) }.map { it.name }) }
- assertEquals(listOf(buds.mac), snaps.filter { com.rfsentinel.app.ui.DeviceFilter.AUDIO.matches(it) }.map { it.mac })
- assertTrue(snaps.none { com.rfsentinel.app.ui.DeviceFilter.VEHICLES.matches(it) || com.rfsentinel.app.ui.DeviceFilter.PHONES.matches(it) })
+ assertEquals(listOf(buds.mac), snaps.filter { DeviceFilter.AUDIO.matches(it) }.map { it.mac })
+ assertTrue(snaps.none { DeviceFilter.VEHICLES.matches(it) || DeviceFilter.PHONES.matches(it) })
DeviceRegistry.clear()
}
+ @Test
+ fun savedDevicesUseTheSameFilters() {
+ fun saved(mac: String, type: String?, source: String = "WIFI", category: String? = null, label: String = type ?: mac, vendor: String? = null) =
+ com.rfsentinel.app.data.TripDeviceEntity(1, mac, label, null, vendor, type, source, category, if (category != null) 60 else 0,
+ null, 0, 0, -60, null, null)
+ val router = saved("02:00:00:00:00:21", "Home router - Bell")
+ val tile = saved("D0:00:00:00:00:22", "Tile", "BLE", "TRACKER", "Tile tracker")
+ val buds = saved("C1:22:33:44:55:23", "Bose NC 700", "BLE")
+ val all = listOf(router, tile, buds)
+ assertEquals(listOf(router), all.filter { DeviceFilter.ROUTERS.matches(it) })
+ assertEquals(listOf(tile), all.filter { DeviceFilter.TRACKERS.matches(it) })
+ assertEquals(listOf(tile), all.filter { DeviceFilter.FLAGGED.matches(it) })
+ assertEquals(listOf(buds), all.filter { DeviceFilter.AUDIO.matches(it) })
+ assertEquals(listOf(tile, buds), all.filter { DeviceFilter.BLE.matches(it) })
+ // Filters that only mean something live aren't offered, and match nothing saved.
+ assertTrue(DeviceFilter.SAVED_ORDER.none { it.liveOnly } && DeviceFilter.KINDS.all { it in DeviceFilter.SAVED_ORDER })
+ assertTrue(all.none { DeviceFilter.NEW.matches(it) })
+ }
+
@Test
fun advertHashIsStable() {
assertEquals(AdvertFingerprint.hash("n=Buds|u=|d=|m=|t=|c="), AdvertFingerprint.hash("n=Buds|u=|d=|m=|t=|c="))