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.

Camera download progress in a notification; README: SØPHIA alternative

CIS-C07037bddb0561
diff --git a/README.md b/README.md
index 7606e90..0724275 100644
--- a/README.md
+++ b/README.md
@@ -6,6 +6,11 @@
surveillance equipment from the Bluetooth and WiFi signals they broadcast.
</p>
+<p align="center">
+ <b>A free, open-source alternative to SØPHIA (s0phia ops / SophiaOps)</b> -
+ a regular Android app, no Termux, no account, no subscription.
+</p>
+
<p align="center">
<a href="https://github.com/CIS-C0/RFSentinel/releases/latest"><img src="https://img.shields.io/github/v/release/CIS-C0/RFSentinel?label=release&color=00BFAE" alt="Latest release" /></a>
<img src="https://img.shields.io/badge/Android-8.0%2B-3DDC84?logo=android&logoColor=white" alt="Android 8.0+" />
@@ -54,7 +59,15 @@
RF Sentinel is a non-rooted Android app that listens to Bluetooth LE
advertisements and WiFi beacons. It lists every device around you with its
vendor, type and signal strength, and flags law-enforcement and surveillance
-equipment:
+equipment.
+
+Looking for a **free SØPHIA / s0phia ops alternative**? RF Sentinel does the same
+kind of passive BLE and WiFi signal scanning (police gear, hidden cameras,
+trackers, drones) as a normal installable APK: open source under GPL-3.0, fully
+offline apart from optional map data, with Android Auto support. *RF Sentinel is
+an independent project, not affiliated with SØPHIA or DetecX.*
+
+What it flags:
| Category | Examples |
|---|---|
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 d0b9308..656692c 100644
--- a/app/src/main/java/com/rfsentinel/app/alpr/AlprStore.kt
+++ b/app/src/main/java/com/rfsentinel/app/alpr/AlprStore.kt
@@ -103,24 +103,30 @@ object AlprStore {
* 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: (done: Int, total: Int) -> Unit = { _, _ -> }
+ onProgress: (Progress) -> Unit = {}
): Int {
val tiles = CameraArea.tilesAround(lat, lon, radiusKm, MAX_SPAN_DEG / 2)
+ val names = listOf("south-west", "south-east", "north-west", "north-east")
var found = 0
var ok = 0
var lastError: Exception? = null
tiles.forEachIndexed { i, t ->
+ val report = { detail: String -> onProgress(Progress(i + 1, i, tiles.size, found, i - ok, "${names[i]} area: $detail")) }
try {
- found += download(context, t[0], t[1], t[2], t[3])
+ found += download(context, t[0], t[1], t[2], t[3], report)
ok++
} catch (e: kotlinx.coroutines.CancellationException) {
throw e
} catch (e: Exception) {
lastError = e
}
- onProgress(i + 1, tiles.size)
+ onProgress(Progress(i + 1, i + 1, tiles.size, found, i + 1 - ok,
+ if (ok == i + 1) "${names[i]} area done" else "${names[i]} area failed - the map will fetch it later"))
}
if (ok == 0) throw lastError ?: java.io.IOException("No answer")
return found
@@ -131,17 +137,22 @@ object AlprStore {
* (cameras deleted from OSM inside the box are dropped). Returns how many
* cameras the box contains.
*/
- suspend fun download(context: Context, south: Double, west: Double, north: Double, east: Double): Int =
+ suspend fun download(
+ context: Context, south: Double, west: Double, north: Double, east: Double,
+ status: (String) -> Unit = {}
+ ): Int =
withContext(Dispatchers.IO) {
require(north - south <= MAX_SPAN_DEG + 1e-9 && east - west <= MAX_SPAN_DEG + 1e-9) { "Area too large - zoom in" }
val body = "data=" + URLEncoder.encode(KnownCameras.query(south, west, north, east), "UTF-8")
// Public servers often answer 429/504 under load: one more round after a pause.
val json = try {
- fetchFirst(body)
+ fetchFirst(body, status)
} catch (e: java.io.IOException) {
+ status("every server busy - retrying in ${RETRY_PAUSE_MS / 1000} s")
kotlinx.coroutines.delay(RETRY_PAUSE_MS)
- fetchFirst(body)
+ fetchFirst(body, status)
}
+ status("reading the answer")
val found = KnownCameras.parse(json)
synchronized(this@AlprStore) {
val inBox = { c: KnownCamera -> c.lat in south..north && c.lon in west..east }
@@ -163,7 +174,7 @@ object AlprStore {
* if the earlier ones already failed); the first JSON answer wins and the
* others are abandoned. Throws an IOException when every server failed.
*/
- private suspend fun fetchFirst(body: String): String {
+ private suspend fun fetchFirst(body: String, status: (String) -> Unit): String {
val requests = kotlinx.coroutines.CoroutineScope(Dispatchers.IO + kotlinx.coroutines.SupervisorJob())
val result = kotlinx.coroutines.CompletableDeferred<String>()
val failures = kotlinx.coroutines.flow.MutableStateFlow(0)
@@ -173,12 +184,19 @@ object AlprStore {
requests.launch {
if (i > 0) kotlinx.coroutines.withTimeoutOrNull(STAGGER_MS * i) { failures.first { it >= i } }
if (result.isCompleted) return@launch
+ val host = URL(endpoint).host
+ status("asking $host")
try {
- result.complete(fetch(endpoint, body) { open += it })
+ val text = fetch(endpoint, body, { open += it }) { kb -> if (!result.isCompleted) status("receiving from $host: $kb KB") }
+ result.complete(text)
} catch (e: Exception) {
- errors += "${URL(endpoint).host}: ${e.message}"
- if (failures.updateAndGet { it + 1 } == ENDPOINTS.size) {
+ val why = describe(e)
+ errors += "$host: $why"
+ val failed = failures.updateAndGet { it + 1 }
+ if (failed == ENDPOINTS.size) {
result.completeExceptionally(java.io.IOException("OpenStreetMap servers busy - try again later"))
+ } else if (!result.isCompleted) {
+ status("$host $why - trying another server")
}
}
}
@@ -192,8 +210,18 @@ object AlprStore {
}
}
- /** One Overpass request; throws unless the answer is a JSON result. */
- private fun fetch(endpoint: String, body: String, onOpen: (HttpURLConnection) -> Unit): String {
+ /** A short, human reason for a failed request. */
+ private fun describe(e: Exception): String = when {
+ e is java.net.SocketTimeoutException -> "didn't answer in time"
+ e is java.net.UnknownHostException -> "unreachable (no internet?)"
+ e.message == "HTTP 429" -> "is rate-limiting (HTTP 429)"
+ e.message == "HTTP 504" || e.message == "HTTP 503" -> "is overloaded (${e.message})"
+ e.message == "server error" -> "returned an error page"
+ else -> "failed (${e.message ?: e.javaClass.simpleName})"
+ }
+
+ /** One Overpass request; throws unless the answer is a JSON result. Reports KB received. */
+ private fun fetch(endpoint: String, body: String, onOpen: (HttpURLConnection) -> Unit, onKb: (Int) -> Unit = {}): String {
val conn = (URL(endpoint).openConnection() as HttpURLConnection).apply {
requestMethod = "POST"
doOutput = true
@@ -206,7 +234,19 @@ object AlprStore {
try {
conn.outputStream.use { it.write(body.toByteArray()) }
if (conn.responseCode != 200) error("HTTP ${conn.responseCode}")
- val text = conn.inputStream.bufferedReader().use { it.readText() }
+ val out = java.io.ByteArrayOutputStream()
+ conn.inputStream.use { input ->
+ val buf = ByteArray(16 * 1024)
+ var lastKb = 0
+ while (true) {
+ val n = input.read(buf)
+ if (n < 0) break
+ out.write(buf, 0, n)
+ val kb = out.size() / 1024
+ if (kb - lastKb >= 16) { lastKb = kb; onKb(kb) }
+ }
+ }
+ val text = out.toString("UTF-8")
// An overloaded server can answer 200 with an HTML error page.
if (!text.trimStart().startsWith("{")) error("server error")
return text
diff --git a/app/src/main/java/com/rfsentinel/app/alpr/CameraPrefetch.kt b/app/src/main/java/com/rfsentinel/app/alpr/CameraPrefetch.kt
index 9adffee..d778986 100644
--- a/app/src/main/java/com/rfsentinel/app/alpr/CameraPrefetch.kt
+++ b/app/src/main/java/com/rfsentinel/app/alpr/CameraPrefetch.kt
@@ -32,8 +32,8 @@ object CameraPrefetch {
sealed interface State {
data object Idle : State
data object Locating : State
- data class Downloading(val done: Int, val total: Int) : State
- data class Done(val cameras: Int) : State
+ data class Downloading(val done: Int, val total: Int, val found: Int = 0, val detail: String = "") : State
+ data class Done(val cameras: Int, val failedAreas: Int = 0) : State
data class Failed(val reason: String) : State
}
@@ -56,21 +56,65 @@ object CameraPrefetch {
return { listeners -= listener }
}
- private fun set(s: State) = main.post { state = s; listeners.toList().forEach { it(s) } }
+ private var appContext: Context? = null
+ private var lastNotified = 0L
+ private val trailingNotify = Runnable { lastNotified = 0L; notify(state) }
+
+ val isRunning: Boolean get() = job?.isActive == true
+
+ private fun set(s: State) = main.post {
+ state = s
+ listeners.toList().forEach { it(s) }
+ notify(s)
+ }
+
+ /** Mirrors the state in a notification, so you can leave the app while it downloads. */
+ private fun notify(s: State) {
+ val ctx = appContext ?: return
+ val now = System.currentTimeMillis()
+ val final = s is State.Done || s is State.Failed
+ main.removeCallbacks(trailingNotify)
+ if (!final && now - lastNotified < 400) {
+ // Android drops too-frequent updates: show the latest one a moment later instead.
+ main.postDelayed(trailingNotify, 400)
+ return
+ }
+ lastNotified = now
+ val h = com.rfsentinel.app.util.NotificationHelper
+ when (s) {
+ State.Idle -> Unit
+ State.Locating -> h.showCameraDownload(ctx, "Downloading known cameras", "Finding your position...", 0, 0, true)
+ is State.Downloading -> h.showCameraDownload(
+ ctx, "Downloading known cameras \u00b7 ${s.done}/${s.total} areas",
+ "${s.detail.replaceFirstChar { it.uppercase() }}\n${s.found} cameras so far \u00b7 you can keep using your phone",
+ s.done, s.total, true
+ )
+ is State.Done -> h.showCameraDownload(
+ ctx, "Known cameras ready",
+ "${s.cameras} plate, speed and red-light cameras saved within ~100 km - they work offline." +
+ (if (s.failedAreas > 0) " ${s.failedAreas} area(s) failed; the map will fetch them when you look there." else ""),
+ 0, 0, false
+ )
+ is State.Failed -> h.showCameraDownload(ctx, "Couldn't download known cameras", s.reason, 0, 0, false)
+ }
+ }
fun start(context: Context) {
if (job?.isActive == true) return
val app = context.applicationContext
+ appContext = app
job = scope.launch {
set(State.Locating)
val here = currentLocation(app)
if (here == null) { set(State.Failed("No location yet - try again outdoors, or open the map later")); return@launch }
- set(State.Downloading(0, 4))
+ set(State.Downloading(0, 4, detail = "starting"))
try {
- val n = AlprStore.downloadAround(app, here.latitude, here.longitude) { done, total ->
- set(State.Downloading(done, total))
+ var failed = 0
+ val n = AlprStore.downloadAround(app, here.latitude, here.longitude) { p ->
+ failed = p.failed
+ set(State.Downloading(p.done, p.total, p.found, p.detail))
}
- set(State.Done(n))
+ set(State.Done(n, failed))
// A running scan starts watching for the new cameras.
if (ScanForegroundService.isRunning) runCatching {
app.startService(Intent(app, ScanForegroundService::class.java).setAction(ScanForegroundService.ACTION_REFRESH_LOCATION))
diff --git a/app/src/main/java/com/rfsentinel/app/ui/CameraPrefetchText.kt b/app/src/main/java/com/rfsentinel/app/ui/CameraPrefetchText.kt
index da22868..e4e05a7 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/CameraPrefetchText.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/CameraPrefetchText.kt
@@ -6,7 +6,10 @@ import com.rfsentinel.app.alpr.CameraPrefetch
fun cameraPrefetchText(s: CameraPrefetch.State, located: Boolean): String = when (s) {
CameraPrefetch.State.Idle -> if (located) "" else "Grant location access first (above)."
CameraPrefetch.State.Locating -> "Finding your position..."
- is CameraPrefetch.State.Downloading -> "Downloading cameras around you... ${s.done}/${s.total}"
- is CameraPrefetch.State.Done -> "✓ ${s.cameras} known cameras saved within ~100 km of you."
+ is CameraPrefetch.State.Downloading ->
+ "Downloading... ${s.done}/${s.total} areas, ${s.found} cameras so far\n${s.detail}\n" +
+ "No need to wait - it keeps going in the background (see your notifications)."
+ is CameraPrefetch.State.Done -> "✓ ${s.cameras} known cameras saved within ~100 km of you." +
+ (if (s.failedAreas > 0) " ${s.failedAreas} area(s) failed - the map fetches them when you look there." else "")
is CameraPrefetch.State.Failed -> "Couldn't download: ${s.reason}"
}
diff --git a/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.kt b/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.kt
index 8d0e82d..033852a 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.kt
@@ -43,6 +43,7 @@ class SetupActivity : AppCompatActivity() {
private lateinit var binding: ActivitySetupBinding
private var step = 0
private var startAfter = true
+ private var prefetchOnFinish = true
private var stopObservingPrefetch: (() -> Unit)? = null
private val permissionLauncher = registerForActivityResult(
@@ -215,8 +216,11 @@ class SetupActivity : AppCompatActivity() {
label("Known cameras near you")
para("Download the plate, speed and red-light cameras mapped in OpenStreetMap within about 100 km of you, " +
"so they're on the map and warn you offline right away. Only that area is sent to the OpenStreetMap server.", small = true)
- val btn = button("Download cameras around me") { com.rfsentinel.app.alpr.CameraPrefetch.start(this) }
+ para("No need to wait for it: tap Finish whenever you like - it keeps downloading in the background, " +
+ "with its progress in your notifications.", small = true)
+ val btn = button("Download cameras around me now") { com.rfsentinel.app.alpr.CameraPrefetch.start(this) }
val status = para("", small = true)
+ check("Download them when I tap Finish (if not started yet)", prefetchOnFinish) { prefetchOnFinish = it }
stopObservingPrefetch = com.rfsentinel.app.alpr.CameraPrefetch.observe { s ->
val located = com.rfsentinel.app.alpr.CameraPrefetch.canRun(this)
btn.isEnabled = located && s !is com.rfsentinel.app.alpr.CameraPrefetch.State.Locating &&
@@ -227,6 +231,12 @@ class SetupActivity : AppCompatActivity() {
private fun finishSetup() {
Prefs.setOnboardingDone(this)
+ val prefetch = com.rfsentinel.app.alpr.CameraPrefetch
+ if (step == STEPS - 1 && prefetchOnFinish && prefetch.canRun(this) && !prefetch.isRunning &&
+ prefetch.state !is com.rfsentinel.app.alpr.CameraPrefetch.State.Done
+ ) {
+ prefetch.start(this) // carries on in the background; progress in the notification
+ }
if (step == STEPS - 1 && startAfter && Permissions.missingRequired(this).isEmpty() && !ScanForegroundService.isRunning) {
runCatching { ScanForegroundService.start(this) }
.onFailure { Toast.makeText(this, "Couldn't start scanning - tap Start on the main screen", Toast.LENGTH_LONG).show() }
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 e725989..99d778b 100644
--- a/app/src/main/java/com/rfsentinel/app/util/NotificationHelper.kt
+++ b/app/src/main/java/com/rfsentinel/app/util/NotificationHelper.kt
@@ -40,8 +40,42 @@ object NotificationHelper {
enableVibration(false)
}
+ val downloadChannel = NotificationChannel(
+ CHANNEL_DOWNLOADS, "Camera downloads", NotificationManager.IMPORTANCE_LOW
+ ).apply { description = "Progress while known cameras are downloaded from OpenStreetMap" }
+
nm.createNotificationChannel(serviceChannel)
nm.createNotificationChannel(alertChannel)
+ nm.createNotificationChannel(downloadChannel)
+ }
+
+ const val CHANNEL_DOWNLOADS = "rf_sentinel_downloads"
+ private const val DOWNLOAD_NOTIFICATION_ID = 2
+
+ /**
+ * Progress of a camera download: a bar while [ongoing] (silent, can't be
+ * swiped away), then the result, which can. Tapping opens the map.
+ */
+ fun showCameraDownload(context: Context, title: String, text: String, done: Int, total: Int, ongoing: Boolean) {
+ val nm = context.getSystemService(NotificationManager::class.java) ?: return
+ val open = PendingIntent.getActivity(
+ context, DOWNLOAD_NOTIFICATION_ID,
+ Intent(context, com.rfsentinel.app.ui.MapActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
+ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
+ )
+ val b = NotificationCompat.Builder(context, CHANNEL_DOWNLOADS)
+ .setSmallIcon(if (ongoing) android.R.drawable.stat_sys_download else android.R.drawable.stat_sys_download_done)
+ .setContentTitle(title)
+ .setContentText(text)
+ .setStyle(NotificationCompat.BigTextStyle().bigText(text))
+ .setContentIntent(open)
+ .setOnlyAlertOnce(true)
+ .setSilent(true)
+ .setOngoing(ongoing)
+ .setAutoCancel(!ongoing)
+ .setCategory(NotificationCompat.CATEGORY_PROGRESS)
+ if (ongoing) b.setProgress(total, done, total == 0)
+ runCatching { nm.notify(DOWNLOAD_NOTIFICATION_ID, b.build()) } // no-op without the notification permission
}
/**