Pier Angelo Vendrame pushed to branch firefox-android-115.2.1-13.5-1 at The Tor Project / Applications / firefox-android
Commits:
-
9020793e
by Pier Angelo Vendrame at 2024-06-10T16:02:49+02:00
3 changed files:
- − fenix/app/src/main/assets/allowed_addons.json
- fenix/app/src/main/java/org/mozilla/fenix/components/Components.kt
- − fenix/app/src/main/java/org/mozilla/fenix/components/TorAddonCollectionProvider.kt
Changes:
| ... | ... | @@ -12,6 +12,7 @@ import androidx.compose.ui.platform.LocalContext |
| 12 | 12 | import androidx.core.app.NotificationManagerCompat
|
| 13 | 13 | import com.google.android.play.core.review.ReviewManagerFactory
|
| 14 | 14 | import mozilla.components.feature.addons.AddonManager
|
| 15 | +import mozilla.components.feature.addons.amo.AddonCollectionProvider
|
|
| 15 | 16 | import mozilla.components.feature.addons.migration.DefaultSupportedAddonsChecker
|
| 16 | 17 | import mozilla.components.feature.addons.update.DefaultAddonUpdater
|
| 17 | 18 | import mozilla.components.feature.autofill.AutofillConfiguration
|
| ... | ... | @@ -113,7 +114,32 @@ class Components(private val context: Context) { |
| 113 | 114 | }
|
| 114 | 115 | |
| 115 | 116 | val addonCollectionProvider by lazyMonitored {
|
| 116 | - TorAddonCollectionProvider(context, core.client)
|
|
| 117 | + // Check if we have a customized (overridden) AMO collection (supported in Nightly & Beta)
|
|
| 118 | + if (FeatureFlags.customExtensionCollectionFeature && context.settings().amoCollectionOverrideConfigured()) {
|
|
| 119 | + AddonCollectionProvider(
|
|
| 120 | + context,
|
|
| 121 | + core.client,
|
|
| 122 | + collectionUser = context.settings().overrideAmoUser,
|
|
| 123 | + collectionName = context.settings().overrideAmoCollection,
|
|
| 124 | + )
|
|
| 125 | + }
|
|
| 126 | + // Use build config otherwise
|
|
| 127 | + else if (!BuildConfig.AMO_COLLECTION_USER.isNullOrEmpty() &&
|
|
| 128 | + !BuildConfig.AMO_COLLECTION_NAME.isNullOrEmpty()
|
|
| 129 | + ) {
|
|
| 130 | + AddonCollectionProvider(
|
|
| 131 | + context,
|
|
| 132 | + core.client,
|
|
| 133 | + serverURL = BuildConfig.AMO_SERVER_URL,
|
|
| 134 | + collectionUser = BuildConfig.AMO_COLLECTION_USER,
|
|
| 135 | + collectionName = BuildConfig.AMO_COLLECTION_NAME,
|
|
| 136 | + maxCacheAgeInMinutes = AMO_COLLECTION_MAX_CACHE_AGE,
|
|
| 137 | + )
|
|
| 138 | + }
|
|
| 139 | + // Fall back to defaults
|
|
| 140 | + else {
|
|
| 141 | + AddonCollectionProvider(context, core.client, maxCacheAgeInMinutes = AMO_COLLECTION_MAX_CACHE_AGE)
|
|
| 142 | + }
|
|
| 117 | 143 | }
|
| 118 | 144 | |
| 119 | 145 | @Suppress("MagicNumber")
|
| 1 | -/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
| 2 | - * License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
| 3 | - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
| 4 | - |
|
| 5 | -// Copyright (c) 2020, The Tor Project, Inc.
|
|
| 6 | - |
|
| 7 | -package org.mozilla.fenix.components
|
|
| 8 | - |
|
| 9 | -import android.content.Context
|
|
| 10 | -import android.graphics.Bitmap
|
|
| 11 | -import kotlinx.coroutines.withContext
|
|
| 12 | -import mozilla.components.concept.fetch.Client
|
|
| 13 | -import mozilla.components.feature.addons.Addon
|
|
| 14 | -import kotlinx.coroutines.Dispatchers
|
|
| 15 | -import mozilla.components.feature.addons.amo.AddonCollectionProvider
|
|
| 16 | -import java.io.IOException
|
|
| 17 | - |
|
| 18 | -internal const val COLLECTION_NAME = "tor_browser_collection"
|
|
| 19 | -internal const val ALLOWED_ADDONS_PATH = "allowed_addons.json"
|
|
| 20 | -internal const val MAX_CACHE_AGE = 1000L * 365L * 24L * 60L // 1000 years
|
|
| 21 | - |
|
| 22 | -class TorAddonCollectionProvider(
|
|
| 23 | - private val context: Context,
|
|
| 24 | - client: Client
|
|
| 25 | -) : AddonCollectionProvider(
|
|
| 26 | - context, client, serverURL = "",
|
|
| 27 | - collectionName = COLLECTION_NAME,
|
|
| 28 | - maxCacheAgeInMinutes = MAX_CACHE_AGE
|
|
| 29 | -) {
|
|
| 30 | - private var isCacheLoaded = false
|
|
| 31 | - |
|
| 32 | - @Throws(IOException::class)
|
|
| 33 | - override suspend fun getAvailableAddons(
|
|
| 34 | - allowCache: Boolean,
|
|
| 35 | - readTimeoutInSeconds: Long?,
|
|
| 36 | - language: String?
|
|
| 37 | - ): List<Addon> {
|
|
| 38 | - ensureCache(language)
|
|
| 39 | - return super.getAvailableAddons(true, readTimeoutInSeconds, language)
|
|
| 40 | - }
|
|
| 41 | - |
|
| 42 | - @Throws(IOException::class)
|
|
| 43 | - override suspend fun getAddonIconBitmap(addon: Addon): Bitmap? {
|
|
| 44 | - // super.getAddonIconBitmap does not look at the cache, so calling
|
|
| 45 | - // ensureCache here is not helpful. In addition, now the cache depends
|
|
| 46 | - // on a language, and that isn't available right now.
|
|
| 47 | - // ensureCache(language)
|
|
| 48 | - return super.getAddonIconBitmap(addon)
|
|
| 49 | - }
|
|
| 50 | - |
|
| 51 | - @Throws(IOException::class)
|
|
| 52 | - private suspend fun ensureCache(language: String?) {
|
|
| 53 | - if (isCacheLoaded) {
|
|
| 54 | - return
|
|
| 55 | - }
|
|
| 56 | - return withContext(Dispatchers.IO) {
|
|
| 57 | - val data = context.assets.open(ALLOWED_ADDONS_PATH).bufferedReader().use {
|
|
| 58 | - it.readText()
|
|
| 59 | - }
|
|
| 60 | - writeToDiskCache(data, language)
|
|
| 61 | - isCacheLoaded = true
|
|
| 62 | - }
|
|
| 63 | - }
|
|
| 64 | -} |