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.

Android Auto: plate cameras and drones on the car map

CIS-C01188307c9324
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 97b8dcd..e252c10 100644
--- a/app/src/main/java/com/rfsentinel/app/alpr/AlprStore.kt
+++ b/app/src/main/java/com/rfsentinel/app/alpr/AlprStore.kt
@@ -68,6 +68,10 @@ object AlprStore {
}
}
+ /** Tests only: set the cache without files or network. */
+ @androidx.annotation.VisibleForTesting
+ fun setForTest(list: List<KnownCamera>) { cameras = list }
+
fun clear(context: Context) {
file(context).delete()
cameras = emptyList()
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 552969b..6c65aba 100644
--- a/app/src/main/java/com/rfsentinel/app/car/HomeScreen.kt
+++ b/app/src/main/java/com/rfsentinel/app/car/HomeScreen.kt
@@ -56,6 +56,14 @@ class HomeScreen(carContext: CarContext) : LiveScreen(carContext) {
items.addItem(navRow("Flagged nearby", flagged, R.drawable.ic_car_warning, DeviceListScreen.Filter.FLAGGED))
items.addItem(navRow("Drones & trackers", dronesTrackers, R.drawable.ic_car_drone, DeviceListScreen.Filter.DRONES_TRACKERS))
items.addItem(navRow("All nearby devices", devices.size, R.drawable.ic_car_list, DeviceListScreen.Filter.ALL))
+ items.addItem(
+ Row.Builder()
+ .setTitle("Plate cameras & drones on the map")
+ .setImage(CarUi.icon(carContext, R.drawable.ic_car_navigate))
+ .setBrowsable(true)
+ .setOnClickListener { screenManager.push(NearbyMapScreen(carContext)) }
+ .build()
+ )
// 5. Spoken announcements in the car (alongside the alert tone)
val voice = Prefs.carVoice(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
new file mode 100644
index 0000000..048353a
--- /dev/null
+++ b/app/src/main/java/com/rfsentinel/app/car/NearbyMapScreen.kt
@@ -0,0 +1,114 @@
+package com.rfsentinel.app.car
+
+import android.annotation.SuppressLint
+import android.location.Location
+import android.location.LocationManager
+import androidx.car.app.CarContext
+import androidx.car.app.CarToast
+import androidx.car.app.model.Action
+import androidx.car.app.model.CarColor
+import androidx.car.app.model.CarLocation
+import androidx.car.app.model.ItemList
+import androidx.car.app.model.Metadata
+import androidx.car.app.model.Place
+import androidx.car.app.model.PlaceListMapTemplate
+import androidx.car.app.model.PlaceMarker
+import androidx.car.app.model.Row
+import androidx.car.app.model.Template
+import com.rfsentinel.app.alpr.AlprStore
+import com.rfsentinel.app.alpr.KnownCameras
+import com.rfsentinel.app.service.DeviceRegistry
+import com.rfsentinel.app.service.ScanForegroundService
+import com.rfsentinel.app.util.Permissions
+import kotlin.math.roundToInt
+
+/**
+ * Android Auto: the closest known plate cameras (OpenStreetMap, downloaded on
+ * the phone) and the drones broadcasting a Remote ID position, on the car's own
+ * map with distances. The car host draws the map; we only supply places.
+ */
+class NearbyMapScreen(carContext: CarContext) : LiveScreen(carContext, periodMs = 5_000L) {
+
+ /** 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?)
+
+ override fun onGetTemplate(): Template {
+ val me = myLocation()
+ val limit = CarUi.listLimit(carContext).coerceAtMost(6)
+ val items = if (me == null) emptyList() else nearby(me.latitude, me.longitude, limit)
+
+ val list = ItemList.Builder()
+ if (me == null) {
+ list.setNoItemsMessage("Waiting for your location...")
+ } else if (items.isEmpty()) {
+ list.setNoItemsMessage(
+ if (AlprStore.cameras.isEmpty()) "No known cameras downloaded - on your phone: Map > menu > Download known plate cameras"
+ else "No known plate cameras or drones within ${SEARCH_RADIUS_M / 1000} km"
+ )
+ }
+ items.forEach { it -> list.addItem(row(it)) }
+
+ return PlaceListMapTemplate.Builder()
+ .setTitle("Plate cameras & drones")
+ .setHeaderAction(Action.BACK)
+ .setCurrentLocationEnabled(me != null)
+ .setItemList(list.build())
+ .build()
+ }
+
+ private fun row(it: Item): Row {
+ val place = Place.Builder(CarLocation.create(it.lat, it.lon))
+ .setMarker(
+ PlaceMarker.Builder()
+ .setColor(if (it.drone) CarColor.BLUE else CarColor.RED)
+ .setLabel(if (it.drone) "D" else "P")
+ .build()
+ ).build()
+ return Row.Builder()
+ .setTitle(it.title)
+ .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))
+ else CarToast.makeText(carContext, "${it.title}: ${distanceText(it.distanceM)} away", CarToast.LENGTH_LONG).show()
+ }
+ .build()
+ }
+
+ @SuppressLint("MissingPermission") // checked via Permissions
+ private fun myLocation(): Location? {
+ ScanForegroundService.lastFix?.let { return it }
+ if (!Permissions.granted(carContext, android.Manifest.permission.ACCESS_FINE_LOCATION)) return null
+ val lm = carContext.getSystemService(LocationManager::class.java) ?: return null
+ return listOf(LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER)
+ .mapNotNull { p -> runCatching { lm.getLastKnownLocation(p) }.getOrNull() }
+ .maxByOrNull { it.time }
+ }
+
+ companion object {
+ const val SEARCH_RADIUS_M = 5_000.0
+
+ /** Nearest known cameras and positioned drones, closest first (pure; unit-tested). */
+ fun nearby(lat: Double, lon: Double, limit: Int): List<Item> {
+ val cams = KnownCameras.near(AlprStore.cameras, lat, lon, SEARCH_RADIUS_M).map { (c, d) ->
+ Item(c.label, c.operator ?: (c.direction?.let { "faces $it°" } ?: "mapped in OpenStreetMap"),
+ c.lat, c.lon, d, drone = false, mac = null)
+ }
+ val drones = DeviceRegistry.snapshot().mapNotNull { s ->
+ val r = s.remoteId ?: return@mapNotNull null
+ val dLat = r.latitude ?: return@mapNotNull null
+ val dLon = r.longitude ?: return@mapNotNull null
+ val d = DeviceRegistry.metersBetween(lat, lon, dLat, dLon)
+ Item("Drone" + (r.uasId?.let { " $it" } ?: ""),
+ listOfNotNull(r.heightM?.let { "${it.roundToInt()} m up" }, r.speedMs?.let { "${(it * 3.6).roundToInt()} km/h" })
+ .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)
+ }
+
+ 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 e05e4f2..69a8d32 100644
--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
@@ -87,6 +87,11 @@ class ScanForegroundService : Service() {
private const val CELL_CHECK_MS = 15_000L
private const val CELL_REPEAT_MS = 30 * 60_000L
+ /** Latest location fix while scanning (for the car map), or null. */
+ @Volatile
+ var lastFix: Location? = null
+ private set
+
/** True while an instance is alive in this process. Source of truth for the UI. */
@Volatile
var isRunning = false
@@ -136,6 +141,7 @@ class ScanForegroundService : Service() {
private var locationFastMode = false
private val locationListener = LocationListener {
lastLocation = it
+ lastFix = it
TripRecorder.onLocation(it)
checkKnownAlpr(it)
cellMonitor?.onLocation(it)
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 edaf248..22de063 100644
--- a/app/src/test/java/com/rfsentinel/app/car/CarScreensTest.kt
+++ b/app/src/test/java/com/rfsentinel/app/car/CarScreensTest.kt
@@ -74,11 +74,12 @@ class CarScreensTest {
fun homeScreenShowsStatusNavigationAndButtons() {
val t = HomeScreen(car).onGetTemplate() as ListTemplate
val rows = t.singleList!!.items.map { it as Row }
- assertEquals(5, rows.size)
+ assertEquals(6, rows.size)
assertTrue(rows[0].title.toString().startsWith("Strong match")) // threat headline
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("Plate cameras & drones on the map", rows[4].title.toString())
val actions = t.actionStrip!!.actions
assertEquals(2, actions.size)
assertEquals("Stop", actions[0].title.toString())
@@ -92,7 +93,7 @@ class CarScreensTest {
mute.onClickDelegate!!.sendClick(object : OnDoneCallback {})
assertTrue(Prefs.alertsMuted(car))
val t = screen.onGetTemplate() as ListTemplate
- assertTrue((t.singleList!!.items[4] as Row).texts[0].toString().contains("muted"))
+ assertTrue((t.singleList!!.items[5] as Row).texts[0].toString().contains("muted"))
val relabeled = t.actionStrip!!.actions[1]
relabeled.onClickDelegate!!.sendClick(object : OnDoneCallback {})
assertTrue(!Prefs.alertsMuted(car))
@@ -120,6 +121,27 @@ class CarScreensTest {
assertTrue(drone.actionStrip!!.actions.any { it.title?.toString() == "Navigate" })
}
+ @Test
+ fun nearbyMapListsDronesThenClosestCameras() {
+ // Synthetic positions: you at 10.5, -20.5; the test drone is at the same point.
+ com.rfsentinel.app.alpr.AlprStore.setForTest(listOf(
+ com.rfsentinel.app.alpr.KnownCamera("node/1", 10.503, -20.5, "Flock Safety", "Example PD", 90),
+ com.rfsentinel.app.alpr.KnownCamera("node/2", 10.51, -20.5, "Motorola", null, null),
+ 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
+ assertTrue(items[0].drone)
+ assertEquals("Flock Safety (ALPR)", items[1].title)
+ assertEquals("330 m", NearbyMapScreen.distanceText(items[1].distanceM))
+ assertEquals("1.1 km", NearbyMapScreen.distanceText(items[2].distanceM))
+
+ // The template (host-drawn map + places) builds within Android Auto's limits.
+ val t = NearbyMapScreen(car).onGetTemplate() as androidx.car.app.model.PlaceListMapTemplate
+ assertTrue(t.itemList!!.items.size <= CarUi.listLimit(car))
+ com.rfsentinel.app.alpr.AlprStore.setForTest(emptyList())
+ }
+
@Test
fun goneDeviceShowsMessage() {
val t = DeviceDetailScreen(car, "AA:BB:CC:DD:EE:FF").onGetTemplate()