let the user allow downloads on mobile data

Downloads asked the platform for an unmetered network and nothing more, so
there was no way to run them on mobile. A setting under Downloads now decides,
defaulting to Wi-Fi only, and it also governs roaming: the platform permits
roaming by default, which would have contradicted the Wi-Fi-only choice.

The flag rides the enqueue request like the download quality does, cached in the
source repository so the poller does not read the preference per row.
This commit is contained in:
austinried
2026-10-04 00:30:03 +00:00
parent 02b3ddbb98
commit caf8369924
9 changed files with 81 additions and 4 deletions
@@ -52,6 +52,7 @@ class DownloadRepositoryTest {
private lateinit var repository: DownloadRepository
private lateinit var artwork: ArtworkStore
private lateinit var dir: File
private val prefs = fakeUserPreferences()
private val messages = CopyOnWriteArrayList<String>()
private val requestedArt = CopyOnWriteArrayList<String>()
private val artFetchedAfterTheEngineRequest = CopyOnWriteArrayList<Boolean>()
@@ -73,7 +74,7 @@ class DownloadRepositoryTest {
.setDriver(BundledSQLiteDriver())
.build()
artwork = ArtworkStore(File(context.cacheDir, "art-${System.nanoTime()}"))
sources = SourceRepository(db, OkHttpClient(), fakeUserPreferences(), artwork)
sources = SourceRepository(db, OkHttpClient(), prefs, artwork)
engine = FakeDownloadEngine()
dir = File(context.cacheDir, "downloads-${System.nanoTime()}")
repository =
@@ -956,6 +957,29 @@ class DownloadRepositoryTest {
assertNull(repository.localUri("s1"))
}
@Test
fun downloadsAreWifiOnlyUntilThePreferenceAllowsMetered() =
runTest {
seedLibrary()
runBlocking { repository.download(1, "s1") }
assertFalse(
engine.requests
.single()
.second.allowMetered,
)
prefs.setDownloadOverMetered(true)
await { sources.downloadsAllowedOverMetered() }
runBlocking { repository.download(1, "s2") }
assertTrue(
engine.requests
.last()
.second.allowMetered,
)
}
private fun requestedSongIds(): List<String> = engine.requests.map { it.second.path.substringAfterLast('/') }
private fun seedSongs(tracks: IntRange) {
@@ -344,12 +344,14 @@ class AppScreenshotTest {
mobileQuality = StreamQuality(192, "mp3"),
syncConcurrency = 4,
downloadQuality = StreamQuality(128, "opus"),
downloadOverMetered = false,
onSelectSource = {},
onEditServer = {},
onWifiQualityChange = {},
onMobileQualityChange = {},
onSyncConcurrencyChange = {},
onDownloadQualityChange = {},
onDownloadOverMeteredChange = {},
onAddServer = {},
onOpenDownloads = {},
onBack = {},