Skip to content

A rootless Android app that boots Alpine Linux: run containers (Podman/Docker/LXC) and GUI desktop apps.

fix(update): allow a sooner retry after a transient update-check failure

ExTvf8449f4a00f6
diff --git a/app/src/main/java/com/excp/podroid/data/repository/UpdateRepository.kt b/app/src/main/java/com/excp/podroid/data/repository/UpdateRepository.kt
index 43ad9d3..8827faf 100644
--- a/app/src/main/java/com/excp/podroid/data/repository/UpdateRepository.kt
+++ b/app/src/main/java/com/excp/podroid/data/repository/UpdateRepository.kt
@@ -34,6 +34,16 @@ internal fun shouldCheck(now: Long, lastCheck: Long, validityMs: Long): Boolean
return elapsed < 0L || elapsed >= validityMs
}
+/**
+ * Timestamp to persist after a failed update check so [shouldCheck] re-opens the
+ * gate at the right time. A definitive outcome (GitHub was actually reached)
+ * backs off the full [validityMs]. A transient failure (offline / DNS / timeout)
+ * is back-dated so the existing validity gate re-opens after only [retryFloorMs]
+ * instead of a full day — one offline launch must not suppress the check for 24h.
+ */
+internal fun backoffStamp(now: Long, transient: Boolean, validityMs: Long, retryFloorMs: Long): Long =
+ if (transient) now - validityMs + retryFloorMs else now
+
/**
* Returns true if `latest` is a higher version than `current`. Compares the
* numeric core (`1.2.3`) first; if those are equal, treats a prerelease suffix
@@ -114,6 +124,10 @@ class UpdateRepository @Inject constructor(
private val dismissedKey = stringPreferencesKey("dismissed_update_version")
private val lastCheckKey = longPreferencesKey("update_check_timestamp")
private val cacheValidityMs = 24 * 60 * 60 * 1000L
+ // A transient (IOException) failure backs off only this long instead of the
+ // full cacheValidityMs, so a single offline launch doesn't suppress the next
+ // in-app update check for a full day.
+ private val retryFloorMs = 20 * 60 * 1000L
suspend fun checkForUpdate(currentVersion: String): UpdateInfo? = withContext(Dispatchers.IO) {
// Wall-clock time so the 24h gate survives device reboots and deep sleep.
@@ -166,10 +180,14 @@ class UpdateRepository @Inject constructor(
throw c
} catch (e: Exception) {
// Network/DataStore/JSON error: log it (a changed GitHub response or
- // JSON shape was previously failing invisibly) and still record the
- // timestamp to back off on the next launch.
+ // JSON shape was previously failing invisibly) and record a timestamp
+ // to back off on the next launch. A transient network failure
+ // (offline / DNS / timeout — all IOException) only earns the short
+ // retry floor; a non-IO error means GitHub was reached but returned
+ // something unusable, so it keeps the full 24h backoff.
android.util.Log.w("UpdateRepository", "update check failed", e)
- runCatching { context.dataStore.edit { it[lastCheckKey] = now } }
+ val stamp = backoffStamp(now, transient = e is java.io.IOException, cacheValidityMs, retryFloorMs)
+ runCatching { context.dataStore.edit { it[lastCheckKey] = stamp } }
null
} finally {
connection?.disconnect()
diff --git a/app/src/test/java/com/excp/podroid/data/repository/UpdateRepositoryTest.kt b/app/src/test/java/com/excp/podroid/data/repository/UpdateRepositoryTest.kt
index 29adfab..ed02f8a 100644
--- a/app/src/test/java/com/excp/podroid/data/repository/UpdateRepositoryTest.kt
+++ b/app/src/test/java/com/excp/podroid/data/repository/UpdateRepositoryTest.kt
@@ -6,6 +6,7 @@
*/
package com.excp.podroid.data.repository
+import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
@@ -55,6 +56,34 @@ class UpdateRepositoryTest {
assertTrue(shouldCheck(validity + 1L, 0L, validity))
}
+ // ------------------------------------------------------------------
+ // backoffStamp (transient failures earn a short retry floor, not 24h)
+ // ------------------------------------------------------------------
+
+ @Test
+ fun `backoffStamp on a transient failure re-opens the gate after the retry floor`() {
+ val validity = 24 * 60 * 60 * 1000L
+ val floor = 20 * 60 * 1000L
+ val now = 1_700_000_000_000L
+ val stamp = backoffStamp(now, transient = true, validity, floor)
+ // Gate stays closed until the floor elapses, then re-opens — not a full day.
+ assertFalse(shouldCheck(now + floor - 1L, stamp, validity))
+ assertTrue(shouldCheck(now + floor, stamp, validity))
+ // And it would NOT have re-opened this early under the full validity window.
+ assertFalse(shouldCheck(now + floor, now, validity))
+ }
+
+ @Test
+ fun `backoffStamp on a definitive failure backs off the full validity window`() {
+ val validity = 24 * 60 * 60 * 1000L
+ val floor = 20 * 60 * 1000L
+ val now = 1_700_000_000_000L
+ val stamp = backoffStamp(now, transient = false, validity, floor)
+ assertEquals(now, stamp)
+ assertFalse(shouldCheck(now + validity - 1L, stamp, validity))
+ assertTrue(shouldCheck(now + validity, stamp, validity))
+ }
+
// ------------------------------------------------------------------
// isNewer (prerelease suffix numeric comparison)
// ------------------------------------------------------------------