2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/26412 - Remove try catch for NimbusFeatureException from FxNimbus value() getter

This commit is contained in:
Gabriel Luong 2022-08-10 11:49:56 -04:00 committed by mergify[bot]
parent dcfcb4dcf5
commit 2e5537d9a5
2 changed files with 3 additions and 17 deletions

View File

@ -4,10 +4,8 @@
package org.mozilla.fenix.components.settings package org.mozilla.fenix.components.settings
import mozilla.components.support.base.log.logger.Logger
import mozilla.components.support.ktx.android.content.PreferencesHolder import mozilla.components.support.ktx.android.content.PreferencesHolder
import mozilla.components.support.ktx.android.content.booleanPreference import mozilla.components.support.ktx.android.content.booleanPreference
import org.mozilla.experiments.nimbus.internal.NimbusFeatureException
import kotlin.properties.ReadWriteProperty import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
@ -29,16 +27,8 @@ fun featureFlagPreference(key: String, default: Boolean, featureFlag: Boolean) =
private class LazyPreference(val key: String, val default: () -> Boolean) : private class LazyPreference(val key: String, val default: () -> Boolean) :
ReadWriteProperty<PreferencesHolder, Boolean> { ReadWriteProperty<PreferencesHolder, Boolean> {
override fun getValue(thisRef: PreferencesHolder, property: KProperty<*>): Boolean { override fun getValue(thisRef: PreferencesHolder, property: KProperty<*>): Boolean =
val defValue = try { thisRef.preferences.getBoolean(key, default())
default()
} catch (e: NimbusFeatureException) {
Logger.error("Failed fetch default value for $key", e)
false
}
return thisRef.preferences.getBoolean(key, defValue)
}
override fun setValue(thisRef: PreferencesHolder, property: KProperty<*>, value: Boolean) = override fun setValue(thisRef: PreferencesHolder, property: KProperty<*>, value: Boolean) =
thisRef.preferences.edit().putBoolean(key, value).apply() thisRef.preferences.edit().putBoolean(key, value).apply()

View File

@ -28,7 +28,6 @@ import mozilla.components.support.ktx.android.content.longPreference
import mozilla.components.support.ktx.android.content.stringPreference import mozilla.components.support.ktx.android.content.stringPreference
import mozilla.components.support.ktx.android.content.stringSetPreference import mozilla.components.support.ktx.android.content.stringSetPreference
import mozilla.components.support.locale.LocaleManager import mozilla.components.support.locale.LocaleManager
import org.mozilla.experiments.nimbus.internal.NimbusFeatureException
import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.Config import org.mozilla.fenix.Config
import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.FeatureFlags
@ -1204,11 +1203,8 @@ class Settings(private val appContext: Context) : PreferencesHolder {
private val onboardScreenSection: Map<OnboardingSection, Boolean> get() = private val onboardScreenSection: Map<OnboardingSection, Boolean> get() =
FxNimbus.features.onboarding.value().sectionsEnabled FxNimbus.features.onboarding.value().sectionsEnabled
private val homescreenSections: Map<HomeScreenSection, Boolean> get() = try { private val homescreenSections: Map<HomeScreenSection, Boolean> get() =
FxNimbus.features.homescreen.value().sectionsEnabled FxNimbus.features.homescreen.value().sectionsEnabled
} catch (e: NimbusFeatureException) {
emptyMap()
}
var historyMetadataUIFeature by lazyFeatureFlagPreference( var historyMetadataUIFeature by lazyFeatureFlagPreference(
appContext.getPreferenceKey(R.string.pref_key_history_metadata_feature), appContext.getPreferenceKey(R.string.pref_key_history_metadata_feature),