2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-11 13:11:01 +00:00

Closes #4075: Add Feature Flag class (#4077)

This commit is contained in:
Jonathan Almeida 2019-07-18 20:20:12 -04:00 committed by Jeff Boek
parent e25ceafd1f
commit d298b5f2f5
5 changed files with 40 additions and 16 deletions

View File

@ -259,14 +259,6 @@ android.applicationVariants.all { variant ->
buildConfigField 'String', 'LEANPLUM_TOKEN', 'null' buildConfigField 'String', 'LEANPLUM_TOKEN', 'null'
println("X_X") println("X_X")
} }
// -------------------------------------------------------------------------------------------------
// Feature build flags
// -------------------------------------------------------------------------------------------------
// NB: flipping SEND_TAB_ENABLED flag back and worth is currently not well supported and may need hand-holding.
// Consult with the android-components peers before changing.
buildConfigField 'Boolean', 'SEND_TAB_ENABLED', (buildType == "nightly" || buildType == "nightlyLegacy" || isDebug).toString()
buildConfigField 'Boolean', 'PULL_TO_REFRESH_ENABLED', (false).toString()
} }
androidExtensions { androidExtensions {

View File

@ -0,0 +1,32 @@
package org.mozilla.fenix
/**
* A single source for setting feature flags that are mostly based on build type.
*/
object FeatureFlags {
// A convenience flag for production builds.
private val production by lazy { BuildConfig.BUILD_TYPE == "production" }
// A convenience flag for beta builds.
private val beta by lazy { BuildConfig.BUILD_TYPE == "beta" }
// A convenience flag for the nightly build and (legacy) nightly channel in Google Play.
private val nightly by lazy { BuildConfig.BUILD_TYPE == "nightly" || BuildConfig.BUILD_TYPE == "nightlyLegacy" }
// A convenience flag for debug builds.
private val debug by lazy { BuildConfig.BUILD_TYPE == "debug" }
/**
* Send Tab is a feature to lets you send a url/tab from a desktop to device and vice versa.
*
* NB: flipping this flag back and worth is currently not well supported and may need
* hand-holding. Consult with the android-components peers before changing.
*
* This flag is temporarily also used for the push service that is requires it to.
* See: https://github.com/mozilla-mobile/fenix/issues/4063
*/
val sendTabEnabled = nightly || debug
/**
* Pull-to-refresh allows you to pull the web content down far enough to have the page to
* reload.
*/
const val pullToRefreshEnabled = false
}

View File

@ -57,7 +57,7 @@ import mozilla.components.support.base.feature.BackHandler
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import mozilla.components.support.ktx.android.view.exitImmersiveModeIfNeeded import mozilla.components.support.ktx.android.view.exitImmersiveModeIfNeeded
import org.mozilla.fenix.BrowsingModeManager import org.mozilla.fenix.BrowsingModeManager
import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.FenixViewModelProvider import org.mozilla.fenix.FenixViewModelProvider
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.IntentReceiverActivity import org.mozilla.fenix.IntentReceiverActivity
@ -343,7 +343,7 @@ class BrowserFragment : Fragment(), BackHandler {
view = view view = view
) )
if (BuildConfig.PULL_TO_REFRESH_ENABLED) { if (FeatureFlags.pullToRefreshEnabled) {
val primaryTextColor = ThemeManager.resolveAttribute(R.attr.primaryText, requireContext()) val primaryTextColor = ThemeManager.resolveAttribute(R.attr.primaryText, requireContext())
view.swipeRefresh.setColorSchemeColors(primaryTextColor) view.swipeRefresh.setColorSchemeColors(primaryTextColor)
swipeRefreshFeature.set( swipeRefreshFeature.set(

View File

@ -33,8 +33,8 @@ import mozilla.components.feature.push.PushType
import mozilla.components.service.fxa.manager.FxaAccountManager import mozilla.components.service.fxa.manager.FxaAccountManager
import mozilla.components.service.fxa.sync.GlobalSyncableStoreProvider import mozilla.components.service.fxa.sync.GlobalSyncableStoreProvider
import mozilla.components.support.base.log.logger.Logger import mozilla.components.support.base.log.logger.Logger
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.Experiments import org.mozilla.fenix.Experiments
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.isInExperiment import org.mozilla.fenix.isInExperiment
import org.mozilla.fenix.test.Mockable import org.mozilla.fenix.test.Mockable
@ -63,7 +63,7 @@ class BackgroundServices(
// NB: flipping this flag back and worth is currently not well supported and may need hand-holding. // NB: flipping this flag back and worth is currently not well supported and may need hand-holding.
// Consult with the android-components peers before changing. // Consult with the android-components peers before changing.
// See https://github.com/mozilla/application-services/issues/1308 // See https://github.com/mozilla/application-services/issues/1308
capabilities = if (BuildConfig.SEND_TAB_ENABLED) { capabilities = if (FeatureFlags.sendTabEnabled) {
setOf(DeviceCapability.SEND_TAB) setOf(DeviceCapability.SEND_TAB)
} else { } else {
emptySet() emptySet()
@ -120,7 +120,7 @@ class BackgroundServices(
GlobalSyncableStoreProvider.configureStore("bookmarks" to bookmarkStorage) GlobalSyncableStoreProvider.configureStore("bookmarks" to bookmarkStorage)
// Sets the PushFeature as the singleton instance for push messages to go to. // Sets the PushFeature as the singleton instance for push messages to go to.
if (BuildConfig.SEND_TAB_ENABLED && pushConfig != null) { if (FeatureFlags.sendTabEnabled && pushConfig != null) {
PushProcessor.install(push) PushProcessor.install(push)
} }
} }
@ -175,7 +175,7 @@ class BackgroundServices(
it.registerForDeviceEvents(deviceEventObserver, ProcessLifecycleOwner.get(), true) it.registerForDeviceEvents(deviceEventObserver, ProcessLifecycleOwner.get(), true)
// This should be removed in the future. See comment on `accountObserver`. // This should be removed in the future. See comment on `accountObserver`.
if (BuildConfig.SEND_TAB_ENABLED && pushConfig != null) { if (FeatureFlags.sendTabEnabled && pushConfig != null) {
it.register(accountObserver) it.register(accountObserver)
} }
CoroutineScope(Dispatchers.Main).launch { it.initAsync().await() } CoroutineScope(Dispatchers.Main).launch { it.initAsync().await() }

View File

@ -12,7 +12,7 @@ import io.reactivex.Observable
import io.reactivex.Observer import io.reactivex.Observer
import io.reactivex.functions.Consumer import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.component_share.* import kotlinx.android.synthetic.main.component_share.*
import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
import org.mozilla.fenix.mvi.UIView import org.mozilla.fenix.mvi.UIView
@ -41,7 +41,7 @@ class ShareUIView(
intent_handler_recyclerview.adapter = adapter intent_handler_recyclerview.adapter = adapter
// And authorized // And authorized
if (BuildConfig.SEND_TAB_ENABLED && if (FeatureFlags.sendTabEnabled &&
!view.context.components.backgroundServices.accountManager.accountNeedsReauth() !view.context.components.backgroundServices.accountManager.accountNeedsReauth()
) { ) {
account_devices_recyclerview.adapter = AccountDevicesShareAdapter(view.context, actionEmitter) account_devices_recyclerview.adapter = AccountDevicesShareAdapter(view.context, actionEmitter)