updater: no phantom update when the running build is unreadable
- Commit
b9d4a5468290cd110f177685e10bd67ffc8892cb- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 09:05 UTC (5 days ago)
- Parents
4ad7ba3
The persisted-available restore in init passed the entry
through unconditionally when SystemBuild.current() returned
null (ro.build.version.incremental empty or build date
invalid): after rebooting into exactly the persisted build
2026090700, an unreadable running build made the screen
headline 'Update available: 2026090700' while running it.
That contradicted the restore's own comment ('only while it
is still newer than what is running'), SystemBuild's
contract (null means 'do not offer an update', not 'offer
everything'), and UpdateChecker, which fails closed on the
same null. Install was never at risk (worker and checker
both fail closed); the phantom lived on the detection/UI
surface.
Restore now requires current != null and isNewer; the
persisted entry is deliberately left in place when the build
is unreadable so a later readable init can still judge it.
Regression test failed pre-fix. Version comparison,
validation ordering, download resume and reboot scheduling
were audited and cleared. Verified: :updater:testDevUnitTest
157 tests pass; lint error is pre-existing on an untouched
file.Diff
updater/src/main/java/com/vayunmathur/updater/platform/UpdaterViewModel.kt
diff --git a/updater/src/main/java/com/vayunmathur/updater/platform/UpdaterViewModel.kt b/updater/src/main/java/com/vayunmathur/updater/platform/UpdaterViewModel.ktindex 402857087b..adf4bc9e79 100644--- a/updater/src/main/java/com/vayunmathur/updater/platform/UpdaterViewModel.kt+++ b/updater/src/main/java/com/vayunmathur/updater/platform/UpdaterViewModel.kt@@ -33,9 +33,14 @@ class UpdaterViewModel(application: Application) : AndroidViewModel(application) } // Restore the update an earlier check found, but only while it is still newer // than what is running: after the reboot into it, the same persisted entry is- // stale and must not be offered again.+ // stale and must not be offered again. An unreadable running build proves+ // nothing either way, so nothing is offered then — the same fail-closed+ // direction UpdateChecker and SystemBuild.current take — and the persisted+ // entry is left in place for a later init that can read the build and judge+ // it. Offering it sight-unseen would offer the very build the device may+ // already have rebooted into. val available = persisted?.takeIf {- current == null || UpdateComparison.isNewer(current, it)+ current != null && UpdateComparison.isNewer(current, it) } if (persisted != null && available == null && current != null) { store.setString(UpdaterPreferences.AVAILABLE_BUILD, "")
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 6febb007d1..c0bdf4efcb 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,25 @@ class UpdaterViewModelTest { 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+ // there is no way to know it is still newer: the device may already have+ // rebooted into exactly that build. Before the fix the restore passed+ // `current == null` straight through, so the screen offered 2026090700 as an+ // update even while running it. The entry itself must survive (a later init+ // that can read the build may still judge it newer), just not be offered.+ TestSysProps.set("ro.build.version.incremental", "")+ store.setLong(UpdaterPreferences.LAST_CHECKED, 777L)+ store.setString(UpdaterPreferences.AVAILABLE_BUILD, "2026090700")+ store.setLong(UpdaterPreferences.AVAILABLE_BUILD_DATE, 2000L)+ val vm = UpdaterViewModel(app)+ awaitState(vm) { it.lastCheckedMillis == 777L }+ assertNull(vm.state.available)+ assertEquals("2026090700", store.getStringAwait(UpdaterPreferences.AVAILABLE_BUILD))+ assertEquals(2000L, store.getLongAwait(UpdaterPreferences.AVAILABLE_BUILD_DATE))+ }+ @Test fun `check now surfaces an available update and stamps the check time`() { fakeBody("2026090700 2000 shiba stable")