appstore: merge update install toggles into one
- Commit
584ea168c4c043f981095065045f3f054469fdbd- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-21 01:59 UTC (3 months ago)
- Parents
5b46be5
Diff
appstore/src/main/java/com/vayunmathur/appstore/data/SettingsRepository.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/SettingsRepository.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/SettingsRepository.ktindex 541cb3882f..e0d3487e05 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/SettingsRepository.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/SettingsRepository.kt@@ -21,26 +21,23 @@ private val Context.settingsDataStore by preferencesDataStore(name = "appstore-s /** * User-adjustable preferences for the store. *- * The persisted value is mirrored into a [StateFlow] so the installer, which commits from a- * plain function, can read the current choice synchronously without blocking on disk. The- * default is applied on read ([DEFAULT_BACKGROUND_UPDATE_INSTALL]) rather than written at- * first launch, so an existing user with nothing stored still gets the on-by-default value.+ * The persisted value is mirrored into a [StateFlow] so the settings UI can render the+ * stored choice without a suspending read. The default is applied on read+ * ([DEFAULT_AUTO_INSTALL_UPDATES]) rather than written at first launch, so an existing user+ * with nothing stored still gets the documented default. */ class SettingsRepository( private val context: Context, scope: CoroutineScope, ) {- private val _backgroundUpdateInstall = MutableStateFlow(DEFAULT_BACKGROUND_UPDATE_INSTALL)-- /** Whether updates to store-owned apps install without a per-app confirmation prompt. */- val backgroundUpdateInstall: StateFlow<Boolean> = _backgroundUpdateInstall.asStateFlow()- private val _autoInstallUpdates = MutableStateFlow(DEFAULT_AUTO_INSTALL_UPDATES) /** * Whether the periodic update check may also download and install updates on its own, * with no tap. Off by default: this installs apps without the user present, so it is- * strictly opt-in. Only ever acts on updates that install silently (see the worker).+ * strictly opt-in. With it off the same updates wait for the user to ask for them.+ * Either way the install itself is silent, so this only decides who starts it. Only+ * ever acts on updates that install silently (see the worker). */ val autoInstallUpdates: StateFlow<Boolean> = _autoInstallUpdates.asStateFlow() @@ -48,46 +45,31 @@ class SettingsRepository( scope.launch { context.settingsDataStore.data .catch { e -> if (e is IOException) emit(emptyPreferences()) else throw e }- .collect { prefs ->- _backgroundUpdateInstall.value = prefs.backgroundUpdateInstall()- _autoInstallUpdates.value = prefs.autoInstallUpdates()- }+ .collect { prefs -> _autoInstallUpdates.value = prefs.autoInstallUpdates() } } } - suspend fun setBackgroundUpdateInstall(enabled: Boolean) {- context.settingsDataStore.edit { it[KEY_BACKGROUND_UPDATE_INSTALL] = enabled }- }- suspend fun setAutoInstallUpdates(enabled: Boolean) { context.settingsDataStore.edit { it[KEY_AUTO_INSTALL_UPDATES] = enabled } } /**- * One-shot read of the persisted values, for callers with no long-lived scope to+ * One-shot read of the persisted value, for callers with no long-lived scope to * collect a flow — the [UpdateCheckWorker] is cold-started by WorkManager and needs the * committed choice, not the not-yet-populated flow default. */ suspend fun readAutoInstallUpdates(): Boolean = read().autoInstallUpdates() - suspend fun readBackgroundUpdateInstall(): Boolean = read().backgroundUpdateInstall()- private suspend fun read(): Preferences = context.settingsDataStore.data .catch { e -> if (e is IOException) emit(emptyPreferences()) else throw e } .first() - private fun Preferences.backgroundUpdateInstall(): Boolean =- this[KEY_BACKGROUND_UPDATE_INSTALL] ?: DEFAULT_BACKGROUND_UPDATE_INSTALL- private fun Preferences.autoInstallUpdates(): Boolean = this[KEY_AUTO_INSTALL_UPDATES] ?: DEFAULT_AUTO_INSTALL_UPDATES companion object {- const val DEFAULT_BACKGROUND_UPDATE_INSTALL = true const val DEFAULT_AUTO_INSTALL_UPDATES = false- private val KEY_BACKGROUND_UPDATE_INSTALL =- booleanPreferencesKey("background_update_installation") private val KEY_AUTO_INSTALL_UPDATES = booleanPreferencesKey("auto_install_updates") }
appstore/src/main/java/com/vayunmathur/appstore/data/UpdateCheckWorker.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/UpdateCheckWorker.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/UpdateCheckWorker.ktindex d085c402a6..cdeb2d387e 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/UpdateCheckWorker.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/UpdateCheckWorker.kt@@ -46,9 +46,9 @@ import java.util.concurrent.TimeUnit * * If the user has opted in to unattended updates ([SettingsRepository.autoInstallUpdates]), * it also downloads and installs — as a foreground service — the updates it can apply- * silently: packages this store is the installer or update owner of, on API 31+ with- * background installation enabled. Everything it can't install without a prompt is left to- * the notification, exactly as before. Auto-install is off by default.+ * silently: packages this store is the installer or update owner of, on API 31+. Everything+ * it can't install without a prompt is left to the notification, exactly as before.+ * Auto-install is off by default. */ class UpdateCheckWorker( private val context: Context,@@ -103,13 +103,8 @@ class UpdateCheckWorker( val settings = SettingsRepository(context, scope) val autoInstall = settings.readAutoInstallUpdates()- // Unattended installs are only safe when they will not raise a dialog: silent- // install requires API 31+ and the background-install toggle. Below that, or with it- // off, fall back to notify-only regardless of the auto-install choice.- val silentCapable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&- settings.readBackgroundUpdateInstall() - if (autoInstall && silentCapable && updates.isNotEmpty()) {+ if (autoInstall && updates.isNotEmpty()) { val eligible = updates.filter { canSilentlyUpdate(it.packageName) } if (eligible.isNotEmpty()) { autoInstall(eligible, db, play, accrescent)@@ -177,13 +172,12 @@ class UpdateCheckWorker( } } - /**+/** * Download and silently install a set of updates, promoting the worker to a foreground * service for the duration so the OS doesn't kill it mid-install. *- * Passes `backgroundUpdateInstall = { true }` because [canSilentlyUpdate] has already- * confirmed each package will install without a prompt; the caller only reaches here- * when the user's silent-install toggle is on.+ * [canSilentlyUpdate] has already confirmed each package will install without a prompt,+ * so nothing here can surface a dialog with the user absent. */ private suspend fun autoInstall( apps: List<UnifiedApp>,@@ -198,7 +192,6 @@ class UpdateCheckWorker( play = play, accrescent = accrescent, ownSigningCertificates = { ApkCertificates.selfSigners(context) },- backgroundUpdateInstall = { true }, ) var installed = 0 for (app in apps) {
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 2abc1adf86..c6450dfe83 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@@ -55,9 +55,8 @@ class InstallCoordinator( private val play: PlayRepository, private val accrescent: AccrescentRepository, private val ownSigningCertificates: () -> Set<String>,- backgroundUpdateInstall: () -> Boolean = { false }, ) {- private val sessionInstaller = SessionInstaller(context, backgroundUpdateInstall)+ private val sessionInstaller = SessionInstaller(context) private val playDownloader = PlayDownloader(context) private val _stages = MutableStateFlow<Map<String, InstallStage>>(emptyMap())
appstore/src/main/java/com/vayunmathur/appstore/data/installer/SessionInstaller.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/installer/SessionInstaller.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/installer/SessionInstaller.ktindex 706a1f7f82..c80c8b4031 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/installer/SessionInstaller.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/installer/SessionInstaller.kt@@ -22,12 +22,6 @@ import java.io.File */ class SessionInstaller( private val context: Context,- /**- * Whether updates to packages this store already owns may install without a per-app- * system prompt. Read at commit time so a toggle change takes effect on the next- * install without rebuilding the installer.- */- private val backgroundUpdateInstall: () -> Boolean = { false }, ) { companion object {@@ -97,10 +91,7 @@ class SessionInstaller( // USER_ACTION_NOT_REQUIRED when this app is the target's update owner, and // a first-time install of a package owned by someone else would prompt // anyway. First installs keep the confirmation dialog unconditionally.- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&- backgroundUpdateInstall() &&- isInstalled(packageName)- ) {+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && isInstalled(packageName)) { setRequireUserAction(PackageInstaller.SessionParams.USER_ACTION_NOT_REQUIRED) } setInstallLocation(android.content.pm.PackageInfo.INSTALL_LOCATION_AUTO)
appstore/src/main/java/com/vayunmathur/appstore/ui/SourcesPage.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/ui/SourcesPage.kt b/appstore/src/main/java/com/vayunmathur/appstore/ui/SourcesPage.ktindex c907245259..d8e1514ed5 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/ui/SourcesPage.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/SourcesPage.kt@@ -27,7 +27,6 @@ import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.DetailScaffold import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.OutlinedButton-import com.vayunmathur.library.ui.SettingsDivider import com.vayunmathur.library.ui.SettingsSwitchRow import com.vayunmathur.library.ui.Text import java.text.SimpleDateFormat@@ -46,7 +45,6 @@ fun SourcesPage( ) { val repos by viewModel.repos.collectAsState() val home by viewModel.home.collectAsState()- val backgroundUpdateInstall by viewModel.backgroundUpdateInstall.collectAsState() val autoInstallUpdates by viewModel.autoInstallUpdates.collectAsState() val fdroid = repos.find { it.url == DefaultRepos.FDROID.url } @@ -85,22 +83,12 @@ fun SourcesPage( } Card(Modifier.fillMaxWidth()) {- Column {- SettingsSwitchRow(- title = stringResource(R.string.setting_background_updates_title),- supportingText = stringResource(R.string.setting_background_updates_summary),- checked = backgroundUpdateInstall,- onCheckedChange = { viewModel.setBackgroundUpdateInstall(it) },- )- SettingsDivider()- SettingsSwitchRow(- title = stringResource(R.string.setting_auto_install_updates_title),- supportingText = stringResource(R.string.setting_auto_install_updates_summary),- checked = autoInstallUpdates && backgroundUpdateInstall,- enabled = backgroundUpdateInstall,- onCheckedChange = { viewModel.setAutoInstallUpdates(it) },- )- }+ SettingsSwitchRow(+ title = stringResource(R.string.setting_auto_install_updates_title),+ supportingText = stringResource(R.string.setting_auto_install_updates_summary),+ checked = autoInstallUpdates,+ onCheckedChange = { viewModel.setAutoInstallUpdates(it) },+ ) } SourceCard(
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 d4fe4d7418..fa90c936a1 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.kt@@ -55,12 +55,7 @@ class AppStoreViewModel( private val accrescent = AccrescentRepository(context, db) private val installedRepo = InstalledAppsRepository(context) private val settings = SettingsRepository(context, viewModelScope)- private val installer = InstallCoordinator(context, db, play, accrescent, { ownSigningCertificates }) {- settings.backgroundUpdateInstall.value- }-- /** On-by-default: updates to store-owned apps install without a per-app prompt. */- val backgroundUpdateInstall: StateFlow<Boolean> = settings.backgroundUpdateInstall+ private val installer = InstallCoordinator(context, db, play, accrescent) { ownSigningCertificates } /** Off-by-default: the periodic check may also download and install updates unattended. */ val autoInstallUpdates: StateFlow<Boolean> = settings.autoInstallUpdates@@ -800,9 +795,9 @@ class AppStoreViewModel( override fun updateAll() { viewModelScope.launch {- // Sequential on purpose: when background install is off PackageInstaller shows a- // confirmation dialog per app on most devices, and firing them concurrently- // buries the user in prompts.+ // 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) }@@ -811,11 +806,6 @@ class AppStoreViewModel( } } - /** Turn silent background installation of updates on or off. */- fun setBackgroundUpdateInstall(enabled: Boolean) {- viewModelScope.launch { settings.setBackgroundUpdateInstall(enabled) }- }- /** Turn fully unattended (no-tap) background update installation on or off. */ fun setAutoInstallUpdates(enabled: Boolean) { viewModelScope.launch { settings.setAutoInstallUpdates(enabled) }
appstore/src/main/res/values-az/strings.xml
diff --git a/appstore/src/main/res/values-az/strings.xml b/appstore/src/main/res/values-az/strings.xmlindex f7fc91b00b..8b6e727800 100644--- a/appstore/src/main/res/values-az/strings.xml+++ b/appstore/src/main/res/values-az/strings.xml@@ -61,8 +61,6 @@ <string name="updates_notification_body">Onları nəzərdən keçirmək və quraşdırmaq üçün App Store-u açın.</string> <string name="updates_channel_name">Tətbiq yeniləmələri</string> <string name="updates_channel_description">Burada quraşdırdığınız tətbiqlərin daha yeni versiyası olduqda sizə xəbər verir.</string>- <string name="setting_background_updates_title">Yeniləmələri arxa fonda quraşdırın</string>- <string name="setting_background_updates_summary">Bu mağazadan quraşdırılmış tətbiqləri hər dəfə sorğu olmadan yeniləyin. İlk dəfə quraşdırılanlar üçün isə hələ də təsdiq tələb olunur.</string> <string name="setting_auto_install_updates_title">Yeniləmələri avtomatik quraşdırın</string> <string name="setting_auto_install_updates_summary">Heç bir əlavə hərəkət tələb olunmadan yeniləmələri avtomatik yoxlayır və quraşdırır. Bu funksiya yalnız həmin mağaza vasitəsilə quraşdırılmış və səssiz şəkildə yenilənə bilən tətbiqlərə şamil edilir; digər tətbiqlər üçün isə sadəcə bildiriş verilir.</string> <plurals name="updates_count">
appstore/src/main/res/values-et/strings.xml
diff --git a/appstore/src/main/res/values-et/strings.xml b/appstore/src/main/res/values-et/strings.xmlindex e6a86e05cf..c28e6ce996 100644--- a/appstore/src/main/res/values-et/strings.xml+++ b/appstore/src/main/res/values-et/strings.xml@@ -47,8 +47,6 @@ <string name="action_check_again">Kontrolli uuesti</string> <string name="all_apps_up_to_date">Kõik on uuendatud</string> <string name="updates_empty_message">Tarkvarahoidlaid kontrollitakse WiFi ühenduse puhul taustal kord kaheteist tunni jooksul.</string>- <string name="setting_background_updates_title">Paigalda uuendused taustal</string>- <string name="setting_background_updates_summary">Uuenda selle rakendusepoe poolt paigaldatud rakenduste uuendused automaatselt ilma küsimata. Esimesel paigaldusel küsitakse alati kinnitust.</string> <string name="install_blocked">%1$s oli blokeeritud: %2$s</string> <string name="install_failed">„%1$s“ rakenduse paigaldamine ei õnnestunud</string> <string name="share_app_text">%1$s - %2$s</string>
appstore/src/main/res/values-fr/strings.xml
diff --git a/appstore/src/main/res/values-fr/strings.xml b/appstore/src/main/res/values-fr/strings.xmlindex 3750fd61ba..a029048cc7 100644--- a/appstore/src/main/res/values-fr/strings.xml+++ b/appstore/src/main/res/values-fr/strings.xml@@ -158,8 +158,6 @@ <string name="updates_notification_body">Ouvrez le Magasin pour les consulter et les installer.</string> <string name="nav_home">Accueil</string> <string name="trust_modern_apps_check_index_signed">L’index du dépôt est signé et vérifié à l’aide de la clé épinglée propre à ce magasin</string>- <string name="setting_background_updates_title">Installer les mises à jour en arrière-plan</string>- <string name="setting_background_updates_summary">Mettre à jour les applications déjà installées par ce magasin sans demander de confirmation à chaque fois. Les premières installations nécessitent toujours une confirmation.</string> <string name="source_chip_grapheneos">GrapheneOS</string> <string name="section_sandboxed_google_play">Google Play en bac à sable</string> <string name="section_sandboxed_google_play_subtitle">Les composants Google Play comme applications ordinaires, sans privilèges</string>
appstore/src/main/res/values-it/strings.xml
diff --git a/appstore/src/main/res/values-it/strings.xml b/appstore/src/main/res/values-it/strings.xmlindex 1ee3bf1616..bf43389456 100644--- a/appstore/src/main/res/values-it/strings.xml+++ b/appstore/src/main/res/values-it/strings.xml@@ -112,6 +112,4 @@ <string name="store_rule_precheck_title">Verificato prima che Android lo veda</string> <string name="store_rule_precheck_detail">Tutto viene verificato prima che il download raggiunga il programma di installazione di sistema. I file rifiutati vengono eliminati.</string> <string name="store_rule_fail_blocks_title">Una verifica fallita blocca, una mancante avvisa</string>- <string name="setting_background_updates_title">Installa aggiornamenti in background</string>- <string name="setting_background_updates_summary">Aggiorna le app già installate da questo store senza chiederlo ogni volta. Le prime installazioni continuano a richiedere conferma.</string> </resources>
appstore/src/main/res/values-pl/strings.xml
diff --git a/appstore/src/main/res/values-pl/strings.xml b/appstore/src/main/res/values-pl/strings.xmlindex 90ce51c11b..f838190502 100644--- a/appstore/src/main/res/values-pl/strings.xml+++ b/appstore/src/main/res/values-pl/strings.xml@@ -59,8 +59,6 @@ <string name="updates_notification_body">Otwórz App Store, aby je przejrzeć i zainstalować.</string> <string name="updates_channel_name">Aktualizacje aplikacji</string> <string name="updates_channel_description">Informuje, czy aplikacje zainstalowane tutaj mają nowszą wersję.</string>- <string name="setting_background_updates_title">Zainstaluj aktualizacje w tle</string>- <string name="setting_background_updates_summary">Aktualizuj aplikacje, które ten sklep już zainstalował, bez pytania za każdym razem. Przy pierwszej instalacji nadal pojawia się prośba o potwierdzenie.</string> <string name="action_install">Instaluj</string> <string name="action_update">Aktualizacja</string> <string name="action_dismiss">Odrzuć</string>
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 fe8d1de150..2ed599c543 100644--- a/appstore/src/main/res/values/strings.xml+++ b/appstore/src/main/res/values/strings.xml@@ -73,10 +73,8 @@ <string name="updates_notification_body">Open the App Store to review and install them.</string> <string name="updates_channel_name">App updates</string> <string name="updates_channel_description">Tells you when apps you installed here have a newer version.</string>- <string name="setting_background_updates_title">Install updates in the background</string>- <string name="setting_background_updates_summary">Update apps this store already installed without asking each time. First-time installs still ask for confirmation.</string> <string name="setting_auto_install_updates_title">Automatically install updates</string>- <string name="setting_auto_install_updates_summary">Check for and install updates on their own, with no tap. Only applies to apps this store installed and can update silently; everything else still just notifies you.</string>+ <string name="setting_auto_install_updates_summary">Install updates as soon as they are found, with no tap. When off, updates wait until you tap Update. Either way apps this store installed update without asking each time; anything else just notifies you.</string> <plurals name="updates_count"> <item quantity="one">%1$d update available</item> <item quantity="other">%1$d updates available</item>