[db] Expose locales list to client
so that the client may have the liberty to specify a custom locales list to resolve localized content when updating the repos
This commit is contained in:
parent
52e3905f4c
commit
8a7897cba2
|
@ -24,7 +24,7 @@ internal class DbV1StreamReceiver(
|
|||
private val compatibilityChecker: CompatibilityChecker,
|
||||
) : IndexV1StreamReceiver {
|
||||
|
||||
private val locales: LocaleListCompat = getLocales(Resources.getSystem().configuration)
|
||||
var locales: LocaleListCompat = getLocales(Resources.getSystem().configuration)
|
||||
|
||||
override fun receive(repo: RepoV2, version: Long, certificate: String?) {
|
||||
db.getRepositoryDao().clear(repoId)
|
||||
|
|
|
@ -13,7 +13,7 @@ internal class DbV2DiffStreamReceiver(
|
|||
private val compatibilityChecker: CompatibilityChecker,
|
||||
) : IndexV2DiffStreamReceiver {
|
||||
|
||||
private val locales: LocaleListCompat = getLocales(Resources.getSystem().configuration)
|
||||
var locales: LocaleListCompat = getLocales(Resources.getSystem().configuration)
|
||||
|
||||
override fun receiveRepoDiff(version: Long, repoJsonObject: JsonObject) {
|
||||
db.getRepositoryDao().updateRepository(repoId, version, repoJsonObject)
|
||||
|
|
|
@ -23,7 +23,7 @@ internal class DbV2StreamReceiver(
|
|||
private val compatibilityChecker: CompatibilityChecker,
|
||||
) : IndexV2StreamReceiver {
|
||||
|
||||
private val locales: LocaleListCompat = getLocales(Resources.getSystem().configuration)
|
||||
var locales: LocaleListCompat = getLocales(Resources.getSystem().configuration)
|
||||
private var clearedRepoData = false
|
||||
private val nonNullFileV2: (FileV2?) -> Unit = { fileV2 ->
|
||||
if (fileV2 != null) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.fdroid.index
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import org.fdroid.database.Repository
|
||||
import org.fdroid.download.Downloader
|
||||
import org.fdroid.download.NotFoundException
|
||||
|
@ -56,6 +57,8 @@ public abstract class IndexUpdater {
|
|||
*/
|
||||
public abstract val formatVersion: IndexFormatVersion
|
||||
|
||||
public abstract var locales: LocaleListCompat?
|
||||
|
||||
/**
|
||||
* Updates a new [repo] for the first time.
|
||||
*/
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.net.Uri
|
|||
import androidx.annotation.AnyThread
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.asLiveData
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
|
@ -71,6 +72,11 @@ public class RepoManager @JvmOverloads constructor(
|
|||
*/
|
||||
private val repoCountDownLatch = CountDownLatch(1)
|
||||
|
||||
public var locales: LocaleListCompat? = null
|
||||
set(value) {
|
||||
repoAdder?.locales = value
|
||||
}
|
||||
|
||||
init {
|
||||
// we need to load the repositories first off the UiThread, so it doesn't deadlock
|
||||
GlobalScope.launch(coroutineContext) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.fdroid.index
|
||||
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import mu.KotlinLogging
|
||||
import org.fdroid.CompatibilityChecker
|
||||
import org.fdroid.database.FDroidDatabase
|
||||
|
@ -27,6 +28,8 @@ public class RepoUpdater(
|
|||
File.createTempFile("dl-", "", tempDir)
|
||||
}
|
||||
|
||||
public var locales: LocaleListCompat? = null
|
||||
|
||||
/**
|
||||
* A list of [IndexUpdater]s to try, sorted by newest first.
|
||||
*/
|
||||
|
@ -82,6 +85,9 @@ public class RepoUpdater(
|
|||
doUpdate: (IndexUpdater) -> IndexUpdateResult,
|
||||
): IndexUpdateResult {
|
||||
indexUpdater.forEach { updater ->
|
||||
locales?.also {
|
||||
updater.locales = it
|
||||
}
|
||||
// don't downgrade to older updaters if repo used new format already
|
||||
val repoFormatVersion = repo.formatVersion
|
||||
if (repoFormatVersion != null && repoFormatVersion > updater.formatVersion) {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
package org.fdroid.index.v1
|
||||
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import mu.KotlinLogging
|
||||
import org.fdroid.CompatibilityChecker
|
||||
import org.fdroid.database.DbV1StreamReceiver
|
||||
|
@ -35,6 +36,8 @@ public class IndexV1Updater(
|
|||
public override val formatVersion: IndexFormatVersion = ONE
|
||||
private val db: FDroidDatabaseInt = database as FDroidDatabaseInt
|
||||
|
||||
public override var locales: LocaleListCompat? = null
|
||||
|
||||
override fun update(
|
||||
repo: Repository,
|
||||
certificate: String?,
|
||||
|
@ -66,6 +69,9 @@ public class IndexV1Updater(
|
|||
val (cert, _) = verifier.getStreamAndVerify { inputStream ->
|
||||
listener?.onUpdateProgress(repo, 0, 0)
|
||||
val streamReceiver = DbV1StreamReceiver(db, repo.repoId, compatibilityChecker)
|
||||
locales?.also {
|
||||
streamReceiver.locales = it
|
||||
}
|
||||
val streamProcessor =
|
||||
IndexV1StreamProcessor(streamReceiver, certificate, repo.timestamp)
|
||||
streamProcessor.process(inputStream)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.fdroid.index.v2
|
||||
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import org.fdroid.CompatibilityChecker
|
||||
import org.fdroid.database.DbV2DiffStreamReceiver
|
||||
import org.fdroid.database.DbV2StreamReceiver
|
||||
|
@ -34,6 +35,8 @@ public class IndexV2Updater(
|
|||
public override val formatVersion: IndexFormatVersion = TWO
|
||||
private val db: FDroidDatabaseInt = database as FDroidDatabaseInt
|
||||
|
||||
public override var locales: LocaleListCompat? = null
|
||||
|
||||
override fun update(
|
||||
repo: Repository,
|
||||
certificate: String?,
|
||||
|
@ -47,11 +50,17 @@ public class IndexV2Updater(
|
|||
return if (diff == null || repo.formatVersion == ONE) {
|
||||
// no diff found (or this is upgrade from v1 repo), so do full index update
|
||||
val streamReceiver = DbV2StreamReceiver(db, repo.repoId, compatibilityChecker)
|
||||
locales?.also {
|
||||
streamReceiver.locales = it
|
||||
}
|
||||
val streamProcessor = IndexV2FullStreamProcessor(streamReceiver, cert)
|
||||
processStream(repo, entry.index, entry.version, streamProcessor)
|
||||
} else {
|
||||
// use available diff
|
||||
val streamReceiver = DbV2DiffStreamReceiver(db, repo.repoId, compatibilityChecker)
|
||||
locales?.also {
|
||||
streamReceiver.locales = it
|
||||
}
|
||||
val streamProcessor = IndexV2DiffStreamProcessor(streamReceiver)
|
||||
processStream(repo, diff, entry.version, streamProcessor)
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import androidx.annotation.AnyThread
|
|||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.core.content.ContextCompat.getSystemService
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
|
@ -117,6 +118,8 @@ internal class RepoAdder(
|
|||
|
||||
private var fetchJob: Job? = null
|
||||
|
||||
var locales: LocaleListCompat? = null
|
||||
|
||||
internal fun fetchRepository(url: String, proxy: Proxy?) {
|
||||
fetchJob = GlobalScope.launch(coroutineContext) {
|
||||
fetchRepositoryInt(url, proxy)
|
||||
|
@ -128,6 +131,7 @@ internal class RepoAdder(
|
|||
internal suspend fun fetchRepositoryInt(
|
||||
url: String,
|
||||
proxy: Proxy? = null,
|
||||
locales: LocaleListCompat? = null,
|
||||
) {
|
||||
if (hasDisallowInstallUnknownSources(context)) {
|
||||
addRepoState.value = AddRepoError(UNKNOWN_SOURCES_DISALLOWED)
|
||||
|
@ -175,7 +179,8 @@ internal class RepoAdder(
|
|||
|
||||
// try fetching repo with v2 format first and fallback to v1
|
||||
try {
|
||||
fetchRepo(nUri.uri, nUri.fingerprint, proxy, nUri.username, nUri.password, receiver)
|
||||
fetchRepo(nUri.uri, nUri.fingerprint, proxy, nUri.username, nUri.password, receiver,
|
||||
locales)
|
||||
} catch (e: SigningException) {
|
||||
log.error(e) { "Error verifying repo with given fingerprint." }
|
||||
addRepoState.value = AddRepoError(INVALID_FINGERPRINT, e)
|
||||
|
@ -209,6 +214,7 @@ internal class RepoAdder(
|
|||
username: String?,
|
||||
password: String?,
|
||||
receiver: RepoPreviewReceiver,
|
||||
locales: LocaleListCompat?,
|
||||
) {
|
||||
try {
|
||||
val repo =
|
||||
|
@ -216,6 +222,9 @@ internal class RepoAdder(
|
|||
val repoFetcher = RepoV2Fetcher(
|
||||
tempFileProvider, downloaderFactory, httpManager, repoUriBuilder, proxy
|
||||
)
|
||||
locales?.also {
|
||||
repoFetcher.locales = it
|
||||
}
|
||||
repoFetcher.fetchRepo(uri, repo, receiver, fingerprint)
|
||||
} catch (e: NotFoundException) {
|
||||
log.warn(e) { "Did not find v2 repo, trying v1 now." }
|
||||
|
@ -223,6 +232,9 @@ internal class RepoAdder(
|
|||
val repo =
|
||||
getTempRepo(uri, IndexFormatVersion.ONE, username, password)
|
||||
val repoFetcher = RepoV1Fetcher(tempFileProvider, downloaderFactory, repoUriBuilder)
|
||||
locales?.also {
|
||||
repoFetcher.locales = it
|
||||
}
|
||||
repoFetcher.fetchRepo(uri, repo, receiver, fingerprint)
|
||||
}
|
||||
}
|
||||
|
@ -314,7 +326,8 @@ internal class RepoAdder(
|
|||
}
|
||||
|
||||
@AnyThread
|
||||
internal suspend fun addArchiveRepo(repo: Repository, proxy: Proxy? = null) =
|
||||
internal suspend fun addArchiveRepo(repo: Repository, proxy: Proxy? = null,
|
||||
locales: LocaleListCompat? = null) =
|
||||
withContext(coroutineContext) {
|
||||
if (repo.isArchiveRepo) error { "Repo ${repo.address} is already an archive repo." }
|
||||
|
||||
|
@ -345,7 +358,7 @@ internal class RepoAdder(
|
|||
}
|
||||
}
|
||||
val uri = Uri.parse(address)
|
||||
fetchRepo(uri, repo.fingerprint, proxy, repo.username, repo.password, receiver)
|
||||
fetchRepo(uri, repo.fingerprint, proxy, repo.username, repo.password, receiver, locales)
|
||||
}
|
||||
|
||||
private fun hasDisallowInstallUnknownSources(context: Context): Boolean {
|
||||
|
|
|
@ -24,7 +24,7 @@ internal class RepoV1Fetcher(
|
|||
private val repoUriBuilder: RepoUriBuilder,
|
||||
) : RepoFetcher {
|
||||
|
||||
private val locales: LocaleListCompat = getLocales(Resources.getSystem().configuration)
|
||||
var locales: LocaleListCompat = getLocales(Resources.getSystem().configuration)
|
||||
|
||||
@Throws(SigningException::class, SerializationException::class)
|
||||
override suspend fun fetchRepo(
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.fdroid.repo
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import mu.KotlinLogging
|
||||
import org.fdroid.database.Repository
|
||||
import org.fdroid.download.DownloadRequest
|
||||
|
@ -29,6 +30,8 @@ internal class RepoV2Fetcher(
|
|||
) : RepoFetcher {
|
||||
private val log = KotlinLogging.logger {}
|
||||
|
||||
var locales: LocaleListCompat? = null
|
||||
|
||||
@Throws(SigningException::class)
|
||||
override suspend fun fetchRepo(
|
||||
uri: Uri,
|
||||
|
@ -57,6 +60,9 @@ internal class RepoV2Fetcher(
|
|||
log.info { "Downloaded entry, now streaming index..." }
|
||||
|
||||
val streamReceiver = RepoV2StreamReceiver(receiver, repo.username, repo.password)
|
||||
locales?.also {
|
||||
streamReceiver.locales = it
|
||||
}
|
||||
val streamProcessor = IndexV2FullStreamProcessor(streamReceiver, cert)
|
||||
val digestInputStream = if (uri.scheme?.startsWith("http") == true) {
|
||||
// stream index for http(s) downloads
|
||||
|
|
|
@ -78,7 +78,7 @@ internal open class RepoV2StreamReceiver(
|
|||
)
|
||||
}
|
||||
|
||||
private val locales: LocaleListCompat = getLocales(Resources.getSystem().configuration)
|
||||
var locales: LocaleListCompat = getLocales(Resources.getSystem().configuration)
|
||||
|
||||
override fun receive(repo: RepoV2, version: Long, certificate: String) {
|
||||
receiver.onRepoReceived(
|
||||
|
|
Loading…
Reference in New Issue