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
Requested networks, WPS and probe fingerprints, police network names, floating map
CIS-C0ced3b03cdc26
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xmlindex d11b3ca..29b14d7 100644--- a/app/src/main/AndroidManifest.xml+++ b/app/src/main/AndroidManifest.xml@@ -67,6 +67,7 @@<activity android:name=".settings.SettingsActivity" android:exported="false" /><activity android:name=".whitelist.WhitelistActivity" android:exported="false" /><activity android:name=".ouilist.OuiListActivity" android:exported="false" />+ <activity android:name=".probes.ProbeListActivity" android:exported="false" /><activity android:name=".ui.DetectionLogActivity" android:exported="false" /><activity android:name=".ui.CellTowersActivity" android:exported="false" /><activity android:name=".ui.WifiAnalyzerActivity" android:exported="false" />diff --git a/app/src/main/java/com/rfsentinel/app/MainActivity.kt b/app/src/main/java/com/rfsentinel/app/MainActivity.ktindex 7b0d3f1..fda13b5 100644--- a/app/src/main/java/com/rfsentinel/app/MainActivity.kt+++ b/app/src/main/java/com/rfsentinel/app/MainActivity.kt@@ -544,6 +544,7 @@ class MainActivity : AppCompatActivity() {return when (item.itemId) {R.id.action_match_log -> { startActivity(Intent(this, DetectionLogActivity::class.java)); true }R.id.action_settings -> { startActivity(Intent(this, SettingsActivity::class.java)); true }+ R.id.action_probes -> { startActivity(Intent(this, com.rfsentinel.app.probes.ProbeListActivity::class.java)); true }R.id.action_whitelist -> { startActivity(Intent(this, WhitelistActivity::class.java)); true }R.id.action_oui_list -> { startActivity(Intent(this, OuiListActivity::class.java)); true }R.id.action_export -> { Exporter.showExportMenu(this); true }diff --git a/app/src/main/java/com/rfsentinel/app/data/AppDatabase.kt b/app/src/main/java/com/rfsentinel/app/data/AppDatabase.ktindex 1a07605..da3fcc1 100644--- a/app/src/main/java/com/rfsentinel/app/data/AppDatabase.kt+++ b/app/src/main/java/com/rfsentinel/app/data/AppDatabase.kt@@ -12,7 +12,7 @@ import androidx.sqlite.db.SupportSQLiteDatabaseDetectionEntity::class, WhitelistEntity::class, KnownDeviceEntity::class,TripEntity::class, TripPointEntity::class, TripDeviceEntity::class],- version = 3,+ version = 4,exportSchema = false)abstract class AppDatabase : RoomDatabase() {@@ -71,13 +71,20 @@ abstract class AppDatabase : RoomDatabase() {}}+ /** v2.12: requested network names on recorded trace devices. */+ val MIGRATION_3_4 = object : Migration(3, 4) {+ override fun migrate(db: SupportSQLiteDatabase) {+ db.execSQL("ALTER TABLE trip_devices ADD COLUMN probed TEXT")+ }+ }+fun getInstance(context: Context): AppDatabase {return INSTANCE ?: synchronized(this) {INSTANCE ?: Room.databaseBuilder(context.applicationContext,AppDatabase::class.java,"rfsentinel.db"- ).addMigrations(MIGRATION_1_2, MIGRATION_2_3).build().also { INSTANCE = it }+ ).addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4).build().also { INSTANCE = it }}}}diff --git a/app/src/main/java/com/rfsentinel/app/data/ProbeLog.kt b/app/src/main/java/com/rfsentinel/app/data/ProbeLog.ktnew file mode 100644index 0000000..cff9a6b--- /dev/null+++ b/app/src/main/java/com/rfsentinel/app/data/ProbeLog.kt@@ -0,0 +1,133 @@+package com.rfsentinel.app.data++import android.content.Context+import com.google.gson.Gson+import com.google.gson.reflect.TypeToken+import java.io.File++/**+ * WiFi network names that devices around you asked for (probe requests), as heard by+ * a USB WiFi adapter or an ESP32 Marauder board. A phone or laptop asks by name for+ * networks it has joined before, so a police car's laptop can give away its+ * department's network. Recording is an option (Settings / the list's switch), off by+ * default: these are other people's network names. Kept only on this phone.+ */+object ProbeLog {++ private const val FILE = "probed_networks.json"+ private const val SAVE_EVERY_MS = 30_000L++ private val book = ProbeBook()+ private var loaded = false+ private var dirty = false+ private var lastSave = 0L+ private val gson = Gson()++ /**+ * Records that [mac] asked for each of [ssids]. 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) {+ if (ssids.isEmpty() || !(force || com.rfsentinel.app.util.Prefs.recordProbes(context))) return+ ensureLoaded(context)+ ssids.forEach { book.record(it, mac, rssi, now) }+ dirty = true+ if (now - lastSave > SAVE_EVERY_MS) save(context, now)+ }++ @Synchronized+ fun all(context: Context): List<ProbeBook.Network> { ensureLoaded(context); return book.all() }++ @Synchronized+ fun remove(context: Context, ssid: String) { ensureLoaded(context); book.remove(ssid); dirty = true; save(context) }++ @Synchronized+ fun clear(context: Context) { ensureLoaded(context); book.clear(); dirty = true; save(context) }++ /** Writes pending changes (the scan stopping, the list closing). */+ @Synchronized+ fun flush(context: Context) { if (dirty) save(context) }++ private fun ensureLoaded(context: Context) {+ if (loaded) return+ loaded = true+ runCatching {+ val f = File(context.filesDir, FILE)+ if (f.exists()) {+ val list: List<ProbeBook.Network> = gson.fromJson(f.readText(), object : TypeToken<List<ProbeBook.Network>>() {}.type)+ book.restore(list.orEmpty())+ }+ }+ }++ private fun save(context: Context, now: Long = System.currentTimeMillis()) {+ lastSave = now+ dirty = false+ runCatching {+ val f = File(context.filesDir, FILE)+ val tmp = File(context.filesDir, "$FILE.tmp")+ tmp.writeText(gson.toJson(book.all()))+ if (!tmp.renameTo(f)) { f.delete(); tmp.renameTo(f) }+ }+ }+}++/** The requested-network list itself (no Android), capped to the most recent names. */+class ProbeBook(private val maxNetworks: Int = 1000, private val maxDevices: Int = 50) {++ data class Network(+ val ssid: String,+ var firstSeen: Long,+ var lastSeen: Long,+ /** Separate encounters: asked for again after a [GAP_MS] pause. */+ var encounters: Int,+ var lastRssi: Int,+ /** Devices that asked for it, most recent last. */+ val devices: MutableList<String>+ )++ private val nets = LinkedHashMap<String, Network>()++ fun record(ssid: String, mac: String, rssi: Int, now: Long) {+ val key = ssid.lowercase()+ val n = nets[key]+ if (n == null) {+ nets[key] = Network(ssid, now, now, 1, rssi, mutableListOf(mac.uppercase()))+ 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)+ }++ /** Newest first. */+ fun all(): List<Network> = nets.values.sortedByDescending { it.lastSeen }.map { it.copy(devices = it.devices.toMutableList()) }++ fun remove(ssid: String) { nets.remove(ssid.lowercase()) }++ fun clear() = nets.clear()++ fun restore(list: List<Network>) {+ 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())+ }+ trim()+ }++ private fun trim() {+ if (nets.size <= maxNetworks) return+ nets.values.sortedBy { it.lastSeen }.take(nets.size - maxNetworks).forEach { nets.remove(it.ssid.lowercase()) }+ }++ companion object {+ const val GAP_MS = 10 * 60_000L+ }+}diff --git a/app/src/main/java/com/rfsentinel/app/data/Trips.kt b/app/src/main/java/com/rfsentinel/app/data/Trips.ktindex 340b3c9..66d06f0 100644--- a/app/src/main/java/com/rfsentinel/app/data/Trips.kt+++ b/app/src/main/java/com/rfsentinel/app/data/Trips.kt@@ -66,9 +66,12 @@ data class TripDeviceEntity(val lastSeen: Long,val bestRssi: Int,val lat: Double?,- val lon: Double?+ val lon: Double?,+ /** WiFi network names it asked for (probe requests via a USB adapter / Marauder), one per line. */+ val probed: String? = null) {val flagged: Boolean get() = category != null+ val probedList: List<String> get() = probed?.split('\n')?.filter { it.isNotEmpty() }.orEmpty()}@Daodiff --git a/app/src/main/java/com/rfsentinel/app/detect/SignatureEngine.kt b/app/src/main/java/com/rfsentinel/app/detect/SignatureEngine.ktindex f68a541..33cb1f4 100644--- a/app/src/main/java/com/rfsentinel/app/detect/SignatureEngine.kt+++ b/app/src/main/java/com/rfsentinel/app/detect/SignatureEngine.kt@@ -274,6 +274,30 @@ object SignatureEngine {return hits}+ /**+ * In-car network names police vehicles get from their vendors' setup guides:+ * - Axon Fleet (in-car video on a Cradlepoint): Axon's guide names the 5 GHz network+ * after the vehicle - its examples are "8554-5g" and "Axon12-5g".+ * - Cradlepoint vehicle routers left on their default name: model + last 3 address+ * digits ("IBR900-3ab", "-5g" on 5 GHz). Also ambulances, transit and utility fleets.+ */+ internal fun policeVehicleSsid(ssid: String): Hit? = when {+ AXON_FLEET_SSID.matches(ssid) -> Hit(Category.PUBLIC_SAFETY, "Police car network - Axon Fleet in-car video", 80,+ "WiFi network \"$ssid\" follows Axon's Fleet naming (\"Axon12-5g\")", AXON_FLEET_GUIDE)+ VEHICLE_NUMBER_5G_SSID.matches(ssid) -> Hit(Category.PUBLIC_SAFETY, "Possible police car network (vehicle number + -5g)", 45,+ "WiFi network \"$ssid\" is a vehicle number + \"-5g\", Axon's Fleet naming (\"8554-5g\"). Weak alone: " ++ "stronger when the router is a Cradlepoint or Sierra Wireless", AXON_FLEET_GUIDE)+ CRADLEPOINT_VEHICLE_SSID.matches(ssid) -> Hit(Category.PUBLIC_SAFETY, "Cradlepoint vehicle router (default network name)", 40,+ "WiFi network \"$ssid\" is a Cradlepoint in-vehicle router's default name (model + last 3 address digits). " ++ "Police cars, but also ambulances, buses and utility fleets", "Cradlepoint default SSID (product label); $IEEE")+ else -> null+ }++ private val AXON_FLEET_SSID = Regex("^axon[-_ ]?\\d{1,6}[-_ ]?5g$", RegexOption.IGNORE_CASE)+ private val VEHICLE_NUMBER_5G_SSID = Regex("^\\d{2,6}[-_ ]5g$", RegexOption.IGNORE_CASE)+ private val CRADLEPOINT_VEHICLE_SSID = Regex("^(ibr\\d{3,4}[a-z]{0,4}|r1900|r2100)-[0-9a-f]{3}(-5g)?$", RegexOption.IGNORE_CASE)+ private const val AXON_FLEET_GUIDE = "Axon Fleet 2/3 network and Cradlepoint configuration guides (axon.com)"+private fun classifyWifi(a: Advert): List<Hit> {val hits = mutableListOf<Hit>()val ssid = a.name?.trim().orEmpty()@@ -286,6 +310,9 @@ object SignatureEngine {hits += Hit(Category.NETWORK_CAMERA, "Arlo camera base station", 88,"WiFi network \"$ssid\" (Arlo base-station SSID)", "$ACAB (field capture)")}+ // Vendor-documented in-car network names (access points only: a client's name is+ // its WPS device name, not a network).+ if (a.wifi?.client != true) policeVehicleSsid(ssid)?.let { hits += it }a.wifi?.infoElements?.firstOrNull { it.first == 221 && RemoteId.isWifiIe(it.second) }?.let {hits += Hit(Category.DRONE, "Drone broadcasting Remote ID (WiFi)", 95,"ASTM F3411 vendor information element (OUI FA:0B:BC) in the WiFi beacon", ASTM)diff --git a/app/src/main/java/com/rfsentinel/app/esp/EspReports.kt b/app/src/main/java/com/rfsentinel/app/esp/EspReports.ktindex cd55426..47437c8 100644--- a/app/src/main/java/com/rfsentinel/app/esp/EspReports.kt+++ b/app/src/main/java/com/rfsentinel/app/esp/EspReports.kt@@ -26,7 +26,9 @@ data class EspSighting(/** Matches the board itself reported. */val hits: List<Hit> = emptyList(),/** A Wi-Fi client device (heard sending probe requests), not an access point. */- val client: Boolean = false+ val client: Boolean = false,+ /** Network names a client asked for by name (probe requests). */+ val probedSsids: List<String> = emptyList())/**@@ -165,7 +167,7 @@ object MarauderReports {private val ANSI = Regex("""\u001B\[[0-9;]*m""")private val BEACON = Regex("""^\s*(-?\d+)\s+Ch:\s*(\d+)\s+([0-9A-Fa-f]{2}(?::[0-9A-Fa-f]{2}){5})\s+ESSID:\s?(.*)$""")- private val PROBE = Regex("""^\s*(-?\d+)\s+Ch:\s*(\d+)\s+Client:\s*([0-9A-Fa-f]{2}(?::[0-9A-Fa-f]{2}){5})\s+Requesting:.*$""")+ private val PROBE = Regex("""^\s*(-?\d+)\s+Ch:\s*(\d+)\s+Client:\s*([0-9A-Fa-f]{2}(?::[0-9A-Fa-f]{2}){5})\s+Requesting:\s?(.*)$""")/** Marauder's `help` header, or its name in a boot banner. */fun recognises(text: String): Boolean =@@ -195,7 +197,8 @@ object MarauderReports {PROBE.find(t)?.let { m ->return EspSighting(mac = m.groupValues[3].uppercase(), rssi = m.groupValues[1].toInt(), ble = false,- frequencyMhz = frequencyOf(m.groupValues[2].toInt()), client = true+ frequencyMhz = frequencyOf(m.groupValues[2].toInt()), client = true,+ probedSsids = listOfNotNull(m.groupValues[4].trim().takeIf { com.rfsentinel.app.usb.MonitorFrames.validSsid(it) }))}return nulldiff --git a/app/src/main/java/com/rfsentinel/app/oui/OuiEntry.kt b/app/src/main/java/com/rfsentinel/app/oui/OuiEntry.ktindex d91d57b..4c56b10 100644--- a/app/src/main/java/com/rfsentinel/app/oui/OuiEntry.kt+++ b/app/src/main/java/com/rfsentinel/app/oui/OuiEntry.kt@@ -10,6 +10,9 @@ data class OuiEntry(* - "AA:BB:CC:DD:EE:FF" one exact device* - "name:<text>" advertised name / SSID contains <text> (case-insensitive)* - "vendor:<text>" manufacturer (IEEE registrant or Bluetooth company) contains <text>+ * - "probe:<ssid>" a device asks for this exact WiFi network name (probe request,+ * heard by a USB WiFi adapter or an ESP32 Marauder board)+ * - "fp:<8 hex>" a device whose probe requests have this fingerprint (same model / OS)*/val prefix: String,val label: String,@@ -26,6 +29,8 @@ data class OuiEntry(val isCustom get() = confidence == "custom"val isNameRule get() = prefix.startsWith(NAME, ignoreCase = true)val isVendorRule get() = prefix.startsWith(VENDOR, ignoreCase = true)+ val isProbeRule get() = prefix.startsWith(PROBE, ignoreCase = true)+ val isFingerprintRule get() = prefix.startsWith(FINGERPRINT, ignoreCase = true)val ruleText get() = prefix.substringAfter(':').trim()val effectiveScore: Int@@ -49,5 +54,7 @@ data class OuiEntry(companion object {const val NAME = "name:"const val VENDOR = "vendor:"+ const val PROBE = "probe:"+ const val FINGERPRINT = "fp:"}}diff --git a/app/src/main/java/com/rfsentinel/app/oui/OuiWatchlist.kt b/app/src/main/java/com/rfsentinel/app/oui/OuiWatchlist.ktindex 9d3b977..8a86d9c 100644--- a/app/src/main/java/com/rfsentinel/app/oui/OuiWatchlist.kt+++ b/app/src/main/java/com/rfsentinel/app/oui/OuiWatchlist.kt@@ -33,11 +33,14 @@ object OuiWatchlist {val byHex: Map<String, OuiEntry>,val nameRules: List<OuiEntry>,val vendorRules: List<OuiEntry>,+ /** Requested-network rules keyed by the lower-cased network name. */+ val probeRules: Map<String, OuiEntry>,+ val fingerprintRules: Map<String, OuiEntry>,val all: List<OuiEntry>)@Volatile- private var state = State(emptyMap(), emptyList(), emptyList(), emptyList())+ private var state = State(emptyMap(), emptyList(), emptyList(), emptyMap(), emptyMap(), emptyList())val availablePresets = listOf("global", "canada", "us")@@ -50,9 +53,11 @@ object OuiWatchlist {readCustom(context).forEach { byKey[it.prefix] = it }val all = byKey.values.toList()state = State(- byHex = all.filter { !it.isNameRule && !it.isVendorRule }.associateBy { MacUtil.hex(it.prefix) },+ byHex = all.filter { !it.isNameRule && !it.isVendorRule && !it.isProbeRule && !it.isFingerprintRule }.associateBy { MacUtil.hex(it.prefix) },nameRules = all.filter { it.isNameRule && it.ruleText.isNotEmpty() },vendorRules = all.filter { it.isVendorRule && it.ruleText.isNotEmpty() },+ probeRules = all.filter { it.isProbeRule && it.ruleText.isNotEmpty() }.associateBy { it.ruleText.lowercase() },+ fingerprintRules = all.filter { it.isFingerprintRule && it.ruleText.isNotEmpty() }.associateBy { it.ruleText.lowercase() },all = all)}@@ -85,6 +90,8 @@ object OuiWatchlist {return when {k.startsWith(OuiEntry.NAME, ignoreCase = true) -> OuiEntry.NAME + k.substringAfter(':').trim()k.startsWith(OuiEntry.VENDOR, ignoreCase = true) -> OuiEntry.VENDOR + k.substringAfter(':').trim()+ k.startsWith(OuiEntry.PROBE, ignoreCase = true) -> OuiEntry.PROBE + k.substringAfter(':').trim()+ k.startsWith(OuiEntry.FINGERPRINT, ignoreCase = true) -> OuiEntry.FINGERPRINT + k.substringAfter(':').trim().lowercase()else -> MacUtil.normalize(k)}}@@ -150,7 +157,8 @@ object OuiWatchlist {/** Valid keys: IEEE block prefix (24/28/36-bit), full MAC, or a non-empty name:/vendor: rule. */fun isValidKey(prefix: String): Boolean {val k = prefix.trim()- if (k.startsWith(OuiEntry.NAME, true) || k.startsWith(OuiEntry.VENDOR, true)) {+ if (k.startsWith(OuiEntry.NAME, true) || k.startsWith(OuiEntry.VENDOR, true) || k.startsWith(OuiEntry.PROBE, true) ||+ k.startsWith(OuiEntry.FINGERPRINT, true)) {return k.substringAfter(':').isNotBlank()}return MacUtil.isValidBlock(k) || MacUtil.isValidMac(k)@@ -192,6 +200,29 @@ object OuiWatchlist {return out}+ /** Hits for devices asking for watched network names ([probed]: names one device requested). */+ fun probeHits(probed: Collection<String>): List<Hit> = probeHits(state.probeRules, probed)++ /** Hits for a device whose probe requests have a watched fingerprint. */+ fun fingerprintHits(fp: String?): List<Hit> = fp?.let { state.fingerprintRules[it.lowercase()] }+ ?.let { listOf(it.toHit("Its probe requests match the watched fingerprint $fp")) }.orEmpty()++ fun isFingerprintWatched(fp: String): Boolean = fp.lowercase() in state.fingerprintRules++ /** Watchlist name / maker rules against what a device's WPS block names. */+ fun wpsHits(wps: com.rfsentinel.app.usb.ProbeIntel.Wps?): List<Hit> =+ if (wps == null) emptyList() else hits("", wps.text.ifEmpty { null }, listOfNotNull(wps.manufacturer))++ /** Whether requests for [ssid] raise an alert. */+ fun isProbeWatched(ssid: String): Boolean = ssid.trim().lowercase() in state.probeRules++ internal fun probeHits(rules: Map<String, OuiEntry>, probed: Collection<String>): List<Hit> {+ if (rules.isEmpty()) return emptyList()+ return probed.mapNotNull { ssid ->+ rules[ssid.trim().lowercase()]?.toHit("Asked for the watched network \"${ssid.trim()}\"")+ }.distinctBy { it.label }+ }+/** The custom (user-added) entry keyed exactly by [prefix], if any. */fun customEntry(prefix: String): OuiEntry? =state.all.firstOrNull { it.prefix == normalizeKey(prefix) && it.isCustom }diff --git a/app/src/main/java/com/rfsentinel/app/ouilist/OuiAdapter.kt b/app/src/main/java/com/rfsentinel/app/ouilist/OuiAdapter.ktindex 2faf340..fd3089a 100644--- a/app/src/main/java/com/rfsentinel/app/ouilist/OuiAdapter.kt+++ b/app/src/main/java/com/rfsentinel/app/ouilist/OuiAdapter.kt@@ -30,6 +30,8 @@ class OuiAdapter(holder.binding.prefixText.text = when {item.isNameRule -> "Name contains \"${item.ruleText}\""item.isVendorRule -> "Maker contains \"${item.ruleText}\""+ item.isProbeRule -> "Asks for network \"${item.ruleText}\""+ item.isFingerprintRule -> "Probe fingerprint ${item.ruleText}"else -> item.prefix}holder.binding.labelText.text = item.labeldiff --git a/app/src/main/java/com/rfsentinel/app/ouilist/OuiListActivity.kt b/app/src/main/java/com/rfsentinel/app/ouilist/OuiListActivity.ktindex 32a41da..e60096b 100644--- a/app/src/main/java/com/rfsentinel/app/ouilist/OuiListActivity.kt+++ b/app/src/main/java/com/rfsentinel/app/ouilist/OuiListActivity.kt@@ -57,6 +57,10 @@ class OuiListActivity : AppCompatActivity() {binding.prefixInput.hint = "Text in the manufacturer name (e.g. Motorola)"binding.prefixInput.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS}+ R.id.typeProbe -> {+ binding.prefixInput.hint = "Exact WiFi network name a device asks for"+ binding.prefixInput.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS+ }else -> {binding.prefixInput.hint = "Prefix AA:BB:CC or device AA:BB:CC:DD:EE:FF"binding.prefixInput.inputType = InputType.TYPE_CLASS_TEXT or@@ -71,6 +75,7 @@ class OuiListActivity : AppCompatActivity() {val key = when (binding.ruleType.checkedRadioButtonId) {R.id.typeName -> OuiEntry.NAME + textR.id.typeVendor -> OuiEntry.VENDOR + text+ R.id.typeProbe -> OuiEntry.PROBE + textelse -> text}if (text.isEmpty() || !OuiWatchlist.isValidKey(key)) {diff --git a/app/src/main/java/com/rfsentinel/app/probes/ProbeListActivity.kt b/app/src/main/java/com/rfsentinel/app/probes/ProbeListActivity.ktnew file mode 100644index 0000000..ae5ece0--- /dev/null+++ b/app/src/main/java/com/rfsentinel/app/probes/ProbeListActivity.kt@@ -0,0 +1,166 @@+package com.rfsentinel.app.probes++import android.os.Bundle+import android.os.Handler+import android.os.Looper+import android.view.LayoutInflater+import android.view.View+import android.view.ViewGroup+import android.widget.EditText+import android.widget.Toast+import androidx.appcompat.app.AlertDialog+import androidx.appcompat.app.AppCompatActivity+import androidx.core.widget.doAfterTextChanged+import androidx.recyclerview.widget.LinearLayoutManager+import androidx.recyclerview.widget.RecyclerView+import com.rfsentinel.app.data.ProbeBook+import com.rfsentinel.app.data.ProbeLog+import com.rfsentinel.app.databinding.ActivityProbeListBinding+import com.rfsentinel.app.databinding.ItemProbeBinding+import com.rfsentinel.app.detect.VendorDb+import com.rfsentinel.app.oui.OuiEntry+import com.rfsentinel.app.oui.OuiWatchlist+import com.rfsentinel.app.util.MacUtil+import com.rfsentinel.app.util.Prefs+import com.rfsentinel.app.util.applySystemBarInsets+import java.text.DateFormat+import java.util.Date++/**+ * Requested networks: the WiFi network names devices around you asked for, newest+ * first. Watch one to get an alert whenever a device asks for it (a "probe:" rule in+ * the watchlist).+ */+class ProbeListActivity : AppCompatActivity() {++ private lateinit var binding: ActivityProbeListBinding+ private val adapter = Adapter()+ private val main = Handler(Looper.getMainLooper())+ private val tick = object : Runnable {+ override fun run() { refresh(); main.postDelayed(this, 3000) }+ }++ override fun onCreate(savedInstanceState: Bundle?) {+ super.onCreate(savedInstanceState)+ binding = ActivityProbeListBinding.inflate(layoutInflater)+ setContentView(binding.root)+ binding.root.applySystemBarInsets()+ title = "Requested networks"+ supportActionBar?.setDisplayHomeAsUpEnabled(true)++ binding.recyclerView.layoutManager = LinearLayoutManager(this)+ binding.recyclerView.adapter = adapter+ binding.recordSwitch.isChecked = Prefs.recordProbes(this)+ binding.recordSwitch.setOnCheckedChangeListener { _, on ->+ Prefs.setRecordProbes(this, on)+ if (on) Toast.makeText(this, "Recording while scanning with a USB WiFi adapter or an ESP32 Marauder board", Toast.LENGTH_LONG).show()+ refresh()+ }+ binding.filterInput.doAfterTextChanged { refresh() }+ binding.clearButton.setOnClickListener {+ AlertDialog.Builder(this)+ .setTitle("Clear the list?")+ .setMessage("Removes every recorded network name. Watched names stay on the watchlist.")+ .setPositiveButton("Clear") { _, _ -> ProbeLog.clear(this); refresh() }+ .setNegativeButton("Cancel", null)+ .show()+ }+ }++ override fun onResume() { super.onResume(); main.post(tick) }++ override fun onPause() {+ super.onPause()+ main.removeCallbacks(tick)+ ProbeLog.flush(this)+ }++ override fun onSupportNavigateUp(): Boolean { finish(); return true }++ private fun refresh() {+ val filter = binding.filterInput.text.toString().trim()+ val all = ProbeLog.all(this)+ val shown = if (filter.isEmpty()) all else all.filter { it.ssid.contains(filter, ignoreCase = true) }+ adapter.submit(shown)+ binding.emptyText.visibility = if (shown.isEmpty()) View.VISIBLE else View.GONE+ binding.emptyText.text = when {+ all.isNotEmpty() -> "No name matches the filter."+ !Prefs.recordProbes(this) -> "Recording is off. Turn it on above, then scan with a USB WiFi adapter or an ESP32 Marauder board plugged in."+ else -> "Nothing yet. Names appear while scanning with a USB WiFi adapter or an ESP32 Marauder board plugged in."+ }+ }++ private fun meta(n: ProbeBook.Network, now: Long): String = listOf(+ if (n.devices.size == 1) "1 device" else "${n.devices.size} devices",+ if (n.encounters == 1) "seen once" else "seen ${n.encounters} times",+ "last ${ago(now - n.lastSeen)}",+ "${n.lastRssi} dBm"+ ).joinToString(" · ") + if (OuiWatchlist.isProbeWatched(n.ssid)) "\nWATCHED - alerts when a device asks for it" else ""++ private fun ago(ms: Long) = when {+ ms < 60_000 -> "now"+ ms < 3_600_000 -> "${ms / 60_000} min ago"+ ms < 86_400_000 -> "${ms / 3_600_000} h ago"+ else -> "${ms / 86_400_000} d ago"+ }++ /** Watch [ssid]: the user names what it is; the label is what alerts say. */+ private fun watch(ssid: String) {+ val input = EditText(this).apply { setText("Asks for \"$ssid\""); setSelectAllOnFocus(true) }+ AlertDialog.Builder(this)+ .setTitle("Alert when a device asks for \"$ssid\"")+ .setMessage("What is it? This is what the alert says.")+ .setView(input)+ .setPositiveButton("Watch") { _, _ ->+ val label = input.text.toString().trim().ifEmpty { "Asks for \"$ssid\"" }+ OuiWatchlist.addCustomEntry(this, OuiEntry(OuiEntry.PROBE + ssid, label, "user-added", "custom"))+ Toast.makeText(this, "Watching \"$ssid\"", Toast.LENGTH_SHORT).show()+ refresh()+ }+ .setNegativeButton("Cancel", null)+ .show()+ }++ private fun unwatch(ssid: String) {+ OuiWatchlist.removeCustomEntry(this, OuiEntry.PROBE + ssid)+ refresh()+ }++ private fun details(n: ProbeBook.Network) {+ val df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)+ val devices = n.devices.reversed().joinToString("\n") { mac ->+ mac + " " + (if (MacUtil.isRandomized(mac)) "random address" else VendorDb.macVendor(mac) ?: "unknown maker")+ }+ val watched = OuiWatchlist.isProbeWatched(n.ssid)+ AlertDialog.Builder(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")+ .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("Close", null)+ .show()+ }++ private inner class Adapter : RecyclerView.Adapter<Adapter.VH>() {+ private var items: List<ProbeBook.Network> = emptyList()++ inner class VH(val b: ItemProbeBinding) : RecyclerView.ViewHolder(b.root)++ fun submit(list: List<ProbeBook.Network>) { items = list; notifyDataSetChanged() }++ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =+ VH(ItemProbeBinding.inflate(LayoutInflater.from(parent.context), parent, false))++ override fun getItemCount() = items.size++ override fun onBindViewHolder(holder: VH, position: Int) {+ val n = items[position]+ val watched = OuiWatchlist.isProbeWatched(n.ssid)+ holder.b.ssidText.text = n.ssid+ 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.root.setOnClickListener { details(n) }+ }+ }+}diff --git a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.ktindex c3a1c81..d61ec4d 100644--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt@@ -445,7 +445,8 @@ class ScanForegroundService : Service() {TripRecorder.onDevice(mac, a.rssi, a.source.name,if (WhitelistCache.contains(mac)) null else c.hits.firstOrNull(),- a.name, c.vendor, c.identity.type, loc, now+ a.name, c.vendor, c.identity.type, loc, now,+ com.rfsentinel.app.usb.ProbeIntel.of(mac)?.probed.orEmpty())}@@ -480,13 +481,35 @@ class ScanForegroundService : Service() {/** Matches an ESP32 board reported, kept a few minutes so re-classification keeps them. */private val espHits = HashMap<String, Pair<Long, List<Hit>>>()+ /** Watchlist matches from what external hardware heard in a device's frames, kept like [espHits]. */+ private val probeHits = HashMap<String, Pair<Long, List<Hit>>>()++ /**+ * What a USB adapter or a Marauder board heard from [mac] beyond its address: the+ * network names it asked for (kept in the requested-networks list when that's on),+ * its WPS maker / model / name and its probe fingerprint. All checked against the watchlist.+ */+ private fun noteProbes(mac: String, ssids: List<String>, rssi: Int, now: Long,+ wps: com.rfsentinel.app.usb.ProbeIntel.Wps? = null, fingerprint: String? = null) {+ com.rfsentinel.app.usb.ProbeIntel.note(mac, wps, fingerprint, ssids)+ // Kept in the requested-networks list when that's on, and always while a trace records.+ if (ssids.isNotEmpty()) com.rfsentinel.app.data.ProbeLog.record(this, mac, ssids, rssi, now, force = TripRecorder.isRecording)+ val hits = OuiWatchlist.probeHits(ssids) + OuiWatchlist.fingerprintHits(fingerprint) + OuiWatchlist.wpsHits(wps)+ if (hits.isEmpty()) return+ val before = probeHits[mac]+ probeHits[mac] = now to hits+ if (before == null || before.second != hits || now - before.first >= ESP_HIT_TTL_MS) classified.remove(mac)+ }+/** One ESP32 report: becomes a normal observation, with the board's own matches added. */private fun processUsbWifi(m: com.rfsentinel.app.usb.MonitorSighting) {val now = System.currentTimeMillis()val mac = com.rfsentinel.app.util.MacUtil.normalize(m.mac)com.rfsentinel.app.esp.HeardBy.usb.mark(mac, now)+ noteProbes(mac, m.probedSsids, m.rssi, now, m.wps, m.fingerprint)process(Advert(- mac = mac, source = Advert.Source.WIFI, rssi = m.rssi, name = m.ssid,+ // A client has no network name; its WPS device name or model says what it is.+ mac = mac, source = Advert.Source.WIFI, rssi = m.rssi, name = m.ssid ?: m.wps?.label,addressType = com.rfsentinel.app.detect.AddressType.ofWifi(mac),wifi = Advert.WifiInfo(m.frequencyMhz, "", null, emptyList(), client = !m.isAccessPoint),timestamp = now@@ -496,6 +519,7 @@ class ScanForegroundService : Service() {private fun processEsp(e: com.rfsentinel.app.esp.EspSighting) {val now = System.currentTimeMillis()com.rfsentinel.app.esp.HeardBy.esp.mark(e.mac, now)+ noteProbes(e.mac, e.probedSsids, e.rssi, now)if (e.hits.isNotEmpty()) {espHits[e.mac] = now to e.hitsclassified.remove(e.mac) // re-classify with the new evidence@@ -523,7 +547,8 @@ class ScanForegroundService : Service() {OuiWatchlist.hits(a.mac, a.name, listOfNotNull(macVendor) + companyVendors) +DeviceRegistry.inheritedHits(a.mac) +listOfNotNull(DeviceRegistry.clusterHit(a.mac, now)) +- espHits[a.mac]?.takeIf { now - it.first < ESP_HIT_TTL_MS }?.second.orEmpty()+ espHits[a.mac]?.takeIf { now - it.first < ESP_HIT_TTL_MS }?.second.orEmpty() ++ probeHits[a.mac]?.takeIf { now - it.first < ESP_HIT_TTL_MS }?.second.orEmpty()val noAirTags = Prefs.excludeAirTags(this)val hits = EvidenceFusion.fuse(raw.filter {Prefs.categoryEnabled(this, it.category) && !(noAirTags && SignatureEngine.isAppleFindMy(it))@@ -843,17 +868,26 @@ class ScanForegroundService : Service() {}}- /** Keeps the floating threat bubble in sync (hidden while our own screens are visible). */+ /**+ * Keeps the floating threat bubble and the floating mini map in sync (hidden while+ * our own screens are visible).+ */private fun startBubble() {bubbleJob?.cancel()- if (!Prefs.threatBubble(this)) { com.rfsentinel.app.ui.ThreatBubble.hide(this); return }+ val bubble = Prefs.threatBubble(this); val miniMap = Prefs.floatingMap(this)+ if (!bubble) com.rfsentinel.app.ui.ThreatBubble.hide(this)+ if (!miniMap) com.rfsentinel.app.ui.FloatingMap.hide(this)+ if (!bubble && !miniMap) returnbubbleJob = serviceScope.launch {while (isActive) {- if (RFSentinelApp.inForeground || !com.rfsentinel.app.ui.ThreatBubble.canShow(this@ScanForegroundService)) {- com.rfsentinel.app.ui.ThreatBubble.hide(this@ScanForegroundService)+ val ctx = this@ScanForegroundService+ if (RFSentinelApp.inForeground || !com.rfsentinel.app.ui.ThreatBubble.canShow(ctx)) {+ com.rfsentinel.app.ui.ThreatBubble.hide(ctx)+ com.rfsentinel.app.ui.FloatingMap.hide(ctx)} else {- val flagged = DeviceRegistry.snapshot().filter { it.best != null && !WhitelistCache.contains(it.mac) }- val threshold = Prefs.alertThreshold(this@ScanForegroundService)+ val devices = DeviceRegistry.snapshot()+ val flagged = devices.filter { it.best != null && !WhitelistCache.contains(it.mac) }+ val threshold = Prefs.alertThreshold(ctx)val top = flagged.maxOfOrNull { it.best!!.confidence } ?: 0val cellWarning = CellMonitor.lastAnomaly?.takeIf { System.currentTimeMillis() - it.first < 15 * 60_000L }val level = when {@@ -862,7 +896,17 @@ class ScanForegroundService : Service() {flagged.isNotEmpty() -> com.rfsentinel.app.ui.ThreatBubble.Level.WEAKelse -> com.rfsentinel.app.ui.ThreatBubble.Level.CLEAR}- com.rfsentinel.app.ui.ThreatBubble.update(this@ScanForegroundService, level, flagged.size)+ if (Prefs.threatBubble(ctx)) com.rfsentinel.app.ui.ThreatBubble.update(ctx, level, flagged.size)+ else com.rfsentinel.app.ui.ThreatBubble.hide(ctx)+ if (Prefs.floatingMap(ctx)) {+ // The same dots as the full map: devices placed where they were heard strongest.+ val dots = devices.mapNotNull { s ->+ val p = s.bestPosition ?: return@mapNotNull null+ com.rfsentinel.app.ui.FloatingMap.Dot(p.lat, p.lon,+ com.rfsentinel.app.ui.DeviceColors.forDevice(ctx, s), com.rfsentinel.app.ui.DeviceColors.isFlagged(s))+ }+ com.rfsentinel.app.ui.FloatingMap.update(ctx, level, flagged.size, lastFix, dots)+ } else com.rfsentinel.app.ui.FloatingMap.hide(ctx)}delay(2_000)}@@ -884,6 +928,8 @@ class ScanForegroundService : Service() {// External hardware is gone with the scan: its "heard by" marks (External filter, badges) go too.com.rfsentinel.app.esp.HeardBy.esp.clear()com.rfsentinel.app.esp.HeardBy.usb.clear()+ com.rfsentinel.app.usb.ProbeIntel.clear()+ com.rfsentinel.app.data.ProbeLog.flush(this)bleEngine.stop()wifiEngine.stop()if (btStateReceiverRegistered) {@@ -898,6 +944,7 @@ class ScanForegroundService : Service() {pipelineThread.quitSafely()cellMonitor?.close()com.rfsentinel.app.ui.ThreatBubble.hide(this)+ com.rfsentinel.app.ui.FloatingMap.hide(this)// Take the final history and trace synchronously, so a scan restarted right// away (new session, new trace) can't clear or reuse them; write them after.val history = takeHistory()diff --git a/app/src/main/java/com/rfsentinel/app/service/TripRecorder.kt b/app/src/main/java/com/rfsentinel/app/service/TripRecorder.ktindex 67553e7..2e20362 100644--- a/app/src/main/java/com/rfsentinel/app/service/TripRecorder.kt+++ b/app/src/main/java/com/rfsentinel/app/service/TripRecorder.kt@@ -141,7 +141,7 @@ object TripRecorder {/** Called for every observation while recording (cheap, in memory). */fun onDevice(mac: String, rssi: Int, source: String, best: Hit?, name: String?, vendor: String?, type: String?,- loc: Location?, now: Long+ loc: Location?, now: Long, probed: List<String> = emptyList()) {val id = activeTripId ?: returndevices.compute(mac) { _, old ->@@ -162,12 +162,20 @@ object TripRecorder {lastSeen = now,bestRssi = if (stronger) rssi else old!!.bestRssi,lat = if (stronger && loc != null) loc.latitude else old?.lat ?: loc?.latitude,- lon = if (stronger && loc != null) loc.longitude else old?.lon ?: loc?.longitude+ lon = if (stronger && loc != null) loc.longitude else old?.lon ?: loc?.longitude,+ probed = mergeProbed(old?.probedList.orEmpty(), probed))}dirty += mac}+ /** Network names asked for so far plus new ones, oldest first, at most 16 (null when none). */+ internal fun mergeProbed(old: List<String>, new: List<String>): String? {+ if (new.isEmpty()) return old.ifEmpty { null }?.joinToString("\n")+ val all = LinkedHashSet(old).apply { new.forEach { remove(it); add(it) } }.toList().takeLast(16)+ return all.joinToString("\n")+ }+/** Writes buffered points / changed devices and the trip's running totals. */suspend fun flush(context: Context, closing: Boolean = false) {val id = activeTripId ?: returndiff --git a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.ktindex e04a8de..6e51e16 100644--- a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt+++ b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt@@ -390,6 +390,23 @@ class SettingsActivity : AppCompatActivity() {binding.shortVoiceSwitch.isChecked = Prefs.shortVoice(this)setupVoiceControls()binding.discreetSwitch.isChecked = Prefs.discreetMode(this)+ binding.floatingMapSwitch.isChecked = Prefs.floatingMap(this) && Settings.canDrawOverlays(this)+ binding.floatingMapSwitch.setOnCheckedChangeListener { sw, on ->+ if (on && !Settings.canDrawOverlays(this)) {+ sw.isChecked = false+ AlertDialog.Builder(this)+ .setTitle("Allow the floating map")+ .setMessage("Android needs the \"Display over other apps\" permission for the floating map. " ++ "Turn it on for RF Sentinel on the next screen, then come back and switch the map on.")+ .setPositiveButton("Open settings") { _, _ ->+ runCatching {+ startActivity(Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, android.net.Uri.parse("package:$packageName")))+ }+ }+ .setNegativeButton("Cancel", null)+ .show()+ }+ }binding.bubbleSwitch.isChecked = Prefs.threatBubble(this) && Settings.canDrawOverlays(this)binding.bubbleSwitch.setOnCheckedChangeListener { sw, on ->if (on && !Settings.canDrawOverlays(this)) {@@ -617,6 +634,8 @@ class SettingsActivity : AppCompatActivity() {Prefs.setDiscreetMode(this, binding.discreetSwitch.isChecked)Prefs.setThreatBubble(this, binding.bubbleSwitch.isChecked)if (!binding.bubbleSwitch.isChecked) com.rfsentinel.app.ui.ThreatBubble.hide(this)+ Prefs.setFloatingMap(this, binding.floatingMapSwitch.isChecked)+ if (!binding.floatingMapSwitch.isChecked) com.rfsentinel.app.ui.FloatingMap.hide(this)val dedupeMin = binding.dedupeInput.text.toString().toLongOrNull() ?: 5LPrefs.setDedupeWindowMs(this, dedupeMin.coerceAtLeast(1) * 60000L)diff --git a/app/src/main/java/com/rfsentinel/app/ui/DeviceActions.kt b/app/src/main/java/com/rfsentinel/app/ui/DeviceActions.ktindex 828af39..7d678c3 100644--- a/app/src/main/java/com/rfsentinel/app/ui/DeviceActions.kt+++ b/app/src/main/java/com/rfsentinel/app/ui/DeviceActions.kt@@ -99,15 +99,25 @@ object DeviceActions {"Watchlist & rules instead."b.scopePrefix.isEnabled = false}+ // A probe fingerprint (USB adapter) marks the device model / OS, even across random addresses.+ val fp = com.rfsentinel.app.usb.ProbeIntel.of(mac)?.fingerprint+ if (fp != null) {+ b.scopeFingerprint.visibility = View.VISIBLE+ b.scopeFingerprint.text = "Every device of this type (probe fingerprint $fp)"+ if (randomized) b.warningText.text = "This is a randomized (private) address: it may change later. " ++ "The probe fingerprint below stays the same - watch that to catch this type of device."+ }b.labelInput.setText(name ?: "")AlertDialog.Builder(activity).setTitle("Add to watchlist").setView(b.root).setPositiveButton("Add") { _, _ ->val wholePrefix = b.scopePrefix.isChecked- val key = if (wholePrefix) oui else mac- val label = b.labelInput.text.toString().trim()- .ifEmpty { if (wholePrefix) "Custom prefix $oui" else "Custom device $mac" }+ val byFingerprint = fp != null && b.scopeFingerprint.isChecked+ val key = when { byFingerprint -> OuiEntry.FINGERPRINT + fp; wholePrefix -> oui; else -> mac }+ val label = b.labelInput.text.toString().trim().ifEmpty {+ when { byFingerprint -> "Device type $fp"; wholePrefix -> "Custom prefix $oui"; else -> "Custom device $mac" }+ }OuiWatchlist.addCustomEntry(activity, OuiEntry(key, label, "user-added from live list", "custom"))toast(activity, "Added $key to the watchlist")}diff --git a/app/src/main/java/com/rfsentinel/app/ui/DeviceDetailActivity.kt b/app/src/main/java/com/rfsentinel/app/ui/DeviceDetailActivity.ktindex d6b1deb..a7be24e 100644--- a/app/src/main/java/com/rfsentinel/app/ui/DeviceDetailActivity.kt+++ b/app/src/main/java/com/rfsentinel/app/ui/DeviceDetailActivity.kt@@ -181,7 +181,9 @@ class DeviceDetailActivity : AppCompatActivity() {}// Action labels+ val fp = com.rfsentinel.app.usb.ProbeIntel.of(mac)?.fingerprintval custom = OuiWatchlist.customEntry(mac) ?: OuiWatchlist.customEntry(MacUtil.oui(mac))+ ?: fp?.let { OuiWatchlist.customEntry(com.rfsentinel.app.oui.OuiEntry.FINGERPRINT + it) }binding.actionWatchlist.text = if (custom != null) "Remove from watchlist" else "Add to watchlist"binding.actionWhitelist.text = when {com.rfsentinel.app.data.TrackerMutes.isMuted(mac) -> "Stop ignoring"@@ -236,6 +238,16 @@ class DeviceDetailActivity : AppCompatActivity() {a?.phy?.let { id += "PHY" to it }a?.txPower?.let { id += "Advertised TX power" to "$it dBm" }s?.facts?.forEach { id += it }+ // Heard by a USB WiFi adapter / Marauder board: its WPS block, fingerprint, network requests.+ com.rfsentinel.app.usb.ProbeIntel.of(mac)?.let { r ->+ r.wps?.deviceName?.let { id += "Device name (WPS)" to it }+ r.wps?.product?.let { id += "Maker / model (WPS)" to it }+ r.fingerprint?.let { fp ->+ id += "Probe fingerprint" to fp + if (OuiWatchlist.isFingerprintWatched(fp)) " · on your watchlist" else+ " (same for every device of this model / OS - Watchlist can watch it)"+ }+ if (r.probed.isNotEmpty()) id += "Networks it asked for" to r.probed.reversed().joinToString(", ")+ }if (id.isNotEmpty()) out += "Identity" to id// Drone Remote IDdiff --git a/app/src/main/java/com/rfsentinel/app/ui/FloatingMap.kt b/app/src/main/java/com/rfsentinel/app/ui/FloatingMap.ktnew file mode 100644index 0000000..fd09f56--- /dev/null+++ b/app/src/main/java/com/rfsentinel/app/ui/FloatingMap.kt@@ -0,0 +1,256 @@+package com.rfsentinel.app.ui++import android.annotation.SuppressLint+import android.content.Context+import android.content.Intent+import android.content.res.Configuration+import android.graphics.Color+import android.graphics.Outline+import android.graphics.PixelFormat+import android.graphics.Typeface+import android.graphics.drawable.GradientDrawable+import android.location.Location+import android.os.Build+import android.os.Handler+import android.os.Looper+import android.provider.Settings+import android.view.Gravity+import android.view.MotionEvent+import android.view.View+import android.view.ViewOutlineProvider+import android.view.WindowManager+import android.widget.FrameLayout+import android.widget.TextView+import android.widget.Toast+import androidx.core.content.edit+import com.rfsentinel.app.service.ScanForegroundService+import com.rfsentinel.app.util.Prefs+import org.osmdroid.tileprovider.tilesource.TileSourceFactory+import org.osmdroid.util.GeoPoint+import org.osmdroid.views.CustomZoomButtonsController+import org.osmdroid.views.MapView+import org.osmdroid.views.overlay.TilesOverlay+import kotlin.math.abs++/**+ * A small floating map drawn over other apps (Google Maps, Waze...) while scanning:+ * centred on you, with the same device dots as RF Sentinel's map (flagged ones larger,+ * on top), a border in the threat colour and the flagged count. Drag to move, tap to+ * open the full map, ✕ to turn it off. Needs "Display over other apps"; hidden while+ * RF Sentinel itself is on screen. While it shows, location runs in precise mode, like+ * the full map.+ */+object FloatingMap {++ /** One device on the mini map. */+ data class Dot(val lat: Double, val lon: Double, val color: Int, val flagged: Boolean)++ private const val SIZE_DP = 170+ private const val MIN_DP = 120+ private const val ZOOM = 16.0+ private const val MIN_ZOOM = 11.0+ private const val MAX_ZOOM = 19.0+ private const val ME_COLOR = 0xFF1A73E8.toInt()++ private val main = Handler(Looper.getMainLooper())+ private var root: FrameLayout? = null+ private var map: MapView? = null+ private var badge: TextView? = null+ private var waiting: TextView? = null+ private var border: GradientDrawable? = null+ private var dots: PointsOverlay<Unit>? = null+ private var me: PointsOverlay<Unit>? = null++ fun canShow(context: Context) = Settings.canDrawOverlays(context)++ /** Shows or updates the mini map (any thread). [here] is your last fix, null while waiting for GPS. */+ fun update(context: Context, level: ThreatBubble.Level, flagged: Int, here: Location?, devices: List<Dot>) = main.post {+ val app = context.applicationContext+ if (!canShow(app)) { removeNow(app); return@post }+ if (root == null) add(app) ?: return@post+ border?.setStroke(dp(app, 3f), level.color)+ badge?.apply {+ text = if (flagged == 0) "✓" else if (flagged > 99) "99+" else flagged.toString()+ background = GradientDrawable().apply { cornerRadius = dp(app, 11f).toFloat(); setColor(level.color) }+ }+ dots?.points = devices.sortedBy { it.flagged }.map {+ PointsOverlay.Point(it.lat, it.lon, Unit, color = it.color, sizeDp = if (it.flagged) 15f else 9f)+ }+ val m = map ?: return@post+ if (here != null) {+ val p = GeoPoint(here.latitude, here.longitude)+ me?.points = listOf(PointsOverlay.Point(p.latitude, p.longitude, Unit, color = ME_COLOR, sizeDp = 14f))+ m.controller.setCenter(p)+ waiting?.visibility = View.GONE+ } else waiting?.visibility = View.VISIBLE+ m.invalidate()+ }++ fun hide(context: Context) = main.post { removeNow(context.applicationContext) }++ private fun removeNow(context: Context) {+ val r = root ?: return+ runCatching { (context.getSystemService(Context.WINDOW_SERVICE) as WindowManager).removeView(r) }+ runCatching { map?.onDetach() }+ root = null; map = null; badge = null; waiting = null; border = null; dots = null; me = null+ ScanForegroundService.mapHidden(context)+ }++ private fun dp(context: Context, v: Float) = (v * context.resources.displayMetrics.density).toInt()++ @SuppressLint("ClickableViewAccessibility", "SetTextI18n")+ private fun add(context: Context): FrameLayout? {+ val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager+ val d = context.resources.displayMetrics.density+ val prefs = context.getSharedPreferences("floating_map", Context.MODE_PRIVATE)+ // The corner handle resizes it, from MIN_DP up to almost the screen width; size and zoom are remembered.+ val minSize = dp(context, MIN_DP.toFloat())+ val maxSize = (context.resources.displayMetrics.widthPixels - dp(context, 16f)).coerceAtLeast(minSize)+ val size = prefs.getInt("size", dp(context, SIZE_DP.toFloat())).coerceIn(minSize, maxSize)+ val lp = WindowManager.LayoutParams(+ size, size,+ if (Build.VERSION.SDK_INT >= 26) WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY+ else @Suppress("DEPRECATION") WindowManager.LayoutParams.TYPE_PHONE,+ WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,+ PixelFormat.TRANSLUCENT+ ).apply {+ gravity = Gravity.TOP or Gravity.END+ x = prefs.getInt("x", dp(context, 8f))+ y = prefs.getInt("y", dp(context, 120f))+ }++ MapIcons.configureOsm(context)+ val radius = 18f * d+ val frame = FrameLayout(context).apply {+ background = GradientDrawable().apply { cornerRadius = radius; setColor(Color.BLACK) }.also { border = it }+ outlineProvider = object : ViewOutlineProvider() {+ override fun getOutline(view: View, outline: Outline) = outline.setRoundRect(0, 0, view.width, view.height, radius)+ }+ clipToOutline = true+ elevation = 6f * d+ }+ val m = MapView(context).apply {+ setTileSource(TileSourceFactory.MAPNIK)+ setMultiTouchControls(false)+ zoomController.setVisibility(CustomZoomButtonsController.Visibility.NEVER)+ isTilesScaledToDpi = true+ controller.setZoom(prefs.getFloat("zoom", ZOOM.toFloat()).toDouble().coerceIn(MIN_ZOOM, MAX_ZOOM))+ val night = (context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES+ if (night) overlayManager.tilesOverlay.setColorFilter(TilesOverlay.INVERT_COLORS)+ }+ val dotLayer = PointsOverlay<Unit>(d) {}+ val meLayer = PointsOverlay<Unit>(d) {}+ m.overlays.add(dotLayer)+ m.overlays.add(meLayer)+ val inset = dp(context, 3f)+ frame.addView(m, FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT).apply {+ setMargins(inset, inset, inset, inset)+ })+ val wait = TextView(context).apply {+ text = "Waiting for GPS"+ setTextColor(Color.WHITE); textSize = 11f+ setBackgroundColor(0x99000000.toInt())+ setPadding(dp(context, 6f), dp(context, 2f), dp(context, 6f), dp(context, 2f))+ }+ frame.addView(wait, FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT,+ Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL).apply { bottomMargin = dp(context, 8f) })+ val count = TextView(context).apply {+ setTextColor(Color.WHITE); textSize = 12f; typeface = Typeface.DEFAULT_BOLD; gravity = Gravity.CENTER+ minWidth = dp(context, 22f); minHeight = dp(context, 22f)+ setPadding(dp(context, 5f), 0, dp(context, 5f), 0)+ contentDescription = "Flagged devices"+ }+ frame.addView(count, FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT,+ Gravity.TOP or Gravity.START).apply { setMargins(dp(context, 7f), dp(context, 7f), 0, 0) })+ val close = TextView(context).apply {+ text = "✕"; setTextColor(Color.WHITE); textSize = 13f; gravity = Gravity.CENTER+ background = GradientDrawable().apply { shape = GradientDrawable.OVAL; setColor(0xAA000000.toInt()) }+ contentDescription = "Turn off the floating map"+ }+ val closeSize = dp(context, 24f)+ frame.addView(close, FrameLayout.LayoutParams(closeSize, closeSize, Gravity.TOP or Gravity.END).apply {+ setMargins(0, dp(context, 6f), dp(context, 6f), 0)+ })++ // Touches go to the window, not the map: drag moves it, pinch resizes it, tap opens the full map.+ var downX = 0f; var downY = 0f; var startX = 0; var startY = 0; var moved = false; var pinched = false+ // Pinch is tracked by hand: ScaleGestureDetector stops below a minimum finger span+ // (~2.5 cm), which a small window reaches quickly when zooming out.+ var pinchSpan = 0f+ fun span(e: MotionEvent) = Math.hypot((e.getX(0) - e.getX(1)).toDouble(), (e.getY(0) - e.getY(1)).toDouble()).toFloat()+ val onTouch = View.OnTouchListener { v, e ->+ when (e.actionMasked) {+ MotionEvent.ACTION_POINTER_DOWN -> if (e.pointerCount == 2) { pinched = true; pinchSpan = span(e) }+ MotionEvent.ACTION_POINTER_UP -> pinchSpan = 0f+ MotionEvent.ACTION_DOWN -> { downX = e.rawX; downY = e.rawY; startX = lp.x; startY = lp.y; moved = false; pinched = false }+ MotionEvent.ACTION_MOVE -> if (e.pointerCount >= 2 && pinchSpan > 0f) {+ // One zoom level per doubling of the finger spread, in or out.+ val now = span(e)+ if (now > 1f) {+ val z = (m.zoomLevelDouble + Math.log((now / pinchSpan).toDouble()) / Math.log(2.0)).coerceIn(MIN_ZOOM, MAX_ZOOM)+ m.controller.setZoom(z)+ pinchSpan = now+ }+ } else if (!pinched && e.pointerCount == 1) {+ val dx = e.rawX - downX; val dy = e.rawY - downY+ if (abs(dx) > 8 * d || abs(dy) > 8 * d) moved = true+ // Gravity END: x grows to the left.+ if (moved) { lp.x = startX - dx.toInt(); lp.y = startY + dy.toInt(); runCatching { wm.updateViewLayout(frame, lp) } }+ }+ MotionEvent.ACTION_UP -> {+ if (pinched) prefs.edit { putFloat("zoom", m.zoomLevelDouble.toFloat()) }+ else if (moved) prefs.edit { putInt("x", lp.x); putInt("y", lp.y) }+ else if (v === close) turnOff(context)+ else context.startActivity(Intent(context, MapActivity::class.java)+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_REORDER_TO_FRONT))+ }+ }+ true+ }+ val cover = View(context).apply {+ setOnTouchListener(onTouch)+ contentDescription = "RF Sentinel map: tap to open, drag to move, pinch to zoom"+ }+ frame.addView(cover, FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT))+ close.bringToFront()+ close.setOnTouchListener(onTouch)++ val handleSize = dp(context, 26f)+ val handle = TextView(context).apply {+ text = "⤡"; setTextColor(Color.WHITE); textSize = 15f; gravity = Gravity.CENTER+ background = GradientDrawable().apply { shape = GradientDrawable.OVAL; setColor(0xAA000000.toInt()) }+ contentDescription = "Resize the floating map"+ }+ frame.addView(handle, FrameLayout.LayoutParams(handleSize, handleSize, Gravity.BOTTOM or Gravity.START).apply {+ setMargins(dp(context, 5f), 0, 0, dp(context, 5f))+ })+ var resizeDownX = 0f; var resizeDownY = 0f; var startSize = 0+ handle.setOnTouchListener { _, e ->+ when (e.actionMasked) {+ MotionEvent.ACTION_DOWN -> { resizeDownX = e.rawX; resizeDownY = e.rawY; startSize = lp.width }+ MotionEvent.ACTION_MOVE -> {+ // Out (left / down) grows it, in (right / up) shrinks it; it stays square.+ val grow = maxOf(resizeDownX - e.rawX, e.rawY - resizeDownY)+ val n = (startSize + grow).toInt().coerceIn(minSize, maxSize)+ if (n != lp.width) { lp.width = n; lp.height = n; runCatching { wm.updateViewLayout(frame, lp) } }+ }+ MotionEvent.ACTION_UP -> prefs.edit { putInt("size", lp.width) }+ }+ true+ }++ return runCatching {+ wm.addView(frame, lp)+ m.onResume()+ root = frame; map = m; badge = count; waiting = wait; dots = dotLayer; me = meLayer+ ScanForegroundService.mapShown(context)+ frame+ }.getOrNull()+ }++ private fun turnOff(context: Context) {+ Prefs.setFloatingMap(context, false)+ removeNow(context)+ Toast.makeText(context, "Floating map off - turn it back on in Settings", Toast.LENGTH_SHORT).show()+ }+}diff --git a/app/src/main/java/com/rfsentinel/app/ui/MapActivity.kt b/app/src/main/java/com/rfsentinel/app/ui/MapActivity.ktindex e28c46b..a621686 100644--- a/app/src/main/java/com/rfsentinel/app/ui/MapActivity.kt+++ b/app/src/main/java/com/rfsentinel/app/ui/MapActivity.kt@@ -450,6 +450,7 @@ class MapActivity : AppCompatActivity() {vendor?.let { append("\n").append(it) }if (cat != null) append("\n${cat.title} · ${Tier.of(confidence).label} $confidence%")evidence?.let { append("\n").append(it) }+ probedList.takeIf { it.isNotEmpty() }?.let { append("\nAsked for networks: ").append(it.joinToString(", ")) }append("\nStrongest signal here: $bestRssi dBm")append("\nHeard ${dateFmt.format(Date(firstSeen))}")}diff --git a/app/src/main/java/com/rfsentinel/app/usb/MonitorFrames.kt b/app/src/main/java/com/rfsentinel/app/usb/MonitorFrames.ktindex dbd1dda..6e59462 100644--- a/app/src/main/java/com/rfsentinel/app/usb/MonitorFrames.kt+++ b/app/src/main/java/com/rfsentinel/app/usb/MonitorFrames.kt@@ -13,6 +13,12 @@ class MonitorFrames {var ssid: String? = null; var bssid: String? = nullvar rssi = NOMINAL_RSSI; var rssiAt = 0L; var measured = false; var channel = 0var lastSeen = 0L+ /** Network names this client asked for (probe requests), oldest first. */+ val probed = LinkedHashSet<String>()+ /** Maker / model / device name from its WPS block, when it sends one. */+ var wps: ProbeIntel.Wps? = null+ /** How it builds its probe requests ([ProbeIntel.fingerprint]). */+ var fingerprint: String? = null// Per-window counters for driver diagnostics (debug builds).var winHits = 0; var winMeasured = 0; var winMax = -128; var winSum = 0Lvar winOfdm = 0; var winA = -128; var winB = -128@@ -63,10 +69,20 @@ class MonitorFrames {touch(a3, ap = true, ch = ies.channel.takeIf { validChannel(it) } ?: channel)?.let {it.isAp = trueif (ies.ssid != null && it.ssid == null) it.ssid = ies.ssid+ ies.wps?.let { w -> it.wps = w }+ }+ }+ // Probe request: a device looking for networks (e.g. a laptop or a Flock camera),+ // often by name - the networks it has joined before.+ 4 -> if (captureClients) touch(a2, ap = false)?.let { s ->+ val ies = Ies.read(b, d + 24, end)+ ies.wps?.let { s.wps = it }+ ProbeIntel.fingerprint(b, d + 24, end)?.let { s.fingerprint = it }+ ies.ssid?.takeIf { validSsid(it) }?.let { name ->+ s.probed.remove(name); s.probed.add(name)+ if (s.probed.size > MAX_PROBED) s.probed.remove(s.probed.first())}}- // Probe request: a device looking for networks (e.g. a laptop or a Flock camera).- 4 -> if (captureClients) touch(a2, ap = false)0, 2, 10, 11, 12 -> if (captureClients) touch(a2, ap = false)?.let { it.bssid = mac(b, a3) }}2 -> if (captureClients) when {@@ -93,7 +109,10 @@ class MonitorFrames {rssi = s.rssi.coerceIn(-120, -20),frequencyMhz = frequencyOf(s.channel),isAccessPoint = s.isAp,- bssid = s.bssid+ bssid = s.bssid,+ probedSsids = s.probed.toList(),+ wps = s.wps,+ fingerprint = s.fingerprint)}sightings.entries.removeAll { now - it.value.lastSeen > pruneMs }@@ -116,10 +135,10 @@ class MonitorFrames {}/** Network name and channel from a management frame's information elements. */- data class Ies(val ssid: String?, val channel: Int) {+ data class Ies(val ssid: String?, val channel: Int, val wps: ProbeIntel.Wps? = null) {companion object {fun read(b: ByteArray, from: Int, end: Int): Ies {- var ssid: String? = null; var ds = 0; var ht = 0+ var ssid: String? = null; var ds = 0; var ht = 0; var wps: ProbeIntel.Wps? = nullvar i = fromwhile (i + 2 <= end) {val tag = b[i].toInt() and 0xff; val tl = b[i + 1].toInt() and 0xff@@ -128,10 +147,14 @@ class MonitorFrames {0 -> if (ssid == null) ssid = String(b, i + 2, tl, Charsets.UTF_8).trim { it <= ' ' }3 -> if (tl >= 1) ds = b[i + 2].toInt() and 0xff // DS parameter set (2.4 GHz)61 -> if (tl >= 1) ht = b[i + 2].toInt() and 0xff // HT operation: primary channel+ 221 -> if (tl >= 4 && b[i + 2].toInt() == 0x00 && b[i + 3].toInt() == 0x50 &&+ (b[i + 4].toInt() and 0xff) == 0xF2 && b[i + 5].toInt() == 0x04) {+ ProbeIntel.parseWps(b, i + 6, i + 2 + tl)?.let { wps = it } // WPS+ }}i += 2 + tl}- return Ies(ssid, if (ds != 0) ds else ht)+ return Ies(ssid, if (ds != 0) ds else ht, wps)}}}@@ -144,6 +167,11 @@ class MonitorFrames {fun validChannel(ch: Int) = ch in 1..14 || ch in 32..177+ /** A network name worth keeping: not empty (a wildcard probe), no control characters. */+ fun validSsid(s: String) = s.isNotEmpty() && s.length <= 32 && s.none { it < ' ' || it == '�' }++ private const val MAX_PROBED = 16+/** Centre frequency of a 20 MHz WiFi channel, 0 when unknown. */fun frequencyOf(ch: Int): Int = when (ch) {in 1..13 -> 2407 + ch * 5diff --git a/app/src/main/java/com/rfsentinel/app/usb/ProbeIntel.kt b/app/src/main/java/com/rfsentinel/app/usb/ProbeIntel.ktnew file mode 100644index 0000000..0d470bb--- /dev/null+++ b/app/src/main/java/com/rfsentinel/app/usb/ProbeIntel.kt@@ -0,0 +1,102 @@+package com.rfsentinel.app.usb++import java.util.concurrent.ConcurrentHashMap+import java.util.zip.CRC32++/**+ * What a WiFi frame says about the device beyond its address, heard in monitor mode:+ * - the WPS block many laptops, printers, routers and IoT devices include in their+ * probe requests and beacons: maker, model and device name (e.g. "Panasonic+ * Toughbook CF-33", a computer name like "PD-UNIT12", a router model);+ * - a fingerprint of how a device builds its probe requests (which elements, in what+ * order, its capability bits and vendor extensions). It stays the same when the+ * address is randomized, so it marks a device model / OS, and can be watchlisted.+ */+object ProbeIntel {++ data class Wps(val manufacturer: String?, val model: String?, val modelNumber: String?, val deviceName: String?) {+ /** "Maker Model Number", or null when the block named nothing. */+ val product: String? get() = listOfNotNull(manufacturer, model, modelNumber).distinct().joinToString(" ").ifBlank { null }+ /** The best single name for the device list. */+ val label: String? get() = deviceName ?: product+ /** Everything it named, for watchlist name rules. */+ val text: String get() = listOfNotNull(deviceName, manufacturer, model, modelNumber).joinToString(" ")+ }++ /** Parses a WPS vendor element's body (after the 00:50:F2:04 header): big-endian type / length attributes. */+ fun parseWps(b: ByteArray, from: Int, end: Int): Wps? {+ var manufacturer: String? = null; var model: String? = null; var number: String? = null; var name: String? = null+ var i = from+ while (i + 4 <= end) {+ val type = ((b[i].toInt() and 0xff) shl 8) or (b[i + 1].toInt() and 0xff)+ val len = ((b[i + 2].toInt() and 0xff) shl 8) or (b[i + 3].toInt() and 0xff)+ if (i + 4 + len > end) break+ val v = { text(b, i + 4, len) }+ when (type) {+ 0x1021 -> manufacturer = v()+ 0x1023 -> model = v()+ 0x1024 -> number = v()+ 0x1011 -> name = v()+ }+ i += 4 + len+ }+ if (manufacturer == null && model == null && number == null && name == null) return null+ return Wps(manufacturer, model, number, name)+ }++ private fun text(b: ByteArray, at: Int, len: Int): String? {+ val s = String(b, at, len, Charsets.UTF_8).trim { it <= ' ' }+ // Placeholders some firmware fills in carry no information.+ return s.takeIf { it.isNotEmpty() && it.none { c -> c < ' ' || c == '�' } && it !in PLACEHOLDERS }+ }++ private val PLACEHOLDERS = setOf("0", "1", "123456", "Unknown", "unknown", "N/A", "NA", " ")++ /**+ * Fingerprint of a probe request's information elements from [from] to [end]: element+ * order plus the fields that describe the hardware and driver, not the moment (no+ * network name, channel, rates or WPS strings). 8 hex digits.+ */+ fun fingerprint(b: ByteArray, from: Int, end: Int): String? {+ val sb = StringBuilder()+ var i = from; var n = 0+ while (i + 2 <= end) {+ val tag = b[i].toInt() and 0xff; val len = b[i + 1].toInt() and 0xff+ if (i + 2 + len > end) break+ val d = i + 2+ when (tag) {+ 0, 1, 3, 50 -> {} // name, rates, channel: change with what / where it asks+ 45 -> sb.append("ht:").append(hex(b, d, minOf(len, 3))) // HT capability info + A-MPDU+ 127 -> sb.append("ext:").append(hex(b, d, len)) // extended capabilities+ 191 -> sb.append("vht:").append(hex(b, d, minOf(len, 4))) // VHT capability info+ 221 -> sb.append("v:").append(hex(b, d, minOf(len, 4))) // vendor element: OUI + type+ 255 -> sb.append("x:").append(if (len > 0) hex(b, d, 1) else "") // extension element id+ else -> sb.append(tag)+ }+ sb.append(','); n+++ i = d + len+ }+ if (n < 2) return null // a bare wildcard request says nothing about the hardware+ val crc = CRC32().apply { update(sb.toString().toByteArray()) }+ return "%08x".format(crc.value)+ }++ private fun hex(b: ByteArray, at: Int, len: Int) = (at until at + len).joinToString("") { "%02x".format(b[it].toInt() and 0xff) }++ /** What external hardware learned about a device this scan, for its detail screen. */+ data class Record(val wps: Wps?, val fingerprint: String?, val probed: List<String>)++ private val byMac = ConcurrentHashMap<String, Record>()++ fun note(mac: String, wps: Wps?, fingerprint: String?, probed: List<String>) {+ if (wps == null && fingerprint == null && probed.isEmpty()) return+ val key = mac.uppercase()+ val old = byMac[key]+ byMac[key] = Record(wps ?: old?.wps, fingerprint ?: old?.fingerprint, probed.ifEmpty { old?.probed.orEmpty() })+ if (byMac.size > 5000) byMac.keys.take(500).forEach { byMac.remove(it) }+ }++ fun of(mac: String): Record? = byMac[mac.uppercase()]++ fun clear() = byMac.clear()+}diff --git a/app/src/main/java/com/rfsentinel/app/usb/UsbWifi.kt b/app/src/main/java/com/rfsentinel/app/usb/UsbWifi.ktindex ec3138b..aa790dc 100644--- a/app/src/main/java/com/rfsentinel/app/usb/UsbWifi.kt+++ b/app/src/main/java/com/rfsentinel/app/usb/UsbWifi.kt@@ -20,7 +20,13 @@ data class MonitorSighting(/** Access point (beacon / probe response) or a client device (probe request, data). */val isAccessPoint: Boolean,/** The access point a client was talking to, when known. */- val bssid: String? = null+ val bssid: String? = null,+ /** Network names a client device asked for by name (probe requests). */+ val probedSsids: List<String> = emptyList(),+ /** Maker / model / device name from its WPS block. */+ val wps: ProbeIntel.Wps? = null,+ /** How it builds its probe requests: marks a device model / OS ([ProbeIntel.fingerprint]). */+ val fingerprint: String? = null)/**diff --git a/app/src/main/java/com/rfsentinel/app/util/Prefs.kt b/app/src/main/java/com/rfsentinel/app/util/Prefs.ktindex 4c71e4a..e262d37 100644--- a/app/src/main/java/com/rfsentinel/app/util/Prefs.kt+++ b/app/src/main/java/com/rfsentinel/app/util/Prefs.kt@@ -158,6 +158,10 @@ object Prefs {fun setShortVoice(context: Context, value: Boolean) = setBool(context, "short_voice", value)/** Leave Apple Find My tags (AirTags and compatible) out of the Trackers category. */+ /** Keep the WiFi network names devices around you ask for (USB WiFi adapter / ESP32 Marauder). */+ fun recordProbes(context: Context): Boolean = bool(context, "record_probes", false)+ fun setRecordProbes(context: Context, value: Boolean) = sp(context).edit().putBoolean("record_probes", value).apply()+fun excludeAirTags(context: Context): Boolean = bool(context, "exclude_airtags", false)fun setExcludeAirTags(context: Context, value: Boolean) {setBool(context, "exclude_airtags", value)@@ -183,6 +187,10 @@ object Prefs {fun setStartedByCar(context: Context, value: Boolean) = setBool(context, "started_by_car", value)/** Floating threat bubble over other apps while scanning. */+ /** Floating mini map with the devices around you, drawn over other apps while scanning. */+ fun floatingMap(context: Context): Boolean = bool(context, "floating_map", false)+ fun setFloatingMap(context: Context, value: Boolean) = setBool(context, "floating_map", value)+fun threatBubble(context: Context): Boolean = bool(context, "threat_bubble", false)fun setThreatBubble(context: Context, value: Boolean) = setBool(context, "threat_bubble", value)diff --git a/app/src/main/java/com/rfsentinel/app/util/TripExport.kt b/app/src/main/java/com/rfsentinel/app/util/TripExport.ktindex 1cb28d3..75b6a43 100644--- a/app/src/main/java/com/rfsentinel/app/util/TripExport.kt+++ b/app/src/main/java/com/rfsentinel/app/util/TripExport.kt@@ -29,6 +29,7 @@ object TripExport {d.category?.let { append(" - ").append(it).append(' ').append(d.confidence).append('%') }append(" - best ").append(d.bestRssi).append(" dBm")d.evidence?.let { append(" - ").append(it) }+ d.probedList.takeIf { it.isNotEmpty() }?.let { append(" - asked for: ").append(it.joinToString(", ")) }}/** GPX 1.1: one track segment + a waypoint per positioned device. */@@ -108,6 +109,7 @@ object TripExport {addProperty("name", d.name); addProperty("vendor", d.vendor); addProperty("deviceType", d.deviceType)addProperty("source", d.source); addProperty("category", d.category); addProperty("confidence", d.confidence)addProperty("evidence", d.evidence); addProperty("bestRssi", d.bestRssi)+ add("requestedNetworks", JsonArray().apply { d.probedList.forEach { add(it) } })addProperty("firstSeen", iso(d.firstSeen)); addProperty("lastSeen", iso(d.lastSeen))})})@@ -121,13 +123,14 @@ object TripExport {/** Spreadsheet of every device heard on the trip. */fun devicesCsv(devices: List<TripDeviceEntity>): String {- val sb = StringBuilder("mac,label,name,vendor,device_type,source,flagged,category,confidence,evidence,first_seen,last_seen,best_rssi,latitude,longitude\n")+ val sb = StringBuilder("mac,label,name,vendor,device_type,source,flagged,category,confidence,evidence,first_seen,last_seen,best_rssi,latitude,longitude,requested_networks\n")devices.forEach { d ->sb.append(d.mac).append(',').append(q(d.label)).append(',').append(q(d.name)).append(',').append(q(d.vendor)).append(',').append(q(d.deviceType)).append(',').append(d.source).append(',').append(d.flagged).append(',').append(d.category ?: "").append(',').append(d.confidence).append(',').append(q(d.evidence)).append(',').append(local(d.firstSeen)).append(',').append(local(d.lastSeen)).append(',')- .append(d.bestRssi).append(',').append(d.lat ?: "").append(',').append(d.lon ?: "").append('\n')+ .append(d.bestRssi).append(',').append(d.lat ?: "").append(',').append(d.lon ?: "").append(',')+ .append(q(d.probedList.joinToString("; ").ifEmpty { null })).append('\n')}return sb.toString()}diff --git a/app/src/main/res/layout/activity_oui_list.xml b/app/src/main/res/layout/activity_oui_list.xmlindex 3c9589e..faea23f 100644--- a/app/src/main/res/layout/activity_oui_list.xml+++ b/app/src/main/res/layout/activity_oui_list.xml@@ -29,6 +29,12 @@android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Maker has" />++ <RadioButton+ android:id="@+id/typeProbe"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:text="Asks for" /></RadioGroup><EditTextdiff --git a/app/src/main/res/layout/activity_probe_list.xml b/app/src/main/res/layout/activity_probe_list.xmlnew file mode 100644index 0000000..ca12cef--- /dev/null+++ b/app/src/main/res/layout/activity_probe_list.xml@@ -0,0 +1,53 @@+<?xml version="1.0" encoding="utf-8"?>+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:orientation="vertical"+ android:padding="16dp">++ <com.google.android.material.switchmaterial.SwitchMaterial+ android:id="@+id/recordSwitch"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:text="Record the networks devices ask for" />++ <TextView+ android:id="@+id/infoText"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:paddingTop="2dp"+ android:paddingBottom="8dp"+ android:textSize="12sp"+ android:textColor="#888888"+ android:text="Phones and laptops ask by name for WiFi networks they joined before. A USB WiFi adapter or an ESP32 Marauder board hears these requests. Kept only on this phone; a map trace recording always keeps them, with the trace. Tap a name to watch it: you get an alert whenever a device asks for it." />++ <EditText+ android:id="@+id/filterInput"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:inputType="text|textNoSuggestions"+ android:importantForAutofill="no"+ android:hint="Filter by name" />++ <TextView+ android:id="@+id/emptyText"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:paddingTop="16dp"+ android:visibility="gone" />++ <androidx.recyclerview.widget.RecyclerView+ android:id="@+id/recyclerView"+ android:layout_width="match_parent"+ android:layout_height="0dp"+ android:layout_weight="1"+ android:layout_marginTop="8dp" />++ <Button+ android:id="@+id/clearButton"+ style="@style/Widget.MaterialComponents.Button.TextButton"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:text="Clear the list" />++</LinearLayout>diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xmlindex def5442..5e69f1f 100644--- a/app/src/main/res/layout/activity_settings.xml+++ b/app/src/main/res/layout/activity_settings.xml@@ -316,6 +316,12 @@android:layout_height="wrap_content"android:text="Floating threat bubble over other apps (e.g. Waze, Maps) while scanning" />+ <com.google.android.material.switchmaterial.SwitchMaterial+ android:id="@+id/floatingMapSwitch"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:text="Floating mini map over other apps while scanning: the devices around you, like the app's map (drag to move, pinch to zoom, corner handle to resize, tap to open the full map)" />+<com.google.android.material.switchmaterial.SwitchMaterialandroid:id="@+id/discreetSwitch"android:layout_width="match_parent"diff --git a/app/src/main/res/layout/dialog_add_watchlist.xml b/app/src/main/res/layout/dialog_add_watchlist.xmlindex e12ec59..f956b56 100644--- a/app/src/main/res/layout/dialog_add_watchlist.xml+++ b/app/src/main/res/layout/dialog_add_watchlist.xml@@ -22,6 +22,12 @@android:id="@+id/scopePrefix"android:layout_width="match_parent"android:layout_height="wrap_content" />++ <RadioButton+ android:id="@+id/scopeFingerprint"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:visibility="gone" /></RadioGroup><TextViewdiff --git a/app/src/main/res/layout/item_probe.xml b/app/src/main/res/layout/item_probe.xmlnew file mode 100644index 0000000..a0e37da--- /dev/null+++ b/app/src/main/res/layout/item_probe.xml@@ -0,0 +1,37 @@+<?xml version="1.0" encoding="utf-8"?>+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:orientation="horizontal"+ android:background="?attr/selectableItemBackground"+ android:padding="12dp"+ android:gravity="center_vertical">++ <LinearLayout+ android:layout_width="0dp"+ android:layout_height="wrap_content"+ android:layout_weight="1"+ android:orientation="vertical">++ <TextView+ android:id="@+id/ssidText"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:textStyle="bold" />++ <TextView+ android:id="@+id/metaText"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:textSize="12sp"+ android:textColor="#888888" />+ </LinearLayout>++ <Button+ android:id="@+id/watchButton"+ style="@style/Widget.MaterialComponents.Button.OutlinedButton"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:text="Watch" />++</LinearLayout>diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xmlindex 86a5cd2..28495db 100644--- a/app/src/main/res/menu/menu_main.xml+++ b/app/src/main/res/menu/menu_main.xml@@ -16,6 +16,7 @@<item android:id="@+id/action_traces" android:title="Recorded traces" app:showAsAction="never" /><item android:id="@+id/action_history" android:title="History map & timeline" app:showAsAction="never" /><item android:id="@+id/action_oui_list" android:title="Watchlist & rules" app:showAsAction="never" />+ <item android:id="@+id/action_probes" android:title="Requested networks" app:showAsAction="never" /><item android:id="@+id/action_whitelist" android:title="Whitelist (trusted devices)" app:showAsAction="never" /><item android:id="@+id/action_settings" android:title="Settings" app:showAsAction="never" /><item android:id="@+id/action_export_all" android:title="Export all devices..." app:showAsAction="never" />diff --git a/app/src/test/java/com/rfsentinel/app/data/ProbeBookTest.kt b/app/src/test/java/com/rfsentinel/app/data/ProbeBookTest.ktnew file mode 100644index 0000000..4a49977--- /dev/null+++ b/app/src/test/java/com/rfsentinel/app/data/ProbeBookTest.kt@@ -0,0 +1,45 @@+package com.rfsentinel.app.data++import org.junit.Assert.assertEquals+import org.junit.Assert.assertTrue+import org.junit.Test++class ProbeBookTest {++ @Test+ fun recordsNetworksDevicesAndEncounters() {+ val b = ProbeBook()+ b.record("PD-MDT", "aa:bb:cc:00:00:01", -70, 0)+ b.record("pd-mdt", "AA:BB:CC:00:00:02", -60, 1_000) // same name, any case+ b.record("PD-MDT", "aa:bb:cc:00:00:01", -65, 2_000) // same device again+ b.record("PD-MDT", "aa:bb:cc:00:00:03", -80, 2_000 + ProbeBook.GAP_MS + 1) // a new encounter+ val n = b.all().single()+ assertEquals("PD-MDT", n.ssid)+ assertEquals(3, n.devices.size)+ assertEquals("AA:BB:CC:00:00:03", n.devices.last())+ assertEquals(2, n.encounters)+ assertEquals(-80, n.lastRssi)+ assertEquals(0L, n.firstSeen)+ }++ @Test+ fun keepsTheNewestNamesAndDevices() {+ val b = ProbeBook(maxNetworks = 3, maxDevices = 2)+ for (i in 1..5) b.record("net$i", "02:00:00:00:00:0$i", -50, i * 1000L)+ assertEquals(listOf("net5", "net4", "net3"), b.all().map { it.ssid })+ for (i in 1..4) b.record("net5", "02:00:00:00:01:0$i", -50, 10_000L + i)+ assertEquals(listOf("02:00:00:00:01:03", "02:00:00:00:01:04"), b.all().first().devices)+ }++ @Test+ fun restoresSavedData() {+ val b = ProbeBook()+ b.record("Home", "02:00:00:00:00:01", -50, 5)+ val saved = b.all()+ val c = ProbeBook()+ c.restore(saved)+ assertEquals(saved, c.all())+ c.remove("HOME")+ assertTrue(c.all().isEmpty())+ }+}diff --git a/app/src/test/java/com/rfsentinel/app/detect/PoliceSsidTest.kt b/app/src/test/java/com/rfsentinel/app/detect/PoliceSsidTest.ktnew file mode 100644index 0000000..127013f--- /dev/null+++ b/app/src/test/java/com/rfsentinel/app/detect/PoliceSsidTest.kt@@ -0,0 +1,32 @@+package com.rfsentinel.app.detect++import org.junit.Assert.assertEquals+import org.junit.Assert.assertNull+import org.junit.Assert.assertTrue+import org.junit.Test++class PoliceSsidTest {++ @Test+ fun axonFleetNamesMatch() {+ val axon = SignatureEngine.policeVehicleSsid("Axon12-5g")!!+ assertEquals(Category.PUBLIC_SAFETY, axon.category)+ assertTrue(axon.confidence >= 80)+ assertTrue(SignatureEngine.policeVehicleSsid("AXON 304 5G")!!.confidence >= 80)+ val number = SignatureEngine.policeVehicleSsid("8554-5g")!!+ assertTrue(number.confidence < 50) // weak alone+ }++ @Test+ fun cradlepointDefaultsMatch() {+ assertTrue(SignatureEngine.policeVehicleSsid("IBR900-3ab") != null)+ assertTrue(SignatureEngine.policeVehicleSsid("IBR1700-1F2-5g") != null)+ assertTrue(SignatureEngine.policeVehicleSsid("R1900-c0d") != null)+ }++ @Test+ fun ordinaryNetworksDont() {+ for (name in listOf("NETGEAR42-5G", "Home-5G", "papillon", "Axon", "IBR900", "MBR1400-3e2", "5g", "1-5g"))+ assertNull(name, SignatureEngine.policeVehicleSsid(name))+ }+}diff --git a/app/src/test/java/com/rfsentinel/app/esp/EspReportsTest.kt b/app/src/test/java/com/rfsentinel/app/esp/EspReportsTest.ktindex e7df628..601abbf 100644--- a/app/src/test/java/com/rfsentinel/app/esp/EspReportsTest.kt+++ b/app/src/test/java/com/rfsentinel/app/esp/EspReportsTest.kt@@ -88,6 +88,8 @@ class EspReportsTest {assertTrue(probe.client)assertNull(probe.name)assertEquals(2462, probe.frequencyMhz)+ assertEquals(listOf("Home"), probe.probedSsids)+ assertTrue(MarauderReports.parse("-60 Ch: 1 Client: 02:11:22:33:44:55 Requesting: ")!!.probedSsids.isEmpty()) // wildcardassertNull(MarauderReports.parse("Beacon sniff"))assertTrue(MarauderReports.recognises("============ Commands ============\nchannel [-s <channel>]"))assertTrue(MarauderReports.isFlipperCli("Welcome to Flipper Zero Command Line Interface!\n>: "))diff --git a/app/src/test/java/com/rfsentinel/app/oui/ProbeRuleTest.kt b/app/src/test/java/com/rfsentinel/app/oui/ProbeRuleTest.ktnew file mode 100644index 0000000..2227906--- /dev/null+++ b/app/src/test/java/com/rfsentinel/app/oui/ProbeRuleTest.kt@@ -0,0 +1,33 @@+package com.rfsentinel.app.oui++import com.rfsentinel.app.detect.Category+import org.junit.Assert.assertEquals+import org.junit.Assert.assertFalse+import org.junit.Assert.assertTrue+import org.junit.Test++class ProbeRuleTest {++ @Test+ fun probeRulesAreValidKeys() {+ assertTrue(OuiWatchlist.isValidKey("probe:PD-MDT"))+ assertFalse(OuiWatchlist.isValidKey("probe: "))+ assertEquals("probe:PD MDT", OuiWatchlist.normalizeKey("PROBE: PD MDT "))+ assertTrue(OuiEntry("probe:x", "x").isProbeRule)+ assertEquals("fp:a1b2c3d4", OuiWatchlist.normalizeKey("FP:A1B2C3D4"))+ assertTrue(OuiEntry("fp:a1b2c3d4", "x").isFingerprintRule)+ }++ @Test+ fun aRequestForAWatchedNameIsAnAlertHit() {+ val rule = OuiEntry("probe:PD-MDT", "Police laptop", "user-added", "custom")+ val rules = mapOf("pd-mdt" to rule)+ val hits = OuiWatchlist.probeHits(rules, listOf("Starbucks", "pd-mdt"))+ assertEquals(1, hits.size)+ assertEquals("Police laptop", hits[0].label)+ assertEquals(Category.CUSTOM, hits[0].category)+ assertEquals(100, hits[0].confidence)+ assertTrue(hits[0].evidence.contains("pd-mdt"))+ assertTrue(OuiWatchlist.probeHits(rules, listOf("PD-MDT2")).isEmpty()) // exact name only+ }+}diff --git a/app/src/test/java/com/rfsentinel/app/usb/ProbeIntelTest.kt b/app/src/test/java/com/rfsentinel/app/usb/ProbeIntelTest.ktnew file mode 100644index 0000000..185c1a4--- /dev/null+++ b/app/src/test/java/com/rfsentinel/app/usb/ProbeIntelTest.kt@@ -0,0 +1,57 @@+package com.rfsentinel.app.usb++import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotEquals+import org.junit.Assert.assertNull+import org.junit.Test++class ProbeIntelTest {++ private fun attr(type: Int, v: String) = byteArrayOf((type shr 8).toByte(), type.toByte(), 0, v.length.toByte()) + v.toByteArray()++ /** A WPS vendor element (221, 00:50:F2:04) with maker / model / number / device name. */+ private fun wpsIe(vararg attrs: ByteArray): ByteArray {+ val body = byteArrayOf(0x00, 0x50, 0xF2.toByte(), 0x04) + attrs.fold(ByteArray(0)) { a, b -> a + b }+ return byteArrayOf(221.toByte(), body.size.toByte()) + body+ }++ private fun ie(tag: Int, vararg v: Int) = byteArrayOf(tag.toByte(), v.size.toByte()) + v.map { it.toByte() }.toByteArray()+ private fun ssid(s: String) = byteArrayOf(0, s.length.toByte()) + s.toByteArray()++ /** A probe request's elements from one laptop: name, rates, channel, HT, ext caps, a vendor element. */+ private fun laptop(name: String, channel: Int, ht0: Int = 0xEF) =+ ssid(name) + ie(1, 0x82, 0x84, 0x8b, 0x96) + ie(3, channel) + ie(45, ht0, 0x09, 0x17, 0xff) ++ ie(127, 0x04, 0x00, 0x0a, 0x82) + ie(221, 0x00, 0x50, 0xf2, 0x08, 0x00)++ @Test+ fun wpsBlockGivesMakerModelAndName() {+ val ie = wpsIe(attr(0x1021, "Panasonic"), attr(0x1023, "Toughbook"), attr(0x1024, "CF-33"), attr(0x1011, "PD-UNIT12"))+ val w = ProbeIntel.parseWps(ie, 6, ie.size)!!+ assertEquals("PD-UNIT12", w.label)+ assertEquals("Panasonic Toughbook CF-33", w.product)+ assertNull(ProbeIntel.parseWps(wpsIe(attr(0x1021, "0")), 6, 12)) // placeholder only+ }++ @Test+ fun fingerprintIgnoresWhatAndWhereItAsks() {+ val a = laptop("PD-MDT", 1); val b = laptop("Home", 11)+ assertEquals(ProbeIntel.fingerprint(a, 0, a.size), ProbeIntel.fingerprint(b, 0, b.size))+ val other = laptop("PD-MDT", 1, ht0 = 0x6F) // a different radio+ assertNotEquals(ProbeIntel.fingerprint(a, 0, a.size), ProbeIntel.fingerprint(other, 0, other.size))+ val bare = ssid("")+ assertNull(ProbeIntel.fingerprint(bare, 0, bare.size))+ }++ @Test+ fun probeRequestsCarryWpsAndFingerprintToTheApp() {+ val hdr = ByteArray(24).also { it[0] = 0x40; for (k in 0 until 6) { it[4 + k] = -1; it[16 + k] = -1 } }+ byteArrayOf(0x02, 0x11, 0x22, 0x33, 0x44, 0x55).copyInto(hdr, 10)+ val frame = hdr + laptop("PD-MDT", 6) + wpsIe(attr(0x1021, "Panasonic"), attr(0x1023, "Toughbook"))+ val t = MonitorFrames()+ t.frame(frame, 0, frame.size, 6, -60, 0)+ val s = t.drain(0, 5000).single()+ assertEquals("Panasonic Toughbook", s.wps?.label)+ assertEquals(listOf("PD-MDT"), s.probedSsids)+ assertEquals(8, s.fingerprint?.length)+ }+}diff --git a/app/src/test/java/com/rfsentinel/app/usb/UsbWifiDriverTest.kt b/app/src/test/java/com/rfsentinel/app/usb/UsbWifiDriverTest.ktindex d17b3fe..80b9eb1 100644--- a/app/src/test/java/com/rfsentinel/app/usb/UsbWifiDriverTest.kt+++ b/app/src/test/java/com/rfsentinel/app/usb/UsbWifiDriverTest.kt@@ -85,7 +85,18 @@ class UsbWifiDriverTest {assertEquals(0 to 2, t.live(0, 1000))}+ private fun namedProbe(sa: String, ssid: String): ByteArray = probeRequest(sa).copyOf(24) ++ byteArrayOf(0, ssid.length.toByte()) + ssid.toByteArray()+@Test+ fun probeRequestsKeepTheNamesAsked() {+ val t = MonitorFrames()+ for (name in listOf("PD-MDT", "Home", "PD-MDT")) namedProbe("da:a1:19:00:00:01", name).let { t.frame(it, 0, it.size, 6, -60, 0) }+ probeRequest("da:a1:19:00:00:01").let { t.frame(it, 0, it.size, 6, -60, 0) } // wildcard: no name+ assertEquals(listOf("Home", "PD-MDT"), t.drain(0, 5000).single().probedSsids)+ }++ @Testfun clientCaptureCanBeTurnedOff() {val t = MonitorFrames().apply { captureClients = false }val p = probeRequest("da:a1:19:00:00:01")diff --git a/app/src/test/java/com/rfsentinel/app/util/TripExportTest.kt b/app/src/test/java/com/rfsentinel/app/util/TripExportTest.ktindex a124448..146b1fe 100644--- a/app/src/test/java/com/rfsentinel/app/util/TripExportTest.kt+++ b/app/src/test/java/com/rfsentinel/app/util/TripExportTest.kt@@ -22,7 +22,7 @@ class TripExportTest {TripDeviceEntity(1, "00:25:DF:00:00:01", "Axon body camera", null, "Axon Enterprise, Inc.", "Body camera", "BLE","BODY_CAM", 90, "BWCDEVICE \"tag\"", 1_010_000L, 1_020_000L, -61, 10.505, -20.565),TripDeviceEntity(1, "C0:00:00:00:00:02", "Phone", "Pixel", null, "Phone", "BLE",- null, 0, null, 1_040_000L, 1_050_000L, -80, 10.515, -20.555),+ null, 0, null, 1_040_000L, 1_050_000L, -80, 10.515, -20.555, probed = "PD-MDT\nHome"),TripDeviceEntity(1, "C0:00:00:00:00:03", "No fix", null, null, null, "WIFI",null, 0, null, 1_040_000L, 1_050_000L, -85, null, null))@@ -70,4 +70,20 @@ class TripExportTest {assertTrue(lines[1].contains("\"BWCDEVICE \"\"tag\"\"\""))assertFalse(lines[3].contains("null"))}++ @Test+ fun requestedNetworksGoIntoTheExports() {+ assertTrue(TripExport.devicesCsv(devices).lines()[0].endsWith("requested_networks"))+ assertTrue(TripExport.devicesCsv(devices).lines()[2].contains("PD-MDT; Home"))+ assertTrue(TripExport.kml(trip, points, devices, onlyFlagged = false).contains("asked for: PD-MDT, Home"))+ }++ @Test+ fun requestedNetworksMergeAcrossObservations() {+ val r = com.rfsentinel.app.service.TripRecorder+ assertEquals(null, r.mergeProbed(emptyList(), emptyList()))+ assertEquals("A\nB", r.mergeProbed(listOf("A"), listOf("B")))+ assertEquals("B\nA", r.mergeProbed(listOf("A", "B"), listOf("A")))+ assertEquals(16, r.mergeProbed((1..16).map { "n$it" }, listOf("x"))!!.lines().size)+ }}