Modern Apps git

← Modern-Apps.git

appstore: summarise update-all failures once per run (#630)

Commit
a02bed7ca24fc7dfc3b6dbcce9081b55e816ee83
Author
vayun-mathur <[email protected]>
When
2026-09-07 04:01 UTC (3 months ago)
Parents
43342e2

Diff

appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallStatusReceiver.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallStatusReceiver.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallStatusReceiver.ktindex 9a6d3c2ee2..696ad9ed4c 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallStatusReceiver.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallStatusReceiver.kt@@ -69,11 +69,54 @@ class InstallStatusReceiver : BroadcastReceiver() {                     else -> message?.takeIf { it.isNotBlank() }                         ?: context.getString(R.string.install_failure_unknown)                 }-                AppMessages.show(-                    context.getString(R.string.install_failed_reason, pkg.orEmpty(), reason),-                    duration = AppMessages.Duration.Long,-                )+                val text = context.getString(R.string.install_failed_reason, pkg.orEmpty(), reason)+                if (!InstallFailureBatch.collect(text)) {+                    AppMessages.show(text, duration = AppMessages.Duration.Long)+                }             }         }     } }++/**+ * Holds install failures back while something is updating several apps in a row.+ *+ * [AppMessages] already drops a repeat of an identical message posted within a few+ * seconds (issue #630). That does not cover an "update all": the installs are sequential,+ * so the failures are minutes apart, and each message names its own package, so no two of+ * them are the same string — the user got one snackbar per app, every one saying the same+ * thing. While a batch is running the failures are collected here instead, and whoever+ * started the batch reports them once.+ *+ * A failure that arrives outside a batch is not this object's business and is shown+ * immediately, which is why [collect] reports whether it took ownership.+ */+object InstallFailureBatch {++    private val collected = mutableListOf<String>()+    private var active = false++    /** Start collecting. Any reasons left over from a previous batch are dropped. */+    @Synchronized+    fun begin() {+        active = true+        collected.clear()+    }++    /** Stop collecting and hand back what came in, for a single summary. */+    @Synchronized+    fun end(): List<String> {+        active = false+        val reasons = collected.toList()+        collected.clear()+        return reasons+    }++    /** True when [reason] was collected, false when the caller should show it itself. */+    @Synchronized+    fun collect(reason: String): Boolean {+        if (!active) return false+        collected += reason+        return true+    }+}
appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.kt b/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.ktindex f9baec23c1..d94eafcfc2 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.kt@@ -24,6 +24,7 @@ import com.vayunmathur.appstore.data.accrescent.AccrescentRepository import com.vayunmathur.appstore.data.grapheneos.GrapheneOSRepository import com.vayunmathur.appstore.data.grapheneos.toUnifiedApp import com.vayunmathur.appstore.data.installer.InstallCoordinator+import com.vayunmathur.appstore.data.installer.InstallFailureBatch import com.vayunmathur.appstore.data.installer.InstallStage import com.vayunmathur.appstore.data.play.PlayAuthState import com.vayunmathur.appstore.data.play.PlayHttpClient@@ -146,6 +147,7 @@ class AppStoreViewModel(      private var searchJob: Job? = null     private var detailJob: Job? = null+    private var updateAllJob: Job? = null      // --- Derived state ---------------------------------------------------------------- @@ -932,19 +934,86 @@ class AppStoreViewModel(         }     } +    /**+     * Update everything, and report the run once when it is over.+     *+     * Sequential on purpose: updates this store isn't the update owner of still get a+     * system confirmation dialog, and firing them concurrently buries the user in prompts.+     *+     * The reporting is the other half of issue #630. A run used to say nothing itself and+     * let each app's failure raise its own snackbar, so a phone whose updates were all+     * failing the same way — Play refusing the lot for going too fast, typically — showed+     * the user the same error once per app. Now the failures are collected and summarised,+     * and a reason that keeps coming back ends the run rather than being demonstrated+     * another dozen times.+     */     override fun updateAll() {-        viewModelScope.launch {-            // Sequential on purpose: updates this store isn't the update owner of still get a-            // system confirmation dialog, and firing them concurrently buries the user in-            // prompts.-            for (app in updates.value) {-                installer.install(app)+        if (updateAllJob?.isActive == true) return+        updateAllJob = viewModelScope.launch {+            val batch = updates.value+            if (batch.isEmpty()) return@launch+            val failures = mutableListOf<String>()+            var started = 0+            var repeats = 0+            var previousReason: String? = null+            InstallFailureBatch.begin()+            try {+                for ((index, app) in batch.withIndex()) {+                    _statusMessage.value = context.getString(+                        R.string.updates_progress, app.name, index + 1, batch.size+                    )+                    val outcome = installer.install(app)+                    if (outcome.started) {+                        started+++                        previousReason = null+                        repeats = 0+                        continue+                    }+                    val reason = outcome.verification.reason()+                    failures += reason+                    repeats = if (reason == previousReason) repeats + 1 else 1+                    previousReason = reason+                    if (repeats >= REPEATED_FAILURE_LIMIT) break+                }+                // PackageInstaller commits asynchronously, so the last app's real verdict+                // is still on its way. Wait for it before summarising, or it lands on its+                // own afterwards — which is the repetition this is here to stop.+                delay(INSTALL_SETTLE_MS)+            } finally {+                _statusMessage.value = ""+                failures += InstallFailureBatch.end()             }-            delay(INSTALL_SETTLE_MS)++            AppMessages.show(+                if (failures.isEmpty()) {+                    context.resources.getQuantityString(+                        R.plurals.updates_batch_installed, started, started+                    )+                } else {+                    context.getString(+                        R.string.updates_batch_partial,+                        started,+                        batch.size,+                        failures.first(),+                    )+                },+                duration = if (failures.isEmpty()) {+                    AppMessages.Duration.Short+                } else {+                    AppMessages.Duration.Long+                },+            )             installedRepo.refresh()         }     } +    /** What to tell the user a failed install went wrong with. */+    private fun VerificationResult.reason(): String = when (this) {+        is VerificationResult.Rejected -> reason+        is VerificationResult.Unverified -> reason+        is VerificationResult.Verified -> context.getString(R.string.install_failure_unknown)+    }+     /** Turn fully unattended (no-tap) background update installation on or off. */     fun setAutoInstallUpdates(enabled: Boolean) {         viewModelScope.launch { settings.setAutoInstallUpdates(enabled) }@@ -997,6 +1066,12 @@ class AppStoreViewModel(         const val RECENT_LIMIT = 30         const val CAROUSEL_LIMIT = 20         const val PLAY_CLUSTER_LIMIT = 4++        /**+         * How many times in a row an update may fail for the same reason before the rest+         * of the run is abandoned. Three is enough to tell a bad app from a bad afternoon.+         */+        const val REPEATED_FAILURE_LIMIT = 3     } } 
appstore/src/main/res/values/strings.xml
diff --git a/appstore/src/main/res/values/strings.xml b/appstore/src/main/res/values/strings.xmlindex 9c67e586be..30d2e1aa97 100644--- a/appstore/src/main/res/values/strings.xml+++ b/appstore/src/main/res/values/strings.xml@@ -99,6 +99,15 @@         <item quantity="one">Installed %1$d update</item>         <item quantity="other">Installed %1$d updates</item>     </plurals>+    <!-- Updates screen, status line under the buttons during Update all. %1$s is the app being updated. -->+    <string name="updates_progress">Updating %1$s — %2$d of %3$d</string>+    <!-- Message after Update all finishes with nothing having gone wrong. -->+    <plurals name="updates_batch_installed">+        <item quantity="one">Updated %1$d app</item>+        <item quantity="other">Updated %1$d apps</item>+    </plurals>+    <!-- Message after Update all when some apps failed. %3$s is the reason the first one gave. -->+    <string name="updates_batch_partial">Updated %1$d of %2$d. The rest failed: %3$s</string>      <!-- Install actions and progress. -->     <string name="action_install">Install</string>