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.

WiGLE results bottom sheet, Find button, where networks were asked for

CIS-C08cfa86253636
diff --git a/app/src/main/java/com/rfsentinel/app/data/ProbeLog.kt b/app/src/main/java/com/rfsentinel/app/data/ProbeLog.kt
index c2df4f3..7c7a34b 100644
--- a/app/src/main/java/com/rfsentinel/app/data/ProbeLog.kt
+++ b/app/src/main/java/com/rfsentinel/app/data/ProbeLog.kt
@@ -26,16 +26,18 @@ object ProbeLog {
/**
* Records that [mac] asked for each of [ssids], with what else its frames said about it ([wps],
- * [fingerprint]: kept for a device that asked for a name). Only while recording is on, or
- * [force]d: a map trace recording keeps them too.
+ * [fingerprint]: kept for a device that asked for a name), and where this phone was ([at]). Only
+ * while recording is on, or [force]d: a map trace recording keeps them too.
*/
@Synchronized
fun record(context: Context, mac: String, ssids: Collection<String>, rssi: Int, now: Long = System.currentTimeMillis(),
- force: Boolean = false, wps: com.rfsentinel.app.usb.ProbeIntel.Wps? = null, fingerprint: String? = null) {
+ force: Boolean = false, wps: com.rfsentinel.app.usb.ProbeIntel.Wps? = null, fingerprint: String? = null,
+ at: Pair<Double, Double>? = null) {
if (ssids.isEmpty() && wps == null && fingerprint == null) return
if (!(force || com.rfsentinel.app.util.Prefs.recordProbes(context))) return
ensureLoaded(context)
- ssids.forEach { book.record(it, mac, rssi, now) }
+ ssids.forEach { book.record(it, mac, rssi, now, at) }
+ if (at != null && onMap?.let { m -> ssids.any { it.equals(m, ignoreCase = true) } } == true) version++
if (!book.recordDevice(mac, ssids, rssi, now, wps?.deviceName, wps?.product, fingerprint)) return
dirty = true
if (now - lastSave > SAVE_EVERY_MS) save(context, now)
@@ -44,6 +46,19 @@ object ProbeLog {
@Synchronized
fun all(context: Context): List<ProbeBook.Network> { ensureLoaded(context); return book.all() }
+ @Synchronized
+ fun network(context: Context, ssid: String): ProbeBook.Network? { ensureLoaded(context); return book.network(ssid) }
+
+ /** The network whose request spots the map shows ("Show on map"), or null. */
+ @Volatile var onMap: String? = null
+ private set
+
+ /** Bumped when [onMap] or a place changes, so the map redraws only then. */
+ @Volatile var version = 0
+ private set
+
+ fun showOnMap(ssid: String?) { onMap = ssid; version++ }
+
/** The devices that asked, grouped ([ProbeBook.groups]), newest first. */
@Synchronized
fun groups(context: Context): List<ProbeBook.Group> {
@@ -56,10 +71,10 @@ object ProbeLog {
fun sharing(context: Context, fp: String): Int { ensureLoaded(context); return book.sharing(fp) }
@Synchronized
- fun remove(context: Context, ssid: String) { ensureLoaded(context); book.remove(ssid); dirty = true; save(context) }
+ fun remove(context: Context, ssid: String) { ensureLoaded(context); book.remove(ssid); version++; dirty = true; save(context) }
@Synchronized
- fun clear(context: Context) { ensureLoaded(context); book.clear(); dirty = true; save(context) }
+ fun clear(context: Context) { ensureLoaded(context); book.clear(); version++; dirty = true; save(context) }
/** Writes pending changes (the scan stopping, the list closing). */
@Synchronized
@@ -114,9 +129,14 @@ class ProbeBook(private val maxNetworks: Int = 1000, private val maxDevices: Int
var encounters: Int,
var lastRssi: Int,
/** Devices that asked for it, most recent last. */
- val devices: MutableList<String>
+ val devices: MutableList<String>,
+ /** Where it was asked for (this phone's position when heard), oldest first. */
+ val spots: MutableList<Spot> = mutableListOf()
)
+ /** One place a network was asked for: the strongest request heard there, by [mac], last heard [at]. */
+ data class Spot(val lat: Double, val lon: Double, val at: Long, val mac: String, val rssi: Int)
+
/** A device that asked for networks: what it asked for and what its frames said about it. */
data class Device(
val mac: String,
@@ -149,22 +169,41 @@ class ProbeBook(private val maxNetworks: Int = 1000, private val maxDevices: Int
private val nets = LinkedHashMap<String, Network>()
private val probers = LinkedHashMap<String, Device>()
- fun record(ssid: String, mac: String, rssi: Int, now: Long) {
+ /** Notes that [mac] asked for [ssid], heard where this phone was ([at], when it had a fix). */
+ fun record(ssid: String, mac: String, rssi: Int, now: Long, at: Pair<Double, Double>? = null) {
val key = ssid.lowercase()
+ val m = mac.uppercase()
val n = nets[key]
if (n == null) {
- nets[key] = Network(ssid, now, now, 1, rssi, mutableListOf(mac.uppercase()))
+ nets[key] = Network(ssid, now, now, 1, rssi, mutableListOf(m)).also { at?.let { p -> spot(it, m, rssi, now, p) } }
trim()
return
}
if (now - n.lastSeen > GAP_MS) n.encounters++
n.lastSeen = now
n.lastRssi = rssi
- val m = mac.uppercase()
n.devices.remove(m); n.devices.add(m)
while (n.devices.size > maxDevices) n.devices.removeAt(0)
+ at?.let { spot(n, m, rssi, now, it) }
}
+ /**
+ * A new place, or the last one again (same encounter, within [SPOT_M]): there it moves to the
+ * strongest request, the one heard closest to the device.
+ */
+ private fun spot(n: Network, mac: String, rssi: Int, now: Long, at: Pair<Double, Double>) {
+ val last = n.spots.lastOrNull()
+ if (last != null && now - last.at <= GAP_MS && meters(last.lat, last.lon, at.first, at.second) < SPOT_M) {
+ n.spots[n.spots.lastIndex] = if (rssi > last.rssi) Spot(at.first, at.second, now, mac, rssi) else last.copy(at = now)
+ return
+ }
+ n.spots.add(Spot(at.first, at.second, now, mac, rssi))
+ while (n.spots.size > MAX_SPOTS) n.spots.removeAt(0)
+ }
+
+ /** One network by name, or null. */
+ fun network(ssid: String): Network? = nets[ssid.lowercase()]?.let { it.copy(devices = it.devices.toMutableList(), spots = it.spots.toMutableList()) }
+
/**
* Notes what [mac] asked for and said about itself. A device that never asked for a name isn't
* kept; returns false when nothing was noted.
@@ -221,7 +260,7 @@ class ProbeBook(private val maxNetworks: Int = 1000, private val maxDevices: Int
}
/** Newest first. */
- fun all(): List<Network> = nets.values.sortedByDescending { it.lastSeen }.map { it.copy(devices = it.devices.toMutableList()) }
+ fun all(): List<Network> = nets.values.sortedByDescending { it.lastSeen }.map { it.copy(devices = it.devices.toMutableList(), spots = it.spots.toMutableList()) }
/** Forgets [ssid], and the devices that asked for nothing else. */
fun remove(ssid: String) {
@@ -267,7 +306,8 @@ class ProbeBook(private val maxNetworks: Int = 1000, private val maxDevices: Int
nets.clear()
@Suppress("SENSELESS_COMPARISON", "USELESS_ELVIS") // Gson can leave fields null
list.filter { it.ssid != null }.forEach {
- nets[it.ssid.lowercase()] = it.copy(devices = (it.devices ?: mutableListOf()).toMutableList())
+ nets[it.ssid.lowercase()] = it.copy(devices = (it.devices ?: mutableListOf()).toMutableList(),
+ spots = (it.spots ?: mutableListOf()).filter { s -> s != null }.toMutableList())
}
trim()
}
@@ -279,5 +319,14 @@ class ProbeBook(private val maxNetworks: Int = 1000, private val maxDevices: Int
companion object {
const val GAP_MS = 10 * 60_000L
+ /** Requests heard this close together, in one encounter, are one place. */
+ const val SPOT_M = 200.0
+ const val MAX_SPOTS = 50
+
+ private fun meters(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double {
+ val dLat = Math.toRadians(lat2 - lat1)
+ val dLon = Math.toRadians(lon2 - lon1) * kotlin.math.cos(Math.toRadians((lat1 + lat2) / 2))
+ return 6_371_000.0 * kotlin.math.sqrt(dLat * dLat + dLon * dLon)
+ }
}
}
diff --git a/app/src/main/java/com/rfsentinel/app/probes/ProbeListActivity.kt b/app/src/main/java/com/rfsentinel/app/probes/ProbeListActivity.kt
index c4d1376..e511fee 100644
--- a/app/src/main/java/com/rfsentinel/app/probes/ProbeListActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/probes/ProbeListActivity.kt
@@ -205,15 +205,44 @@ class ProbeListActivity : AppCompatActivity() {
val df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)
val devices = n.devices.reversed().joinToString("\n") { mac -> "$mac ${maker(mac)}" }
val watched = OuiWatchlist.isProbeWatched(n.ssid)
- MaterialAlertDialogBuilder(this)
+ val dp = resources.displayMetrics.density
+ val spots = n.spots
+ val where = if (spots.isEmpty()) "Where: not known (heard without a GPS fix, or before places were kept)"
+ else if (spots.size == 1) "Asked for at 1 place" else "Asked for at ${spots.size} places"
+ lateinit var dialog: androidx.appcompat.app.AlertDialog
+ val body = LinearLayout(this).apply {
+ orientation = LinearLayout.VERTICAL
+ val pad = (20 * dp).toInt(); setPadding(pad, (8 * dp).toInt(), pad, 0)
+ addView(TextView(this@ProbeListActivity).apply {
+ text = "First seen ${df.format(Date(n.firstSeen))}\nLast seen ${df.format(Date(n.lastSeen))}\n$where\n\n" +
+ "Devices that asked for it:\n$devices"
+ setTextIsSelectable(true)
+ })
+ if (spots.isNotEmpty()) addView(com.google.android.material.button.MaterialButton(this@ProbeListActivity, null,
+ com.google.android.material.R.attr.materialButtonOutlinedStyle).apply {
+ text = "Show on map"
+ setOnClickListener { dialog.dismiss(); showOnMap(n) }
+ }, LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)
+ .apply { topMargin = (8 * dp).toInt() })
+ }
+ dialog = MaterialAlertDialogBuilder(this)
.setTitle(n.ssid)
- .setMessage("First seen ${df.format(Date(n.firstSeen))}\nLast seen ${df.format(Date(n.lastSeen))}\n\nDevices that asked for it:\n$devices")
+ .setView(ScrollView(this).apply { addView(body) })
.setPositiveButton(if (watched) "Stop watching" else "Watch") { _, _ -> if (watched) unwatch(n.ssid) else watch(n.ssid) }
.setNeutralButton("Remove from list") { _, _ -> ProbeLog.remove(this, n.ssid); refresh() }
.setNegativeButton("Find on WiGLE") { _, _ -> WigleUi.search(this, n.ssid) }
.show()
}
+ /** The map with the places [n] was asked for, on the latest one. */
+ private fun showOnMap(n: ProbeBook.Network) {
+ val last = n.spots.lastOrNull() ?: return
+ ProbeLog.showOnMap(n.ssid)
+ startActivity(android.content.Intent(this, com.rfsentinel.app.ui.MapActivity::class.java)
+ .putExtra(com.rfsentinel.app.ui.MapActivity.EXTRA_CENTER_LAT, last.lat)
+ .putExtra(com.rfsentinel.app.ui.MapActivity.EXTRA_CENTER_LON, last.lon))
+ }
+
/** A device (or a group of addresses likely to be one): what it is, and every name it asked for as chips. */
private fun deviceDetails(g: ProbeBook.Group) {
val df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)
@@ -287,6 +316,7 @@ class ProbeListActivity : AppCompatActivity() {
holder.b.metaText.text = meta(n, System.currentTimeMillis())
holder.b.watchButton.text = if (watched) "Watching" else "Watch"
holder.b.watchButton.setOnClickListener { if (watched) unwatch(n.ssid) else watch(n.ssid) }
+ holder.b.findButton.setOnClickListener { WigleUi.search(this@ProbeListActivity, n.ssid) }
holder.b.root.setOnClickListener { details(n) }
}
}
@@ -301,6 +331,7 @@ class ProbeListActivity : AppCompatActivity() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
VH(ItemProbeBinding.inflate(LayoutInflater.from(parent.context), parent, false).also {
it.watchButton.visibility = View.GONE
+ it.findButton.visibility = View.GONE
})
override fun getItemCount() = items.size
diff --git a/app/src/main/java/com/rfsentinel/app/probes/WigleUi.kt b/app/src/main/java/com/rfsentinel/app/probes/WigleUi.kt
index ada36c5..0465e28 100644
--- a/app/src/main/java/com/rfsentinel/app/probes/WigleUi.kt
+++ b/app/src/main/java/com/rfsentinel/app/probes/WigleUi.kt
@@ -4,12 +4,25 @@ import android.content.Context
import android.content.Intent
import android.location.Location
import android.location.LocationManager
+import android.graphics.Typeface
+import android.text.SpannableString
+import android.text.Spanned
+import android.text.TextUtils
+import android.text.style.StyleSpan
+import android.util.TypedValue
+import android.view.ViewGroup
import android.widget.EditText
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
+import androidx.recyclerview.widget.DividerItemDecoration
+import androidx.recyclerview.widget.LinearLayoutManager
+import androidx.recyclerview.widget.RecyclerView
+import com.google.android.material.bottomsheet.BottomSheetBehavior
+import com.google.android.material.bottomsheet.BottomSheetDialog
+import com.google.android.material.button.MaterialButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.rfsentinel.app.online.Wigle
import com.rfsentinel.app.online.WiglePins
@@ -157,16 +170,79 @@ object WigleUi {
}
val nets = if (me == null) answer.nets
else answer.nets.sortedBy { DeviceRegistry.metersBetween(me.first, me.second, it.lat, it.lon) }
- val rows = nets.map { n -> line(n, me) }.toTypedArray()
val where = if (answer.near) "within ${Wigle.NEAR_KM.toInt()} km" else "worldwide"
- val more = if (answer.total > nets.size) " (${nets.size} of ${answer.total} shown)" else ""
- MaterialAlertDialogBuilder(a)
- .setTitle("\"$text\" $where$more")
- .setItems(rows) { _, which -> pinAndShow(a, listOf(nets[which]), text, nets[which]) }
- .setPositiveButton("Pin all on map") { _, _ -> pinAndShow(a, nets, text, nets.first()) }
- .apply { if (answer.near) setNeutralButton("Worldwide") { _, _ -> search(a, text, worldwide = true) } }
- .setNegativeButton("Close", null)
- .show()
+ val dp = a.resources.displayMetrics.density
+ fun px(v: Int) = (v * dp).toInt()
+ val pad = px(20)
+ val sheet = BottomSheetDialog(a)
+
+ // Title and count on top, the answers scrolling in the middle, the buttons always at the bottom.
+ val header = LinearLayout(a).apply {
+ orientation = LinearLayout.VERTICAL
+ setPadding(pad, px(16), pad, px(8))
+ addView(TextView(a).apply {
+ this.text = "\"$text\" $where"
+ textSize = 18f; setTypeface(typeface, Typeface.BOLD)
+ maxLines = 2; ellipsize = TextUtils.TruncateAt.END
+ })
+ addView(TextView(a).apply {
+ this.text = (if (answer.total > nets.size) "${nets.size} of ${answer.total} shown"
+ else if (nets.size == 1) "1 network" else "${nets.size} networks") +
+ if (me != null && nets.size > 1) ", nearest first" else ""
+ textSize = 13f; alpha = 0.75f
+ })
+ }
+ val tapBackground = TypedValue().also { a.theme.resolveAttribute(android.R.attr.selectableItemBackground, it, true) }.resourceId
+ val list = RecyclerView(a).apply {
+ layoutManager = LinearLayoutManager(a)
+ addItemDecoration(DividerItemDecoration(a, DividerItemDecoration.VERTICAL))
+ adapter = object : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
+ override fun getItemCount() = nets.size
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = object : RecyclerView.ViewHolder(
+ TextView(a).apply {
+ layoutParams = RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
+ setPadding(pad, px(10), pad, px(10))
+ textSize = 14f
+ setBackgroundResource(tapBackground)
+ }) {}
+ override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
+ val n = nets[position]
+ val row = line(n, me)
+ val nameEnd = row.indexOf('\n').takeIf { it >= 0 } ?: row.length
+ (holder.itemView as TextView).text = SpannableString(row).apply {
+ setSpan(StyleSpan(Typeface.BOLD), 0, nameEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
+ }
+ holder.itemView.setOnClickListener { sheet.dismiss(); pinAndShow(a, listOf(n), text, n) }
+ }
+ }
+ }
+ val buttons = LinearLayout(a).apply {
+ orientation = LinearLayout.HORIZONTAL
+ setPadding(px(16), px(8), px(16), px(12))
+ fun button(label: String, filled: Boolean, onClick: () -> Unit) = addView(
+ (if (filled) MaterialButton(a) else MaterialButton(a, null, com.google.android.material.R.attr.materialButtonOutlinedStyle)).apply {
+ this.text = label; maxLines = 1; ellipsize = TextUtils.TruncateAt.END
+ setOnClickListener { sheet.dismiss(); onClick() }
+ },
+ LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f).apply { marginStart = px(4); marginEnd = px(4) })
+ button("Pin all", true) { pinAndShow(a, nets, text, nets.first()) }
+ if (answer.near) button("Worldwide", false) { search(a, text, worldwide = true) }
+ button("Close", false) {}
+ }
+ // At most ~85% of the screen: the list gives up the height, never the header or the buttons.
+ val maxHeight = (a.resources.displayMetrics.heightPixels * 0.85).toInt()
+ val root = object : LinearLayout(a) {
+ override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) = super.onMeasure(widthMeasureSpec,
+ MeasureSpec.makeMeasureSpec(minOf(maxHeight, MeasureSpec.getSize(heightMeasureSpec).takeIf { it > 0 } ?: maxHeight), MeasureSpec.AT_MOST))
+ }.apply {
+ orientation = LinearLayout.VERTICAL
+ addView(header)
+ addView(list, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f))
+ addView(buttons)
+ }
+ sheet.setContentView(root)
+ sheet.behavior.apply { skipCollapsed = true; state = BottomSheetBehavior.STATE_EXPANDED }
+ sheet.show()
}
/** One answer as a list row: name and address, then where, when and how far. */
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 bba5b5d..af9cef5 100644
--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
@@ -712,8 +712,11 @@ class ScanForegroundService : Service() {
skeleton: Long? = null) {
com.rfsentinel.app.usb.ProbeIntel.note(mac, wps, fingerprint, ssids, hidden, skeleton)
// Kept in the requested-networks list when that's on, and always while a trace records.
+ // Where it was asked for: this phone's position, when the fix is fresh and good enough to place devices.
+ val at = lastFix?.takeIf { usableForPlacing(it) }
+ ?.let { it.latitude to it.longitude }
com.rfsentinel.app.data.ProbeLog.record(this, mac, ssids, rssi, now, force = TripRecorder.isRecording,
- wps = wps, fingerprint = fingerprint)
+ wps = wps, fingerprint = fingerprint, at = at)
val hits = OuiWatchlist.probeHits(ssids) + OuiWatchlist.fingerprintHits(fingerprint) + OuiWatchlist.wpsHits(wps) +
OuiWatchlist.fingerprintHits(skeleton?.let { com.rfsentinel.app.usb.ProbeIntel.shapeKey(it) })
if (hits.isEmpty()) return
diff --git a/app/src/main/java/com/rfsentinel/app/ui/MapShared.kt b/app/src/main/java/com/rfsentinel/app/ui/MapShared.kt
index 0005d84..c716450 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/MapShared.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/MapShared.kt
@@ -110,6 +110,27 @@ internal object MapDialogs {
.show()
}
+ /** A place where [ssid] was asked for; [hide] takes that network's places off the map. */
+ fun showAsked(a: AppCompatActivity, ssid: String, s: com.rfsentinel.app.data.ProbeBook.Spot, me: Pair<Double, Double>?, hide: () -> Unit) {
+ val df = java.text.DateFormat.getDateTimeInstance(java.text.DateFormat.SHORT, java.text.DateFormat.SHORT)
+ val maker = if (com.rfsentinel.app.util.MacUtil.isRandomized(s.mac)) "random address"
+ else com.rfsentinel.app.detect.VendorDb.macVendor(s.mac) ?: "unknown maker"
+ val text = buildString {
+ append("Asked for by ${s.mac} $maker\n")
+ append("Last heard here: ${df.format(java.util.Date(s.at))}\n")
+ append("Signal: ${s.rssi} dBm\n")
+ me?.let { append("Distance: " + com.rfsentinel.app.util.Units.distance(
+ DeviceRegistry.metersBetween(it.first, it.second, s.lat, s.lon)) + "\n") }
+ append("\nWhere this phone was when it heard the strongest request at this spot. The device was within WiFi range of it.")
+ }
+ MaterialAlertDialogBuilder(a)
+ .setTitle(ssid)
+ .setMessage(text)
+ .setPositiveButton("Hide from map") { _, _ -> hide() }
+ .setNegativeButton("Close", null)
+ .show()
+ }
+
/** [me] = your position (lat, lon) for the distance, when known. */
fun showAircraft(a: AppCompatActivity, p: com.rfsentinel.app.online.PoliceAircraft.Plane, hit: com.rfsentinel.app.detect.Hit?,
me: Pair<Double, Double>?) {
diff --git a/app/src/main/java/com/rfsentinel/app/ui/RfMap.kt b/app/src/main/java/com/rfsentinel/app/ui/RfMap.kt
index 85ae495..f28c06e 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/RfMap.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/RfMap.kt
@@ -7,6 +7,7 @@ import com.rfsentinel.app.alpr.AlprStore
import com.rfsentinel.app.alpr.Cctv
import com.rfsentinel.app.alpr.CctvStore
import com.rfsentinel.app.alpr.KnownCamera
+import com.rfsentinel.app.data.ProbeLog
import com.rfsentinel.app.online.PoliceAircraft
import com.rfsentinel.app.online.WazePolice
import com.rfsentinel.app.online.WiglePins
@@ -50,6 +51,7 @@ internal class RfMap(private val activity: AppCompatActivity, val map: MapEngine
private const val WAZE = "rf-waze"; private const val DRONE_OPS = "rf-drone-ops"; private const val DRONES = "rf-drones"
private const val AIRCRAFT = "rf-aircraft"
private const val WIGLE = "rf-wigle"; private const val WIGLE_COLOR = "#8E24AA"
+ private const val ASKED = "rf-asked"; private const val ASKED_COLOR = "#00897B"
private const val NAV_ROUTES = "rf-nav-routes"; private const val NAV_PLACES = "rf-nav-places"
private const val NAV_ROUTE_COLOR = "#1A73E8"; private const val NAV_ALT_COLOR = "#7C8DA6"
@@ -92,6 +94,9 @@ internal class RfMap(private val activity: AppCompatActivity, val map: MapEngine
private var wigle: Map<String, WiglePins.Pin> = emptyMap()
/** What the WiGLE layer was drawn for (pins' version, filter, trace mode): redrawn only when it changes. */
private var wigleDrawn: String? = null
+ /** The places the shown requested network was asked for, by id, and what they were drawn for. */
+ private var asked: Map<String, com.rfsentinel.app.data.ProbeBook.Spot> = emptyMap()
+ private var askedDrawn: String? = null
/** The area the camera, CCTV and tower layers were drawn for (redrawn when the view leaves it). */
private var staticBox: MapEngine.Box? = null
private var staticAt = 0L
@@ -113,9 +118,11 @@ internal class RfMap(private val activity: AppCompatActivity, val map: MapEngine
val (ink, halo) = labelColors(dark)
map.setPaint(LABELS, "text-color", ink); map.setPaint(LABELS, "text-halo-color", halo)
map.setPaint("$WIGLE-labels", "text-color", ink); map.setPaint("$WIGLE-labels", "text-halo-color", halo)
+ map.setPaint("$ASKED-labels", "text-color", ink); map.setPaint("$ASKED-labels", "text-halo-color", halo)
}
staticBox = null
wigleDrawn = null
+ askedDrawn = null
safe("loaded") { onLoaded() }
}
}
@@ -143,7 +150,7 @@ internal class RfMap(private val activity: AppCompatActivity, val map: MapEngine
/** Every layer, as map style JSON (the same on both engines). */
private fun addLayers(dark: Boolean) {
- listOf(NAV_ROUTES, NAV_PLACES, PRECISION, CONES, CAM_CONES, TRACE, DRONE_LINES, TOWERS, CCTV, CAMERAS, DEVICES, WIGLE, WAZE, DRONE_OPS, DRONES, AIRCRAFT)
+ listOf(NAV_ROUTES, NAV_PLACES, PRECISION, CONES, CAM_CONES, TRACE, DRONE_LINES, TOWERS, CCTV, CAMERAS, DEVICES, WIGLE, ASKED, WAZE, DRONE_OPS, DRONES, AIRCRAFT)
.forEach { map.addSource(it) }
fun get(k: String) = a("get", k)
val color = a("to-color", get("color"))
@@ -209,6 +216,13 @@ internal class RfMap(private val activity: AppCompatActivity, val map: MapEngine
layout = o("text-field" to get("label"), "text-font" to font, "text-size" to 12.0, "text-anchor" to "top",
"text-offset" to a(0.0, 1.0), "text-optional" to true),
paint = o("text-color" to ink, "text-halo-color" to halo, "text-halo-width" to 1.5)),
+ // Where a requested network was asked for ("Show on map" in the list): teal, with when.
+ layer(ASKED, "circle", paint = o("circle-color" to ASKED_COLOR, "circle-radius" to 7.0,
+ "circle-stroke-color" to "#FFFFFF", "circle-stroke-width" to 2.0)),
+ layer("$ASKED-labels", "symbol", ASKED,
+ layout = o("text-field" to get("label"), "text-font" to font, "text-size" to 12.0, "text-anchor" to "top",
+ "text-offset" to a(0.0, 1.0), "text-optional" to true),
+ paint = o("text-color" to ink, "text-halo-color" to halo, "text-halo-width" to 1.5)),
// Waze reports: blue police, red accident, orange hazard, brown closure, purple jam.
layer(WAZE, "circle", paint = o("circle-color" to color, "circle-radius" to 9.0,
"circle-stroke-color" to "#FFFFFF", "circle-stroke-width" to 2.0)),
@@ -329,6 +343,7 @@ internal class RfMap(private val activity: AppCompatActivity, val map: MapEngine
})
drawWigle()
+ drawAsked()
val trace = if (TripRecorder.isRecording) TripRecorder.livePoints() else emptyList()
drawTrace(trace.map { it.lat to it.lon }, TRACE_COLOR)
return shown
@@ -348,6 +363,21 @@ internal class RfMap(private val activity: AppCompatActivity, val map: MapEngine
})
}
+ /** Where the network picked in the requested-networks list was asked for, when it changed. */
+ fun drawAsked() {
+ if (!ready()) return
+ val ssid = ProbeLog.onMap
+ val key = "${ProbeLog.version}|$ssid|$tripMode"
+ if (key == askedDrawn) return
+ askedDrawn = key
+ val spots = if (ssid == null || tripMode) emptyList() else ProbeLog.network(activity, ssid)?.spots.orEmpty()
+ val df = java.text.DateFormat.getDateTimeInstance(java.text.DateFormat.SHORT, java.text.DateFormat.SHORT)
+ asked = spots.withIndex().associate { (i, s) -> "asked-$i" to s }
+ set(ASKED, asked.map { (id, s) ->
+ GeoJson.feature(GeoJson.point(s.lat, s.lon), "id" to id, "label" to df.format(java.util.Date(s.at)))
+ })
+ }
+
/**
* Cameras, CCTV and cell towers: many, and they don't move - drawn for the area in view (and
* around it), again once the view leaves that area or every 15 s for new downloads.
@@ -493,7 +523,7 @@ internal class RfMap(private val activity: AppCompatActivity, val map: MapEngine
val r = 22f * activity.resources.displayMetrics.density
val box = RectF(x - r, y - r, x + r, y + r)
val asked = listOf(AIRCRAFT to "hex", WAZE to "id", DRONES to "mac", DRONE_OPS to "mac", DOTS to "mac",
- CAMERAS to "id", CCTV to "id", TOWERS to "id", WIGLE to "id")
+ CAMERAS to "id", CCTV to "id", TOWERS to "id", WIGLE to "id", ASKED to "id")
map.query(box, asked) { found ->
if (activity.isFinishing || activity.isDestroyed) return@query
safe("tap") { showTapped(found, me) }
@@ -508,6 +538,11 @@ internal class RfMap(private val activity: AppCompatActivity, val map: MapEngine
MapDialogs.showWigle(activity, p, me) { WiglePins.remove(activity, p.net.bssid); drawWigle() }
return
}
+ found[9].firstNotNullOfOrNull { asked[it] }?.let { s ->
+ val ssid = ProbeLog.onMap ?: return
+ MapDialogs.showAsked(activity, ssid, s, me) { ProbeLog.showOnMap(null); drawAsked() }
+ return
+ }
(drone + op).firstNotNullOfOrNull { drones[it] }?.let { s ->
MapDialogs.showDrone(activity, s.mac, MapDialogs.droneDetails(s, s.remoteId!!)); return
}
diff --git a/app/src/main/res/layout/item_probe.xml b/app/src/main/res/layout/item_probe.xml
index 3220723..707e72b 100644
--- a/app/src/main/res/layout/item_probe.xml
+++ b/app/src/main/res/layout/item_probe.xml
@@ -34,4 +34,12 @@
android:layout_height="wrap_content"
android:text="Watch" />
+ <Button
+ android:id="@+id/findButton"
+ style="@style/Widget.MaterialComponents.Button.OutlinedButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="6dp"
+ android:text="Find" />
+
</LinearLayout>
diff --git a/app/src/test/java/com/rfsentinel/app/data/ProbeSpotsTest.kt b/app/src/test/java/com/rfsentinel/app/data/ProbeSpotsTest.kt
new file mode 100644
index 0000000..b722cf0
--- /dev/null
+++ b/app/src/test/java/com/rfsentinel/app/data/ProbeSpotsTest.kt
@@ -0,0 +1,56 @@
+package com.rfsentinel.app.data
+
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertNull
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+class ProbeSpotsTest {
+
+ private val here = 10.0 to 20.0
+ private val nextDoor = 10.0005 to 20.0 // ~55 m away
+ private val farAway = 10.01 to 20.0 // ~1.1 km away
+
+ @Test
+ fun nearbyRequestsInOneEncounterAreOnePlaceAtTheStrongest() {
+ val b = ProbeBook()
+ b.record("Home", "02:00:00:00:00:01", -80, 0, here)
+ b.record("Home", "02:00:00:00:00:02", -60, 1_000, nextDoor)
+ b.record("Home", "02:00:00:00:00:01", -90, 2_000, here)
+ val s = b.network("home")!!.spots.single()
+ assertEquals(nextDoor.first, s.lat, 0.0)
+ assertEquals(-60, s.rssi)
+ assertEquals("02:00:00:00:00:02", s.mac)
+ assertEquals(2_000L, s.at)
+ }
+
+ @Test
+ fun anotherPlaceOrALaterEncounterIsANewSpot() {
+ val b = ProbeBook()
+ b.record("Home", "02:00:00:00:00:01", -70, 0, here)
+ b.record("Home", "02:00:00:00:00:01", -70, 1_000, farAway)
+ b.record("Home", "02:00:00:00:00:01", -70, 2_000 + ProbeBook.GAP_MS + 1, farAway)
+ assertEquals(3, b.network("Home")!!.spots.size)
+ }
+
+ @Test
+ fun noFixNoPlaceAndOldListsLoad() {
+ val b = ProbeBook()
+ b.record("Cafe", "02:00:00:00:00:01", -70, 0)
+ assertTrue(b.network("Cafe")!!.spots.isEmpty())
+ // A list saved before places were kept: Gson leaves the field null.
+ val old = ProbeBook.Network("Office", 1, 2, 1, -50, mutableListOf("AA:AA:AA:AA:AA:01"))
+ val f = ProbeBook.Network::class.java.getDeclaredField("spots").apply { isAccessible = true }
+ f.set(old, null)
+ b.restore(listOf(old))
+ assertTrue(b.network("office")!!.spots.isEmpty())
+ assertNull(b.network("nothing"))
+ }
+
+ @Test
+ fun placesAreCapped() {
+ val b = ProbeBook()
+ for (i in 0 until ProbeBook.MAX_SPOTS + 5) b.record("Home", "02:00:00:00:00:01", -70, i * (ProbeBook.GAP_MS + 1), here)
+ assertEquals(ProbeBook.MAX_SPOTS, b.network("Home")!!.spots.size)
+ }
+}