updater: the running build itself is never offered as its own update
- Commit
ff2217b8870f5536706ca7510f385e29330eb2bc- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 14:34 UTC (4 days ago)
- Parents
913d39f
isNewer compared build dates only, ignoring build identity:
re-publishing the running build with a later build date
offered it as an update — contradicting
UpdateComparison's own doc ('re-publishing the same build
is not offered'), UpdateMetadata's definition of build as
the target identity, and OtaDownloadPlan, which already
treats target == running build as a meaningless self-to-self
update. The same flaw made init restore a persisted phantom
naming the running build.
isNewer now also requires candidate.build != current.build;
date ordering among distinct builds is unchanged. Three
regression tests (domain, checker, persisted restore) failed
pre-fix. Verified: :updater:testDevUnitTest 160 tests pass;
the 1 lint error is pre-existing on the untouched Route.kt.Diff
updater/src/main/java/com/vayunmathur/updater/domain/UpdateComparison.kt
diff --git a/updater/src/main/java/com/vayunmathur/updater/domain/UpdateComparison.kt b/updater/src/main/java/com/vayunmathur/updater/domain/UpdateComparison.ktindex 4bbd768efb..0b93a807df 100644--- a/updater/src/main/java/com/vayunmathur/updater/domain/UpdateComparison.kt+++ b/updater/src/main/java/com/vayunmathur/updater/domain/UpdateComparison.kt@@ -9,11 +9,19 @@ package com.vayunmathur.updater.domain * uses to reason about update ordering, so it is the honest comparison. * * Strictly greater-than, so re-publishing the same build is not offered as an update.+ *+ * The running build itself is not an update either, whatever the candidate date says: a+ * metadata line that names the build already installed (republished or rebuilt under the+ * same build id, with a later timestamp) would otherwise be offered as an update to+ * itself — shown on screen as an available build identical to the current one, then+ * downloaded in full and rebooted into with nothing changed. Build identity is checked+ * first, so among distinct builds the ordering stays the date comparison above. */ object UpdateComparison { fun isNewer(current: CurrentBuild, candidate: UpdateMetadata): Boolean =- candidate.buildDateUtcSeconds > current.buildDateUtcSeconds+ candidate.build != current.build &&+ candidate.buildDateUtcSeconds > current.buildDateUtcSeconds /** * The already-installed build, read from system properties.
updater/src/test/java/com/vayunmathur/updater/domain/UpdateMetadataTest.kt
diff --git a/updater/src/test/java/com/vayunmathur/updater/domain/UpdateMetadataTest.kt b/updater/src/test/java/com/vayunmathur/updater/domain/UpdateMetadataTest.ktindex 4238ac120d..e15378d41a 100644--- a/updater/src/test/java/com/vayunmathur/updater/domain/UpdateMetadataTest.kt+++ b/updater/src/test/java/com/vayunmathur/updater/domain/UpdateMetadataTest.kt@@ -101,6 +101,20 @@ class UpdateComparisonTest { ) } + /**+ * The running build itself is never an update to itself. A server line that names the+ * build already installed with a later timestamp (a republished/rebuilt line for the+ * running release) must not be offered: the screen would read "Current build 2026090500"+ * beside "Update available: 2026090500", and the install would download the full+ * self-package and reboot into the same build.+ */+ @Test+ fun `the running build itself is not an update even with a later date`() {+ assertFalse(+ UpdateComparison.isNewer(current, UpdateMetadata("2026090500", 1_788_644_317L)),+ )+ }+ /** * The comparison is on DATE, not on the build string. A republish that bumps the id without * moving the date is not an update, and a build id that sorts oddly must not change the
updater/src/test/java/com/vayunmathur/updater/platform/SystemBuildCheckerTest.kt
diff --git a/updater/src/test/java/com/vayunmathur/updater/platform/SystemBuildCheckerTest.kt b/updater/src/test/java/com/vayunmathur/updater/platform/SystemBuildCheckerTest.ktindex 917ebd6d16..2bea2c2d57 100644--- a/updater/src/test/java/com/vayunmathur/updater/platform/SystemBuildCheckerTest.kt+++ b/updater/src/test/java/com/vayunmathur/updater/platform/SystemBuildCheckerTest.kt@@ -67,6 +67,16 @@ class SystemBuildCheckerTest { assertTrue(urls.single().endsWith("/shiba-stable"), urls.toString()) } + @Test+ fun `check reports the running build itself as up to date even with a later date`() {+ // Running 2026090700; the server line names that same build with a newer timestamp.+ // Offering it would show "Update available: 2026090700" on a device already running+ // 2026090700 and download the full self-package.+ TestSysProps.setRunningBuild(build = "2026090700", dateUtcSeconds = 1000L)+ fakeCheck("2026090700 2000 shiba stable")+ assertEquals(UpdateChecker.Result.UpToDate, UpdateChecker.check())+ }+ @Test fun `check reports an equal or older build as up to date`() { TestSysProps.setRunningBuild(dateUtcSeconds = 2000L)
updater/src/test/java/com/vayunmathur/updater/platform/UpdaterViewModelTest.kt
diff --git a/updater/src/test/java/com/vayunmathur/updater/platform/UpdaterViewModelTest.kt b/updater/src/test/java/com/vayunmathur/updater/platform/UpdaterViewModelTest.ktindex c0bdf4efcb..37fb8f5c15 100644--- a/updater/src/test/java/com/vayunmathur/updater/platform/UpdaterViewModelTest.kt+++ b/updater/src/test/java/com/vayunmathur/updater/platform/UpdaterViewModelTest.kt@@ -105,6 +105,23 @@ class UpdaterViewModelTest { assertTrue(store.getStringAwait(UpdaterPreferences.AVAILABLE_BUILD).isNullOrEmpty()) } + @Test+ fun `init does not restore a persisted update that names the running build itself`() = runBlocking {+ // A persisted entry naming the build already running (2026090500) with a later+ // stored date must not be restored as an available update to itself, and the+ // stale entry is dropped like any other no-longer-newer one.+ store.setString(UpdaterPreferences.AVAILABLE_BUILD, "2026090500")+ store.setLong(UpdaterPreferences.AVAILABLE_BUILD_DATE, 2000L)+ val vm = UpdaterViewModel(app)+ awaitState(vm) { it.currentBuild == "2026090500" }+ assertNull(vm.state.available)+ repeat(100) {+ if (store.getStringAwait(UpdaterPreferences.AVAILABLE_BUILD).isNullOrEmpty()) return@runBlocking+ Thread.sleep(20)+ }+ assertTrue(store.getStringAwait(UpdaterPreferences.AVAILABLE_BUILD).isNullOrEmpty())+ }+ @Test fun `init does not restore a persisted update when the running build cannot be read`() = runBlocking { // The persisted entry names 2026090700, but with the running build unreadable