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
Trace exports include every logged sighting (GPX, KML, GeoJSON, sightings CSV)
CIS-C074c5b4cd3eb0
diff --git a/app/src/main/java/com/rfsentinel/app/util/Exporter.kt b/app/src/main/java/com/rfsentinel/app/util/Exporter.ktindex 7f40484..5a6b47a 100644--- a/app/src/main/java/com/rfsentinel/app/util/Exporter.kt+++ b/app/src/main/java/com/rfsentinel/app/util/Exporter.kt@@ -215,18 +215,19 @@ object Exporter {/** Export one recorded trace: pick a format, then whether to include every device. *//** [snapshot]: a saved device list ([com.rfsentinel.app.data.Snapshots]) - no route, just the devices. */fun showTripExport(activity: AppCompatActivity, tripId: Long, snapshot: Boolean = false) {- val formats = listOf("gpx", "kml", "geojson", "csv")- val labels = arrayOf(+ val formats = listOf("gpx", "kml", "geojson", "csv") + if (snapshot) emptyList() else listOf("sightings")+ val labels = listOfNotNull(if (snapshot) "GPX - device waypoints (GPS / map apps)" else "GPX - track + device waypoints (GPS / map apps)","KML - Google Earth / My Maps","GeoJSON - web maps, QGIS",- if (snapshot) "CSV - devices in this snapshot (spreadsheet)" else "CSV - devices heard on this trace (spreadsheet)"- )+ if (snapshot) "CSV - devices in this snapshot (spreadsheet)" else "CSV - devices heard on this trace (spreadsheet)",+ if (snapshot) null else "CSV - every sighting with its position (spreadsheet)"+ ).toTypedArray()MaterialAlertDialogBuilder(activity).setTitle(if (snapshot) "Export snapshot" else "Export trace").setItems(labels) { _, which ->val format = formats[which]- if (format == "csv") {+ if (format == "csv" || format == "sightings") {exportTrip(activity, tripId, format, onlyFlagged = false)} else {MaterialAlertDialogBuilder(activity)@@ -251,20 +252,27 @@ object Exporter {val trip = dao.get(tripId) ?: run { toast(activity, "Trace not found"); return@launchExport }val points = dao.points(tripId)val devices = dao.devices(tripId)- if (points.isEmpty() && devices.none { it.lat != null } && format != "csv") {+ val pings = dao.pings(tripId)+ if (format == "sightings" && pings.isEmpty()) {+ toast(activity, "No sightings logged on this trace. Turn on Log every sighting in traces before recording.")+ return@launchExport+ }+ if (points.isEmpty() && devices.none { it.lat != null } && format != "csv" && format != "sightings") {toast(activity, if (trip.snapshot) "No device in this snapshot has a position" else "This trace has no GPS points yet")return@launchExport}val (text, mime, ext) = withContext(Dispatchers.Default) {when (format) {- "gpx" -> Triple(TripExport.gpx(trip, points, devices, onlyFlagged), "application/gpx+xml", "gpx")- "kml" -> Triple(TripExport.kml(trip, points, devices, onlyFlagged), "application/vnd.google-earth.kml+xml", "kml")- "geojson" -> Triple(TripExport.geoJson(trip, points, devices, onlyFlagged), "application/geo+json", "geojson")+ "gpx" -> Triple(TripExport.gpx(trip, points, devices, onlyFlagged, pings), "application/gpx+xml", "gpx")+ "kml" -> Triple(TripExport.kml(trip, points, devices, onlyFlagged, pings), "application/vnd.google-earth.kml+xml", "kml")+ "geojson" -> Triple(TripExport.geoJson(trip, points, devices, onlyFlagged, pings), "application/geo+json", "geojson")+ "sightings" -> Triple(TripExport.sightingsCsv(pings, devices), "text/csv", "csv")else -> Triple(TripExport.devicesCsv(devices), "text/csv", "csv")}}val safeName = trip.name.replace(Regex("[^A-Za-z0-9_-]+"), "_").trim('_').take(40)- share(activity, "rf_sentinel_trace_${safeName}.$ext", text, mime, "Export trace")+ val kind = if (format == "sightings") "sightings" else "trace"+ share(activity, "rf_sentinel_${kind}_${safeName}.$ext", text, mime, "Export trace")}}diff --git a/app/src/main/java/com/rfsentinel/app/util/TripExport.kt b/app/src/main/java/com/rfsentinel/app/util/TripExport.ktindex 47d5c45..43ec416 100644--- a/app/src/main/java/com/rfsentinel/app/util/TripExport.kt+++ b/app/src/main/java/com/rfsentinel/app/util/TripExport.kt@@ -5,6 +5,7 @@ import com.google.gson.JsonArrayimport com.google.gson.JsonObjectimport com.rfsentinel.app.data.TripDeviceEntityimport com.rfsentinel.app.data.TripEntity+import com.rfsentinel.app.data.TripPingEntityimport com.rfsentinel.app.data.TripPointEntityimport com.rfsentinel.app.detect.DeviceIntelimport java.text.SimpleDateFormat@@ -14,7 +15,8 @@ import java.util.TimeZone/*** Exports a recorded trace: your GPS track plus the devices heard along it- * (placed where their signal was strongest). Pure Kotlin, unit-tested.+ * (placed where their signal was strongest), and every logged sighting when "Log every sighting in traces" was on.+ * Pure Kotlin, unit-tested.*/object TripExport {@@ -33,8 +35,18 @@ object TripExport {d.probedList.takeIf { it.isNotEmpty() }?.let { append(" - asked for: ").append(it.joinToString(", ")) }}- /** GPX 1.1: one track segment + a waypoint per positioned device. */- fun gpx(trip: TripEntity, points: List<TripPointEntity>, devices: List<TripDeviceEntity>, onlyFlagged: Boolean): String {+ /** The sightings of the exported devices (only the flagged ones' with [onlyFlagged]), each with its device's label. */+ private fun sightings(pings: List<TripPingEntity>, devices: List<TripDeviceEntity>, onlyFlagged: Boolean): List<Pair<TripPingEntity, String>> {+ val byMac = devices.associateBy { it.mac }+ return pings.mapNotNull { p ->+ val d = byMac[p.mac]+ if (onlyFlagged && d?.flagged != true) null else p to (d?.label ?: p.mac)+ }+ }++ /** GPX 1.1: one track segment + a waypoint per positioned device, and one per sighting (type SIGHTING). */+ fun gpx(trip: TripEntity, points: List<TripPointEntity>, devices: List<TripDeviceEntity>, onlyFlagged: Boolean,+ pings: List<TripPingEntity> = emptyList()): String {val sb = StringBuilder()sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")sb.append("<gpx version=\"1.1\" creator=\"RF Sentinel\" xmlns=\"http://www.topografix.com/GPX/1/1\">\n")@@ -47,6 +59,11 @@ object TripExport {sb.append(" <type>").append(x(d.category ?: "DEVICE")).append("</type>\n")sb.append(" </wpt>\n")}+ sightings(pings, devices, onlyFlagged).forEach { (p, label) ->+ sb.append(String.format(Locale.US, " <wpt lat=\"%.7f\" lon=\"%.7f\"><time>%s</time>", p.lat, p.lon, iso(p.time)))+ .append("<name>").append(x(label)).append("</name><desc>").append(x("${p.mac} - ${p.rssi} dBm")).append("</desc>")+ .append("<type>SIGHTING</type></wpt>\n")+ }sb.append(" <trk><name>").append(x(trip.name)).append("</name><trkseg>\n")points.forEach { p ->sb.append(String.format(Locale.US, " <trkpt lat=\"%.7f\" lon=\"%.7f\"><time>%s</time></trkpt>\n", p.lat, p.lon, iso(p.time)))@@ -56,13 +73,15 @@ object TripExport {}/** KML: the trace as a line, devices as placemarks (flagged in red, others grey). */- fun kml(trip: TripEntity, points: List<TripPointEntity>, devices: List<TripDeviceEntity>, onlyFlagged: Boolean): String {+ fun kml(trip: TripEntity, points: List<TripPointEntity>, devices: List<TripDeviceEntity>, onlyFlagged: Boolean,+ pings: List<TripPingEntity> = emptyList()): String {val sb = StringBuilder()sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n<Document>\n")sb.append(" <name>").append(x(trip.name)).append("</name>\n")sb.append(" <Style id=\"trace\"><LineStyle><color>ff2d62e0</color><width>4</width></LineStyle></Style>\n")sb.append(" <Style id=\"flagged\"><IconStyle><color>ff1a26b3</color></IconStyle></Style>\n")sb.append(" <Style id=\"device\"><IconStyle><color>ff9e9e9e</color><scale>0.6</scale></IconStyle></Style>\n")+ sb.append(" <Style id=\"sighting\"><IconStyle><scale>0.3</scale></IconStyle></Style>\n")if (points.size >= 2) {sb.append(" <Placemark><name>Trace</name><styleUrl>#trace</styleUrl><LineString><tessellate>1</tessellate><coordinates>\n")points.forEach { p -> sb.append(String.format(Locale.US, " %.7f,%.7f,0\n", p.lon, p.lat)) }@@ -74,12 +93,23 @@ object TripExport {.append("<description>").append(x(describe(d) + " - " + local(d.firstSeen))).append("</description>").append(String.format(Locale.US, "<Point><coordinates>%.7f,%.7f,0</coordinates></Point></Placemark>\n", d.lon, d.lat))}+ val seen = sightings(pings, devices, onlyFlagged)+ if (seen.isNotEmpty()) {+ sb.append(" <Folder><name>Every sighting</name>\n")+ seen.forEach { (p, label) ->+ sb.append(" <Placemark><name>").append(x(label)).append("</name><styleUrl>#sighting</styleUrl>")+ .append("<description>").append(x("${p.mac} - ${p.rssi} dBm - ${local(p.time)}")).append("</description>")+ .append(String.format(Locale.US, "<Point><coordinates>%.7f,%.7f,0</coordinates></Point></Placemark>\n", p.lon, p.lat))+ }+ sb.append(" </Folder>\n")+ }sb.append("</Document>\n</kml>\n")return sb.toString()}/** GeoJSON FeatureCollection (RFC 7946): LineString trace + Point devices. */- fun geoJson(trip: TripEntity, points: List<TripPointEntity>, devices: List<TripDeviceEntity>, onlyFlagged: Boolean): String {+ fun geoJson(trip: TripEntity, points: List<TripPointEntity>, devices: List<TripDeviceEntity>, onlyFlagged: Boolean,+ pings: List<TripPingEntity> = emptyList()): String {val features = JsonArray()if (points.isNotEmpty()) {features.add(JsonObject().apply {@@ -115,6 +145,19 @@ object TripExport {})})}+ sightings(pings, devices, onlyFlagged).forEach { (p, label) ->+ features.add(JsonObject().apply {+ addProperty("type", "Feature")+ add("geometry", JsonObject().apply {+ addProperty("type", "Point")+ add("coordinates", JsonArray().apply { add(p.lon); add(p.lat) })+ })+ add("properties", JsonObject().apply {+ addProperty("kind", "sighting"); addProperty("mac", p.mac); addProperty("label", label)+ addProperty("rssi", p.rssi); addProperty("time", iso(p.time))+ })+ })+ }val root = JsonObject().apply {addProperty("type", "FeatureCollection")add("features", features)@@ -122,6 +165,16 @@ object TripExport {return GsonBuilder().setPrettyPrinting().serializeNulls().create().toJson(root)}+ /** Spreadsheet of every logged sighting: when, which device, how strong, and where you were. */+ fun sightingsCsv(pings: List<TripPingEntity>, devices: List<TripDeviceEntity>): String {+ val sb = StringBuilder("time,mac,label,rssi,latitude,longitude\n")+ sightings(pings, devices, onlyFlagged = false).forEach { (p, label) ->+ sb.append(local(p.time)).append(',').append(p.mac).append(',').append(q(label)).append(',').append(p.rssi).append(',')+ .append(String.format(Locale.US, "%.7f,%.7f", p.lat, p.lon)).append('\n')+ }+ return sb.toString()+ }+/** 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,requested_networks\n")diff --git a/app/src/test/java/com/rfsentinel/app/util/TripExportTest.kt b/app/src/test/java/com/rfsentinel/app/util/TripExportTest.ktindex 146b1fe..8c2dbb7 100644--- a/app/src/test/java/com/rfsentinel/app/util/TripExportTest.kt+++ b/app/src/test/java/com/rfsentinel/app/util/TripExportTest.kt@@ -3,6 +3,7 @@ package com.rfsentinel.app.utilimport com.google.gson.JsonParserimport com.rfsentinel.app.data.TripDeviceEntityimport com.rfsentinel.app.data.TripEntity+import com.rfsentinel.app.data.TripPingEntityimport com.rfsentinel.app.data.TripPointEntityimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertFalse@@ -42,6 +43,23 @@ class TripExportTest {assertEquals(1, flaggedOnly.getElementsByTagName("wpt").length)}+ @Test+ fun sightingsAreExportedForTheChosenDevices() {+ val pings = listOf(+ TripPingEntity(tripId = 1, mac = "00:25:DF:00:00:01", time = 1_011_000L, rssi = -70, lat = 10.504, lon = -20.566),+ TripPingEntity(tripId = 1, mac = "00:25:DF:00:00:01", time = 1_015_000L, rssi = -62, lat = 10.505, lon = -20.565),+ TripPingEntity(tripId = 1, mac = "C0:00:00:00:00:02", time = 1_041_000L, rssi = -81, lat = 10.515, lon = -20.555)+ )+ assertEquals(2 + 3, parseXml(TripExport.gpx(trip, points, devices, onlyFlagged = false, pings)).getElementsByTagName("wpt").length)+ assertEquals(1 + 2, parseXml(TripExport.gpx(trip, points, devices, onlyFlagged = true, pings)).getElementsByTagName("wpt").length)+ assertEquals(3 + 3, parseXml(TripExport.kml(trip, points, devices, onlyFlagged = false, pings)).getElementsByTagName("Placemark").length)+ val features = JsonParser.parseString(TripExport.geoJson(trip, points, devices, onlyFlagged = false, pings)).asJsonObject["features"].asJsonArray+ assertEquals(3, features.count { it.asJsonObject["properties"].asJsonObject["kind"].asString == "sighting" })+ val csv = TripExport.sightingsCsv(pings, devices).trim().lines()+ assertEquals(4, csv.size)+ assertTrue(csv[1].contains("Axon body camera") && csv[1].endsWith("-70,10.5040000,-20.5660000"))+ }+@Testfun kmlIsValidXmlWithLineAndPlacemarks() {val doc = parseXml(TripExport.kml(trip, points, devices, onlyFlagged = false))