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
Trackers that never leave a phone's side don't alert as following
CIS-C0186c9b5e498e
diff --git a/app/src/main/java/com/rfsentinel/app/detect/DeviceIntel.kt b/app/src/main/java/com/rfsentinel/app/detect/DeviceIntel.ktindex 5db5841..9d00c50 100644--- a/app/src/main/java/com/rfsentinel/app/detect/DeviceIntel.kt+++ b/app/src/main/java/com/rfsentinel/app/detect/DeviceIntel.kt@@ -102,6 +102,13 @@ object DeviceIntel {"^nintendo|^switch_|^ps[45]-|^xbox" to "Game console").map { (re, type) -> Regex(re, RegexOption.IGNORE_CASE) to type }+ private val PHONE_TYPE = Regex("^(iphone|apple watch|phone hotspot|phone / computer|apple device \\(iphone|samsung device|google device)", RegexOption.IGNORE_CASE)+ private val PHONE_NAME = Regex("iphone|galaxy|pixel|'s phone|oneplus|redmi|moto g", RegexOption.IGNORE_CASE)++ /** True when a device's type (from [identify]) or broadcast name says it's a phone (or a phone's hotspot). */+ fun isPhone(type: String?, name: String?): Boolean =+ type?.let { PHONE_TYPE.containsMatchIn(it) } == true || name?.let { PHONE_NAME.containsMatchIn(it) } == true+/** What a network's name says it is ([SSID_TYPES]), or null. */fun ssidType(ssid: String): String? = SSID_TYPES.firstOrNull { it.first.containsMatchIn(ssid.trim()) }?.seconddiff --git a/app/src/main/java/com/rfsentinel/app/detect/SignatureEngine.kt b/app/src/main/java/com/rfsentinel/app/detect/SignatureEngine.ktindex 285eeba..ecb7dce 100644--- a/app/src/main/java/com/rfsentinel/app/detect/SignatureEngine.kt+++ b/app/src/main/java/com/rfsentinel/app/detect/SignatureEngine.kt@@ -24,6 +24,13 @@ object SignatureEngine {/** An Apple Find My tag match (AirTag or compatible), for Settings > Exclude AirTags. */fun isAppleFindMy(hit: Hit) = hit.category == Category.TRACKER && hit.label.startsWith("Apple Find My")+ /**+ * A tracker match whose tag says by itself that it's away from its owner (Apple Find My, Google Find Hub+ * "separated" frames). Other tags (Tile, SmartTag, Chipolo...) don't, so the owner is inferred instead+ * ([com.rfsentinel.app.service.DeviceRegistry.ownerPhone]).+ */+ fun reportsOwnerState(hit: Hit) = isAppleFindMy(hit) || hit.label.startsWith("Google Find Hub")+private const val ACAB = "all-cameras-are-beacons signature reference (Apache-2.0)"private const val SIG = "Bluetooth SIG assigned numbers"diff --git a/app/src/main/java/com/rfsentinel/app/service/DeviceRegistry.kt b/app/src/main/java/com/rfsentinel/app/service/DeviceRegistry.ktindex f7455e4..0318236 100644--- a/app/src/main/java/com/rfsentinel/app/service/DeviceRegistry.kt+++ b/app/src/main/java/com/rfsentinel/app/service/DeviceRegistry.kt@@ -5,6 +5,7 @@ import com.rfsentinel.app.data.WhitelistCacheimport com.rfsentinel.app.detect.AddressTypeimport com.rfsentinel.app.detect.Advertimport com.rfsentinel.app.detect.AdvertFingerprint+import com.rfsentinel.app.detect.Categoryimport com.rfsentinel.app.detect.PatrolClusterimport com.rfsentinel.app.detect.WifiFingerprintimport com.rfsentinel.app.detect.DeviceIntel@@ -393,6 +394,26 @@ object DeviceRegistry {}.sortedByDescending { it.third }.take(max).map { it.first to it.second }}+ /**+ * The phone a tracker travels with, as its name or type, when there is one: a phone (not itself a+ * tracker) heard with [mac] at every one of its places along your way ([sharedPlaces]). A tag that+ * never leaves a phone's side is most likely that phone owner's (a passenger's keys or bag), the+ * way an AirTag near its owner's iPhone doesn't report itself separated. Null otherwise.+ */+ fun ownerPhone(mac: String): String? {+ val t = tracks[mac] ?: return null+ val mine = synchronized(t) { t.path.toList() }+ val places = sharedPlaces(mine, mine).takeIf { it > 0 } ?: return null+ return tracks.values.firstNotNullOfOrNull { o ->+ if (o === t) return@firstNotNullOfOrNull null+ val (theirs, label, phone) = synchronized(o) {+ Triple(o.path.toList(), o.name ?: o.identity.type,+ o.hits.none { it.category == Category.TRACKER } && DeviceIntel.isPhone(o.identity.type, o.name))+ }+ label.takeIf { phone && sharedPlaces(mine, theirs) >= places }+ }+ }+/** How many separate places of [a] had [b] heard too (within [TOGETHER_MS]), when they make a companion; else 0. */internal fun sharedPlaces(a: List<GeoSample>, b: List<GeoSample>): Int {if (b.size < TOGETHER_PLACES) return 0diff --git a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.ktindex af9cef5..34a594b 100644--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt@@ -68,6 +68,7 @@ class ScanForegroundService : Service() {companion object {/** Radar beeps: start after the alert's own beeps, last up to 2 min, stop once the device is out of range. */private const val RADAR_QUIET_MS = 2_500L+ private const val OWNER_CHECK_MS = 30_000Lprivate const val RADAR_HOLD_MS = 120_000L/** "GPS connected" again only after the fix was lost this long. */private const val GPS_RECONNECT_MS = 120_000L@@ -687,7 +688,11 @@ class ScanForegroundService : Service() {val followM = Prefs.followMinMeters(this).toDouble()// Followers that stay in range, and ones that keep turning up at places along your way.if (loc != null && !best.listOnly) placeFollow.heard(mac, DeviceRegistry.linkedFrom(mac), now, loc.latitude, loc.longitude)- if (loc != null && Prefs.followerAlerts(this) && !trackerPaused && !best.listOnly &&+ // A tag that can't say it's with its owner (Tile, SmartTag, Chipolo...) and never leaves a phone's+ // side is that phone owner's, like an AirTag near its iPhone: no follow alert while that holds.+ val withOwner = loc != null && best.category == Category.TRACKER && !SignatureEngine.reportsOwnerState(best) &&+ ownerPhone(mac, now) != null+ if (loc != null && Prefs.followerAlerts(this) && !trackerPaused && !best.listOnly && !withOwner &&(DeviceRegistry.checkFollowing(mac, followMs, followM).also { if (it) placeFollow.alertedNow(mac, now) } ||placeFollow.follower(mac, now, followMs, followM).also { if (it) DeviceRegistry.markFollowing(mac) })) {@@ -696,6 +701,15 @@ class ScanForegroundService : Service() {}}+ /** [DeviceRegistry.ownerPhone] per tracker, rechecked every [OWNER_CHECK_MS]. */+ private val ownerChecks = HashMap<String, Pair<Long, String?>>()++ private fun ownerPhone(mac: String, now: Long): String? = synchronized(ownerChecks) {+ ownerChecks[mac]?.takeIf { now - it.first < OWNER_CHECK_MS }?.let { return it.second }+ if (ownerChecks.size > 200) ownerChecks.entries.removeIf { now - it.value.first >= OWNER_CHECK_MS }+ DeviceRegistry.ownerPhone(mac).also { ownerChecks[mac] = now to it }+ }+/** Matches an ESP32 board reported, kept a few minutes so re-classification keeps them. */private val espHits = HashMap<String, Pair<Long, List<Hit>>>()diff --git a/app/src/main/java/com/rfsentinel/app/ui/DeviceDetailActivity.kt b/app/src/main/java/com/rfsentinel/app/ui/DeviceDetailActivity.ktindex 023471b..62a670a 100644--- a/app/src/main/java/com/rfsentinel/app/ui/DeviceDetailActivity.kt+++ b/app/src/main/java/com/rfsentinel/app/ui/DeviceDetailActivity.kt@@ -317,6 +317,12 @@ class DeviceDetailActivity : AppCompatActivity() {DeviceRegistry.companions(DeviceRegistry.currentAddress(mac)).takeIf { it.isNotEmpty() }?.let { c ->id += "Moved together with" to c.joinToString("\n") { (m, label) -> (DeviceNames.of(m) ?: label) + " · " + m }}+ s?.hits?.firstOrNull { it.category == com.rfsentinel.app.detect.Category.TRACKER }+ ?.takeIf { !com.rfsentinel.app.detect.SignatureEngine.reportsOwnerState(it) }?.let {+ DeviceRegistry.ownerPhone(DeviceRegistry.currentAddress(mac))?.let { phone ->+ id += "With its owner" to "Moved with $phone at every place: most likely that phone owner's tag, so it doesn't alert as following you"+ }+ }// Heard by a USB WiFi adapter / Marauder board: its WPS block, fingerprint, network requests.com.rfsentinel.app.usb.ProbeIntel.of(mac)?.let { r ->if (r.hidden) id += "Hidden network" to (s?.name?.let { "Its name, \"$it\", was revealed by a device joining or asking for it" }diff --git a/app/src/test/java/com/rfsentinel/app/detect/IdentifyMoreTest.kt b/app/src/test/java/com/rfsentinel/app/detect/IdentifyMoreTest.ktindex ac594fc..10ac8bd 100644--- a/app/src/test/java/com/rfsentinel/app/detect/IdentifyMoreTest.kt+++ b/app/src/test/java/com/rfsentinel/app/detect/IdentifyMoreTest.kt@@ -84,6 +84,36 @@ class IdentifyMoreTest {assertEquals(0, DeviceRegistry.sharedPlaces(way, way.map { it.copy(time = it.time + 3_600_000L) }))}+ @Test+ fun aTagThatNeverLeavesAPhoneIsItsOwners() {+ DeviceRegistry.clear(); DeviceRegistry.startSession()+ val tile = Advert("D0:00:00:00:00:01", Advert.Source.BLE, -60, null,+ serviceData = mapOf(Advert.uuid16(0xFEED) to bytes(0x02, 0x00)))+ val tileHit = Hit(Category.TRACKER, "Tile tracker", 55, "e", "test")+ val phone = Advert("D0:00:00:00:00:02", Advert.Source.BLE, -60, "Galaxy S24")+ val watch = Advert("D0:00:00:00:00:03", Advert.Source.BLE, -60, "Fitbit")+ // Five places ~550 m apart, a minute each; the phone is there at all of them, the watch at the first three.+ (0 until 5).forEach { i ->+ val at = GeoSample(i * 60_000L, 45.0 + i * 0.005, -70.0)+ DeviceRegistry.report(tile, listOf(tileHit), DeviceIntel.Identity("Tile", emptyList()), null, null, at, at.time)+ DeviceRegistry.report(phone, emptyList(), DeviceIntel.Identity("Samsung device", emptyList()), null, null, at, at.time + 5_000)+ if (i < 3) DeviceRegistry.report(watch, emptyList(), DeviceIntel.Identity("Wearable", emptyList()), null, null, at, at.time + 5_000)+ }+ assertEquals("Galaxy S24", DeviceRegistry.ownerPhone(tile.mac))+ // Without the phone, nothing: a watch there all the way isn't a phone.+ DeviceRegistry.clear(); DeviceRegistry.startSession()+ (0 until 5).forEach { i ->+ val at = GeoSample(i * 60_000L, 45.0 + i * 0.005, -70.0)+ DeviceRegistry.report(tile, listOf(tileHit), DeviceIntel.Identity("Tile", emptyList()), null, null, at, at.time)+ DeviceRegistry.report(watch, emptyList(), DeviceIntel.Identity("Wearable", emptyList()), null, null, at, at.time + 5_000)+ }+ assertNull(DeviceRegistry.ownerPhone(tile.mac))+ // AirTags and Find Hub tags say it themselves; the rest need this.+ assertTrue(SignatureEngine.reportsOwnerState(Hit(Category.TRACKER, SignatureEngine.APPLE_FIND_MY_LABEL, 70, "e", "s")))+ assertTrue(!SignatureEngine.reportsOwnerState(tileHit))+ DeviceRegistry.clear()+ }+@Testfun advertHashIsStable() {assertEquals(AdvertFingerprint.hash("n=Buds|u=|d=|m=|t=|c="), AdvertFingerprint.hash("n=Buds|u=|d=|m=|t=|c="))