Modern Apps git

← Modern-Apps.git

appstore: allow disabling built-in sources (#647)

Commit
aa47900338636c852812ef24699b354841ab7fad
Author
vayun-mathur <[email protected]>
When
2026-09-07 00:59 UTC (3 months ago)
Parents
c3db2fc

Diff

appstore/src/main/java/com/vayunmathur/appstore/data/AppModels.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/AppModels.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/AppModels.ktindex aee0c7fe69..6d4aaccb95 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/AppModels.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/AppModels.kt@@ -39,6 +39,16 @@ enum class AppSource {          */         val PRIORITY: List<AppSource> =             listOf(GRAPHENEOS, MODERN_APPS, FDROID, ACCRESCENT, PLAYSTORE)++        /**+         * Sources the user may switch off, in the order the sources screen lists them.+         *+         * [GRAPHENEOS] is absent on purpose. It carries nothing but the Sandboxed Google Play+         * components, which only exist on a device whose OS already ships the gmscompat layer+         * they belong to, and which must never be updated from anywhere else — so a switch+         * would either do nothing or strand three system packages on a stale build.+         */+        val TOGGLEABLE: List<AppSource> = listOf(MODERN_APPS, FDROID, PLAYSTORE, ACCRESCENT)     } } @@ -140,6 +150,8 @@ data class RepoDescriptor(  * pipeline *and* the mirror operator in its trusted set, with no published source to  * check the binary against. The f-droid.org archive is excluded for a different reason:  * it exists to serve superseded versions, which is the opposite of what we want.+ *+ * Either of these can be switched off (see [AppSource.TOGGLEABLE]); neither can be replaced.  */ object DefaultRepos {     val FDROID = RepoDescriptor(
appstore/src/main/java/com/vayunmathur/appstore/data/CatalogRepository.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/CatalogRepository.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/CatalogRepository.ktindex cf23803398..aad2166cea 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/CatalogRepository.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/CatalogRepository.kt@@ -18,8 +18,16 @@ data class SyncReport(     /** How many F-Droid apps carry the reproducible badge this sync. */     val fdroidReproducible: Int = 0,     val modernCount: Int? = null,+    /** Sources the user has switched off, which this run skipped rather than attempted. */+    val skipped: Set<AppSource> = emptySet(), ) {-    val anyFailed: Boolean get() = fdroidCount == null || modernCount == null+    val anyFailed: Boolean+        get() = (AppSource.FDROID !in skipped && fdroidCount == null) ||+            (AppSource.MODERN_APPS !in skipped && modernCount == null)++    /** True when every offline source is switched off, so there was nothing to sync. */+    val allSkipped: Boolean+        get() = DefaultRepos.ALL.all { it.source in skipped } }  /**@@ -134,23 +142,54 @@ class CatalogRepository(      *      * Each source is independent: one failing leaves the other's rows updated and its own      * previous rows untouched, rather than aborting the whole run.+     *+     * A source missing from [enabled] is skipped and its cached rows dropped, so nothing it+     * published is still offered by browse, search or the update check.      */-    suspend fun sync(onProgress: (SyncStep) -> Unit = {}): SyncReport = withContext(Dispatchers.IO) {+    suspend fun sync(+        enabled: Set<AppSource>,+        onProgress: (SyncStep) -> Unit = {},+    ): SyncReport = withContext(Dispatchers.IO) {         ensureDefaultRepos()+        purgeDisabled(enabled) -        onProgress(SyncStep.FDROID)-        val fdroid = runCatching { fdroidProvider.syncIntoDb() }.getOrNull()+        val fdroid = if (DefaultRepos.FDROID.source in enabled) {+            onProgress(SyncStep.FDROID)+            runCatching { fdroidProvider.syncIntoDb() }.getOrNull()+        } else {+            null+        } -        onProgress(SyncStep.MODERN_APPS)-        val modern = runCatching { modernProvider.syncIntoDb() }.getOrNull()+        val modern = if (DefaultRepos.MODERN_APPS.source in enabled) {+            onProgress(SyncStep.MODERN_APPS)+            runCatching { modernProvider.syncIntoDb() }.getOrNull()+        } else {+            null+        }          SyncReport(             fdroidCount = fdroid,             fdroidReproducible = fdroidProvider.lastReproducibleCount,             modernCount = modern,+            skipped = DefaultRepos.ALL.mapNotNullTo(mutableSetOf()) {+                it.source.takeIf { source -> source !in enabled }+            },         )     } +    /**+     * Drop the cached rows of every offline source not in [enabled].+     *+     * The [RepoEntity] itself stays, so the sources screen can still show what the repo is+     * pinned to and when it last synced — turning a source off is not the same as forgetting+     * it, and re-enabling it should not have to re-derive the pin.+     */+    suspend fun purgeDisabled(enabled: Set<AppSource>) = withContext(Dispatchers.IO) {+        DefaultRepos.ALL.filterNot { it.source in enabled }.forEach {+            db.cachedAppDao().deleteByRepo(it.url)+        }+    }+     /** Seed the fixed repository set and prune rows left by older configurations. */     private suspend fun ensureDefaultRepos() {         val existing = db.repoDao().all()
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 e0d3487e05..ff1150e95e 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/SettingsRepository.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/SettingsRepository.kt@@ -5,6 +5,7 @@ import androidx.datastore.preferences.core.Preferences import androidx.datastore.preferences.core.booleanPreferencesKey import androidx.datastore.preferences.core.edit import androidx.datastore.preferences.core.emptyPreferences+import androidx.datastore.preferences.core.stringSetPreferencesKey import androidx.datastore.preferences.preferencesDataStore import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow@@ -31,6 +32,7 @@ class SettingsRepository(     scope: CoroutineScope, ) {     private val _autoInstallUpdates = MutableStateFlow(DEFAULT_AUTO_INSTALL_UPDATES)+    private val _enabledSources = MutableStateFlow(AppSource.entries.toSet())      /**      * Whether the periodic update check may also download and install updates on its own,@@ -41,11 +43,23 @@ class SettingsRepository(      */     val autoInstallUpdates: StateFlow<Boolean> = _autoInstallUpdates.asStateFlow() +    /**+     * The sources the store may talk to. Everything not in [AppSource.TOGGLEABLE] is always in+     * here.+     *+     * What is persisted is the *disabled* set, so a source added in a later version starts out+     * on rather than silently off for everyone who already had the app.+     */+    val enabledSources: StateFlow<Set<AppSource>> = _enabledSources.asStateFlow()+     init {         scope.launch {             context.settingsDataStore.data                 .catch { e -> if (e is IOException) emit(emptyPreferences()) else throw e }-                .collect { prefs -> _autoInstallUpdates.value = prefs.autoInstallUpdates() }+                .collect { prefs ->+                    _autoInstallUpdates.value = prefs.autoInstallUpdates()+                    _enabledSources.value = prefs.enabledSources()+                }         }     } @@ -53,6 +67,15 @@ class SettingsRepository(         context.settingsDataStore.edit { it[KEY_AUTO_INSTALL_UPDATES] = enabled }     } +    suspend fun setSourceEnabled(source: AppSource, enabled: Boolean) {+        if (source !in AppSource.TOGGLEABLE) return+        context.settingsDataStore.edit { prefs ->+            val disabled = prefs[KEY_DISABLED_SOURCES].orEmpty()+            prefs[KEY_DISABLED_SOURCES] =+                if (enabled) disabled - source.name else disabled + source.name+        }+    }+     /**      * 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@@ -60,6 +83,9 @@ class SettingsRepository(      */     suspend fun readAutoInstallUpdates(): Boolean = read().autoInstallUpdates() +    /** One-shot read of [enabledSources], for the same cold-started callers. */+    suspend fun readEnabledSources(): Set<AppSource> = read().enabledSources()+     private suspend fun read(): Preferences =         context.settingsDataStore.data             .catch { e -> if (e is IOException) emit(emptyPreferences()) else throw e }@@ -68,9 +94,19 @@ class SettingsRepository(     private fun Preferences.autoInstallUpdates(): Boolean =         this[KEY_AUTO_INSTALL_UPDATES] ?: DEFAULT_AUTO_INSTALL_UPDATES +    private fun Preferences.enabledSources(): Set<AppSource> {+        // An unrecognised name is ignored rather than treated as a disabled source, so a+        // downgrade cannot leave the store permanently unable to re-enable something.+        val disabled = this[KEY_DISABLED_SOURCES].orEmpty()+            .mapNotNullTo(mutableSetOf()) { runCatching { AppSource.valueOf(it) }.getOrNull() }+        return AppSource.entries.toSet() - disabled+    }+     companion object {         const val DEFAULT_AUTO_INSTALL_UPDATES = false         private val KEY_AUTO_INSTALL_UPDATES =             booleanPreferencesKey("auto_install_updates")+        private val KEY_DISABLED_SOURCES =+            stringSetPreferencesKey("disabled_sources")     } }
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 96625c902d..5bcab8bb01 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/UpdateCheckWorker.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/UpdateCheckWorker.kt@@ -67,10 +67,12 @@ class UpdateCheckWorker(         val play = PlayRepository(context)         val accrescent = AccrescentRepository(context, db)         val grapheneOS = GrapheneOSRepository(context)+        val settings = SettingsRepository(context, scope)+        val enabled = settings.readEnabledSources() -        catalog.sync()+        catalog.sync(enabled)         installedRepo.refresh()-        play.restore()+        if (AppSource.PLAYSTORE in enabled) play.restore()          val installed = installedRepo.updatable.value         val fromCatalog = catalog.updatesFor(installed)@@ -80,35 +82,43 @@ class UpdateCheckWorker(         // here: only the builds GrapheneOS re-hosts are the ones this device can use. Their         // updates come from GrapheneOS's own signed index instead, below.         val index = catalog.packageIndex.value-        val unknown = installed-            .filter {-                it.packageName !in index &&-                    it.packageName !in SandboxedGooglePlay.PACKAGES+        val fromPlay = if (AppSource.PLAYSTORE in enabled) {+            val unknown = installed+                .filter {+                    it.packageName !in index &&+                        it.packageName !in SandboxedGooglePlay.PACKAGES+                }+                .map { it.packageName }+            val remote = play.details(unknown).associateBy { it.packageName }+            installed.mapNotNull { inst ->+                remote[inst.packageName]?.takeIf { it.versionCode > inst.versionCode }             }-            .map { it.packageName }-        val remote = play.details(unknown).associateBy { it.packageName }-        val fromPlay = installed.mapNotNull { inst ->-            remote[inst.packageName]?.takeIf { it.versionCode > inst.versionCode }+        } else {+            emptyList()         }          // Accrescent: refresh its signed allowlist, then ask its API for a newer build of each         // installed package it vouches for. Auto-install still routes through InstallCoordinator,         // which re-verifies signer + min-version before committing.-        accrescent.refreshRepoData()-        val accrescentIds = accrescent.appIds()-        val fromAccrescent = installed-            .filter { it.packageName in accrescentIds }-            .mapNotNull { inst ->-                val update = runCatching {-                    accrescent.updateInfo(inst.packageName, inst.versionCode)-                }.getOrNull() ?: return@mapNotNull null-                val details = accrescent.details(inst.packageName) ?: UnifiedApp(-                    packageName = inst.packageName,-                    source = AppSource.ACCRESCENT,-                    name = inst.packageName.substringAfterLast('.'),-                )-                details.copy(versionCode = update.versionCode, versionName = update.versionName)-            }+        val fromAccrescent = if (AppSource.ACCRESCENT in enabled) {+            accrescent.refreshRepoData()+            val accrescentIds = accrescent.appIds()+            installed+                .filter { it.packageName in accrescentIds }+                .mapNotNull { inst ->+                    val update = runCatching {+                        accrescent.updateInfo(inst.packageName, inst.versionCode)+                    }.getOrNull() ?: return@mapNotNull null+                    val details = accrescent.details(inst.packageName) ?: UnifiedApp(+                        packageName = inst.packageName,+                        source = AppSource.ACCRESCENT,+                        name = inst.packageName.substringAfterLast('.'),+                    )+                    details.copy(versionCode = update.versionCode, versionName = update.versionName)+                }+        } else {+            emptyList()+        }          // GrapheneOS: refresh its signed index and offer a newer build of each Sandboxed         // Google Play component that is installed. Skipped on stock Android, where these@@ -130,7 +140,6 @@ class UpdateCheckWorker(             .sortedBy { it.source.priority }             .distinctBy { it.packageName } -        val settings = SettingsRepository(context, scope)         val autoInstall = settings.readAutoInstallUpdates()          if (autoInstall && updates.isNotEmpty()) {
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 d8ec91d0f6..2099935146 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/ui/SourcesPage.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/SourcesPage.kt@@ -10,12 +10,14 @@ import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue+import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import com.vayunmathur.appstore.R+import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.data.DefaultRepos import com.vayunmathur.appstore.data.ModernAppsRepo import com.vayunmathur.appstore.data.accrescent.AccrescentRepo@@ -28,15 +30,17 @@ import com.vayunmathur.library.ui.DetailScaffold import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.OutlinedButton import com.vayunmathur.library.ui.SettingsSwitchRow+import com.vayunmathur.library.ui.Switch import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.appBarScrollBehavior import java.text.SimpleDateFormat import java.util.Date  /**- * Sources are fixed and not user-editable — see [DefaultRepos] for why. This page shows- * what each source is pinned to, so the pins can be compared against their published- * values rather than taken on faith.+ * The source list is fixed — see [DefaultRepos] for why nothing can be added to it. What the+ * user does control is which of them the store talks to at all, and this page is where that+ * choice is made. It also shows what each source is pinned to, so the pins can be compared+ * against their published values rather than taken on faith.  */ @Composable fun SourcesPage(@@ -47,7 +51,11 @@ fun SourcesPage(     val repos by viewModel.repos.collectAsState()     val home by viewModel.home.collectAsState()     val autoInstallUpdates by viewModel.autoInstallUpdates.collectAsState()+    val enabledSources by viewModel.enabledSources.collectAsState()     val fdroid = repos.find { it.url == DefaultRepos.FDROID.url }+    val noneEnabled = AppSource.TOGGLEABLE.none { it in enabledSources }+    // Sync only refreshes the two offline indexes; with both off it has nothing to fetch.+    val nothingToSync = DefaultRepos.ALL.none { it.source in enabledSources }      DetailScaffold(         title = stringResource(R.string.repositories),@@ -62,7 +70,7 @@ fun SourcesPage(         Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {             Button(                 onClick = { viewModel.syncSources() },-                enabled = !home.isSyncing,+                enabled = !home.isSyncing && !nothingToSync,                 modifier = Modifier.weight(1f),             ) {                 Text(@@ -76,6 +84,13 @@ fun SourcesPage(                 Text(stringResource(R.string.trust_page_title))             }         }+        if (noneEnabled) {+            Text(+                stringResource(R.string.sources_all_disabled),+                style = MaterialTheme.typography.labelSmall,+                color = MaterialTheme.colorScheme.error,+            )+        }         if (home.statusMessage.isNotBlank()) {             Text(                 home.statusMessage,@@ -99,6 +114,8 @@ fun SourcesPage(             pinLabel = stringResource(R.string.source_modern_apps_pin),             pins = viewModel.ownSigningCertificates,             lastSync = 0L,+            enabled = AppSource.MODERN_APPS in enabledSources,+            onEnabledChange = { viewModel.setSourceEnabled(AppSource.MODERN_APPS, it) },         )         SourceCard(             title = stringResource(R.string.source_fdroid),@@ -108,6 +125,8 @@ fun SourcesPage(                 fdroid?.fingerprint ?: DefaultRepos.FDROID.pinnedFingerprint             ),             lastSync = fdroid?.lastSync ?: 0L,+            enabled = AppSource.FDROID in enabledSources,+            onEnabledChange = { viewModel.setSourceEnabled(AppSource.FDROID, it) },         )         SourceCard(             title = stringResource(R.string.source_play),@@ -115,6 +134,8 @@ fun SourcesPage(             pinLabel = stringResource(R.string.source_play_pin),             pins = emptySet(),             lastSync = 0L,+            enabled = AppSource.PLAYSTORE in enabledSources,+            onEnabledChange = { viewModel.setSourceEnabled(AppSource.PLAYSTORE, it) },         )         SourceCard(             title = stringResource(R.string.source_accrescent),@@ -122,6 +143,8 @@ fun SourcesPage(             pinLabel = stringResource(R.string.source_accrescent_pin),             pins = setOf(AccrescentRepo.REPODATA_PUBKEY),             lastSync = 0L,+            enabled = AppSource.ACCRESCENT in enabledSources,+            onEnabledChange = { viewModel.setSourceEnabled(AppSource.ACCRESCENT, it) },             abbreviatePins = false,         )     }@@ -134,6 +157,8 @@ private fun SourceCard(     pinLabel: String,     pins: Set<String>,     lastSync: Long,+    enabled: Boolean,+    onEnabledChange: (Boolean) -> Unit,     /**      * Whether [pins] are hex certificate fingerprints to abbreviate for display. Accrescent's      * pin is a base64 signify ed25519 key, not a hex fingerprint, so it is shown verbatim.@@ -143,12 +168,21 @@ private fun SourceCard(     val locale = LocalConfiguration.current.locales[0]     Card(Modifier.fillMaxWidth()) {         Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(4.dp)) {-            Text(title, style = MaterialTheme.typography.titleSmall, fontWeight = FontWeight.SemiBold)-            Text(-                subtitle,-                style = MaterialTheme.typography.labelSmall,-                color = MaterialTheme.colorScheme.onSurfaceVariant,-            )+            Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {+                Column(Modifier.weight(1f)) {+                    Text(+                        title,+                        style = MaterialTheme.typography.titleSmall,+                        fontWeight = FontWeight.SemiBold,+                    )+                    Text(+                        subtitle,+                        style = MaterialTheme.typography.labelSmall,+                        color = MaterialTheme.colorScheme.onSurfaceVariant,+                    )+                }+                Switch(checked = enabled, onCheckedChange = onEnabledChange)+            }             Spacer(Modifier.height(4.dp))             Text(                 pinLabel,
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 3ec5106f0b..6ff2c38db8 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.kt@@ -66,6 +66,9 @@ class AppStoreViewModel(     /** Off-by-default: the periodic check may also download and install updates unattended. */     val autoInstallUpdates: StateFlow<Boolean> = settings.autoInstallUpdates +    /** The sources the user has left switched on. See [AppSource.TOGGLEABLE]. */+    val enabledSources: StateFlow<Set<AppSource>> = settings.enabledSources+     /** SHA-256 of this app's own signing certificate — the Modern Apps trust root. */     val ownSigningCertificates: Set<String> by lazy { ApkCertificates.selfSigners(context) } @@ -314,12 +317,16 @@ class AppStoreViewModel(      init {         viewModelScope.launch {+            // The persisted choice rather than the flow's optimistic default: a source the+            // user switched off must not be contacted once on every cold start while the+            // stored value is still on its way.+            val enabled = settings.readEnabledSources()             installedRepo.refresh()-            play.restore()-            loadHome()-            refreshPlayInstalledPackages()+            if (AppSource.PLAYSTORE in enabled) play.restore()+            loadHome(enabled)+            refreshPlayInstalledPackages(enabled)         }-        viewModelScope.launch { loadAccrescent() }+        viewModelScope.launch { loadAccrescent(settings.readEnabledSources()) }         viewModelScope.launch {             // Recompute catalogue-side updates whenever either half changes. The Play             // half needs a network call and is driven by checkForUpdates() instead.@@ -361,7 +368,13 @@ class AppStoreViewModel(      * account, no network) leaves the previous answer in place rather than emptying the      * library, so a transient failure can't hide apps Play was known to host.      */-    private suspend fun refreshPlayInstalledPackages() {+    private suspend fun refreshPlayInstalledPackages(+        enabled: Set<AppSource> = enabledSources.value,+    ) {+        if (AppSource.PLAYSTORE !in enabled) {+            _playInstalledPackages.value = emptySet()+            return+        }         val index = catalog.packageIndex.value         val candidates = installedRepo.apps.value             .map { it.packageName }@@ -378,7 +391,8 @@ class AppStoreViewModel(      * Refresh Accrescent's signed allowlist and its home listings. Both fail soft: a network      * blip leaves the previous rows and attribution set in place rather than emptying them.      */-    private suspend fun loadAccrescent() {+    private suspend fun loadAccrescent(enabled: Set<AppSource> = enabledSources.value) {+        if (AppSource.ACCRESCENT !in enabled) return         accrescent.refreshRepoData()         val ids = accrescent.appIds()         if (ids.isNotEmpty()) _accrescentPackages.value = ids@@ -413,7 +427,7 @@ class AppStoreViewModel(      * anonymous account. Those failing is normal — no network, no account — and leaves the      * offline rows exactly as they were rather than emptying the screen.      */-    private suspend fun loadHome() {+    private suspend fun loadHome(enabled: Set<AppSource> = enabledSources.value) {         _isLoadingHome.value = true         _recentlyUpdated.value = catalog.recentlyUpdated(RECENT_LIMIT) @@ -430,6 +444,11 @@ class AppStoreViewModel(             }         } +        if (AppSource.PLAYSTORE !in enabled) {+            _isLoadingHome.value = false+            return+        }+         val clusters = play.homeClusters()         _playSections.value = clusters             .filter { it.apps.isNotEmpty() }@@ -532,8 +551,9 @@ class AppStoreViewModel(     fun syncSources() {         if (_isSyncing.value) return         viewModelScope.launch {+            val enabled = enabledSources.value             _isSyncing.value = true-            val report = catalog.sync { step ->+            val report = catalog.sync(enabled) { step ->                 _statusMessage.value = context.getString(                     when (step) {                         SyncStep.FDROID -> R.string.sync_step_fdroid@@ -546,6 +566,7 @@ class AppStoreViewModel(              AppMessages.show(                 when {+                    report.allSkipped -> context.getString(R.string.sync_all_sources_off)                     !report.anyFailed -> context.getString(                         R.string.sync_done,                         (report.fdroidCount ?: 0) + (report.modernCount ?: 0),@@ -558,12 +579,55 @@ class AppStoreViewModel(             )              _categories.value = catalog.categories()-            loadHome()-            loadAccrescent()+            loadHome(enabled)+            loadAccrescent(enabled)             installedRepo.refresh()         }     } +    /**+     * Turn a source on or off, and make the rest of the store agree immediately.+     *+     * Disabling drops the source's cached rows and whatever it had already contributed to the+     * screens, rather than waiting for the next sync: the point of the switch is that the store+     * stops offering that source's apps, and leaving them on screen until something else+     * happens to refresh would read as the switch not working.+     */+    fun setSourceEnabled(source: AppSource, enabled: Boolean) {+        viewModelScope.launch {+            settings.setSourceEnabled(source, enabled)+            // Computed here rather than re-read from the flow: the DataStore write has to make+            // a round trip before enabledSources reflects it, and everything below needs the+            // choice the user just made.+            val next =+                if (enabled) enabledSources.value + source else enabledSources.value - source+            catalog.purgeDisabled(next)+            if (!enabled) forgetSource(source)+            _categories.value = catalog.categories()+            loadHome(next)+            loadAccrescent(next)+        }+    }++    /** Drop what a source had already contributed to the screens. */+    private fun forgetSource(source: AppSource) {+        when (source) {+            AppSource.PLAYSTORE -> {+                _playSections.value = emptyList()+                _playUpdates.value = emptyList()+                _playInstalledPackages.value = emptySet()+            }+            AppSource.ACCRESCENT -> {+                _accrescentApps.value = emptyList()+                _accrescentPackages.value = emptySet()+                _accrescentUpdates.value = emptyList()+            }+            // The offline sources have no in-memory rows of their own: browse, search and the+            // update check all read the Room cache that purgeDisabled just emptied.+            else -> Unit+        }+    }+     // --- Search -----------------------------------------------------------------------      override fun setSearch(query: String) {@@ -578,6 +642,7 @@ class AppStoreViewModel(         searchJob = viewModelScope.launch {             delay(SEARCH_DEBOUNCE_MS)             _isSearching.value = true+            val enabled = enabledSources.value              // Local first and published immediately: the F-Droid catalogue is on disk, so             // there is no reason to make the user wait on Play before seeing anything.@@ -586,8 +651,9 @@ class AppStoreViewModel(              // Accrescent search is client-side over the listings already cached from the home             // carousel (its API has no search RPC), so it adds no network round-trip here.-            val accrescentResults = accrescent.search(query)-            val remote = play.search(query)+            val accrescentResults =+                if (AppSource.ACCRESCENT in enabled) accrescent.search(query) else emptyList()+            val remote = if (AppSource.PLAYSTORE in enabled) play.search(query) else emptyList()             _searchResults.value = rank(merge(local, remote, accrescentResults), query)             _isSearching.value = false             _hasSearched.value = true@@ -665,7 +731,9 @@ class AppStoreViewModel(             }             // Play listings from a cluster are shells: no description, no             // screenshots, no version code. Fill them in before the page settles.-            if (app.source == AppSource.PLAYSTORE && app.screenshots.isEmpty()) {+            if (app.source == AppSource.PLAYSTORE && app.screenshots.isEmpty() &&+                AppSource.PLAYSTORE in enabledSources.value+            ) {                 _isLoadingDetails.value = true                 val details = play.details(app.packageName)                 if (details != null) _selectedApp.value = details@@ -692,8 +760,10 @@ class AppStoreViewModel(                 source = AppSource.PLAYSTORE,                 name = packageName.substringAfterLast('.'),             )-            val details = play.details(packageName)-            if (details != null) _selectedApp.value = details+            if (AppSource.PLAYSTORE in enabledSources.value) {+                val details = play.details(packageName)+                if (details != null) _selectedApp.value = details+            }             _isLoadingDetails.value = false         }     }@@ -801,6 +871,7 @@ class AppStoreViewModel(     override fun checkForUpdates() {         if (_isCheckingUpdates.value) return         viewModelScope.launch {+            val enabled = enabledSources.value             _isCheckingUpdates.value = true             _statusMessage.value = context.getString(R.string.updates_checking) @@ -814,29 +885,33 @@ class AppStoreViewModel(             // updates come from its signed index below instead.             val index = catalog.packageIndex.value             val installed = installedRepo.updatable.value-            val playCandidates = installed-                .filter {-                    it.packageName !in index &&-                        it.packageName !in SandboxedGooglePlay.PACKAGES-                }-                .map { it.packageName }+            if (AppSource.PLAYSTORE in enabled) {+                val playCandidates = installed+                    .filter {+                        it.packageName !in index &&+                            it.packageName !in SandboxedGooglePlay.PACKAGES+                    }+                    .map { it.packageName } -            val remote = play.details(playCandidates).associateBy { it.packageName }-            _playUpdates.value = installed.mapNotNull { inst ->-                remote[inst.packageName]?.takeIf { it.versionCode > inst.versionCode }+                val remote = play.details(playCandidates).associateBy { it.packageName }+                _playUpdates.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()) _playInstalledPackages.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()) _playInstalledPackages.value = remote.keys.toSet()              // Accrescent: refresh the signed allowlist, then ask its API for a newer build of             // each installed package it vouches for.-            accrescent.refreshRepoData()-            val accrescentIds = accrescent.appIds()-            if (accrescentIds.isNotEmpty()) _accrescentPackages.value = accrescentIds-            _accrescentUpdates.value = installed-                .filter { it.packageName in accrescentIds }-                .mapNotNull { inst -> accrescentUpdate(inst.packageName, inst.versionCode) }+            if (AppSource.ACCRESCENT in enabled) {+                accrescent.refreshRepoData()+                val accrescentIds = accrescent.appIds()+                if (accrescentIds.isNotEmpty()) _accrescentPackages.value = accrescentIds+                _accrescentUpdates.value = installed+                    .filter { it.packageName in accrescentIds }+                    .mapNotNull { inst -> accrescentUpdate(inst.packageName, inst.versionCode) }+            }              // GrapheneOS: its signed index is the only place a Sandboxed Google Play update             // can come from, which is why the three are held back from the Play list above.
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 b25519e2a4..b2d2ba5705 100644--- a/appstore/src/main/res/values/strings.xml+++ b/appstore/src/main/res/values/strings.xml@@ -10,7 +10,10 @@     <string name="this_will_uninstall_you_can_reinstall_la">%1$s will be removed. You can install it again any time.</string>     <string name="last_sync">Last sync: %1$s</string>     <string name="repositories">Sources</string>-    <string name="sources_are_fixed">These three sources are built in and cannot be changed. Other F-Droid repos just hand out binaries someone else built, so there is nothing to check them against.</string>+    <!-- Sources page, under the title. Explains that the list is fixed but each entry can be switched off. -->+    <string name="sources_are_fixed">These sources are built in and no others can be added — other F-Droid repos just hand out binaries someone else built, so there is nothing to check them against. Switch off any you do not want the store to use.</string>+    <!-- Sources page, warning shown when the user has switched every source off. -->+    <string name="sources_all_disabled">Every source is switched off, so there is nothing to browse, search or update from.</string>      <!-- Bottom navigation. -->     <string name="nav_home">Home</string>@@ -50,6 +53,8 @@     <string name="sync_failed_all">Neither source would sync. Your existing catalogue is unchanged.</string>     <string name="sync_failed_fdroid">F-Droid didn\'t sync. Its existing apps are unchanged.</string>     <string name="sync_failed_modern_apps">Modern Apps didn\'t sync. Its existing apps are unchanged.</string>+    <!-- Message after tapping Sync sources with every source switched off. -->+    <string name="sync_all_sources_off">Nothing to sync — every source is switched off.</string>     <string name="play_unavailable">Play Store results unavailable: %1$s</string>      <!-- Search. -->