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.

Snapshot list uses the main list's adapter and rows

CIS-C05b8c0413a512
diff --git a/app/src/main/java/com/rfsentinel/app/MainActivity.kt b/app/src/main/java/com/rfsentinel/app/MainActivity.kt
index c5c647f..203fac5 100644
--- a/app/src/main/java/com/rfsentinel/app/MainActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/MainActivity.kt
@@ -52,10 +52,8 @@ class MainActivity : AppCompatActivity() {
private const val RADIO_LIVE_MS = 15_000L
/** Radio transmissions stay on the radar this long after they were last heard (the list keeps 5 minutes). */
private const val RADIO_RADAR_MS = 60_000L
- private const val BLUETOOTH_TAG_COLOR = 0xFF1565C0.toInt()
/** Location off: Android gives the app no Bluetooth or WiFi results. Tapping the warning opens the setting. */
private const val LOCATION_OFF = "Location is off - no devices can be seen. Tap to turn it on"
- private const val WIFI_TAG_COLOR = 0xFF00838F.toInt()
private const val REFRESH_MS = 1_000L
private const val WEAK_COLOR = 0xFFB26A00.toInt()
private const val WHITELIST_COLOR = 0xFF6B7B80.toInt()
@@ -782,14 +780,9 @@ class MainActivity : AppCompatActivity() {
* under the All filter. Read every 15 s while scanning; tap opens Tools > Cell towers.
*/
/** The radio tag on ordinary rows, like the purple CELL tag on cell towers. */
- private fun radioTag(s: DeviceRegistry.Snapshot): String = when {
- Advert.Source.BLE in s.sources && Advert.Source.WIFI in s.sources -> "BLUETOOTH + WIFI"
- Advert.Source.WIFI in s.sources -> "WIFI"
- else -> "BLUETOOTH"
- }
+ private fun radioTag(s: DeviceRegistry.Snapshot): String = com.rfsentinel.app.ui.DeviceRows.radioTag(s.sources)
- private fun radioColor(s: DeviceRegistry.Snapshot): Int =
- if (Advert.Source.BLE in s.sources) BLUETOOTH_TAG_COLOR else WIFI_TAG_COLOR
+ private fun radioColor(s: DeviceRegistry.Snapshot): Int = com.rfsentinel.app.ui.DeviceRows.radioColor(s.sources)
private fun liveCellCount(now: Long): Int =
if (ScanForegroundService.isRunning && now - com.rfsentinel.app.service.CellTowerStore.currentAt <= 60_000L)
@@ -983,7 +976,7 @@ class MainActivity : AppCompatActivity() {
private fun colorFor(s: DeviceRegistry.Snapshot): Int {
val best = s.best ?: return com.rfsentinel.app.ui.ThemeManager.ink(this, WHITELIST_COLOR)
- return com.rfsentinel.app.ui.ThemeManager.ink(this, if (best.tier == Tier.WEAK) WEAK_COLOR else best.category.colorArgb)
+ return com.rfsentinel.app.ui.DeviceRows.matchColor(this, best.category, best.tier)
}
private fun toRow(s: DeviceRegistry.Snapshot, now: Long, threshold: Int): DeviceRow {
diff --git a/app/src/main/java/com/rfsentinel/app/ui/DeviceRows.kt b/app/src/main/java/com/rfsentinel/app/ui/DeviceRows.kt
new file mode 100644
index 0000000..43abeee
--- /dev/null
+++ b/app/src/main/java/com/rfsentinel/app/ui/DeviceRows.kt
@@ -0,0 +1,78 @@
+package com.rfsentinel.app.ui
+
+import android.content.Context
+import com.rfsentinel.app.data.DeviceNames
+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.Tier
+import com.rfsentinel.app.util.ProximityUtil
+import java.text.DateFormat
+import java.util.Date
+
+/** The device list's row look, shared by the main list and saved snapshots so both read the same. */
+object DeviceRows {
+ const val BLUETOOTH_TAG_COLOR = 0xFF1565C0.toInt()
+ const val WIFI_TAG_COLOR = 0xFF00838F.toInt()
+ const val WEAK_COLOR = 0xFFB26A00.toInt()
+ const val WHITELIST_COLOR = 0xFF6B7B80.toInt()
+
+ /** An ordinary (not flagged) row's tag: the radios it was heard on. */
+ fun radioTag(sources: Set<Advert.Source>): String = when {
+ Advert.Source.BLE in sources && Advert.Source.WIFI in sources -> "BLUETOOTH + WIFI"
+ Advert.Source.WIFI in sources -> "WIFI"
+ else -> "BLUETOOTH"
+ }
+
+ fun radioColor(sources: Set<Advert.Source>): Int = if (Advert.Source.BLE in sources) BLUETOOTH_TAG_COLOR else WIFI_TAG_COLOR
+
+ /** A match's colour: weak matches amber, others their category's. */
+ fun matchColor(context: Context, category: Category, tier: Tier): Int =
+ ThemeManager.ink(context, if (tier == Tier.WEAK) WEAK_COLOR else category.colorArgb)
+
+ private val timeFmt = DateFormat.getTimeInstance(DateFormat.SHORT)
+
+ /** A device saved in a snapshot, as the main list shows a live one (heard from-to instead of "now"). */
+ fun saved(context: Context, d: TripDeviceEntity): DeviceRow {
+ val whitelisted = WhitelistCache.contains(d.mac)
+ val category = Category.parse(d.category)?.takeIf { d.confidence > 0 }
+ val tier = Tier.of(d.confidence)
+ val alert = category != null && d.flagged && !whitelisted
+ val sources = setOfNotNull(Advert.Source.entries.firstOrNull { it.name == d.source })
+ val type = DeviceIntel.savedType(d.deviceType, d.vendor, d.mac) ?: d.deviceType
+ val label = DeviceIntel.savedLabel(d.label, d.deviceType, d.vendor, d.mac)
+ val alias = DeviceNames.of(d.mac)
+ val tag = when {
+ whitelisted -> "WHITELISTED"
+ category != null -> "${category.shortTag} · ${tier.label} ${d.confidence}%"
+ else -> radioTag(sources)
+ }
+ val badges = buildList { if (Favorites.contains(d.mac)) add("★") }
+ return DeviceRow(
+ mac = d.mac,
+ title = alias ?: label,
+ subtitle = d.mac + (d.vendor?.let { " · $it" } ?: ""),
+ meta = listOfNotNull(
+ if (alias != null) label
+ else if (category != null && d.name != null && d.name != label) "\"${d.name}\"" else type?.takeIf { it != label },
+ if (category != null) sources.joinToString("+") { if (it == Advert.Source.BLE) "BLE" else "WiFi" }.ifEmpty { null } else null,
+ "${ProximityUtil.band(d.bestRssi)} ${d.bestRssi} dBm",
+ timeFmt.format(Date(d.firstSeen)) + "–" + timeFmt.format(Date(d.lastSeen))
+ ).joinToString(" · ") + if (badges.isNotEmpty()) " " + badges.joinToString(" ") else "",
+ tag = tag,
+ tagColor = when {
+ whitelisted -> ThemeManager.ink(context, WHITELIST_COLOR)
+ category == null -> ThemeManager.ink(context, radioColor(sources))
+ else -> matchColor(context, category, tier)
+ },
+ highlight = if (alert) matchColor(context, category!!, tier) else null,
+ flashing = false,
+ bold = alert,
+ rssi = d.bestRssi,
+ confidence = d.confidence.takeIf { category != null && !whitelisted }
+ )
+ }
+}
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 32125bc..4c80217 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/SnapshotActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/SnapshotActivity.kt
@@ -2,29 +2,22 @@ package com.rfsentinel.app.ui
import android.content.Intent
import android.os.Bundle
-import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuItem
import android.view.View
-import android.view.ViewGroup
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import androidx.core.widget.doAfterTextChanged
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
-import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.chip.Chip
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.rfsentinel.app.data.AppDatabase
import com.rfsentinel.app.data.TripDeviceEntity
import com.rfsentinel.app.data.TripEntity
import com.rfsentinel.app.databinding.ActivityLogBinding
-import com.rfsentinel.app.databinding.ItemDetectionBinding
-import com.rfsentinel.app.detect.Category
import com.rfsentinel.app.detect.DeviceIntel
-import com.rfsentinel.app.detect.Tier
import com.rfsentinel.app.util.Exporter
-import com.rfsentinel.app.util.ProximityUtil
import com.rfsentinel.app.util.applySystemBarInsets
import kotlinx.coroutines.launch
import java.text.DateFormat
@@ -45,44 +38,12 @@ class SnapshotActivity : AppCompatActivity() {
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)
- private val adapter = object : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
- /** Devices, and group headers (Group by) as their text. */
- var items: List<Any> = emptyList()
-
- override fun getItemCount() = items.size
-
- override fun getItemViewType(position: Int) = if (items[position] is String) 1 else 0
-
- override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
- if (viewType == 1) object : RecyclerView.ViewHolder(DeviceAdapter.groupHeader(parent)) {}
- else object : RecyclerView.ViewHolder(ItemDetectionBinding.inflate(LayoutInflater.from(parent.context), parent, false).root) {}
-
- override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
- val d = items[position]
- if (d is String) { (holder.itemView as android.widget.TextView).text = d; return }
- d as TripDeviceEntity
- val b = ItemDetectionBinding.bind(holder.itemView)
- val category = Category.parse(d.category)
- val type = DeviceIntel.savedType(d.deviceType, d.vendor, d.mac)
- val label = DeviceIntel.savedLabel(d.label, d.deviceType, d.vendor, d.mac)
- b.labelText.text = label
- b.labelText.setTextColor(
- if (category != null) ThemeManager.ink(this@SnapshotActivity, category.colorArgb) else b.macText.currentTextColor
- )
- b.macText.text = d.mac + (d.vendor?.let { " · $it" } ?: "")
- val parts = mutableListOf<String>()
- category?.let { parts += it.shortTag }
- if (d.confidence > 0) parts += "${Tier.of(d.confidence).label} ${d.confidence}%"
- d.name?.takeIf { it != d.label }?.let { parts += it }
- type?.takeIf { it != d.deviceType && it != label }?.let { parts += it }
- parts += "${if (d.source == "WIFI") "WiFi" else "Bluetooth"} ${ProximityUtil.band(d.bestRssi)} ${d.bestRssi} dBm"
- parts += timeFmt.format(Date(d.firstSeen)) + "–" + timeFmt.format(Date(d.lastSeen))
- b.metaText.text = parts.joinToString(" · ")
- holder.itemView.setOnClickListener { DeviceActions.openDetails(this@SnapshotActivity, d.mac) }
- }
- }
+ /** The main list's own rows and adapter, so a snapshot reads exactly like the live list. */
+ private val adapter = DeviceAdapter(
+ onClick = { DeviceActions.openDetails(this, it.mac) },
+ onLongPress = { DeviceActions.showQuickActions(this, it.mac) }
+ )
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -94,6 +55,9 @@ class SnapshotActivity : AppCompatActivity() {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
binding.recyclerView.layoutManager = LinearLayoutManager(this)
binding.recyclerView.adapter = adapter
+ // As the main list: room under the last row.
+ binding.recyclerView.clipToPadding = false
+ binding.recyclerView.setPadding(0, 0, 0, (8 * resources.displayMetrics.density).toInt())
binding.searchInput.doAfterTextChanged { show() }
filter = savedInstanceState?.getString("filter")?.let(DeviceFilter::parse) ?: DeviceFilter.savedStart(this)
for (f in DeviceFilter.SAVED_ORDER) {
@@ -148,12 +112,14 @@ class SnapshotActivity : AppCompatActivity() {
compareBy<DeviceOrder.Item<TripDeviceEntity>> { it.value.category == null }.thenByDescending { it.value.confidence }
.thenByDescending { it.rssi }
)
- adapter.items = sections.flatMap { sec -> listOfNotNull(sec.header?.let { DeviceOrder.headerLabel(sec) }) + sec.items }
+ adapter.visual = VisualMode.on(this, VisualMode.Screen.DEVICE_LIST)
+ adapter.submitList(sections.flatMap { sec ->
+ listOfNotNull(sec.header?.let { DeviceRow.header(it, DeviceOrder.headerLabel(sec)) }) + sec.items.map { DeviceRows.saved(this, it) }
+ })
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."
supportActionBar?.subtitle = fmt.format(Date(t.startTime)) + " · " +