Skip to content
Snippets Groups Projects
Verified Commit 9020793e authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame :jack_o_lantern:
Browse files

fixup! Modify add-on support

Bug 42619: Remove our custom AddonCollectionProvider.

Our own custom list of allowed addons will get outdate very soon,
breaking the installation of addons from AMO, and maybe preventing the
update of the ones already installed.

However, the AMO collection might not be available until the boostrap is
done in some conditions (when it has never been cached, or if the cache
expired) and in these cases the installed addons will not be displayed
either.
parent 15bb1028
Branches
No related tags found
1 merge request!111Bug 42619: Remove our custom AddonCollectionProvider.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -12,6 +12,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.core.app.NotificationManagerCompat
import com.google.android.play.core.review.ReviewManagerFactory
import mozilla.components.feature.addons.AddonManager
import mozilla.components.feature.addons.amo.AddonCollectionProvider
import mozilla.components.feature.addons.migration.DefaultSupportedAddonsChecker
import mozilla.components.feature.addons.update.DefaultAddonUpdater
import mozilla.components.feature.autofill.AutofillConfiguration
......@@ -113,7 +114,32 @@ class Components(private val context: Context) {
}
val addonCollectionProvider by lazyMonitored {
TorAddonCollectionProvider(context, core.client)
// Check if we have a customized (overridden) AMO collection (supported in Nightly & Beta)
if (FeatureFlags.customExtensionCollectionFeature && context.settings().amoCollectionOverrideConfigured()) {
AddonCollectionProvider(
context,
core.client,
collectionUser = context.settings().overrideAmoUser,
collectionName = context.settings().overrideAmoCollection,
)
}
// Use build config otherwise
else if (!BuildConfig.AMO_COLLECTION_USER.isNullOrEmpty() &&
!BuildConfig.AMO_COLLECTION_NAME.isNullOrEmpty()
) {
AddonCollectionProvider(
context,
core.client,
serverURL = BuildConfig.AMO_SERVER_URL,
collectionUser = BuildConfig.AMO_COLLECTION_USER,
collectionName = BuildConfig.AMO_COLLECTION_NAME,
maxCacheAgeInMinutes = AMO_COLLECTION_MAX_CACHE_AGE,
)
}
// Fall back to defaults
else {
AddonCollectionProvider(context, core.client, maxCacheAgeInMinutes = AMO_COLLECTION_MAX_CACHE_AGE)
}
}
@Suppress("MagicNumber")
......
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Copyright (c) 2020, The Tor Project, Inc.
package org.mozilla.fenix.components
import android.content.Context
import android.graphics.Bitmap
import kotlinx.coroutines.withContext
import mozilla.components.concept.fetch.Client
import mozilla.components.feature.addons.Addon
import kotlinx.coroutines.Dispatchers
import mozilla.components.feature.addons.amo.AddonCollectionProvider
import java.io.IOException
internal const val COLLECTION_NAME = "tor_browser_collection"
internal const val ALLOWED_ADDONS_PATH = "allowed_addons.json"
internal const val MAX_CACHE_AGE = 1000L * 365L * 24L * 60L // 1000 years
class TorAddonCollectionProvider(
private val context: Context,
client: Client
) : AddonCollectionProvider(
context, client, serverURL = "",
collectionName = COLLECTION_NAME,
maxCacheAgeInMinutes = MAX_CACHE_AGE
) {
private var isCacheLoaded = false
@Throws(IOException::class)
override suspend fun getAvailableAddons(
allowCache: Boolean,
readTimeoutInSeconds: Long?,
language: String?
): List<Addon> {
ensureCache(language)
return super.getAvailableAddons(true, readTimeoutInSeconds, language)
}
@Throws(IOException::class)
override suspend fun getAddonIconBitmap(addon: Addon): Bitmap? {
// super.getAddonIconBitmap does not look at the cache, so calling
// ensureCache here is not helpful. In addition, now the cache depends
// on a language, and that isn't available right now.
// ensureCache(language)
return super.getAddonIconBitmap(addon)
}
@Throws(IOException::class)
private suspend fun ensureCache(language: String?) {
if (isCacheLoaded) {
return
}
return withContext(Dispatchers.IO) {
val data = context.assets.open(ALLOWED_ADDONS_PATH).bufferedReader().use {
it.readText()
}
writeToDiskCache(data, language)
isCacheLoaded = true
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment