Bug 1866293 - Add support for installing an add-on a from local file.

fenix/122.0
Arturo Mejia 6 months ago committed by mergify[bot]
parent 9b519f65fb
commit 8abee316da

@ -36,6 +36,7 @@ import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.AuthType
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.concept.sync.Profile
import mozilla.components.feature.addons.ui.AddonFilePicker
import mozilla.components.service.glean.private.NoExtras
import mozilla.components.support.ktx.android.view.showKeyboard
import mozilla.components.ui.widgets.withCenterAlignedButtons
@ -70,6 +71,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
private val args by navArgs<SettingsFragmentArgs>()
private lateinit var accountUiView: AccountUiView
private lateinit var addonFilePicker: AddonFilePicker
private val profilerViewModel: ProfilerViewModel by activityViewModels()
@VisibleForTesting
@ -107,6 +109,18 @@ class SettingsFragment : PreferenceFragmentCompat() {
updateFxAAllowDomesticChinaServerMenu = ::updateFxAAllowDomesticChinaServerMenu,
)
addonFilePicker = AddonFilePicker(
requireContext(),
requireComponents.addonManager,
) {
Toast.makeText(
context,
getString(R.string.mozac_feature_addons_failed_to_install_generic),
Toast.LENGTH_LONG,
).show()
}
addonFilePicker.registerForResults(this)
// It's important to update the account UI state in onCreate since that ensures we'll never
// display an incorrect state in the UI. We take care to not also call it as part of onResume
// if it was just called here (via the 'creatingFragment' flag).
@ -386,6 +400,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
resources.getString(R.string.pref_key_nimbus_experiments) -> {
SettingsFragmentDirections.actionSettingsFragmentToNimbusExperimentsFragment()
}
resources.getString(R.string.pref_key_install_local_addon) -> {
addonFilePicker.launch()
null
}
resources.getString(R.string.pref_key_override_amo_collection) -> {
val context = requireContext()
val dialogView = LayoutInflater.from(context).inflate(R.layout.amo_collection_override_dialog, null)
@ -488,6 +506,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
(requireContext().components.core.engine.profiler?.isProfilerActive() != null)
}
setupCookieBannerPreference()
setupInstallAddonFromFilePreference(requireContext().settings())
setupAmoCollectionOverridePreference(requireContext().settings())
setupGeckoLogsPreference(requireContext().settings())
setupAllowDomesticChinaFxaServerPreference()
@ -698,6 +717,13 @@ class SettingsFragment : PreferenceFragmentCompat() {
}
}
@VisibleForTesting
internal fun setupInstallAddonFromFilePreference(settings: Settings) {
with(requirePreference<Preference>(R.string.pref_key_install_local_addon)) {
isVisible = settings.showSecretDebugMenuThisSession
}
}
@VisibleForTesting
internal fun setupHttpsOnlyPreferences() {
val httpsOnlyPreference =

@ -38,6 +38,7 @@
<string name="pref_key_delete_browsing_data_on_quit_categories" translatable="false">pref_key_delete_browsing_data_on_quit_categories</string>
<string name="pref_key_last_known_mode_private" translatable="false">pref_key_last_known_mode_private</string>
<string name="pref_key_addons" translatable="false">pref_key_addons</string>
<string name="pref_key_install_local_addon" translatable="false">pref_key_install_local_addon</string>
<string name="pref_key_override_amo_user" translatable="false">pref_key_override_amo_user</string>
<string name="pref_key_override_amo_collection" translatable="false">pref_key_override_amo_collection</string>
<string name="pref_key_enable_gecko_logs" translatable="false">pref_key_enable_gecko_logs</string>

@ -610,6 +610,8 @@
<!-- Preference for add_ons -->
<string name="preferences_addons">Add-ons</string>
<!-- Preference for installing a local add-on -->
<string name="preferences_install_local_addon">Install add-on from file</string>
<!-- Preference for notifications -->
<string name="preferences_notifications">Notifications</string>
<!-- Summary for notification preference indicating notifications are allowed -->

@ -149,6 +149,12 @@
app:iconSpaceReserved="false"
android:title="@string/preferences_addons" />
<androidx.preference.Preference
android:key="@string/pref_key_install_local_addon"
app:iconSpaceReserved="false"
app:isPreferenceVisible="false"
android:title="@string/preferences_install_local_addon" />
<androidx.preference.Preference
android:key="@string/pref_key_override_amo_collection"
app:iconSpaceReserved="false"

@ -31,6 +31,7 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.Config
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
@ -57,6 +58,7 @@ class SettingsFragmentTest {
every { testContext.components.core.engine.profiler } returns mockk(relaxed = true)
every { testContext.components.core.client } returns client
every { testContext.components.settings } returns mockk(relaxed = true)
every { testContext.components.addonManager } returns mockk(relaxed = true)
every { testContext.components.analytics } returns mockk(relaxed = true)
every { testContext.components.backgroundServices } returns mockk(relaxed = true)
@ -95,6 +97,33 @@ class SettingsFragmentTest {
assertTrue(preferenceAmoCollectionOverride.isVisible)
}
@Test
fun `Install add-on from file pref is visible if debug menu active and feature is enabled`() = runTestOnMain {
val settingsFragment = SettingsFragment()
val activity = Robolectric.buildActivity(FragmentActivity::class.java).create().get()
activity.supportFragmentManager.beginTransaction()
.add(settingsFragment, "test")
.commitNow()
advanceUntilIdle()
val preference = settingsFragment.findPreference<Preference>(
settingsFragment.getPreferenceKey(R.string.pref_key_install_local_addon),
)
settingsFragment.setupInstallAddonFromFilePreference(mockk(relaxed = true))
assertNotNull(preference)
assertFalse(preference!!.isVisible)
val settings: Settings = mockk(relaxed = true)
every { settings.showSecretDebugMenuThisSession } returns true
settingsFragment.setupInstallAddonFromFilePreference(settings)
assertTrue(preference.isVisible)
unmockkObject(Config)
}
@Test
fun `Add-on collection override pref is visible if already configured and feature is enabled`() = runTestOnMain {
val settingsFragment = SettingsFragment()

Loading…
Cancel
Save