From 4641e1778854d629d5c68e6d58a5af964c39d6d8 Mon Sep 17 00:00:00 2001 From: Chenxia Liu Date: Tue, 4 Jun 2019 20:59:00 -0400 Subject: [PATCH] Closes #2320 - Add command-line control for specifying experiments. --- .../org/mozilla/tv/firefox/IntentValidator.kt | 18 ++++++++++++-- .../experiments/ExperimentsProvider.kt | 24 +++++++++---------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/mozilla/tv/firefox/IntentValidator.kt b/app/src/main/java/org/mozilla/tv/firefox/IntentValidator.kt index 6f84a724f1..b48613a5eb 100644 --- a/app/src/main/java/org/mozilla/tv/firefox/IntentValidator.kt +++ b/app/src/main/java/org/mozilla/tv/firefox/IntentValidator.kt @@ -10,7 +10,9 @@ import android.os.Bundle import androidx.annotation.VisibleForTesting import android.text.TextUtils import mozilla.components.browser.session.Session +import mozilla.components.service.fretboard.ExperimentDescriptor import mozilla.components.support.utils.SafeIntent +import org.mozilla.tv.firefox.ext.serviceLocator import org.mozilla.tv.firefox.telemetry.TelemetryIntegration import org.mozilla.tv.firefox.utils.UrlUtils @@ -27,6 +29,7 @@ data class ValidatedIntentData(val url: String, val source: Session.Source) */ object IntentValidator { @VisibleForTesting const val DIAL_PARAMS_KEY = "com.amazon.extra.DIAL_PARAM" + private const val ACTIVE_EXPERIMENTS_KEY = "activeExperiments" /** * Validate that [intent] contains all expected parameters. @@ -50,9 +53,9 @@ object IntentValidator { } fun validate(context: Context, intent: SafeIntent): ValidatedIntentData? { - val action = intent.action + setExperimentOverrides(intent, context) - when (action) { + when (intent.action) { Intent.ACTION_MAIN -> { val dialParams = intent.extras?.getString(DIAL_PARAMS_KEY) ?: return null if (dialParams.isNotEmpty()) { @@ -81,4 +84,15 @@ object IntentValidator { } return null } + + private fun setExperimentOverrides(intent: SafeIntent, context: Context) { + intent.extras?.getStringArray(ACTIVE_EXPERIMENTS_KEY)?.let { strArray -> + val fretboard = context.serviceLocator.fretboardProvider.fretboard + fretboard.clearAllOverrides(context) + + strArray.forEach { + fretboard.setOverride(context, ExperimentDescriptor(it), true) + } + } + } } diff --git a/app/src/main/java/org/mozilla/tv/firefox/experiments/ExperimentsProvider.kt b/app/src/main/java/org/mozilla/tv/firefox/experiments/ExperimentsProvider.kt index 41c172acf8..0f67e1d2d5 100644 --- a/app/src/main/java/org/mozilla/tv/firefox/experiments/ExperimentsProvider.kt +++ b/app/src/main/java/org/mozilla/tv/firefox/experiments/ExperimentsProvider.kt @@ -61,22 +61,22 @@ class ExperimentsProvider(private val fretboard: Fretboard, private val context: } fun shouldShowTvGuideChannels(): Boolean { - return false // TODO Before enabling this code: +// TODO before releasing to more than 0 population: // - Add final channel content (list will be added to #2322) // - Make sure all tiles have images (assets will be added to #2357) // - Remove ChannelRepo#padToTen -// val expDescriptor = checkBranchVariants(ExperimentConfig.TV_GUIDE_CHANNELS) -// return when { -// // The user is currently not part of the experiment -// expDescriptor == null -> false -// expDescriptor.name.endsWith(ExperimentSuffix.A.value) -> false -// expDescriptor.name.endsWith(ExperimentSuffix.B.value) -> true -// else -> { -// Sentry.capture(ExperimentIllegalStateException("TV Guide Channels Illegal Branch Name")) -// false -// } -// } + val expDescriptor = checkBranchVariants(ExperimentConfig.TV_GUIDE_CHANNELS) + return when { + // The user is currently not part of the experiment + expDescriptor == null -> false + expDescriptor.name.endsWith(ExperimentSuffix.A.value) -> false + expDescriptor.name.endsWith(ExperimentSuffix.B.value) -> true + else -> { + Sentry.capture(ExperimentIllegalStateException("TV Guide Channels Illegal Branch Name")) + false + } + } } /**