A rootless Android app that boots Alpine Linux: run containers (Podman/Docker/LXC) and GUI desktop apps.
fix(data): recover from throttle-read failure and always record update back-off
ExTvb40cdae1ec5f
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.ktindex 4f511ac..f1f4395 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@@ -2,10 +2,12 @@ package com.excp.podroid.data.repositoryimport android.content.Contextimport androidx.datastore.preferences.core.edit+import androidx.datastore.preferences.core.emptyPreferencesimport androidx.datastore.preferences.core.longPreferencesKeyimport androidx.datastore.preferences.core.stringPreferencesKeyimport dagger.hilt.android.qualifiers.ApplicationContextimport kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.flow.catchimport kotlinx.coroutines.flow.firstimport kotlinx.coroutines.withContextimport org.json.JSONObject@@ -116,15 +118,18 @@ class UpdateRepository @Inject constructor(suspend fun checkForUpdate(currentVersion: String): UpdateInfo? = withContext(Dispatchers.IO) {// Wall-clock time so the 24h gate survives device reboots and deep sleep.val now = System.currentTimeMillis()- val lastCheck = context.dataStore.data.first()[lastCheckKey] ?: 0L+ var connection: java.net.HttpURLConnection? = null+ try {+ val lastCheck = context.dataStore.data+ .catch { e -> if (e is java.io.IOException) emit(emptyPreferences()) else throw e }+ .first()[lastCheckKey] ?: 0L- if (!shouldCheck(now, lastCheck, cacheValidityMs)) {- return@withContext null- }+ if (!shouldCheck(now, lastCheck, cacheValidityMs)) {+ return@withContext null+ }- val connection = URL("https://api.github.com/repos/ExTV/Podroid/releases/latest")- .openConnection() as java.net.HttpURLConnection- try {+ connection = URL("https://api.github.com/repos/ExTV/Podroid/releases/latest")+ .openConnection() as java.net.HttpURLConnectionconnection.connectTimeout = 5000connection.readTimeout = 5000connection.setRequestProperty("Accept", "application/vnd.github+json")@@ -155,11 +160,11 @@ class UpdateRepository @Inject constructor(val normalizedCurrent = currentVersion.removeSuffix("-debug")if (isNewer(tag, normalizedCurrent)) UpdateInfo(tag, url) else null} catch (_: Exception) {- // Network error: still record the timestamp to back off on the next launch.+ // Network/DataStore error: still record the timestamp to back off on the next launch.runCatching { context.dataStore.edit { it[lastCheckKey] = now } }null} finally {- connection.disconnect()+ connection?.disconnect()}}