Skip to content
This repository has been archived by the owner on Apr 17, 2021. It is now read-only.

Commit

Permalink
Closes #2320 - Add command-line control for specifying experiments.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuche authored and mcomella committed Jun 5, 2019
1 parent e8fc03b commit 4641e17
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
18 changes: 16 additions & 2 deletions app/src/main/java/org/mozilla/tv/firefox/IntentValidator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand All @@ -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()) {
Expand Down Expand Up @@ -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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

/**
Expand Down

0 comments on commit 4641e17

Please sign in to comment.