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
Position marker: classic dot with a heading beam and a 3D arrow; Bluetooth address type worked out from the address when the phone doesn't report it
CIS-C0aa589672e719
diff --git a/app/src/main/java/com/rfsentinel/app/detect/Advert.kt b/app/src/main/java/com/rfsentinel/app/detect/Advert.ktindex 4f8ee98..29b032c 100644--- a/app/src/main/java/com/rfsentinel/app/detect/Advert.kt+++ b/app/src/main/java/com/rfsentinel/app/detect/Advert.kt@@ -65,7 +65,7 @@ class Advert(/*** How trackable a device's address is. For BLE the controller reports public vs- * random (API 35+); the random sub-type comes from the top two bits of the+ * random (API 35+; before that it is guessed, see [guess]); the random sub-type comes from the top two bits of the* most significant byte (Bluetooth Core Spec Vol 6, Part B, 1.3).*/enum class AddressType(val label: String, val trackable: String) {@@ -75,7 +75,12 @@ enum class AddressType(val label: String, val trackable: String) {NON_RESOLVABLE("Non-resolvable private", "Rotates - not trackable"),WIFI_GLOBAL("WiFi, globally unique", "Fixed hardware address - trackable"),WIFI_LOCAL("WiFi, locally administered", "Randomized / private address"),- UNKNOWN("Unknown", "Android didn't report the address type (needs Android 15+)");+ // This phone's Bluetooth didn't say (it does from Android 15 on): worked out from the address itself.+ LIKELY_PUBLIC("Probably public (IEEE-assigned)", "Probably trackable - the address belongs to a registered maker"),+ LIKELY_STATIC("Probably random static", "Probably stable until reboot or reset - partly trackable"),+ LIKELY_RPA("Probably resolvable private (RPA)", "Probably rotates every few minutes - hard to track"),+ LIKELY_NON_RESOLVABLE("Probably non-resolvable private", "Probably rotates - not trackable"),+ UNKNOWN("Unknown", "This phone's Bluetooth didn't report the address type");companion object {/** Sub-type of a BLE random address from its most significant byte. */@@ -89,6 +94,21 @@ enum class AddressType(val label: String, val trackable: String) {}}+ /**+ * The type of a BLE address the phone didn't report (before Android 15 it never does): public when the+ * address belongs to a maker in the IEEE register ([registered]), unless the advert shows a device that+ * always uses random addresses ([alwaysRandom]: Apple, Find My); otherwise the random sub-type.+ */+ fun guess(mac: String, registered: Boolean, alwaysRandom: Boolean): AddressType {+ if (registered && !alwaysRandom) return LIKELY_PUBLIC+ return when (ofRandom(mac)) {+ RANDOM_STATIC -> LIKELY_STATIC+ RESOLVABLE_PRIVATE -> LIKELY_RPA+ NON_RESOLVABLE -> LIKELY_NON_RESOLVABLE+ else -> UNKNOWN+ }+ }+fun ofWifi(mac: String): AddressType {val msb = mac.take(2).toIntOrNull(16) ?: return UNKNOWNreturn if (msb and 0x02 != 0) WIFI_LOCAL else WIFI_GLOBALdiff --git a/app/src/main/java/com/rfsentinel/app/service/AdvertFactory.kt b/app/src/main/java/com/rfsentinel/app/service/AdvertFactory.ktindex 1ca4487..6a4694f 100644--- a/app/src/main/java/com/rfsentinel/app/service/AdvertFactory.kt+++ b/app/src/main/java/com/rfsentinel/app/service/AdvertFactory.kt@@ -6,12 +6,16 @@ import android.bluetooth.le.ScanResultimport android.os.Buildimport com.rfsentinel.app.detect.AddressTypeimport com.rfsentinel.app.detect.Advert+import com.rfsentinel.app.detect.VendorDbimport com.rfsentinel.app.util.MacUtilimport android.net.wifi.ScanResult as WifiScanResult/** Converts Android scan results into the platform-neutral [Advert]. */object AdvertFactory {+ /** Apple's Bluetooth company ID: iPhones, AirPods, AirTags and Find My items always advertise from random addresses. */+ private const val APPLE = 0x004C+@SuppressLint("MissingPermission") // scan results are only delivered with the scan permissionfun fromBle(r: ScanResult): Advert? {val mac = r.device?.address?.let { MacUtil.normalize(it) } ?: return null@@ -20,7 +24,7 @@ object AdvertFactory {rec?.manufacturerSpecificData?.let { arr ->for (i in 0 until arr.size()) arr.valueAt(i)?.let { mfg[arr.keyAt(i)] = it }}- val addressType = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {+ val reported = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {when (r.device.addressType) {BluetoothDevice.ADDRESS_TYPE_PUBLIC -> AddressType.PUBLICBluetoothDevice.ADDRESS_TYPE_RANDOM -> AddressType.ofRandom(mac)@@ -29,6 +33,9 @@ object AdvertFactory {} else {AddressType.UNKNOWN}+ // Not reported (older Android, or the Bluetooth chip didn't say): worked out from the address.+ val addressType = if (reported != AddressType.UNKNOWN) reported+ else AddressType.guess(mac, registered = VendorDb.macVendor(mac) != null, alwaysRandom = APPLE in mfg)val tx = rec?.txPowerLevel?.takeIf { it != Int.MIN_VALUE }val phy = when (r.primaryPhy) {1 -> if (r.secondaryPhy == 2) "LE 1M / 2M (extended)" else if (r.isLegacy) "LE 1M (legacy)" else "LE 1M (extended)"diff --git a/app/src/main/java/com/rfsentinel/app/ui/MarkerArt.kt b/app/src/main/java/com/rfsentinel/app/ui/MarkerArt.ktindex e39dde5..f0f9f68 100644--- a/app/src/main/java/com/rfsentinel/app/ui/MarkerArt.kt+++ b/app/src/main/java/com/rfsentinel/app/ui/MarkerArt.kt@@ -6,12 +6,14 @@ import android.graphics.Canvasimport android.graphics.LinearGradientimport android.graphics.Paintimport android.graphics.Path+import android.graphics.RadialGradientimport android.graphics.RectFimport android.graphics.Shaderimport android.graphics.Color/**- * The position marker on the map (your arrow): an arrow, or a car seen from above, in a colour of your choice.+ * The position marker on the map (your arrow): a dot with a heading beam, an arrow (flat or 3D), or a car seen+ * from above, in a colour of your choice.* Everything is drawn here in code on a 100 x 200 unit sheet with the front at the top, so any size is sharp and* any colour works; the map turns it with your direction of travel. Pure drawing: the same function makes the* map's marker and the pictures in Settings.@@ -19,7 +21,7 @@ import android.graphics.Colorobject MarkerArt {enum class Style(val key: String, val label: String) {- ARROW("arrow", "Arrow"), CHEVRON("chevron", "Chevron"),+ DOT("dot", "Classic dot"), ARROW("arrow", "Arrow"), ARROW_3D("arrow3d", "3D arrow"), CHEVRON("chevron", "Chevron"),SEDAN("sedan", "Sedan"), HATCHBACK("hatchback", "Hatchback"), WAGON("wagon", "Wagon"), SUV("suv", "SUV"),PICKUP("pickup", "Pickup"), SPORTS("sports", "Sports car"), RACER("racer", "Racer"), CONVERTIBLE("convertible", "Convertible"),MINI("mini", "Mini"), VAN("van", "Van"), TRUCK("truck", "Truck"), TAXI("taxi", "Taxi"), MOTORCYCLE("motorcycle", "Motorcycle");@@ -61,7 +63,9 @@ object MarkerArt {val c = Canvas(bmp)c.scale(h / 200f, h / 200f)when (style) {+ Style.DOT -> dot(c, color)Style.ARROW -> arrow(c, color, ARROW)+ Style.ARROW_3D -> arrow3d(c, color)Style.CHEVRON -> arrow(c, color, CHEVRON)Style.SEDAN -> car(c, color, SEDAN)Style.HATCHBACK -> car(c, color, HATCHBACK)@@ -134,6 +138,71 @@ object MarkerArt {c.drawPath(path, line(shade(color, 0.6f), 1.5f))}+ /**+ * The classic map dot: a dot in a white ring on its shadow, with a soft beam towards where you're heading. Its+ * middle is the middle of the sheet (the point the map puts on your position and turns around).+ */+ private fun dot(c: Canvas, color: Int) {+ val cy = 100f+ val beamR = 90f+ val beam = Path().apply {+ moveTo(CX, cy); arcTo(RectF(CX - beamR, cy - beamR, CX + beamR, cy + beamR), -90f - 34f, 68f); close()+ }+ c.drawPath(beam, Paint(Paint.ANTI_ALIAS_FLAG).apply {+ shader = RadialGradient(CX, cy, beamR,+ intArrayOf(Color.argb(170, Color.red(color), Color.green(color), Color.blue(color)),+ Color.argb(80, Color.red(color), Color.green(color), Color.blue(color)), Color.argb(0, Color.red(color), Color.green(color), Color.blue(color))),+ floatArrayOf(0f, 0.5f, 1f), Shader.TileMode.CLAMP)+ })+ c.drawCircle(CX + 1f, cy + 3f, 31f, fill(0x55000000).apply { maskFilter = BlurMaskFilter(5f, BlurMaskFilter.Blur.NORMAL) })+ c.drawCircle(CX, cy, 31f, fill(0xFFFFFFFF.toInt()))+ c.drawCircle(CX, cy, 31f, line(0x26000000, 1.2f))+ c.drawCircle(CX, cy, 22f, Paint(Paint.ANTI_ALIAS_FLAG).apply {+ shader = RadialGradient(CX - 7f, cy - 7f, 30f, lighten(color, 0.22f), shade(color, 0.86f), Shader.TileMode.CLAMP)+ })+ }++ /**+ * A navigation arrow with depth: a broad arrowhead lit from the left (two facets), standing on its own+ * thickness, so it reads as a solid piece lying on the road, also when the map is tilted.+ */+ private fun arrow3d(c: Canvas, color: Int) {+ val top = floatArrayOf(50f, 18f, 90f, 168f, 50f, 138f, 10f, 168f)+ val depth = 14f+ val face = poly(top)+ // The ground shadow, below the solid.+ c.save(); c.translate(3f, depth + 6f)+ c.drawPath(face, fill(0x5C000000).apply { maskFilter = BlurMaskFilter(7f, BlurMaskFilter.Blur.NORMAL) })+ c.restore()+ // The solid: every edge swept down by the thickness, with the white rim around all of it.+ val solid = Path().apply {+ addPath(face); addPath(face, 0f, depth)+ var i = 0+ while (i < top.size) {+ val x1 = top[i]; val y1 = top[i + 1]; val x2 = top[(i + 2) % top.size]; val y2 = top[(i + 3) % top.size]+ addPath(Path().apply { moveTo(x1, y1); lineTo(x2, y2); lineTo(x2, y2 + depth); lineTo(x1, y1 + depth); close() })+ i += 2+ }+ }+ c.drawPath(solid, line(0xFFFFFFFF.toInt(), 8f))+ c.drawPath(solid, fill(0xFFFFFFFF.toInt()))+ c.drawPath(solid, Paint(Paint.ANTI_ALIAS_FLAG).apply {+ shader = LinearGradient(0f, 18f, 0f, 168f + depth, shade(color, 0.5f), shade(color, 0.34f), Shader.TileMode.CLAMP)+ })+ // The top: the left facet in the light, the right one in shade, a ridge down the middle.+ val left = Path().apply { moveTo(50f, 18f); lineTo(50f, 138f); lineTo(10f, 168f); close() }+ val right = Path().apply { moveTo(50f, 18f); lineTo(90f, 168f); lineTo(50f, 138f); close() }+ c.drawPath(left, Paint(Paint.ANTI_ALIAS_FLAG).apply {+ shader = LinearGradient(10f, 168f, 50f, 18f, lighten(color, 0.08f), lighten(color, 0.34f), Shader.TileMode.CLAMP)+ })+ c.drawPath(right, Paint(Paint.ANTI_ALIAS_FLAG).apply {+ shader = LinearGradient(90f, 168f, 50f, 18f, shade(color, 0.7f), shade(color, 0.9f), Shader.TileMode.CLAMP)+ })+ c.drawLine(50f, 20f, 50f, 136f, line(lighten(color, 0.5f), 1.6f))+ // The rim between the top and the sides.+ c.drawPath(face, line(lighten(color, 0.6f), 1.4f))+ }+// ---- cars --------------------------------------------------------------------------------------------private enum class Extra { RAILS, BED, SPOILER, STRIPES, ROOF_SIGN, OPEN_TOP, RIBS, LONG_ROOF }diff --git a/app/src/test/java/com/rfsentinel/app/detect/AddressTypeGuessTest.kt b/app/src/test/java/com/rfsentinel/app/detect/AddressTypeGuessTest.ktnew file mode 100644index 0000000..a1637cd--- /dev/null+++ b/app/src/test/java/com/rfsentinel/app/detect/AddressTypeGuessTest.kt@@ -0,0 +1,33 @@+package com.rfsentinel.app.detect++import org.junit.Assert.assertEquals+import org.junit.Assert.assertFalse+import org.junit.Test++/** The address type when the phone doesn't report it (before Android 15): worked out from the address itself. */+class AddressTypeGuessTest {++ @Test+ fun aRegisteredMakersAddressIsProbablyPublic() {+ assertEquals(AddressType.LIKELY_PUBLIC, AddressType.guess("5C:1B:2E:88:40:11", registered = true, alwaysRandom = false))+ }++ @Test+ fun appleAndFindMyAreNeverPublicEvenWhenTheAddressLooksRegistered() {+ assertEquals(AddressType.LIKELY_RPA, AddressType.guess("5C:1B:2E:88:40:11", registered = true, alwaysRandom = true))+ assertEquals(AddressType.LIKELY_STATIC, AddressType.guess("D2:5E:91:3A:07:BC", registered = true, alwaysRandom = true))+ }++ @Test+ fun otherwiseTheRandomSubTypeFromTheTopBits() {+ assertEquals(AddressType.LIKELY_STATIC, AddressType.guess("D2:5E:91:3A:07:BC", registered = false, alwaysRandom = false))+ assertEquals(AddressType.LIKELY_RPA, AddressType.guess("6E:0A:77:12:C3:95", registered = false, alwaysRandom = false))+ assertEquals(AddressType.LIKELY_NON_RESOLVABLE, AddressType.guess("1A:31:C4:0B:9E:22", registered = false, alwaysRandom = false))+ assertEquals("reserved bits", AddressType.UNKNOWN, AddressType.guess("8A:31:C4:0B:9E:22", registered = false, alwaysRandom = false))+ }++ @Test+ fun noTrackabilityTextBlamesTheOtherDevicesAndroidVersion() {+ for (t in AddressType.entries) assertFalse(t.name, "Android 15" in t.trackable)+ }+}diff --git a/app/src/test/java/com/rfsentinel/app/ui/MarkerArtTest.kt b/app/src/test/java/com/rfsentinel/app/ui/MarkerArtTest.ktindex 498e4ef..717aaaf 100644--- a/app/src/test/java/com/rfsentinel/app/ui/MarkerArtTest.kt+++ b/app/src/test/java/com/rfsentinel/app/ui/MarkerArtTest.kt@@ -44,7 +44,7 @@ class MarkerArtTest {fun theFrontIsAtTheTopOfEveryCarAndTheBackAtTheBottom() {fun headlight(p: Int) = Color.red(p) > 235 && Color.green(p) > 225 && Color.blue(p) in 150..215 && Color.alpha(p) > 200fun tail(p: Int) = Color.red(p) in 180..230 && Color.green(p) < 80 && Color.blue(p) < 80 && Color.alpha(p) > 200- for (s in MarkerArt.Style.entries.filter { it != MarkerArt.Style.ARROW && it != MarkerArt.Style.CHEVRON }) {+ for (s in MarkerArt.Style.entries.filter { it !in listOf(MarkerArt.Style.DOT, MarkerArt.Style.ARROW, MarkerArt.Style.ARROW_3D, MarkerArt.Style.CHEVRON) }) {val b = MarkerArt.render(s, blue, 300)val top = 0 until b.height / 4; val bottom = b.height * 3 / 4 until b.heightassertTrue("${s.key}: headlights at the front", count(b, top, ::headlight) > 20)@@ -56,7 +56,7 @@ class MarkerArtTest {@Testfun anArrowPointsUp() {- for (s in listOf(MarkerArt.Style.ARROW, MarkerArt.Style.CHEVRON)) {+ for (s in listOf(MarkerArt.Style.ARROW, MarkerArt.Style.ARROW_3D, MarkerArt.Style.CHEVRON)) {val b = MarkerArt.render(s, blue, 200)// The tip is at the top, in the middle; the top corners are empty and the base is wide.assertTrue(Color.alpha(b.getPixel(b.width / 2, 40)) > 200)@@ -65,6 +65,17 @@ class MarkerArtTest {}}+ @Test+ fun theClassicDotSitsOnYourPositionAndItsBeamPointsAhead() {+ val b = MarkerArt.render(MarkerArt.Style.DOT, blue, 200)+ val mid = b.getPixel(b.width / 2, b.height / 2)+ assertTrue("a solid blue dot in the middle", Color.alpha(mid) > 240 && Color.blue(mid) > Color.red(mid) + 80)+ assertTrue("a white ring around it", Color.red(b.getPixel(b.width / 2, b.height / 2 - 27)) > 240)+ val ahead = Color.alpha(b.getPixel(b.width / 2, 55))+ assertTrue("a see-through beam ahead", ahead in 10..200)+ assertEquals("nothing behind", 0, Color.alpha(b.getPixel(b.width / 2, 170)))+ }+@Testfun theColourChangesTheMarker() {val a = MarkerArt.render(MarkerArt.Style.SEDAN, MarkerArt.colorOf("red").argb, 200)@@ -83,7 +94,7 @@ class MarkerArtTest {val px = IntArray(b.width * b.height); b.getPixels(px, 0, b.width, 0, 0, b.width, b.height)assertTrue("${s.key} differs from the others", seen.add(px.contentHashCode()))}- assertEquals(15, MarkerArt.Style.entries.size)+ assertEquals(17, MarkerArt.Style.entries.size)assertEquals(16, MarkerArt.colors.size)}