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
Merge PR #13: share UI, settings and detection helpers
CIS-C044e4283837c5
diff --cc app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.ktindex 20135f2,3112974..2991cc1--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt@@@ -1085,26 -1077,24 +1085,25 @@@ class ScanForegroundService : Service(val prevLogged = lastLogged[a.mac] ?: 0Lif (now - prevLogged < LOG_THROTTLE_MS) returnlastLogged[a.mac] = now+ logDetection(a.mac, a.source.name, best, now, loc?.latitude, loc?.longitude,+ rssi = a.rssi, vendor = vendor, deviceName = a.name,- radio = com.rfsentinel.app.detect.DeviceIntel.radioSummary(a))++ radio = com.rfsentinel.app.detect.DeviceIntel.radioSummary(a),++ heardBy = via?.let { "via $it" } ?: com.rfsentinel.app.esp.HeardBy.own(a.mac, a.source))+ }++ private fun logDetection(+ mac: String, source: String, hit: Hit, now: Long, latitude: Double?, longitude: Double?,- rssi: Int = 0, vendor: String? = null, deviceName: String? = null, radio: String? = null++ rssi: Int = 0, vendor: String? = null, deviceName: String? = null, radio: String? = null, heardBy: String? = null+ ) {val tag = Prefs.gpsTaggingEnabled(this)+ val row = DetectionEntity(+ mac = mac, label = hit.label, source = source, rssi = rssi, timestamp = now,+ latitude = if (tag) latitude else null, longitude = if (tag) longitude else null,+ category = hit.category.name, confidence = hit.confidence, evidence = hit.evidence,- vendor = vendor, deviceName = deviceName, radio = radio++ vendor = vendor, deviceName = deviceName, radio = radio, heardBy = heardBy+ )serviceScope.launch {- AppDatabase.getInstance(this@ScanForegroundService).detectionDao().insert(- DetectionEntity(- mac = a.mac,- label = best.label,- source = a.source.name,- rssi = a.rssi,- timestamp = now,- latitude = if (tag) loc?.latitude else null,- longitude = if (tag) loc?.longitude else null,- category = best.category.name,- confidence = best.confidence,- evidence = best.evidence,- vendor = vendor,- deviceName = a.name,- radio = com.rfsentinel.app.detect.DeviceIntel.radioSummary(a),- heardBy = via?.let { "via $it" } ?: com.rfsentinel.app.esp.HeardBy.own(a.mac, a.source)- )- )+ AppDatabase.getInstance(this@ScanForegroundService).detectionDao().insert(row)}}@@@ -1528,25 -1510,13 +1518,15 @@@e.tdma -> "TETRA radio nearby"else -> "Radio transmitting nearby"} + (via?.let { ", via $it" } ?: "")- radioDetection(hit, "RADIO " + e.mhz + " MHz", e.snrDb, detail, now, "radio:" + e.freqHz, spoken, e.confidence >= threshold, via)- radioDetection(hit, "RADIO " + e.mhz + " MHz", e.snrDb, now, "radio:" + e.freqHz, spoken, e.confidence >= threshold)++ radioDetection(hit, "RADIO " + e.mhz + " MHz", e.snrDb, now, "radio:" + e.freqHz, spoken, e.confidence >= threshold, via)}/** A radio [hit] into the detection history (tagged with where you are), and alerted when [alert]. */- private fun radioDetection(hit: Hit, mac: String, rssi: Int, evidence: String, now: Long, key: String, spoken: String, alert: Boolean,- private fun radioDetection(hit: Hit, mac: String, rssi: Int, now: Long, key: String, spoken: String, alert: Boolean) {++ private fun radioDetection(hit: Hit, mac: String, rssi: Int, now: Long, key: String, spoken: String, alert: Boolean,+ via: String? = null) {val loc = lastLocation- val tag = Prefs.gpsTaggingEnabled(this)- if (via == null || Prefs.saveLinked(this)) serviceScope.launch {- AppDatabase.getInstance(this@ScanForegroundService).detectionDao().insert(- DetectionEntity(- mac = mac, label = hit.label, source = "SDR", rssi = rssi,- timestamp = now,- latitude = if (tag) loc?.latitude else null, longitude = if (tag) loc?.longitude else null,- category = hit.category.name, confidence = hit.confidence, evidence = evidence,- heardBy = via?.let { "via $it" }- )- )- }- logDetection(mac, "SDR", hit, now, loc?.latitude, loc?.longitude, rssi = rssi)++ if (via == null || Prefs.saveLinked(this))++ logDetection(mac, "SDR", hit, now, loc?.latitude, loc?.longitude, rssi = rssi, heardBy = via?.let { "via $it" })// Dismissed from the list (swiped left): logged, no alert.if (!alert || com.rfsentinel.app.data.AlertMutes.isMuted(this, key, now)) returnval off = alertsOff(hit.category)@@@ -1762,19 -1721,9 +1732,9 @@@}/** An attack heard over time rather than one device: logged, and alerted like a detection. */- private fun reportAttack(mac: String, source: String, hit: Hit, name: String?, key: String, spoken: String, now: Long) {+ private fun reportAttack(mac: String, source: String, hit: Hit, name: String?, key: String, spoken: String, now: Long, heardBy: String) {val loc = lastLocation- val tag = Prefs.gpsTaggingEnabled(this)- serviceScope.launch {- AppDatabase.getInstance(this@ScanForegroundService).detectionDao().insert(- DetectionEntity(- mac = mac, label = hit.label, source = source, rssi = 0, timestamp = now,- latitude = if (tag) loc?.latitude else null, longitude = if (tag) loc?.longitude else null,- category = Category.HACKER.name, confidence = hit.confidence, evidence = hit.evidence, deviceName = name,- heardBy = heardBy- )- )- }- logDetection(mac, source, hit, now, loc?.latitude, loc?.longitude, deviceName = name)++ logDetection(mac, source, hit, now, loc?.latitude, loc?.longitude, deviceName = name, heardBy = heardBy)if (hit.confidence >= Prefs.alertThreshold(this, hit.category)) {val off = alertsOff(hit.category)NotificationHelper.sendMapAlert(this, key, hit, com.rfsentinel.app.ui.DetectionLogActivity::class.java, banner = AlertKind.BANNER !in off)diff --cc app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.ktindex c0c0348,8e2e91b..b8344f2--- a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt+++ b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt@@@ -1395,39 -1439,13 +1442,31 @@@ class SettingsActivity : AppCompatActivminLines = 2; maxLines = 8; gravity = android.view.Gravity.TOPinputType = android.text.InputType.TYPE_CLASS_TEXT or android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINEimportantForAutofill = View.IMPORTANT_FOR_AUTOFILL_NO- addTextChangedListener(object : android.text.TextWatcher {- override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}- override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}- override fun afterTextChanged(s: android.text.Editable?) { save(s?.toString().orEmpty()) }- })+ doAfterTextChanged { save(it?.toString().orEmpty()) }})}- fun switch(t: String, on: Boolean, info: String? = null, save: (Boolean) -> Unit) = SwitchMaterial(this).apply {- text = t; isChecked = on- setOnCheckedChangeListener { _, v -> save(v) }- }.also { box.addView(if (info == null) it else infoRow(it, info)) }+ info(label("Network SDR"), "Uses an RTL-SDR on another device over WiFi, such as an ESP32 board or a computer running " ++ "rtl_tcp. Enter its address and port; the port is ${com.rfsentinel.app.sdr.RtlTcp.DEFAULT_PORT} if left out. A plugged-in " ++ "USB SDR is used first. Streaming takes about 5 MB/s of WiFi.", "Network SDR")+ box.addView(android.widget.EditText(this).apply {+ setText(Prefs.networkSdr(this@SettingsActivity)); hint = "192.168.4.1:1234"+ isSingleLine = true+ inputType = android.text.InputType.TYPE_CLASS_TEXT or android.text.InputType.TYPE_TEXT_VARIATION_URI+ importantForAutofill = View.IMPORTANT_FOR_AUTOFILL_NO+ addTextChangedListener(object : android.text.TextWatcher {+ override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}+ override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}+ override fun afterTextChanged(s: android.text.Editable?) {+ Prefs.setNetworkSdr(this@SettingsActivity, s?.toString().orEmpty().trim())+ com.rfsentinel.app.sdr.SdrRadio.networkChanged()+ }+ })+ })+// What the SDR does: any mix; with more than one ticked it takes turns.var showSdrOptions: () -> Unit = {}- info(label("Scan with the SDR"), "Tick what the RTL-SDR or HackRF does while scanning. One SDR hears one thing at a time: " ++ info(box.label("Scan with the SDR"), "Tick what the RTL-SDR or HackRF does while scanning. One SDR hears one thing at a time: " +"with more than one ticked it takes turns, and each scan hears nothing while another has its turn. " +"Tick only one to give it all the time.", "Scan with the SDR")fun scan(t: String, on: Boolean, details: String, save: (Boolean) -> Unit) = android.widget.CheckBox(this).apply {