Skip to content

RF Sentinel (RFSentinel): free, open-source police detector app for Android. Spots police body cams, Flock ALPR cameras, AirTag trackers, Remote ID drones, smart glasses and fake cell towers from Bluetooth LE and WiFi. No root.

Fix bugs found in review: spam recount, off-globe positions, FCS fingerprints, split UTF-8, BOM import, Waze parse, CSV quoting

CIS-C020ad6c4e4c39
diff --git a/app/src/main/java/com/rfsentinel/app/detect/HackerWatch.kt b/app/src/main/java/com/rfsentinel/app/detect/HackerWatch.kt
index 8ad7fac..eefd37c 100644
--- a/app/src/main/java/com/rfsentinel/app/detect/HackerWatch.kt
+++ b/app/src/main/java/com/rfsentinel/app/detect/HackerWatch.kt
@@ -199,24 +199,28 @@ object HackerWatch {
// ---- Bluetooth spam flood -------------------------------------------------------------
- private val spamTimes = ArrayDeque<Long>()
+ /** Pairing-popup addresses heard in the last minute, oldest first, so one address counts once. */
+ private val spamSeen = LinkedHashMap<String, Long>()
private var lastFlood = Long.MIN_VALUE / 2
const val SPAM_THRESHOLD = 50
/**
* Called once per newly heard Bluetooth address. A flood of new addresses sending
* pairing pop-ups (Apple proximity pairing / nearby action, Google Fast Pair, Microsoft
- * Swift Pair) is what Flipper Zero and ESP32 "BLE spam" attacks look like.
+ * Swift Pair) is what Flipper Zero and ESP32 "BLE spam" attacks look like. An address already
+ * counted is skipped, even if the caller sees it as new again (its classification cache cleared).
*/
@Synchronized
fun bleSpam(a: Advert, now: Long): Hit? {
if (a.source != Advert.Source.BLE || !isPairingPopup(a)) return null
- spamTimes.addLast(now)
- while (spamTimes.isNotEmpty() && now - spamTimes.first() > 60_000L) spamTimes.removeFirst()
- if (spamTimes.size < SPAM_THRESHOLD || now - lastFlood < 10 * 60_000L) return null
+ val it = spamSeen.values.iterator()
+ while (it.hasNext() && now - it.next() > 60_000L) it.remove()
+ if (spamSeen.containsKey(a.mac)) return null
+ spamSeen[a.mac] = now
+ if (spamSeen.size < SPAM_THRESHOLD || now - lastFlood < 10 * 60_000L) return null
lastFlood = now
return Hit(Category.HACKER, "Bluetooth spam attack nearby", 75,
- "${spamTimes.size} new devices sent pairing pop-ups in one minute - typical of a Flipper Zero / ESP32 " +
+ "${spamSeen.size} new devices sent pairing pop-ups in one minute - typical of a Flipper Zero / ESP32 " +
"Bluetooth spam attack. Ignore pairing requests you didn't start.", SRC)
}
@@ -300,6 +304,6 @@ object HackerWatch {
@Synchronized
fun reset() {
- bySsid.clear(); twinsFlagged.clear(); spamTimes.clear(); lastFlood = Long.MIN_VALUE / 2; networks.clear()
+ bySsid.clear(); twinsFlagged.clear(); spamSeen.clear(); lastFlood = Long.MIN_VALUE / 2; networks.clear()
}
}
diff --git a/app/src/main/java/com/rfsentinel/app/detect/RemoteId.kt b/app/src/main/java/com/rfsentinel/app/detect/RemoteId.kt
index 994877a..8c06ceb 100644
--- a/app/src/main/java/com/rfsentinel/app/detect/RemoteId.kt
+++ b/app/src/main/java/com/rfsentinel/app/detect/RemoteId.kt
@@ -98,12 +98,12 @@ object RemoteId {
?.let { acc.copy(uasId = it, idType = "French ID (signalement électronique)") } ?: acc
3 -> if (acc.idType?.startsWith("French") == true) acc else Bytes.ascii(b, v, len)?.trim()
?.takeIf { it.isNotEmpty() }?.let { acc.copy(uasId = it, idType = ID_TYPES[1]) } ?: acc
- 4 -> if (len == 4) acc.copy(latitude = int() * 1e-5) else acc
- 5 -> if (len == 4) acc.copy(longitude = int() * 1e-5) else acc
+ 4 -> if (len == 4 && int() in -9_000_000..9_000_000) acc.copy(latitude = int() * 1e-5) else acc
+ 5 -> if (len == 4 && int() in -18_000_000..18_000_000) acc.copy(longitude = int() * 1e-5) else acc
6 -> if (len == 2) acc.copy(altitudeGeoM = int().toDouble()) else acc
7 -> if (len == 2) acc.copy(heightM = int().toDouble()) else acc
- 8 -> if (len == 4) acc.copy(operatorLatitude = int() * 1e-5) else acc
- 9 -> if (len == 4) acc.copy(operatorLongitude = int() * 1e-5) else acc
+ 8 -> if (len == 4 && int() in -9_000_000..9_000_000) acc.copy(operatorLatitude = int() * 1e-5) else acc
+ 9 -> if (len == 4 && int() in -18_000_000..18_000_000) acc.copy(operatorLongitude = int() * 1e-5) else acc
10 -> if (len == 1) acc.copy(speedMs = Bytes.u8(b, v).toDouble()) else acc
11 -> if (len == 2) acc.copy(directionDeg = int().takeIf { it in 0..359 } ?: acc.directionDeg) else acc
else -> acc
@@ -182,8 +182,8 @@ object RemoteId {
}
return info.copy(
status = STATUS.getOrNull(status) ?: info.status,
- latitude = if (lat != 0) lat * 1e-7 else info.latitude,
- longitude = if (lon != 0) lon * 1e-7 else info.longitude,
+ latitude = latOf(lat) ?: info.latitude,
+ longitude = lonOf(lon) ?: info.longitude,
altitudeGeoM = decodeAltitude(altGeo) ?: info.altitudeGeoM,
heightM = decodeAltitude(height) ?: info.heightM,
speedMs = speed ?: info.speedMs,
@@ -196,11 +196,15 @@ object RemoteId {
val lat = Bytes.i32le(b, off + 2)
val lon = Bytes.i32le(b, off + 6)
return info.copy(
- operatorLatitude = if (lat != 0) lat * 1e-7 else info.operatorLatitude,
- operatorLongitude = if (lon != 0) lon * 1e-7 else info.operatorLongitude
+ operatorLatitude = latOf(lat) ?: info.operatorLatitude,
+ operatorLongitude = lonOf(lon) ?: info.operatorLongitude
)
}
+ /** Degrees x 1e7; 0 is "no fix", and a value off the globe is a corrupt frame: both null. */
+ private fun latOf(e7: Int): Double? = (e7 * 1e-7).takeIf { e7 != 0 && it in -90.0..90.0 }
+ private fun lonOf(e7: Int): Double? = (e7 * 1e-7).takeIf { e7 != 0 && it in -180.0..180.0 }
+
/** Encoded 0 means "unknown" (-1000 m). */
private fun decodeAltitude(enc: Int): Double? = if (enc == 0) null else enc * 0.5 - 1000.0
}
diff --git a/app/src/main/java/com/rfsentinel/app/esp/EspReader.kt b/app/src/main/java/com/rfsentinel/app/esp/EspReader.kt
index 9ec2011..e6c3a01 100644
--- a/app/src/main/java/com/rfsentinel/app/esp/EspReader.kt
+++ b/app/src/main/java/com/rfsentinel/app/esp/EspReader.kt
@@ -19,6 +19,7 @@ class EspReader(
private val onSightings: (List<EspSighting>) -> Unit
) {
@Volatile private var stopped = false
+ private val text = Utf8Chunks()
fun stop() { stopped = true }
@@ -101,7 +102,7 @@ class EspReader(
val n = port.read(buf, 500)
// A quiet V2X board only starts streaming once a vehicle is in range.
if (n > 0 && V2x.looksLikeStream(buf, n)) { pollV2x(buf, buf.copyOf(n)); return }
- if (n > 0) consume(String(buf, 0, n))
+ if (n > 0) consume(text.decode(buf, n))
if (!askedDump && mode == OuiSpyReports.Mode.DETECTOR) {
askedDump = true
port.write("CMD:DUMP_LIVE\n")
@@ -155,7 +156,7 @@ class EspReader(
while (!stopped && System.currentTimeMillis() < until) {
val n = port.read(buf, 300)
if (n > 0) {
- pending.append(String(buf, 0, n))
+ pending.append(text.decode(buf, n))
while (true) {
val nl = pending.indexOf('\n')
if (nl < 0) break
@@ -287,10 +288,32 @@ class EspReader(
while (!stopped && System.currentTimeMillis() < until) {
val n = port.read(buf, 300)
if (n > 0) {
- sb.append(String(buf, 0, n))
+ sb.append(text.decode(buf, n))
if (done(sb.toString())) break
}
}
return sb.toString()
}
}
+
+/**
+ * Serial reads as text: a character split across two reads (an accented or emoji network name)
+ * waits for its last bytes instead of turning into two replacement characters.
+ */
+internal class Utf8Chunks {
+ private var carry = ByteArray(0)
+
+ fun decode(buf: ByteArray, n: Int): String {
+ val all = if (carry.isEmpty()) buf.copyOf(n) else carry + buf.copyOf(n)
+ var cut = all.size
+ for (back in 1..minOf(3, all.size)) {
+ val b = all[all.size - back].toInt() and 0xff
+ if (b and 0xC0 == 0x80) continue // continuation byte: look further back for its lead byte
+ val need = when { b >= 0xF0 -> 4; b >= 0xE0 -> 3; b >= 0xC0 -> 2; else -> 1 }
+ if (need > back) cut = all.size - back
+ break
+ }
+ carry = all.copyOfRange(cut, all.size)
+ return String(all, 0, cut, Charsets.UTF_8)
+ }
+}
diff --git a/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBleProtocol.kt b/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBleProtocol.kt
index 84f500e..09aad1a 100644
--- a/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBleProtocol.kt
+++ b/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBleProtocol.kt
@@ -124,13 +124,14 @@ object OuiSpyBleProtocol {
}
private fun drone(d: ByteArray, b: ByteBuffer, mac: String, rssi: Int, method: Int): EspSighting {
- fun coord(at: Int) = b.getDouble(at).takeIf { it != 0.0 && it.isFinite() }
+ // A value off the globe is a corrupt packet (the map refuses latitudes past ±90).
+ fun coord(at: Int, max: Double) = b.getDouble(at).takeIf { it != 0.0 && it.isFinite() && it in -max..max }
val info = RemoteId.Info(
uasId = text(d, 19, 21),
- latitude = coord(61), longitude = coord(69),
+ latitude = coord(61, 90.0), longitude = coord(69, 180.0),
altitudeGeoM = b.getShort(77).toDouble(),
heightM = b.getShort(79).toDouble(),
- operatorLatitude = coord(85), operatorLongitude = coord(93),
+ operatorLatitude = coord(85, 90.0), operatorLongitude = coord(93, 180.0),
selfIdDescription = text(d, 101, 24)
)
val via = when (method) { 0 -> "Bluetooth"; 1 -> "Wi-Fi NAN"; else -> "Wi-Fi beacon" }
diff --git a/app/src/main/java/com/rfsentinel/app/online/WazePolice.kt b/app/src/main/java/com/rfsentinel/app/online/WazePolice.kt
index 6e3977f..792db57 100644
--- a/app/src/main/java/com/rfsentinel/app/online/WazePolice.kt
+++ b/app/src/main/java/com/rfsentinel/app/online/WazePolice.kt
@@ -257,10 +257,11 @@ object WazePolice {
/** Alerts of the wanted types from the API's JSON (re-filtered here in case the server ignores the type filter). */
internal fun parse(json: String, types: Set<Type> = setOf(Type.POLICE)): List<Report> {
val root = JsonParser.parseString(json).asJsonObject
- val data = root.getAsJsonObject("data") ?: return emptyList()
- val alerts = data.getAsJsonArray("alerts") ?: return emptyList()
+ // "data": null or one odd entry leaves out only what is missing, not the whole answer.
+ val data = root.get("data")?.takeIf { it.isJsonObject }?.asJsonObject ?: return emptyList()
+ val alerts = data.get("alerts")?.takeIf { it.isJsonArray }?.asJsonArray ?: return emptyList()
return alerts.mapNotNull { e ->
- val o = e.asJsonObject
+ val o = e.takeIf { it.isJsonObject }?.asJsonObject ?: return@mapNotNull null
val type = Type.ofWire(o.str("type"))?.takeIf { it in types } ?: return@mapNotNull null
Report(
id = o.str("alert_id") ?: return@mapNotNull null,
diff --git a/app/src/main/java/com/rfsentinel/app/sdr/AdsbTracker.kt b/app/src/main/java/com/rfsentinel/app/sdr/AdsbTracker.kt
index ff903b2..ff2fee3 100644
--- a/app/src/main/java/com/rfsentinel/app/sdr/AdsbTracker.kt
+++ b/app/src/main/java/com/rfsentinel/app/sdr/AdsbTracker.kt
@@ -47,7 +47,7 @@ class AdsbTracker {
// that can't be in the wrong zone), never against yours: a far aircraft would land near you.
if (pos == null && p.positionAt > 0 && now - p.positionAt <= PAIR_MS)
pos = ModeS.localPosition(info.cprLat, info.cprLon, odd, p.lat, p.lon)
- if (pos == null) return
+ if (pos == null || pos.first !in -90.0..90.0) return
if (refLat != null && refLon != null && DeviceRegistry.metersBetween(refLat, refLon, pos.first, pos.second) > MAX_RANGE_M) return
p.lat = pos.first; p.lon = pos.second; p.positionAt = now
}
diff --git a/app/src/main/java/com/rfsentinel/app/sdr/ModeS.kt b/app/src/main/java/com/rfsentinel/app/sdr/ModeS.kt
index 170a2fd..e4babb9 100644
--- a/app/src/main/java/com/rfsentinel/app/sdr/ModeS.kt
+++ b/app/src/main/java/com/rfsentinel/app/sdr/ModeS.kt
@@ -259,7 +259,8 @@ object ModeS {
/**
* Global decode from an even and an odd airborne frame (at most 10 s apart); [oddNewer]
- * picks the newer one's latitude. Null when they straddle a longitude-zone boundary.
+ * picks the newer one's latitude. Null when they straddle a longitude-zone boundary or don't
+ * give a latitude on the globe.
*/
fun globalPosition(evenLat: Int, evenLon: Int, oddLat: Int, oddLon: Int, oddNewer: Boolean): Pair<Double, Double>? {
val le = evenLat / CPR_MAX; val lo = oddLat / CPR_MAX
@@ -268,6 +269,8 @@ object ModeS {
var latO = 360.0 / 59 * (mod(j, 59.0) + lo)
if (latE >= 270) latE -= 360
if (latO >= 270) latO -= 360
+ // A bad frame pair can land off the globe (dump1090 drops these too).
+ if (latE !in -90.0..90.0 || latO !in -90.0..90.0) return null
if (nl(latE) != nl(latO)) return null
val lat = if (oddNewer) latO else latE
val nlLat = nl(lat)
diff --git a/app/src/main/java/com/rfsentinel/app/service/DeviceRegistry.kt b/app/src/main/java/com/rfsentinel/app/service/DeviceRegistry.kt
index 70e092d..7fbe3cc 100644
--- a/app/src/main/java/com/rfsentinel/app/service/DeviceRegistry.kt
+++ b/app/src/main/java/com/rfsentinel/app/service/DeviceRegistry.kt
@@ -361,7 +361,6 @@ object DeviceRegistry {
return tracks.values.map { t -> synchronized(t) { snap(t, full = false) } }
}
- /** Full snapshot (history, path, raw advert) for the detail screen. */
/**
* Addresses heard in the last [withinMs] whose adverts have the fingerprint [fp]
* ([AdvertFingerprint.of]): other devices of the same model nearby, or one device changing address.
@@ -384,6 +383,7 @@ object DeviceRegistry {
}
}
+ /** Full snapshot (history, path, raw advert) for the detail screen. */
fun get(mac: String): Snapshot? = tracks[mac]?.let { t -> synchronized(t) { snap(t, full = true) } }
/** Devices heard since [since] with their summary, for persisting to known_devices. */
diff --git a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
index 09fdd8a..b8cf9ff 100644
--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
@@ -407,7 +407,6 @@ class ScanForegroundService : Service() {
this, Manifest.permission.ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_GRANTED
- /** A fix good enough to pin a device on the map: under 30 s old and within ~50 m. */
/**
* Where you are now: the last fix moved on by your speed and course for the second or two
* since it came, so readings taken between fixes aren't placed behind you.
@@ -433,6 +432,7 @@ class ScanForegroundService : Service() {
}
}
+ /** A fix good enough to pin a device on the map: under 30 s old and within ~50 m. */
private fun usableForPlacing(l: Location): Boolean {
val ageMs = (android.os.SystemClock.elapsedRealtimeNanos() - l.elapsedRealtimeNanos) / 1_000_000
return ageMs in 0..PLACING_MAX_AGE_MS && (!l.hasAccuracy() || l.accuracy <= PLACING_MAX_ACCURACY_M)
diff --git a/app/src/main/java/com/rfsentinel/app/usb/MonitorFrames.kt b/app/src/main/java/com/rfsentinel/app/usb/MonitorFrames.kt
index ee37470..39298f7 100644
--- a/app/src/main/java/com/rfsentinel/app/usb/MonitorFrames.kt
+++ b/app/src/main/java/com/rfsentinel/app/usb/MonitorFrames.kt
@@ -103,15 +103,18 @@ class MonitorFrames {
// often by name - the networks it has joined before.
// (Bare scanner probes - a fresh random address each burst - are skipped: see isScannerProbe.)
4 -> if (captureClients && !isScannerProbe(b, d, end)) touch(a2, ap = false)?.let { s ->
- val ies = Ies.read(b, d + 24, end)
+ // Without the checksum some drivers keep: read as elements, its bytes would now and
+ // then add a bogus one and flip the fingerprint.
+ val body = ProbeIntel.withoutFcs(b, d, end)
+ val ies = Ies.read(b, d + 24, body)
ies.wps?.let { s.wps = it }
if (ies.wildcard) {
s.wildcard = true
(s.probeRate ?: com.rfsentinel.app.detect.ProbeBehaviour.Counter().also { s.probeRate = it }).probe(now)
}
if (ies.flockIe) s.flockIe = true
- ProbeIntel.fingerprint(b, d + 24, end)?.let { s.fingerprint = it }
- ProbeIntel.skeletonHash(b, d + 24, ProbeIntel.withoutFcs(b, d, end))?.let { s.skeleton = it }
+ ProbeIntel.fingerprint(b, d + 24, body)?.let { s.fingerprint = it }
+ ProbeIntel.skeletonHash(b, d + 24, body)?.let { s.skeleton = 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())
diff --git a/app/src/main/java/com/rfsentinel/app/util/DeviceHistoryImport.kt b/app/src/main/java/com/rfsentinel/app/util/DeviceHistoryImport.kt
index 7c3d973..96aec76 100644
--- a/app/src/main/java/com/rfsentinel/app/util/DeviceHistoryImport.kt
+++ b/app/src/main/java/com/rfsentinel/app/util/DeviceHistoryImport.kt
@@ -105,6 +105,8 @@ object DeviceHistoryImport {
}
buffered.reset()
val reader = BufferedReader(InputStreamReader(buffered, Charsets.UTF_8))
+ // A byte-order mark (Windows editors save one) would read as a stray first character.
+ reader.mark(1); if (reader.read() != 0xFEFF) reader.reset()
if (first == '['.code || first == '{'.code) jsonRows(reader) else csvRows(reader)
}
diff --git a/app/src/main/java/com/rfsentinel/app/util/Exporter.kt b/app/src/main/java/com/rfsentinel/app/util/Exporter.kt
index 49593bf..71e2ace 100644
--- a/app/src/main/java/com/rfsentinel/app/util/Exporter.kt
+++ b/app/src/main/java/com/rfsentinel/app/util/Exporter.kt
@@ -294,7 +294,7 @@ object Exporter {
.append(q(r.label)).append(',')
.append(r.category).append(',')
.append(r.confidence).append(',')
- .append(r.source).append(',')
+ .append(q(r.source)).append(',')
.append(r.rssi).append(',')
.append(q(r.vendor)).append(',')
.append(q(r.deviceName)).append(',')
diff --git a/app/src/main/res/layout/activity_device_detail.xml b/app/src/main/res/layout/activity_device_detail.xml
index 3d76a6f..b3fa2c4 100644
--- a/app/src/main/res/layout/activity_device_detail.xml
+++ b/app/src/main/res/layout/activity_device_detail.xml
@@ -147,12 +147,6 @@
android:layout_height="wrap_content"
android:layout_marginTop="4dp">
- <com.google.android.material.chip.Chip
- android:id="@+id/actionLearn"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="I saw it" />
-
<com.google.android.material.chip.Chip
android:id="@+id/actionWhitelist"
android:layout_width="wrap_content"
@@ -177,6 +171,12 @@
android:layout_height="wrap_content"
android:text="Add note" />
+ <com.google.android.material.chip.Chip
+ android:id="@+id/actionLearn"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="I saw it" />
+
<com.google.android.material.chip.Chip
android:id="@+id/actionCopy"
android:layout_width="wrap_content"
diff --git a/app/src/test/java/com/rfsentinel/app/detect/HackerWatchTest.kt b/app/src/test/java/com/rfsentinel/app/detect/HackerWatchTest.kt
index 842490b..40f64a5 100644
--- a/app/src/test/java/com/rfsentinel/app/detect/HackerWatchTest.kt
+++ b/app/src/test/java/com/rfsentinel/app/detect/HackerWatchTest.kt
@@ -53,6 +53,15 @@ class HackerWatchTest {
assertNull(HackerWatch.bleSpam(ble("AA:BB:CC:00:01:01"), 10_000L)) // not a pop-up
}
+ @Test
+ fun oneAddressHeardAgainIsNotASpamFlood() {
+ // Its classification cache cleared (watchlist edit, new evidence): the same phones look "new" again.
+ val popup = mapOf(0x004C to byteArrayOf(0x07, 0x19))
+ val t0 = 50_000_000L
+ for (round in 0 until 3) for (i in 0 until HackerWatch.SPAM_THRESHOLD / 2)
+ assertNull(HackerWatch.bleSpam(ble("AA:BB:CD:00:00:%02X".format(i), mfr = popup), t0 + round * 1_000L + i))
+ }
+
@Test
fun actionCamerasAndTrafficSystems() {
assertEquals("GoPro camera", SignatureEngine.classify(ble("AA:00:00:00:00:10", mfr = mapOf(0x02F2 to ByteArray(2)))).first().label)
diff --git a/app/src/test/java/com/rfsentinel/app/esp/Utf8ChunksTest.kt b/app/src/test/java/com/rfsentinel/app/esp/Utf8ChunksTest.kt
new file mode 100644
index 0000000..5e5b9e3
--- /dev/null
+++ b/app/src/test/java/com/rfsentinel/app/esp/Utf8ChunksTest.kt
@@ -0,0 +1,25 @@
+package com.rfsentinel.app.esp
+
+import org.junit.Assert.assertEquals
+import org.junit.Test
+
+class Utf8ChunksTest {
+
+ @Test
+ fun aCharacterSplitAcrossReadsStaysWhole() {
+ val bytes = "Café 📡\n".toByteArray(Charsets.UTF_8)
+ // Every split point, including inside the 2-byte é and the 4-byte emoji.
+ for (cut in 0..bytes.size) {
+ val t = Utf8Chunks()
+ val a = bytes.copyOfRange(0, cut); val b = bytes.copyOfRange(cut, bytes.size)
+ assertEquals("cut at $cut", "Café 📡\n", t.decode(a, a.size) + t.decode(b, b.size))
+ }
+ }
+
+ @Test
+ fun plainTextPassesStraightThrough() {
+ val t = Utf8Chunks()
+ val buf = "MAC: AA:BB\nrest".toByteArray() + ByteArray(10)
+ assertEquals("MAC: AA:BB\nrest", t.decode(buf, 15))
+ }
+}
diff --git a/app/src/test/java/com/rfsentinel/app/online/OnlineSourcesTest.kt b/app/src/test/java/com/rfsentinel/app/online/OnlineSourcesTest.kt
index 6beda23..8b1f0fd 100644
--- a/app/src/test/java/com/rfsentinel/app/online/OnlineSourcesTest.kt
+++ b/app/src/test/java/com/rfsentinel/app/online/OnlineSourcesTest.kt
@@ -83,6 +83,13 @@ class OnlineSourcesTest {
assertTrue(hit.evidence.contains("3 drivers confirmed"))
}
+ @Test
+ fun anOddWazeEntryLeavesOutOnlyItself() {
+ val json = """{"data":{"alerts":["stray", null, {"alert_id":"p","type":"POLICE","latitude":10.0,"longitude":-20.0}]}}"""
+ assertEquals(listOf("p"), WazePolice.parse(json).map { it.id })
+ assertTrue(WazePolice.parse("""{"data":null}""").isEmpty())
+ }
+
@Test
fun wazeTypesAndRadius() {
val json = """{"data":{"alerts":[
diff --git a/app/src/test/java/com/rfsentinel/app/sdr/ModeSTest.kt b/app/src/test/java/com/rfsentinel/app/sdr/ModeSTest.kt
index f909b37..ad06980 100644
--- a/app/src/test/java/com/rfsentinel/app/sdr/ModeSTest.kt
+++ b/app/src/test/java/com/rfsentinel/app/sdr/ModeSTest.kt
@@ -36,6 +36,12 @@ class ModeSTest {
assertEquals(52.2572, la, 0.0001); assertEquals(3.9194, lo, 0.0001)
}
+ @Test
+ fun aFramePairOffTheGlobeIsDropped() {
+ // Even 0, odd 0.66 of the CPR range: both latitudes come out near 120 degrees.
+ assertNull(ModeS.globalPosition(0, (0.66 * 131072).toInt(), (0.66 * 131072).toInt(), 0, oddNewer = true))
+ }
+
@Test
fun groundSpeedAndAirspeed() {
val v = ModeS.decode(frame("8D485020994409940838175B284F"))
diff --git a/app/src/test/java/com/rfsentinel/app/usb/ProbeShapeTest.kt b/app/src/test/java/com/rfsentinel/app/usb/ProbeShapeTest.kt
index c369f5d..e1f61e5 100644
--- a/app/src/test/java/com/rfsentinel/app/usb/ProbeShapeTest.kt
+++ b/app/src/test/java/com/rfsentinel/app/usb/ProbeShapeTest.kt
@@ -39,6 +39,22 @@ class ProbeShapeTest {
assertEquals(plain.size, ProbeIntel.withoutFcs(withFcs, 0, withFcs.size))
}
+ @Test
+ fun aKeptChecksumNeverChangesTheFingerprint() {
+ // Find a probe whose checksum bytes read like a short element (tag, length 0..2) after the real ones.
+ var frame: ByteArray? = null
+ for (k in 0..65535) {
+ val f = ByteArray(24).also { it[0] = 0x40; it[10] = 0x02; it[11] = 0x11; it[14] = (k shr 8).toByte(); it[15] = k.toByte() } + ies
+ val c = CRC32().apply { update(f) }.value
+ if (((c shr 8) and 0xff) <= 2) { frame = f + ByteArray(4) { ((c shr (8 * it)) and 0xff).toByte() }; break }
+ }
+ val f = frame!!
+ val mf = MonitorFrames()
+ mf.frame(f, 0, f.size, 6, -50, now = 1_000L)
+ val heard = mf.drain(1_000L, 10_000L).single()
+ assertEquals(ProbeIntel.fingerprint(ies, 0, ies.size), heard.fingerprint)
+ }
+
private fun client(mac: String, shape: Long) = Advert(mac = mac, source = Advert.Source.WIFI, rssi = -70, name = null,
wifi = Advert.WifiInfo(2437, "", null, emptyList(), client = true, probeSkeleton = shape), timestamp = 0L)
diff --git a/app/src/test/java/com/rfsentinel/app/util/DeviceHistoryImportTest.kt b/app/src/test/java/com/rfsentinel/app/util/DeviceHistoryImportTest.kt
index 7c35642..dc7491f 100644
--- a/app/src/test/java/com/rfsentinel/app/util/DeviceHistoryImportTest.kt
+++ b/app/src/test/java/com/rfsentinel/app/util/DeviceHistoryImportTest.kt
@@ -47,6 +47,11 @@ class DeviceHistoryImportTest {
assertNull(runBlocking { db.knownDeviceDao().get("AA:BB:CC:00:00:02") }!!.name)
}
+ @Test
+ fun aJsonFileSavedWithAByteOrderMarkIsRead() {
+ assertEquals(2, run("" + json).added)
+ }
+
@Test
fun importingTheSameFileAgainChangesNothing() {
run(json)