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.

Review fixes; device dots on the maps in list/radar colours

CIS-C06a883af62ac8
diff --git a/README.md b/README.md
index 0724275..56eb888 100644
--- a/README.md
+++ b/README.md
@@ -172,9 +172,12 @@ The app never connects to a device. The details screen shows:
### Map and traces
-- The **map** shows your position, the trace being recorded, and devices placed
- where your phone was when their signal was strongest. That approximates the
- device's position, not a fix.
+- The **map** (the floating **Map** button on the main screen) shows your
+ position, the trace being recorded, and every device heard around you as a dot
+ in the same colours as the list and radar, placed where your phone was when its
+ signal was strongest. That approximates the device's position, not a fix: only
+ precise, fresh GPS fixes are used, and the map switches to GPS while it's open.
+ Tap *All devices* to show flagged ones only.
- **Record trace** saves your GPS route and every device heard along it. It
keeps running with the screen off, and can start automatically with each scan.
- Traces export as **GPX**, **KML**, **GeoJSON** or **CSV**, with all devices or
diff --git a/app/src/main/java/com/rfsentinel/app/MainActivity.kt b/app/src/main/java/com/rfsentinel/app/MainActivity.kt
index 32de07f..3f0a18a 100644
--- a/app/src/main/java/com/rfsentinel/app/MainActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/MainActivity.kt
@@ -177,6 +177,7 @@ class MainActivity : AppCompatActivity() {
binding.radarView.visibility = if (radar) View.VISIBLE else View.GONE
binding.recyclerView.visibility = if (radar) View.GONE else View.VISIBLE
binding.viewToggleButton.text = if (radar) "List view" else "Radar view"
+ if (!binding.mapButton.isExtended) binding.mapButton.extend()
}
private fun updateStatus() {
diff --git a/app/src/main/java/com/rfsentinel/app/RFSentinelApp.kt b/app/src/main/java/com/rfsentinel/app/RFSentinelApp.kt
index 72cbfdd..19ddd06 100644
--- a/app/src/main/java/com/rfsentinel/app/RFSentinelApp.kt
+++ b/app/src/main/java/com/rfsentinel/app/RFSentinelApp.kt
@@ -36,6 +36,8 @@ class RFSentinelApp : Application() {
override fun onActivityDestroyed(a: android.app.Activity) {}
})
NotificationHelper.createChannels(this)
+ // A fresh process means no camera download is running: drop any leftover progress.
+ NotificationHelper.clearStaleCameraDownload(this)
OuiWatchlist.load(this)
WhitelistCache.start(this, appScope)
CarState.start(this)
diff --git a/app/src/main/java/com/rfsentinel/app/alpr/AlprStore.kt b/app/src/main/java/com/rfsentinel/app/alpr/AlprStore.kt
index 656692c..943ded2 100644
--- a/app/src/main/java/com/rfsentinel/app/alpr/AlprStore.kt
+++ b/app/src/main/java/com/rfsentinel/app/alpr/AlprStore.kt
@@ -97,15 +97,15 @@ object AlprStore {
}
}
+ /** Where a [downloadAround] is: [done] of [total] areas finished, [found] cameras so far. */
+ data class Progress(val area: Int, val done: Int, val total: Int, val found: Int, val failed: Int, val detail: String)
+
/**
* Downloads every known camera within about [radiusKm] of a point, in up to
* four tiles (small requests get through busy servers more easily). Tiles
* that fail are skipped - the map fetches them later. Returns how many
* cameras were found, or throws when no tile could be downloaded.
*/
- /** Where a [downloadAround] is: [done] of [total] areas finished, [found] cameras so far. */
- data class Progress(val area: Int, val done: Int, val total: Int, val found: Int, val failed: Int, val detail: String)
-
suspend fun downloadAround(
context: Context, lat: Double, lon: Double, radiusKm: Double = 100.0,
onProgress: (Progress) -> Unit = {}
@@ -159,8 +159,10 @@ object AlprStore {
val merged = cameras.filterNot(inBox) + found
file(context).writeText(gson.toJson(merged))
cameras = merged
- val area = CameraArea(south, west, north, east, System.currentTimeMillis())
- areas = areas.filterNot { area.contains(it) } + area
+ val now = System.currentTimeMillis()
+ val area = CameraArea(south, west, north, east, now)
+ // Long-stale areas only cost space (their cameras stay cached for offline warnings).
+ areas = areas.filterNot { area.contains(it) || now - it.time > 4 * REFRESH_MS } + area
runCatching { areasFile(context).writeText(gson.toJson(areas)) }
}
found.size
diff --git a/app/src/main/java/com/rfsentinel/app/alpr/KnownCameras.kt b/app/src/main/java/com/rfsentinel/app/alpr/KnownCameras.kt
index 723ed00..ab9f1e3 100644
--- a/app/src/main/java/com/rfsentinel/app/alpr/KnownCameras.kt
+++ b/app/src/main/java/com/rfsentinel/app/alpr/KnownCameras.kt
@@ -88,21 +88,25 @@ object KnownCameras {
* prefer the copy that has the speed limit, then the node (exact position).
*/
fun dedupe(cameras: List<KnownCamera>): List<KnownCamera> {
- val kept = ArrayList<KnownCamera>()
fun isNode(c: KnownCamera) = c.osmId.startsWith("node")
- for (c in cameras.sortedByDescending { (if (it.maxspeed != null) 2 else 0) + (if (isNode(it)) 1 else 0) }) {
- val dup = c.type != KnownCamera.Kind.ALPR && kept.any {
- it.type == c.type &&
- DeviceRegistry.metersBetween(it.lat, it.lon, c.lat, c.lon) < (if (isNode(it) && isNode(c)) 40.0 else 150.0)
- }
- if (!dup) kept += c
+ // ~150 m in degrees, generously (longitude degrees shrink away from the equator).
+ fun close(a: KnownCamera, b: KnownCamera, m: Double) =
+ kotlin.math.abs(a.lat - b.lat) < 0.0015 && kotlin.math.abs(a.lon - b.lon) < 0.0015 / max(0.05, cos(Math.toRadians(a.lat))) &&
+ DeviceRegistry.metersBetween(a.lat, a.lon, b.lat, b.lon) < m
+ // Plate readers are never merged (several often share a pole), so only speed
+ // and red-light cameras - a few per city - go through the pairwise check.
+ val (plates, enforcement) = cameras.partition { it.type == KnownCamera.Kind.ALPR }
+ val kept = ArrayList<KnownCamera>()
+ for (c in enforcement.sortedByDescending { (if (it.maxspeed != null) 2 else 0) + (if (isNode(it)) 1 else 0) }) {
+ if (kept.none { it.type == c.type && close(it, c, if (isNode(it) && isNode(c)) 40.0 else 150.0) }) kept += c
}
// Keep the exact node position when a relation won only because it had the limit.
- return kept.map { k ->
- if (isNode(k) || k.type == KnownCamera.Kind.ALPR) k
- else cameras.firstOrNull { isNode(it) && it.type == k.type && DeviceRegistry.metersBetween(it.lat, it.lon, k.lat, k.lon) < 150.0 }
+ val merged = kept.map { k ->
+ if (isNode(k)) k
+ else enforcement.firstOrNull { isNode(it) && it.type == k.type && close(it, k, 150.0) }
?.let { n -> k.copy(lat = n.lat, lon = n.lon) } ?: k
}
+ return plates + merged
}
/** Parses an Overpass JSON response (nodes, and ways/relations via their centre). */
diff --git a/app/src/main/java/com/rfsentinel/app/car/HomeScreen.kt b/app/src/main/java/com/rfsentinel/app/car/HomeScreen.kt
index 625522e..7f3bd4e 100644
--- a/app/src/main/java/com/rfsentinel/app/car/HomeScreen.kt
+++ b/app/src/main/java/com/rfsentinel/app/car/HomeScreen.kt
@@ -58,7 +58,7 @@ class HomeScreen(carContext: CarContext) : LiveScreen(carContext) {
items.addItem(navRow("All nearby devices", devices.size, R.drawable.ic_car_list, DeviceListScreen.Filter.ALL))
items.addItem(
Row.Builder()
- .setTitle("Cameras & drones on the map")
+ .setTitle("Map: cameras, devices & drones")
.setImage(CarUi.icon(carContext, R.drawable.ic_car_navigate))
.setBrowsable(true)
.setOnClickListener { screenManager.push(NearbyMapScreen(carContext)) }
diff --git a/app/src/main/java/com/rfsentinel/app/car/NearbyMapScreen.kt b/app/src/main/java/com/rfsentinel/app/car/NearbyMapScreen.kt
index 8347311..12cd29f 100644
--- a/app/src/main/java/com/rfsentinel/app/car/NearbyMapScreen.kt
+++ b/app/src/main/java/com/rfsentinel/app/car/NearbyMapScreen.kt
@@ -33,7 +33,9 @@ class NearbyMapScreen(carContext: CarContext) : LiveScreen(carContext, periodMs
/** One row: a camera or a drone. */
data class Item(val title: String, val detail: String, val lat: Double, val lon: Double, val distanceM: Double,
- val drone: Boolean, val mac: String?, val kind: com.rfsentinel.app.alpr.KnownCamera.Kind? = null)
+ val drone: Boolean, val mac: String?, val kind: com.rfsentinel.app.alpr.KnownCamera.Kind? = null,
+ /** Flagged device: its list / radar colour (category, or amber when weak). */
+ val deviceColor: Int? = null)
override fun onGetTemplate(): Template {
val me = myLocation()
@@ -53,7 +55,7 @@ class NearbyMapScreen(carContext: CarContext) : LiveScreen(carContext, periodMs
items.forEach { it -> list.addItem(row(it)) }
val template = PlaceListMapTemplate.Builder()
- .setTitle("Cameras & drones")
+ .setTitle("Map: cameras, devices, drones")
.setHeaderAction(Action.BACK)
.setCurrentLocationEnabled(me != null)
.setItemList(list.build())
@@ -66,9 +68,14 @@ class NearbyMapScreen(carContext: CarContext) : LiveScreen(carContext, periodMs
val place = Place.Builder(CarLocation.create(it.lat, it.lon))
.setMarker(
PlaceMarker.Builder()
- .setColor(if (it.drone) CarColor.BLUE else if (it.kind == com.rfsentinel.app.alpr.KnownCamera.Kind.ALPR) CarColor.RED else CarColor.YELLOW)
+ .setColor(when {
+ it.drone -> CarColor.BLUE
+ it.deviceColor != null -> CarColor.createCustom(it.deviceColor, it.deviceColor)
+ it.kind == com.rfsentinel.app.alpr.KnownCamera.Kind.ALPR -> CarColor.RED
+ else -> CarColor.YELLOW
+ })
.setLabel(when (it.kind) {
- null -> "D"
+ null -> if (it.drone) "D" else "!"
com.rfsentinel.app.alpr.KnownCamera.Kind.SPEED -> "S"
com.rfsentinel.app.alpr.KnownCamera.Kind.RED_LIGHT -> "R"
com.rfsentinel.app.alpr.KnownCamera.Kind.ALPR -> "P"
@@ -80,7 +87,7 @@ class NearbyMapScreen(carContext: CarContext) : LiveScreen(carContext, periodMs
.addText(distanceText(it.distanceM) + " · " + it.detail)
.setMetadata(Metadata.Builder().setPlace(place).build())
.setOnClickListener {
- if (it.drone && it.mac != null) screenManager.push(DeviceDetailScreen(carContext, it.mac))
+ if (it.mac != null) screenManager.push(DeviceDetailScreen(carContext, it.mac))
else CarToast.makeText(carContext, "${it.title}: ${distanceText(it.distanceM)} away", CarToast.LENGTH_LONG).show()
}
.build()
@@ -109,7 +116,8 @@ class NearbyMapScreen(carContext: CarContext) : LiveScreen(carContext, periodMs
}
companion object {
- const val SEARCH_RADIUS_M = 5_000.0
+ /** The list shows only the nearest few, so look well ahead along the road. */
+ const val SEARCH_RADIUS_M = 20_000.0
/** Nearest known cameras and positioned drones, closest first (pure; unit-tested). */
fun nearby(lat: Double, lon: Double, limit: Int): List<Item> {
@@ -127,8 +135,18 @@ class NearbyMapScreen(carContext: CarContext) : LiveScreen(carContext, periodMs
.joinToString(" · ").ifEmpty { "Remote ID" },
dLat, dLon, d, drone = true, mac = s.mac)
}
- // Drones first (they move and matter now), then cameras by distance.
- return (drones.sortedBy { it.distanceM } + cams).take(limit)
+ // Flagged devices where your phone heard them best (the same spot as on the phone map).
+ val devices = DeviceRegistry.snapshot().mapNotNull { s ->
+ val best = s.best ?: return@mapNotNull null
+ if (com.rfsentinel.app.data.WhitelistCache.contains(s.mac) || s.remoteId?.hasPosition == true) return@mapNotNull null
+ val pos = s.bestPosition ?: return@mapNotNull null
+ val d = DeviceRegistry.metersBetween(lat, lon, pos.lat, pos.lon)
+ if (d > SEARCH_RADIUS_M) return@mapNotNull null
+ Item(best.label, best.category.shortTag + " \u00b7 heard here", pos.lat, pos.lon, d, drone = false, mac = s.mac,
+ deviceColor = if (best.tier == com.rfsentinel.app.detect.Tier.WEAK) com.rfsentinel.app.ui.DeviceColors.WEAK else best.category.colorArgb)
+ }
+ // Drones first (they move and matter now), then flagged devices, then cameras by distance.
+ return (drones.sortedBy { it.distanceM } + devices.sortedBy { it.distanceM } + cams).take(limit)
}
fun distanceText(m: Double) = if (m < 1000) "${(m / 10).roundToInt() * 10} m" else String.format(java.util.Locale.US, "%.1f km", m / 1000)
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 6b55215..cdd4499 100644
--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
@@ -86,6 +86,15 @@ class ScanForegroundService : Service() {
private const val KNOWN_ALPR_REPEAT_MS = 30 * 60_000L
private const val CELL_CHECK_MS = 15_000L
private const val CELL_REPEAT_MS = 30 * 60_000L
+ private const val PLACING_MAX_AGE_MS = 30_000L
+ private const val PLACING_MAX_ACCURACY_M = 50f
+
+ /**
+ * True while the map is on screen: location switches to precise GPS so the
+ * devices it shows are placed where they really were heard.
+ */
+ @Volatile
+ var mapVisible = false
/** Latest location fix while scanning (for the car map), or null. */
@Volatile
@@ -258,6 +267,12 @@ 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. */
+ 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)
+ }
+
// ---- Scanning -----------------------------------------------------------
private fun startBle() {
@@ -297,17 +312,17 @@ class ScanForegroundService : Service() {
}
/**
- * Location is needed for GPS tagging, follower alerts and trace recording.
- * While recording, fixes come every ~3 s / 5 m for a smooth trace; otherwise
- * every ~20 s / 25 m to save battery.
+ * Location is needed for GPS tagging, follower alerts, trace recording and
+ * known-camera warnings. While recording or watching for cameras, GPS fixes
+ * come every ~3 s / 5 m; otherwise balanced fixes every ~20 s / 25 m to save battery.
*/
@SuppressLint("MissingPermission") // checked by hasFineLocation()
fun updateLocationUpdates() {
val wanted = hasFineLocation() &&
- (Prefs.gpsTaggingEnabled(this) || Prefs.followerAlerts(this) || TripRecorder.isRecording || knownAlprActive())
+ (Prefs.gpsTaggingEnabled(this) || Prefs.followerAlerts(this) || TripRecorder.isRecording || knownAlprActive() || mapVisible)
// Frequent fixes while recording a trace or watching for known cameras
// (at highway speed a 20 s interval could skip right past one).
- val fast = TripRecorder.isRecording || knownAlprActive()
+ val fast = TripRecorder.isRecording || knownAlprActive() || mapVisible
val lm = getSystemService(LOCATION_SERVICE) as LocationManager
if (locationListening && (!wanted || fast != locationFastMode)) {
lm.removeUpdates(locationListener)
@@ -324,7 +339,19 @@ class ScanForegroundService : Service() {
}
providers.forEach { p ->
try {
- if (fast) lm.requestLocationUpdates(p, 3_000L, 5f, locationListener, Looper.getMainLooper())
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
+ // Fused location defaults to "balanced" (often WiFi/cell, ~100 m, and
+ // paused while it thinks you're stationary): too coarse to warn about a
+ // camera a few hundred metres ahead. Fast mode asks for real GPS.
+ val request = android.location.LocationRequest.Builder(if (fast) 3_000L else 20_000L)
+ .setQuality(
+ if (fast) android.location.LocationRequest.QUALITY_HIGH_ACCURACY
+ else android.location.LocationRequest.QUALITY_BALANCED_POWER_ACCURACY
+ )
+ .setMinUpdateDistanceMeters(if (fast) 5f else 25f)
+ .build()
+ lm.requestLocationUpdates(p, request, mainExecutor, locationListener)
+ } else if (fast) lm.requestLocationUpdates(p, 3_000L, 5f, locationListener, Looper.getMainLooper())
else lm.requestLocationUpdates(p, 20_000L, 25f, locationListener, Looper.getMainLooper())
lm.getLastKnownLocation(p)?.let { if (lastLocation == null) lastLocation = it }
} catch (e: Exception) {
@@ -357,7 +384,9 @@ class ScanForegroundService : Service() {
prev
}
- val loc = lastLocation
+ // Place devices only with a fresh, precise fix: a stale or WiFi/cell-based one
+ // (often 100 m+ off) would put the dot far from where the device really was.
+ val loc = lastLocation?.takeIf { usableForPlacing(it) }
val geo = loc?.let { DeviceRegistry.GeoSample(now, it.latitude, it.longitude) }
val isFirst = DeviceRegistry.report(a, c.hits, c.identity, c.vendor, remoteId, geo, now)
if (isFirst) serviceScope.launch { loadHistory(mac) }
diff --git a/app/src/main/java/com/rfsentinel/app/ui/DemoData.kt b/app/src/main/java/com/rfsentinel/app/ui/DemoData.kt
index bda1e4f..502029c 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/DemoData.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/DemoData.kt
@@ -129,7 +129,15 @@ object DemoData {
OuiWatchlist.hits(a.mac, a.name, listOfNotNull(vendor)) +
listOfNotNull(DeviceRegistry.clusterHit(a.mac, t))
val rid = if (a.mac == DEMO_DRONE && anchor != null) demoRemoteId(anchor, s) else null
- DeviceRegistry.report(a, EvidenceFusion.fuse(raw), DeviceIntel.identify(a, VendorDb.macVendor(a.mac)), vendor, rid, null, t)
+ // Made-up spots around you within real Bluetooth / WiFi range (5-60 m),
+ // so the map shows the devices too.
+ val spot = anchor?.let {
+ val angle = Math.toRadians(i * 137.5)
+ val m = 5.0 + (i * 17 % 56)
+ DeviceRegistry.GeoSample(t, it.first + m / 111_000.0 * kotlin.math.cos(angle),
+ it.second + m / (111_000.0 * kotlin.math.cos(Math.toRadians(it.first))) * kotlin.math.sin(angle))
+ }
+ DeviceRegistry.report(a, EvidenceFusion.fuse(raw), DeviceIntel.identify(a, VendorDb.macVendor(a.mac)), vendor, rid, spot, t)
}
}
}
diff --git a/app/src/main/java/com/rfsentinel/app/ui/DeviceColors.kt b/app/src/main/java/com/rfsentinel/app/ui/DeviceColors.kt
new file mode 100644
index 0000000..f2ae48a
--- /dev/null
+++ b/app/src/main/java/com/rfsentinel/app/ui/DeviceColors.kt
@@ -0,0 +1,38 @@
+package com.rfsentinel.app.ui
+
+import android.content.Context
+import com.google.android.material.color.MaterialColors
+import com.rfsentinel.app.R
+import com.rfsentinel.app.data.WhitelistCache
+import com.rfsentinel.app.detect.Category
+import com.rfsentinel.app.detect.Tier
+import com.rfsentinel.app.service.DeviceRegistry
+
+/**
+ * One colour code for a device everywhere it's drawn - the list, the radar,
+ * the phone map and the car map: its category colour for probable and strong
+ * matches, amber for weak ones, and the theme's quiet scope colour for
+ * ordinary (or whitelisted) devices. Night Drive turns them all red.
+ */
+object DeviceColors {
+
+ const val WEAK = 0xFFB26A00.toInt()
+
+ /** Ordinary devices: the radar scope colour of the current theme. */
+ fun ordinary(context: Context): Int =
+ MaterialColors.getColor(context, R.attr.rfScopeColor, 0xFF0B5C63.toInt())
+
+ /** A match of [category] with [confidence]%; null category = ordinary device. */
+ fun forMatch(context: Context, category: Category?, confidence: Int): Int =
+ if (category == null) ordinary(context)
+ else ThemeManager.ink(context, if (confidence in 1 until Tier.MEDIUM.min) WEAK else category.colorArgb)
+
+ /** Flagged = matched and not whitelisted. */
+ fun isFlagged(s: DeviceRegistry.Snapshot) = s.best != null && !WhitelistCache.contains(s.mac)
+
+ fun forDevice(context: Context, s: DeviceRegistry.Snapshot): Int {
+ val best = s.best
+ return if (best == null || !isFlagged(s)) ordinary(context)
+ else ThemeManager.ink(context, if (best.tier == Tier.WEAK) WEAK else best.category.colorArgb)
+ }
+}
diff --git a/app/src/main/java/com/rfsentinel/app/ui/MapActivity.kt b/app/src/main/java/com/rfsentinel/app/ui/MapActivity.kt
index dba6169..6d64292 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/MapActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/MapActivity.kt
@@ -61,7 +61,6 @@ class MapActivity : AppCompatActivity() {
companion object {
const val EXTRA_TRIP_ID = "trip_id"
- private const val ORDINARY_COLOR = 0xFF607D8B.toInt()
private const val TRACE_COLOR = 0xFFE0622D.toInt()
private const val PAST_TRACE_COLOR = 0xFF1F5FBF.toInt()
private const val DRONE_COLOR = 0xFF1F5FBF.toInt()
@@ -76,7 +75,7 @@ class MapActivity : AppCompatActivity() {
private lateinit var binding: ActivityMapBinding
private var tripId: Long? = null
private var trip: TripEntity? = null
- private var showAll = false
+ private var showAll = true
private var centeredOnce = false
private val trace = Polyline()
@@ -114,8 +113,12 @@ class MapActivity : AppCompatActivity() {
setupMap()
binding.map.post { drawKnownAlpr() }
+ // Every device heard around you by default (same colours as the list and radar).
+ showAll = com.rfsentinel.app.util.Prefs.mapShowAll(this)
+ binding.showAllChip.isChecked = showAll
binding.showAllChip.setOnCheckedChangeListener { _, checked ->
showAll = checked
+ com.rfsentinel.app.util.Prefs.setMapShowAll(this, checked)
if (tripId != null) loadTrip() else renderLive()
}
binding.centerButton.setOnClickListener { centerOnMe() }
@@ -177,15 +180,20 @@ class MapActivity : AppCompatActivity() {
override fun onResume() {
super.onResume()
binding.map.onResume()
+ // Precise GPS while the map is on screen, so devices land where they were heard.
+ if (tripId == null) { ScanForegroundService.mapVisible = true; refreshServiceLocation() }
}
override fun onPause() {
+ if (tripId == null) { ScanForegroundService.mapVisible = false; refreshServiceLocation() }
binding.map.onPause()
super.onPause()
}
override fun onDestroy() {
myLocation.disableMyLocation()
+ binding.map.removeCallbacks(autoDownloadCameras)
+ binding.map.removeCallbacks(redrawKnownAlpr)
binding.map.onDetach()
super.onDestroy()
}
@@ -210,14 +218,14 @@ class MapActivity : AppCompatActivity() {
val devices = DeviceRegistry.snapshot()
val drawn = devices.mapNotNull { s ->
val pos = s.bestPosition ?: return@mapNotNull null
- val flagged = s.best != null && !WhitelistCache.contains(s.mac)
+ val flagged = DeviceColors.isFlagged(s)
if (!flagged && !showAll) return@mapNotNull null
val best = s.best
Pin(
s.mac, pos.lat, pos.lon,
best?.label ?: s.name ?: s.deviceType,
flagged,
- if (!flagged) ORDINARY_COLOR else if (best!!.tier == Tier.WEAK) 0xFFB26A00.toInt() else best.category.colorArgb,
+ DeviceColors.forDevice(this, s),
buildString {
append(s.mac)
s.vendor?.let { append("\n").append(it) }
@@ -332,11 +340,7 @@ class MapActivity : AppCompatActivity() {
val cat = Category.parse(category)
return Pin(
mac, lat!!, lon!!, label, flagged,
- when {
- cat == null -> ORDINARY_COLOR
- confidence < Tier.MEDIUM.min -> 0xFFB26A00.toInt()
- else -> cat.colorArgb
- },
+ DeviceColors.forMatch(this@MapActivity, if (flagged) cat else null, confidence),
buildString {
append(mac)
vendor?.let { append("\n").append(it) }
diff --git a/app/src/main/java/com/rfsentinel/app/util/AlertPlayer.kt b/app/src/main/java/com/rfsentinel/app/util/AlertPlayer.kt
index a8d6698..4b4f062 100644
--- a/app/src/main/java/com/rfsentinel/app/util/AlertPlayer.kt
+++ b/app/src/main/java/com/rfsentinel/app/util/AlertPlayer.kt
@@ -91,10 +91,17 @@ object AlertPlayer {
}
}
- /** Silent and vibrate ringer modes mute the beeps on the phone (vibration still runs). */
- private fun ringerAllowsSound(context: Context): Boolean =
- context.getSystemService(AudioManager::class.java)?.ringerMode != AudioManager.RINGER_MODE_SILENT &&
- context.getSystemService(AudioManager::class.java)?.ringerMode != AudioManager.RINGER_MODE_VIBRATE
+ /**
+ * Silent and vibrate ringer modes, and Do Not Disturb, mute the beeps on the
+ * phone (vibration still runs) - like the notification sound they replace.
+ */
+ private fun ringerAllowsSound(context: Context): Boolean {
+ val mode = context.getSystemService(AudioManager::class.java)?.ringerMode
+ if (mode == AudioManager.RINGER_MODE_SILENT || mode == AudioManager.RINGER_MODE_VIBRATE) return false
+ val filter = context.getSystemService(android.app.NotificationManager::class.java)?.currentInterruptionFilter
+ return filter == null || filter == android.app.NotificationManager.INTERRUPTION_FILTER_ALL ||
+ filter == android.app.NotificationManager.INTERRUPTION_FILTER_UNKNOWN
+ }
/** Short "may duck" focus so music dips under the alert, then comes back. */
@Synchronized
diff --git a/app/src/main/java/com/rfsentinel/app/util/NotificationHelper.kt b/app/src/main/java/com/rfsentinel/app/util/NotificationHelper.kt
index 99d778b..d06cc83 100644
--- a/app/src/main/java/com/rfsentinel/app/util/NotificationHelper.kt
+++ b/app/src/main/java/com/rfsentinel/app/util/NotificationHelper.kt
@@ -78,6 +78,13 @@ object NotificationHelper {
runCatching { nm.notify(DOWNLOAD_NOTIFICATION_ID, b.build()) } // no-op without the notification permission
}
+ /** Clears a progress notification left behind when the app was killed mid-download. */
+ fun clearStaleCameraDownload(context: Context) {
+ val nm = context.getSystemService(NotificationManager::class.java) ?: return
+ val stale = runCatching { nm.activeNotifications.any { it.id == DOWNLOAD_NOTIFICATION_ID && it.isOngoing } }.getOrDefault(false)
+ if (stale) nm.cancel(DOWNLOAD_NOTIFICATION_ID)
+ }
+
/**
* Brings the app back exactly like tapping its launcher icon: the existing
* task comes to the front on whatever screen you left, or MainActivity
diff --git a/app/src/main/java/com/rfsentinel/app/util/Prefs.kt b/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
index 4bbb0fb..7dca587 100644
--- a/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
+++ b/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
@@ -98,6 +98,9 @@ object Prefs {
/** Fetch known cameras for the map area on screen (and around you in the car) automatically. */
fun autoCameras(context: Context): Boolean = bool(context, "auto_cameras", true)
fun setAutoCameras(context: Context, value: Boolean) = setBool(context, "auto_cameras", value)
+ /** Map: every device heard (true) or flagged ones only. */
+ fun mapShowAll(context: Context): Boolean = bool(context, "map_show_all", true)
+ fun setMapShowAll(context: Context, value: Boolean) = setBool(context, "map_show_all", value)
fun showKnownAlpr(context: Context): Boolean = bool(context, "show_known_alpr", true)
fun setShowKnownAlpr(context: Context, value: Boolean) = setBool(context, "show_known_alpr", value)
diff --git a/app/src/test/java/com/rfsentinel/app/alpr/KnownCamerasTest.kt b/app/src/test/java/com/rfsentinel/app/alpr/KnownCamerasTest.kt
index c037b5e..d11404d 100644
--- a/app/src/test/java/com/rfsentinel/app/alpr/KnownCamerasTest.kt
+++ b/app/src/test/java/com/rfsentinel/app/alpr/KnownCamerasTest.kt
@@ -79,6 +79,18 @@ class KnownCamerasTest {
assertTrue(q.startsWith("[out:json][timeout:25]")) // short timeout: busy servers refuse long ones first
}
+ @Test
+ fun dedupeStaysFastWithThousandsOfPlateReaders() {
+ // Synthetic grid: 6000 plate readers and 600 speed cameras (a dense metro area).
+ val cams = (0 until 6000).map { KnownCamera("node/$it", 10.0 + (it % 80) * 0.01, -21.0 + (it / 80) * 0.01, null, null, null, KnownCamera.Kind.ALPR) } +
+ (0 until 600).map { KnownCamera("node/s$it", 10.0 + (it % 30) * 0.03, -21.0 + (it / 30) * 0.03, null, null, null, KnownCamera.Kind.SPEED, 50) }
+ val t = System.nanoTime()
+ val out = KnownCameras.dedupe(cams)
+ val ms = (System.nanoTime() - t) / 1_000_000
+ assertEquals(6600, out.size) // nothing here is a duplicate
+ assertTrue("dedupe took $ms ms", ms < 1500)
+ }
+
@Test
fun oldCacheEntriesArePlateReaders() {
val old = com.google.gson.Gson().fromJson(
diff --git a/app/src/test/java/com/rfsentinel/app/car/CarScreensTest.kt b/app/src/test/java/com/rfsentinel/app/car/CarScreensTest.kt
index 7656f09..56c4021 100644
--- a/app/src/test/java/com/rfsentinel/app/car/CarScreensTest.kt
+++ b/app/src/test/java/com/rfsentinel/app/car/CarScreensTest.kt
@@ -79,7 +79,7 @@ class CarScreensTest {
assertTrue(rows[1].title.toString().startsWith("Flagged nearby (2)"))
assertTrue(rows[2].title.toString().startsWith("Drones & trackers (1)"))
assertTrue(rows[3].title.toString().startsWith("All nearby devices (14)"))
- assertEquals("Cameras & drones on the map", rows[4].title.toString())
+ assertEquals("Map: cameras, devices & drones", rows[4].title.toString())
val actions = t.actionStrip!!.actions
assertEquals(2, actions.size)
assertEquals("Stop", actions[0].title.toString())
@@ -130,7 +130,7 @@ class CarScreensTest {
com.rfsentinel.app.alpr.KnownCamera("node/3", 11.5, -20.5, "Far away", null, null)
))
val items = NearbyMapScreen.nearby(10.5, -20.5, 6)
- assertEquals(3, items.size) // the far camera is outside 5 km
+ assertEquals(3, items.size) // the far camera (~110 km) is outside the search radius
assertTrue(items[0].drone)
assertEquals("Flock Safety (ALPR)", items[1].title)
assertEquals("330 m", NearbyMapScreen.distanceText(items[1].distanceM))