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: devices-around-me map

CIS-C0343ec3816bfa
diff --git a/README.md b/README.md
index 56eb888..eb5da4b 100644
--- a/README.md
+++ b/README.md
@@ -204,9 +204,12 @@ RF Sentinel runs in Android Auto as a driver-safe, template-based app:
- **Device lists** (flagged, drones & trackers, all nearby) and **device details**
with Whitelist, Watch and Favorite actions. **Navigate** opens your car's
navigation app for drones with a known position.
-- **Cameras & drones map:** the closest known plate, speed and red-light cameras (downloaded
- on the phone from OpenStreetMap) and Remote ID drones, on the car's map
- with distances.
+- **Devices around me map:** the devices heard around you on the car's map, like
+ the phone map, in the list and radar colours - flagged ones first, then the
+ strongest ordinary ones (Android Auto shows about six places at a time).
+ Tap one for its details.
+- **Cameras map** (the *Cameras* button): the closest known plate, speed and
+ red-light cameras (OpenStreetMap) and Remote ID drones, with distances.
- **Alerts** appear as a heads-up on the car screen. While connected, they play
through the car speakers as navigation-guidance audio, briefly lowering your
music.
diff --git a/app/src/main/java/com/rfsentinel/app/car/CarUi.kt b/app/src/main/java/com/rfsentinel/app/car/CarUi.kt
index d8020bd..0bf996b 100644
--- a/app/src/main/java/com/rfsentinel/app/car/CarUi.kt
+++ b/app/src/main/java/com/rfsentinel/app/car/CarUi.kt
@@ -27,6 +27,17 @@ object CarUi {
}
/** Max rows the car allows in a list (typically 6 while driving). */
+ /** Where the driver is: the scanner's latest fix, else the phone's last known position. */
+ @android.annotation.SuppressLint("MissingPermission") // checked via Permissions
+ fun currentLocation(context: CarContext): android.location.Location? {
+ com.rfsentinel.app.service.ScanForegroundService.lastFix?.let { return it }
+ if (!com.rfsentinel.app.util.Permissions.granted(context, android.Manifest.permission.ACCESS_FINE_LOCATION)) return null
+ val lm = context.getSystemService(android.location.LocationManager::class.java) ?: return null
+ return listOf(android.location.LocationManager.GPS_PROVIDER, android.location.LocationManager.NETWORK_PROVIDER)
+ .mapNotNull { p -> runCatching { lm.getLastKnownLocation(p) }.getOrNull() }
+ .maxByOrNull { it.time }
+ }
+
fun listLimit(context: CarContext): Int = runCatching {
context.getCarService(ConstraintManager::class.java)
.getContentLimit(ConstraintManager.CONTENT_LIMIT_TYPE_LIST)
diff --git a/app/src/main/java/com/rfsentinel/app/car/DevicesMapScreen.kt b/app/src/main/java/com/rfsentinel/app/car/DevicesMapScreen.kt
new file mode 100644
index 0000000..45a9d65
--- /dev/null
+++ b/app/src/main/java/com/rfsentinel/app/car/DevicesMapScreen.kt
@@ -0,0 +1,124 @@
+package com.rfsentinel.app.car
+
+import android.text.SpannableString
+import android.text.Spanned
+import androidx.car.app.CarContext
+import androidx.car.app.model.Action
+import androidx.car.app.model.ActionStrip
+import androidx.car.app.model.CarColor
+import androidx.car.app.model.CarLocation
+import androidx.car.app.model.DistanceSpan
+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.data.WhitelistCache
+import com.rfsentinel.app.detect.Tier
+import com.rfsentinel.app.service.DeviceRegistry
+import com.rfsentinel.app.service.ScanForegroundService
+import com.rfsentinel.app.ui.DeviceColors
+
+/**
+ * Android Auto: the devices heard around you on the car's map, like the phone
+ * map - each placed where your phone was when its signal was strongest, in the
+ * list / radar colour. Android Auto lets a non-navigation app show only a short
+ * list of places (usually 6), so flagged devices come first, then the strongest
+ * ordinary ones. "Cameras" switches to the known-camera map.
+ */
+class DevicesMapScreen(carContext: CarContext) : LiveScreen(carContext, periodMs = 4_000L, preciseLocation = true) {
+
+ /** One device to show. */
+ data class Item(
+ val mac: String, val title: String, val detail: String,
+ val lat: Double, val lon: Double, val distanceM: Double,
+ val flagged: Boolean, val color: Int, val tag: String?
+ )
+
+ override fun onGetTemplate(): Template {
+ val me = CarUi.currentLocation(carContext)
+ val limit = CarUi.listLimit(carContext).coerceAtMost(6)
+ val items = if (me == null) emptyList() else around(me.latitude, me.longitude, limit)
+
+ val list = ItemList.Builder()
+ if (items.isEmpty()) list.setNoItemsMessage(
+ when {
+ !ScanForegroundService.isRunning -> "Not scanning - tap Start on the RF Sentinel home screen"
+ me == null -> "Waiting for your location..."
+ else -> "No devices placed yet - they appear as GPS fixes come in"
+ }
+ )
+ items.forEach { list.addItem(row(it)) }
+
+ val template = PlaceListMapTemplate.Builder()
+ .setTitle("Devices around me")
+ .setHeaderAction(Action.BACK)
+ .setCurrentLocationEnabled(me != null)
+ .setActionStrip(
+ ActionStrip.Builder().addAction(
+ Action.Builder().setTitle("Cameras")
+ .setOnClickListener { screenManager.push(NearbyMapScreen(carContext, fromDevicesMap = true)) }
+ .build()
+ ).build()
+ )
+ .setItemList(list.build())
+ if (me != null) template.setAnchor(Place.Builder(CarLocation.create(me.latitude, me.longitude)).build())
+ return template.build()
+ }
+
+ private fun row(it: Item): Row {
+ val marker = PlaceMarker.Builder().setColor(CarColor.createCustom(it.color, it.color))
+ it.tag?.let { t -> marker.setLabel(t) }
+ val place = Place.Builder(CarLocation.create(it.lat, it.lon)).setMarker(marker.build()).build()
+ // Map rows must carry their distance as a DistanceSpan (the car formats it).
+ val text = SpannableString(" · " + it.detail)
+ text.setSpan(DistanceSpan.create(NearbyMapScreen.distanceOf(it.distanceM)), 0, 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE)
+ return Row.Builder()
+ .setTitle(it.title)
+ .addText(text)
+ .setMetadata(Metadata.Builder().setPlace(place).build())
+ .setOnClickListener { screenManager.push(DeviceDetailScreen(carContext, it.mac)) }
+ .build()
+ }
+
+ companion object {
+ /** Ordinary devices: the radar scope colour of the default theme (cars don't use app themes). */
+ const val ORDINARY_COLOR = 0xFF0B5C63.toInt()
+
+ /**
+ * Devices with a position, most relevant first: flagged (strongest
+ * evidence first), then ordinary by signal strength. Drones use their
+ * own Remote ID position. Pure apart from the registry; unit-tested.
+ */
+ fun around(lat: Double, lon: Double, limit: Int): List<Item> =
+ DeviceRegistry.snapshot().mapNotNull { s ->
+ if (WhitelistCache.contains(s.mac)) return@mapNotNull null
+ val rid = s.remoteId?.takeIf { it.hasPosition }
+ val pLat = rid?.latitude ?: s.bestPosition?.lat ?: return@mapNotNull null
+ val pLon = rid?.longitude ?: s.bestPosition?.lon ?: return@mapNotNull null
+ val best = s.best
+ val flagged = DeviceColors.isFlagged(s)
+ Item(
+ mac = s.mac,
+ title = best?.label ?: s.name ?: s.deviceType,
+ // Short enough for one line on a car screen.
+ detail = if (best != null) "${best.category.shortTag} · ${best.tier.label}"
+ else (if (s.source == com.rfsentinel.app.detect.Advert.Source.WIFI) "WiFi" else "Bluetooth") + " · ${s.rssi} dBm",
+ lat = pLat, lon = pLon,
+ distanceM = DeviceRegistry.metersBetween(lat, lon, pLat, pLon),
+ flagged = flagged,
+ color = when {
+ best == null -> ORDINARY_COLOR
+ best.tier == Tier.WEAK -> DeviceColors.WEAK
+ else -> best.category.colorArgb
+ },
+ tag = best?.category?.shortTag?.take(1)
+ ) to (if (flagged) 1_000 + (best?.confidence ?: 0) else 0) * 1_000 + (s.rssi + 200)
+ }
+ .sortedByDescending { it.second }
+ .take(limit)
+ .map { it.first }
+ }
+}
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 7f3bd4e..3f2f7ed 100644
--- a/app/src/main/java/com/rfsentinel/app/car/HomeScreen.kt
+++ b/app/src/main/java/com/rfsentinel/app/car/HomeScreen.kt
@@ -58,10 +58,10 @@ 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("Map: cameras, devices & drones")
+ .setTitle("Map: devices & cameras around me")
.setImage(CarUi.icon(carContext, R.drawable.ic_car_navigate))
.setBrowsable(true)
- .setOnClickListener { screenManager.push(NearbyMapScreen(carContext)) }
+ .setOnClickListener { screenManager.push(DevicesMapScreen(carContext)) }
.build()
)
diff --git a/app/src/main/java/com/rfsentinel/app/car/LiveScreen.kt b/app/src/main/java/com/rfsentinel/app/car/LiveScreen.kt
index afabc8d..97982c0 100644
--- a/app/src/main/java/com/rfsentinel/app/car/LiveScreen.kt
+++ b/app/src/main/java/com/rfsentinel/app/car/LiveScreen.kt
@@ -13,8 +13,19 @@ import kotlinx.coroutines.launch
* refresh of the same template type and title as an update, not a new step, so
* this doesn't use up the driver's navigation-depth budget.
*/
-abstract class LiveScreen(carContext: CarContext, private val periodMs: Long = 3_000L) : Screen(carContext) {
+abstract class LiveScreen(
+ carContext: CarContext,
+ private val periodMs: Long = 3_000L,
+ /** Map screens: precise GPS while shown, so devices are placed where they were heard. */
+ preciseLocation: Boolean = false
+) : Screen(carContext) {
init {
+ if (preciseLocation) lifecycle.addObserver(object : androidx.lifecycle.DefaultLifecycleObserver {
+ override fun onStart(owner: androidx.lifecycle.LifecycleOwner) =
+ com.rfsentinel.app.service.ScanForegroundService.mapShown(carContext)
+ override fun onStop(owner: androidx.lifecycle.LifecycleOwner) =
+ com.rfsentinel.app.service.ScanForegroundService.mapHidden(carContext)
+ })
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
while (true) {
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 e849f68..50f34bb 100644
--- a/app/src/main/java/com/rfsentinel/app/car/NearbyMapScreen.kt
+++ b/app/src/main/java/com/rfsentinel/app/car/NearbyMapScreen.kt
@@ -29,7 +29,11 @@ import kotlin.math.roundToInt
* 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) {
+class NearbyMapScreen(
+ carContext: CarContext,
+ /** Opened from the devices map: its "Devices" button goes back instead of stacking another. */
+ private val fromDevicesMap: Boolean = false
+) : LiveScreen(carContext, periodMs = 5_000L, preciseLocation = true) {
/** 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,
@@ -38,7 +42,7 @@ class NearbyMapScreen(carContext: CarContext) : LiveScreen(carContext, periodMs
val deviceColor: Int? = null)
override fun onGetTemplate(): Template {
- val me = myLocation()
+ val me = CarUi.currentLocation(carContext)
if (me != null) autoDownloadAround(me)
val limit = CarUi.listLimit(carContext).coerceAtMost(6)
val items = if (me == null) emptyList() else nearby(me.latitude, me.longitude, limit)
@@ -55,8 +59,15 @@ class NearbyMapScreen(carContext: CarContext) : LiveScreen(carContext, periodMs
items.forEach { it -> list.addItem(row(it)) }
val template = PlaceListMapTemplate.Builder()
- .setTitle("Cameras & devices")
+ .setTitle("Cameras nearby")
.setHeaderAction(Action.BACK)
+ .setActionStrip(
+ androidx.car.app.model.ActionStrip.Builder().addAction(
+ Action.Builder().setTitle("Devices").setOnClickListener {
+ if (fromDevicesMap) screenManager.pop() else screenManager.push(DevicesMapScreen(carContext))
+ }.build()
+ ).build()
+ )
.setCurrentLocationEnabled(me != null)
.setItemList(list.build())
// Centre on the driver, not on 0°,0°, when there is nothing to show.
@@ -110,16 +121,6 @@ class NearbyMapScreen(carContext: CarContext) : LiveScreen(carContext, periodMs
}
}
- @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 {
/** The list shows only the nearest few, so look well ahead along the road. */
const val SEARCH_RADIUS_M = 20_000.0
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 79d21dc..33c8fd0 100644
--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
@@ -90,11 +90,22 @@ class ScanForegroundService : Service() {
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.
+ * Maps on screen (phone or car). While any is, location switches to precise
+ * GPS so the devices they show are placed where they really were heard.
*/
- @Volatile
- var mapVisible = false
+ private val mapViewers = java.util.concurrent.atomic.AtomicInteger(0)
+ val mapVisible: Boolean get() = mapViewers.get() > 0
+
+ fun mapShown(context: Context) { mapViewers.incrementAndGet(); refreshLocation(context) }
+ fun mapHidden(context: Context) { mapViewers.updateAndGet { (it - 1).coerceAtLeast(0) }; refreshLocation(context) }
+
+ /** Re-applies the location mode of a running scan (never starts one). */
+ private fun refreshLocation(context: Context) {
+ if (!isRunning) return
+ runCatching {
+ context.startService(Intent(context, ScanForegroundService::class.java).setAction(ACTION_REFRESH_LOCATION))
+ }
+ }
/** Latest location fix while scanning (for the car map), or null. */
@Volatile
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 6d64292..ddb992f 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/MapActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/MapActivity.kt
@@ -181,11 +181,11 @@ class MapActivity : AppCompatActivity() {
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() }
+ if (tripId == null) ScanForegroundService.mapShown(this)
}
override fun onPause() {
- if (tripId == null) { ScanForegroundService.mapVisible = false; refreshServiceLocation() }
+ if (tripId == null) ScanForegroundService.mapHidden(this)
binding.map.onPause()
super.onPause()
}
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 0c4b0cb..fe11c6b 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("Map: cameras, devices & drones", rows[4].title.toString())
+ assertEquals("Map: devices & cameras around me", rows[4].title.toString())
val actions = t.actionStrip!!.actions
assertEquals(2, actions.size)
assertEquals("Stop", actions[0].title.toString())
@@ -121,6 +121,34 @@ class CarScreensTest {
assertTrue(drone.actionStrip!!.actions.any { it.title?.toString() == "Navigate" })
}
+ @Test
+ fun devicesMapShowsFlaggedFirstInListColours() {
+ // Synthetic positions around you at 10.5, -20.5: the Axon was heard 100 m north,
+ // an ordinary phone 50 m east; the drone has its own Remote ID position.
+ val here = DeviceRegistry.GeoSample(System.currentTimeMillis(), 10.5009, -20.5)
+ DeviceRegistry.report(
+ Advert(axonMac, Advert.Source.BLE, -50, "Axon Body 4"),
+ listOf(Hit(Category.BODY_CAM, "Axon body camera", 90, "BWCDEVICE tag in advert payload", "test")),
+ DeviceIntel.Identity("Body camera", emptyList()), "Axon Enterprise, Inc.", null, here
+ )
+ DeviceRegistry.report(
+ Advert("C0:00:00:00:00:00", Advert.Source.BLE, -60, "Device 0"), emptyList(),
+ DeviceIntel.Identity("Phone", emptyList()), null, null,
+ DeviceRegistry.GeoSample(System.currentTimeMillis(), 10.5, -20.49954)
+ )
+ val items = DevicesMapScreen.around(10.5, -20.5, 6)
+ assertEquals(listOf(droneMac, axonMac, "C0:00:00:00:00:00"), items.map { it.mac }) // flagged by evidence, then ordinary
+ assertEquals(Category.BODY_CAM.colorArgb, items[1].color)
+ assertEquals(DevicesMapScreen.ORDINARY_COLOR, items[2].color)
+ assertEquals(100.0, items[1].distanceM, 5.0)
+
+ ScanForegroundService.setLastFixForTest(android.location.Location("test").apply { latitude = 10.5; longitude = -20.5 })
+ val t = DevicesMapScreen(car).onGetTemplate() as androidx.car.app.model.PlaceListMapTemplate
+ assertEquals(3, t.itemList!!.items.size) // rows really present (each needs a DistanceSpan)
+ assertEquals("Cameras", t.actionStrip!!.actions.single().title.toString())
+ ScanForegroundService.setLastFixForTest(null)
+ }
+
@Test
fun nearbyMapListsDronesThenClosestCameras() {
// Synthetic positions: you at 10.5, -20.5; the test drone is at the same point.