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.

Settings: Include prerelease builds in update checks (off by default)

CIS-C0ecb06cedb464
diff --git a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
index 348be34..b1e9462 100644
--- a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
@@ -1011,6 +1011,8 @@ class SettingsActivity : AppCompatActivity() {
/** The ⓘ of the settings laid out in the layout file, and the units beside their number fields. */
private fun addDetails() {
info(binding.autoUpdateSwitch, "When RF Sentinel opens, it asks GitHub whether a newer release is out. Off: nothing is sent until you tap Check for updates.")
+ info(binding.prereleaseSwitch, "Update checks also offer prerelease builds: test versions published on GitHub before " +
+ "a full release, with the newest features and more bugs. Off: only full releases are offered.")
info(binding.discreetSwitch, "Hides what was detected on the lock screen and in notifications.")
info(binding.screenLabel, "Always on: the screen never turns off while RF Sentinel is open.\n\nOn while charging: stays on in the car or on a desk (recommended).\n\nNormal: turns off like any other app.")
info(binding.rotationLabel, "Normal follows the phone's auto-rotate.\n\nAuto-rotate, upside down too: also turns upside down, which phones like the Pixel never do on their own.\n\nAlways upside down: the USB-C port at the top, for an antenna or adapter plugged in.")
@@ -2756,6 +2758,7 @@ class SettingsActivity : AppCompatActivity() {
binding.rtl5gSwitch.isChecked = Prefs.rtl8821au5g(this)
binding.rtl5gSwitch.setOnCheckedChangeListener { _, on -> Prefs.setRtl8821au5g(this, on) }
binding.autoUpdateSwitch.isChecked = Prefs.autoUpdateCheck(this)
+ binding.prereleaseSwitch.isChecked = Prefs.updatePrereleases(this)
fun showRadius(km: Int) {
binding.cameraRadiusText.text = "Download radius: ${com.rfsentinel.app.util.Units.km(km)}"
binding.prefetchCamerasButton.text = "Download cameras around me"
@@ -3025,6 +3028,7 @@ class SettingsActivity : AppCompatActivity() {
// Turning the check on or off here answers the one-time question too.
if (binding.autoUpdateSwitch.isChecked != Prefs.autoUpdateCheck(this)) Prefs.setUpdateCheckAsked(this, true)
Prefs.setAutoUpdateCheck(this, binding.autoUpdateSwitch.isChecked)
+ Prefs.setUpdatePrereleases(this, binding.prereleaseSwitch.isChecked)
Prefs.setRetentionDays(this, (binding.retentionInput.text.toString().toIntOrNull() ?: 90).coerceAtLeast(0))
diff --git a/app/src/main/java/com/rfsentinel/app/util/Prefs.kt b/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
index 9c0391a..dcbe9f3 100644
--- a/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
+++ b/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
@@ -337,6 +337,9 @@ object Prefs {
/** Check GitHub for a new release when the app opens. Off by default: it contacts GitHub. */
fun autoUpdateCheck(context: Context): Boolean = bool(context, "auto_update_check", false)
fun setAutoUpdateCheck(context: Context, value: Boolean) = setBool(context, "auto_update_check", value)
+ /** Update checks also offer GitHub prereleases (test builds), off by default. */
+ fun updatePrereleases(context: Context): Boolean = bool(context, "update_prereleases", false)
+ fun setUpdatePrereleases(context: Context, value: Boolean) = setBool(context, "update_prereleases", value)
/** Whether you were asked (once) if the app may check for updates; until then it never checks on its own. */
fun updateCheckAsked(context: Context): Boolean = bool(context, "update_check_asked", false)
fun setUpdateCheckAsked(context: Context, value: Boolean) = setBool(context, "update_check_asked", value)
diff --git a/app/src/main/java/com/rfsentinel/app/util/UpdateChecker.kt b/app/src/main/java/com/rfsentinel/app/util/UpdateChecker.kt
index 391c2cc..46b77a3 100644
--- a/app/src/main/java/com/rfsentinel/app/util/UpdateChecker.kt
+++ b/app/src/main/java/com/rfsentinel/app/util/UpdateChecker.kt
@@ -10,6 +10,7 @@ import com.rfsentinel.app.BuildConfig
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
+import org.json.JSONArray
import org.json.JSONObject
import java.net.HttpURLConnection
import java.net.URL
@@ -21,6 +22,8 @@ import java.net.URL
object UpdateChecker {
private const val API = "https://api.github.com/repos/CIS-C0/RFSentinel/releases/latest"
+ /** Every release, prereleases too (newest first), for Settings › Include prerelease builds. */
+ private const val API_ALL = "https://api.github.com/repos/CIS-C0/RFSentinel/releases?per_page=10"
private const val RELEASES = "https://github.com/CIS-C0/RFSentinel/releases/latest"
/** The newest release: its version, the APK's link, size and SHA-256 (as GitHub lists them) and the notes page. */
@@ -41,9 +44,17 @@ object UpdateChecker {
* The newest release from GitHub's answer: version, this build's APK asset with its size and SHA-256, the notes
* page. The full build takes the "-release.apk" asset, the FOSS build the "-foss.apk" one.
*/
- internal fun parseLatest(text: String, foss: Boolean = BuildConfig.FLAVOR == "foss"): Latest {
+ internal fun parseLatest(text: String, foss: Boolean = BuildConfig.FLAVOR == "foss"): Latest = parse(JSONObject(text), foss)
+
+ /** The highest version in GitHub's release list, prereleases included, drafts not. */
+ internal fun parseNewest(text: String, foss: Boolean = BuildConfig.FLAVOR == "foss"): Latest {
+ val list = JSONArray(text)
+ return (0 until list.length()).map { list.getJSONObject(it) }.filter { !it.optBoolean("draft") }.map { parse(it, foss) }
+ .reduceOrNull { a, b -> if (isNewer(b.version, a.version)) b else a } ?: throw IllegalStateException("No releases on GitHub")
+ }
+
+ private fun parse(json: JSONObject, foss: Boolean): Latest {
val suffix = if (foss) "-foss.apk" else "-release.apk"
- val json = JSONObject(text)
val assets = json.optJSONArray("assets")
var apk: String? = null; var size = 0L; var sha: String? = null
if (assets != null) for (i in 0 until assets.length()) {
@@ -56,15 +67,16 @@ object UpdateChecker {
return Latest(json.getString("tag_name").trimStart('v'), apk, json.optString("html_url", RELEASES), size, sha)
}
- private fun fetch(): Latest {
- val conn = (URL(API).openConnection() as HttpURLConnection).apply {
+ private fun fetch(prereleases: Boolean): Latest {
+ val conn = (URL(if (prereleases) API_ALL else API).openConnection() as HttpURLConnection).apply {
connectTimeout = 10_000; readTimeout = 10_000
setRequestProperty("Accept", "application/vnd.github+json")
setRequestProperty("User-Agent", "${BuildConfig.APPLICATION_ID}/${BuildConfig.VERSION_NAME}")
}
try {
if (conn.responseCode != 200) throw IllegalStateException("GitHub answered ${conn.responseCode}")
- return parseLatest(conn.inputStream.bufferedReader().use { it.readText() })
+ val text = conn.inputStream.bufferedReader().use { it.readText() }
+ return if (prereleases) parseNewest(text) else parseLatest(text)
} finally {
conn.disconnect()
}
@@ -136,8 +148,9 @@ object UpdateChecker {
if (!silent) Toast.makeText(activity, "Checking for updates…", Toast.LENGTH_SHORT).show()
if (checking) return
checking = true
+ val prereleases = Prefs.updatePrereleases(activity)
activity.lifecycleScope.launch {
- val result = try { withContext(Dispatchers.IO) { runCatching { fetch() } } } finally { checking = false }
+ val result = try { withContext(Dispatchers.IO) { runCatching { fetch(prereleases) } } } finally { checking = false }
// Reached GitHub: the next automatic check is an interval away; not reached: soon.
val now = System.currentTimeMillis()
Prefs.setLastUpdateCheck(activity, if (result.isSuccess) now else now - AUTO_INTERVAL_MS + RETRY_MS)
diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml
index 486b84b..8ba3ed8 100644
--- a/app/src/main/res/layout/activity_settings.xml
+++ b/app/src/main/res/layout/activity_settings.xml
@@ -27,6 +27,12 @@
android:layout_height="wrap_content"
android:text="Check for updates on app open" />
+ <com.google.android.material.switchmaterial.SwitchMaterial
+ android:id="@+id/prereleaseSwitch"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Include prerelease builds" />
+
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/discreetSwitch"
android:layout_width="match_parent"
diff --git a/app/src/test/java/com/rfsentinel/app/util/UpdateInstallerTest.kt b/app/src/test/java/com/rfsentinel/app/util/UpdateInstallerTest.kt
index edc460f..e2cc9b1 100644
--- a/app/src/test/java/com/rfsentinel/app/util/UpdateInstallerTest.kt
+++ b/app/src/test/java/com/rfsentinel/app/util/UpdateInstallerTest.kt
@@ -96,4 +96,16 @@ class UpdateInstallerTest {
assertTrue("30 minutes after a failure", UpdateChecker.due(recorded, t + h / 2))
assertTrue("a clock set back never blocks it", UpdateChecker.due(now + h, now))
}
+
+ @Test
+ fun withPrereleasesTheHighestVersionWinsAndDraftsDont() {
+ val list = """[
+ {"tag_name":"v2.34.0","draft":true,"assets":[]},
+ {"tag_name":"v2.32.1","prerelease":false,"assets":[]},
+ {"tag_name":"v2.33.0","prerelease":true,"assets":[{"name":"RFSentinel-v2.33.0-release.apk","browser_download_url":"p","size":1}]},
+ {"tag_name":"v2.32.0","prerelease":false,"assets":[]}]"""
+ val l = UpdateChecker.parseNewest(list, foss = false)
+ assertEquals("2.33.0", l.version)
+ assertEquals("p", l.apkUrl)
+ }
}