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
Fix Android Auto map crash and silent detection alerts (v2.10.1)
CIS-C0515c71937ab6
diff --git a/README.md b/README.mdindex 2063036..788ad21 100644--- a/README.md+++ b/README.md@@ -201,6 +201,11 @@ Sideloaded apps only appear in Android Auto after one-time setup:3. Open **⋮ → Developer settings** and enable **Unknown sources**.4. Reconnect to the car.+Still missing? Android Auto only refreshes its app list when an app is installed+or updated. Enable *Unknown sources* first, then install (or reinstall) the APK,+open RF Sentinel once on the phone, and reconnect. Also check **Android Auto+settings → Customize launcher** in case it's listed under hidden apps.+## ThemesPick a theme in the setup wizard or under **Settings → Appearance**.diff --git a/app/build.gradle.kts b/app/build.gradle.ktsindex 31e2883..f8b6035 100644--- a/app/build.gradle.kts+++ b/app/build.gradle.kts@@ -6,8 +6,8 @@ plugins {}// Bump both for every release. versionName ends up in the APK file name.-val appVersionCode = 22-val appVersionName = "2.10.0"+val appVersionCode = 23+val appVersionName = "2.10.1"// Release signing credentials live in keystore.properties (git-ignored).// Without that file, release builds are produced unsigned.diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xmlindex 2a44723..cd11498 100644--- a/app/src/main/AndroidManifest.xml+++ b/app/src/main/AndroidManifest.xml@@ -14,6 +14,8 @@<uses-permission android:name="android.permission.BLUETOOTH_SCAN" /><!-- Only to recognise your car's Bluetooth connection for auto-start (asked when you turn it on). --><uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />+ <!-- Android Auto: the plate camera & drone map screen (PlaceListMapTemplate). -->+ <uses-permission android:name="androidx.car.app.MAP_TEMPLATES" /><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /><uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />diff --git a/app/src/main/java/com/rfsentinel/app/car/NearbyMapScreen.kt b/app/src/main/java/com/rfsentinel/app/car/NearbyMapScreen.ktindex 048353a..119067e 100644--- a/app/src/main/java/com/rfsentinel/app/car/NearbyMapScreen.kt+++ b/app/src/main/java/com/rfsentinel/app/car/NearbyMapScreen.kt@@ -49,12 +49,14 @@ class NearbyMapScreen(carContext: CarContext) : LiveScreen(carContext, periodMs}items.forEach { it -> list.addItem(row(it)) }- return PlaceListMapTemplate.Builder()+ val template = PlaceListMapTemplate.Builder().setTitle("Plate cameras & drones").setHeaderAction(Action.BACK).setCurrentLocationEnabled(me != null).setItemList(list.build())- .build()+ // Centre on the driver, not on 0°,0°, when there is nothing to show.+ if (me != null) template.setAnchor(Place.Builder(CarLocation.create(me.latitude, me.longitude)).build())+ return template.build()}private fun row(it: Item): Row {diff --git a/app/src/main/java/com/rfsentinel/app/util/AlertPlayer.kt b/app/src/main/java/com/rfsentinel/app/util/AlertPlayer.ktindex 934e3d0..a8d6698 100644--- a/app/src/main/java/com/rfsentinel/app/util/AlertPlayer.kt+++ b/app/src/main/java/com/rfsentinel/app/util/AlertPlayer.kt@@ -6,7 +6,6 @@ import android.media.AudioFocusRequestimport android.media.AudioManagerimport android.os.Handlerimport android.os.Looper-import android.media.RingtoneManagerimport android.os.Buildimport android.os.VibrationEffectimport android.os.Vibrator@@ -17,19 +16,23 @@ import com.rfsentinel.app.detect.Tierimport java.util.Locale/**- * Plays match alerts directly (default notification sound, a vibration pattern+ * Plays match alerts directly (synthesized beeps, a vibration pattern* that encodes the confidence tier, optional spoken announcement) instead of* relying on the notification, so alerts still work when notifications are- * denied or muted. Honors the ringer mode and Do Not Disturb like any- * notification sound.+ * denied or muted. On the phone, silent and vibrate ringer modes mute the+ * beeps; in the car they always play.** Vibration: one pulse = weak, two = probable, three = strong, long-short-long* = something is following you.*/object AlertPlayer {- private val phoneAttributes = AudioAttributes.Builder()- .setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT)+ /**+ * Phone beeps use the navigation-guidance usage too: it follows the media+ * volume (like Locate), which is usually up while driving, and dips music.+ */+ private val phoneToneAttributes = AudioAttributes.Builder()+ .setUsage(AudioAttributes.USAGE_ASSISTANCE_NAVIGATION_GUIDANCE).setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build()@@ -61,17 +64,14 @@ object AlertPlayer {val muted = Prefs.alertsMuted(context)val willSpeak = !muted && spoken != null && (Prefs.voiceEnabled(context) || (inCar && Prefs.carVoice(context)))if (!muted && (Prefs.soundEnabled(context) || willSpeak)) {- if (inCar) duckOthers(context, if (willSpeak) 6_000L else 2_500L)+ duckOthers(context, if (willSpeak) 6_000L else 2_500L)}- if (!muted && Prefs.soundEnabled(context)) {- try {- val uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)- RingtoneManager.getRingtone(context, uri)- ?.apply { audioAttributes = if (inCar) carToneAttributes else phoneAttributes }- ?.play()- } catch (e: Exception) {- // No default sound configured / audio unavailable - vibration still runs.- }+ var beepMs = 0+ if (!muted && Prefs.soundEnabled(context) && (inCar || ringerAllowsSound(context))) {+ // Our own beeps (1 weak, 2 probable, 3 strong, long-short-long following) at+ // media volume, like Locate: the notification chime was too soft and too quiet.+ val beeps = when (tier) { Tier.STRONG -> 3; Tier.MEDIUM -> 2; else -> 1 }+ beepMs = Beeper.play(if (inCar) carToneAttributes else phoneToneAttributes, Beeper.pattern(beeps, following))}if (Prefs.vibrateEnabled(context)) {val pattern = when {@@ -82,9 +82,20 @@ object AlertPlayer {}vibrate(context, pattern)}- if (willSpeak) speak(context.applicationContext, spoken!!, if (inCar) carSpeechAttributes else phoneSpeechAttributes)+ if (willSpeak) {+ val app = context.applicationContext+ val attrs = if (inCar) carSpeechAttributes else phoneSpeechAttributes+ // Speak after the beeps, not over them.+ if (beepMs > 0) main.postDelayed({ speak(app, spoken!!, attrs) }, beepMs + 150L)+ else speak(app, spoken!!, attrs)+ }}+ /** Silent and vibrate ringer modes mute the beeps on the phone (vibration still runs). */+ private fun ringerAllowsSound(context: Context): Boolean =+ context.getSystemService(AudioManager::class.java)?.ringerMode != AudioManager.RINGER_MODE_SILENT &&+ context.getSystemService(AudioManager::class.java)?.ringerMode != AudioManager.RINGER_MODE_VIBRATE+/** Short "may duck" focus so music dips under the alert, then comes back. */@Synchronizedprivate fun duckOthers(context: Context, forMs: Long) {diff --git a/app/src/main/java/com/rfsentinel/app/util/Beeper.kt b/app/src/main/java/com/rfsentinel/app/util/Beeper.ktnew file mode 100644index 0000000..8c201c4--- /dev/null+++ b/app/src/main/java/com/rfsentinel/app/util/Beeper.kt@@ -0,0 +1,73 @@+package com.rfsentinel.app.util++import android.media.AudioAttributes+import android.media.AudioFormat+import android.media.AudioTrack+import android.os.Handler+import android.os.Looper+import kotlin.math.PI+import kotlin.math.min+import kotlin.math.sin++/**+ * Synthesized alert beeps, played with the given audio attributes so the same+ * pattern works on the phone speaker and through the car. No sound file, no+ * dependence on the user's notification sound or notification volume.+ */+object Beeper {++ private const val RATE = 22_050+ private const val FREQ_HZ = 1_760.0+ private const val FADE_MS = 6++ /** (beep ms, pause ms) pairs. */+ fun pattern(beeps: Int, following: Boolean): List<Pair<Int, Int>> = when {+ following -> listOf(450 to 120, 130 to 120, 450 to 0)+ else -> List(beeps.coerceIn(1, 3)) { i -> 140 to if (i == beeps - 1) 0 else 110 }+ }++ fun durationMs(pattern: List<Pair<Int, Int>>) = pattern.sumOf { it.first + it.second }++ /** 16-bit mono PCM for a pattern (pure; unit-tested). */+ fun pcm(pattern: List<Pair<Int, Int>>): ShortArray {+ val out = ShortArray(durationMs(pattern) * RATE / 1000)+ var pos = 0+ val fade = FADE_MS * RATE / 1000+ for ((on, off) in pattern) {+ val n = on * RATE / 1000+ for (i in 0 until n) {+ // Short fade in/out so the beep doesn't click.+ val env = min(1.0, min(i, n - 1 - i).toDouble() / fade)+ out[pos + i] = (sin(2 * PI * FREQ_HZ * i / RATE) * env * 0.8 * Short.MAX_VALUE).toInt().toShort()+ }+ pos += n + off * RATE / 1000+ }+ return out+ }++ /** Plays the pattern; returns how long it lasts (ms), or 0 if audio failed. */+ fun play(attributes: AudioAttributes, pattern: List<Pair<Int, Int>>): Int {+ val data = pcm(pattern)+ return try {+ val track = AudioTrack.Builder()+ .setAudioAttributes(attributes)+ .setAudioFormat(+ AudioFormat.Builder()+ .setEncoding(AudioFormat.ENCODING_PCM_16BIT)+ .setSampleRate(RATE)+ .setChannelMask(AudioFormat.CHANNEL_OUT_MONO)+ .build()+ )+ .setTransferMode(AudioTrack.MODE_STATIC)+ .setBufferSizeInBytes(data.size * 2)+ .build()+ track.write(data, 0, data.size)+ track.play()+ val ms = durationMs(pattern)+ Handler(Looper.getMainLooper()).postDelayed({ runCatching { track.release() } }, ms + 300L)+ ms+ } catch (e: Exception) {+ 0+ }+ }+}diff --git a/app/src/test/java/com/rfsentinel/app/util/BeeperTest.kt b/app/src/test/java/com/rfsentinel/app/util/BeeperTest.ktnew file mode 100644index 0000000..7197f04--- /dev/null+++ b/app/src/test/java/com/rfsentinel/app/util/BeeperTest.kt@@ -0,0 +1,28 @@+package com.rfsentinel.app.util++import org.junit.Assert.assertEquals+import org.junit.Assert.assertTrue+import org.junit.Test++class BeeperTest {++ @Test+ fun patternMatchesTierAndFollowing() {+ assertEquals(1, Beeper.pattern(1, following = false).size)+ assertEquals(3, Beeper.pattern(3, following = false).size)+ assertEquals(0, Beeper.pattern(3, following = false).last().second)+ val f = Beeper.pattern(1, following = true)+ assertTrue(f.first().first > f[1].first) // long-short-long+ }++ @Test+ fun pcmIsAudibleWithSilentGaps() {+ val p = Beeper.pattern(2, following = false)+ val pcm = Beeper.pcm(p)+ assertEquals(Beeper.durationMs(p) * 22_050 / 1000, pcm.size)+ assertTrue(pcm.maxOf { it.toInt() } > 20_000)+ // Middle of the gap between the two beeps is silent.+ val gapMid = (140 + 55) * 22_050 / 1000+ assertEquals(0, pcm[gapMid].toInt())+ }+}