appstore: fail update check/install softly instead of crashing (#812)
- Commit
1b22cc2df1a597ff195044614510a6bc913fc142- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-14 00:11 UTC (1 month ago)
- Parents
ea664b2
Diff
appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepository.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepository.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepository.ktindex b720ab24a6..ea42add94d 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepository.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepository.kt@@ -74,7 +74,8 @@ class AccrescentRepository( suspend fun signerFor(appId: String): String? = trustStore.signerFor(appId) suspend fun minVersionFor(appId: String): Long? = trustStore.minVersionFor(appId) suspend fun entryFor(appId: String) = trustStore.entryFor(appId)- suspend fun appIds(): Set<String> = trustStore.appIds()+ suspend fun appIds(): Set<String> =+ runCatching { trustStore.appIds() }.getOrDefault(emptySet()) // --- Browse / search ------------------------------------------------------------ @@ -93,6 +94,10 @@ class AccrescentRepository( } catch (expected: IllegalStateException) { Log.status(TAG, "listApps failed", expected) AccrescentPage(emptyList(), "")+ } catch (expected: Exception) {+ // gRPC failures (StatusRuntimeException) — fail soft like a network blip (issue #812).+ Log.status(TAG, "listApps failed", expected)+ AccrescentPage(emptyList(), "") } } @@ -151,6 +156,10 @@ class AccrescentRepository( } catch (expected: IllegalStateException) { Log.status(TAG, "listAppListings page $pages failed", expected) null+ } catch (expected: Exception) {+ // gRPC failures (StatusRuntimeException) — fail soft like a network blip (issue #812).+ Log.status(TAG, "listAppListings page $pages failed", expected)+ null } } @@ -173,6 +182,10 @@ class AccrescentRepository( } catch (expected: IllegalStateException) { Log.status(TAG, "details failed for $appId", expected) null+ } catch (expected: Exception) {+ // gRPC failures (StatusRuntimeException) — fail soft like a network blip (issue #812).+ Log.status(TAG, "details failed for $appId", expected)+ null } }
appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.ktindex df4fb01cf9..56aa241b6e 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.kt@@ -1,6 +1,7 @@ package com.vayunmathur.appstore.data.installer import android.content.Context+import com.aurora.gplayapi.exceptions.GooglePlayException import com.vayunmathur.library.log.Log import com.vayunmathur.appstore.data.AppDatabase import com.vayunmathur.appstore.data.AppSource@@ -118,6 +119,14 @@ class InstallCoordinator( failInstall(app.packageName, e) } catch (e: IllegalStateException) { failInstall(app.packageName, e)+ } catch (e: GooglePlayException) {+ // Purchase throttled (e.g. 429, issue #797/#812): withApi covers reads,+ // but purchase() throws — fail the row instead of crashing the tap.+ failInstall(app.packageName, e)+ } catch (e: Exception) {+ // Accrescent gRPC (StatusRuntimeException), dispenser AuthError, Room, etc.+ // A tap on Update must never crash the store (issue #812).+ failInstall(app.packageName, e) } }
appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreUpdateOps.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreUpdateOps.kt b/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreUpdateOps.ktindex 4fb5a981e7..dec4a7a2cc 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreUpdateOps.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreUpdateOps.kt@@ -19,45 +19,49 @@ import kotlinx.coroutines.launch internal fun AppStoreViewModel.checkForUpdatesImpl() { if (isCheckingUpdatesFlow.value) return viewModelScope.launch {- val enabled = enabledSources.value- isCheckingUpdatesFlow.value = true- statusMessageFlow.value = context.getString(R.string.updates_checking)+ try {+ val enabled = enabledSources.value+ isCheckingUpdatesFlow.value = true+ statusMessageFlow.value = context.getString(R.string.updates_checking) - installedRepo.refresh()- catalogUpdatesFlow.value = catalog.updatesFor(installedRepo.updatable.value)+ installedRepo.refresh()+ catalogUpdatesFlow.value = catalog.updatesFor(installedRepo.updatable.value) - // Only ask Play about packages neither offline source lists — for the rest the- // catalogue already answered, and Play would just re-answer it over the network.- val index = catalog.packageIndex.value- val installed = installedRepo.updatable.value- if (AppSource.PLAYSTORE in enabled) {- val playCandidates = installed- .filter { it.packageName !in index }- .map { it.packageName }+ // Only ask Play about packages neither offline source lists — for the rest the+ // catalogue already answered, and Play would just re-answer it over the network.+ val index = catalog.packageIndex.value+ val installed = installedRepo.updatable.value+ if (AppSource.PLAYSTORE in enabled) {+ val playCandidates = installed+ .filter { it.packageName !in index }+ .map { it.packageName } - val remote = play.details(playCandidates).associateBy { it.packageName }- playUpdatesFlow.value = installed.mapNotNull { inst ->- remote[inst.packageName]?.takeIf { it.versionCode > inst.versionCode }+ val remote = play.details(playCandidates).associateBy { it.packageName }+ playUpdatesFlow.value = installed.mapNotNull { inst ->+ remote[inst.packageName]?.takeIf { it.versionCode > inst.versionCode }+ }+ // The same response tells us which of these packages Play actually hosts, which+ // the library uses to tell a genuine Play app from a sideloaded one.+ if (remote.isNotEmpty()) playInstalledPackagesFlow.value = remote.keys.toSet() }- // The same response tells us which of these packages Play actually hosts, which- // the library uses to tell a genuine Play app from a sideloaded one.- if (remote.isNotEmpty()) playInstalledPackagesFlow.value = remote.keys.toSet()- } - // Accrescent: refresh the signed allowlist, then ask its API for a newer build of- // each installed package it vouches for.- if (AppSource.ACCRESCENT in enabled) {- accrescent.refreshRepoData()- val accrescentIds = accrescent.appIds()- if (accrescentIds.isNotEmpty()) accrescentPackagesFlow.value = accrescentIds- accrescentUpdatesFlow.value = installed- .filter { it.packageName in accrescentIds }- .mapNotNull { inst -> accrescentUpdate(inst.packageName, inst.versionCode) }- }+ // Accrescent: refresh the signed allowlist, then ask its API for a newer build of+ // each installed package it vouches for.+ if (AppSource.ACCRESCENT in enabled) {+ accrescent.refreshRepoData()+ val accrescentIds = accrescent.appIds()+ if (accrescentIds.isNotEmpty()) accrescentPackagesFlow.value = accrescentIds+ accrescentUpdatesFlow.value = installed+ .filter { it.packageName in accrescentIds }+ .mapNotNull { inst -> accrescentUpdate(inst.packageName, inst.versionCode) }+ } - lastUpdateCheckFlow.value = System.currentTimeMillis()- statusMessageFlow.value = ""- isCheckingUpdatesFlow.value = false+ lastUpdateCheckFlow.value = System.currentTimeMillis()+ statusMessageFlow.value = ""+ } finally {+ // An escaping failure (e.g. gRPC/Room) must not wedge the tab mid-check (#812).+ isCheckingUpdatesFlow.value = false+ } } }