Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
First use of Nimbus FML plugin (#23400)
Browse files Browse the repository at this point in the history
* Consume Nimbus FML plugin

* Convert Homescreen to use FML

* Convert nimbusValidation to use FML

* Convert legacy experiments to use the feature API and FML

Remove dead helper code and documentation

* Fixup failing test

Co-authored-by: Grisha Kruglov <gkruglov@mozilla.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 28, 2022
1 parent e92fe26 commit 82a6f8c
Show file tree
Hide file tree
Showing 16 changed files with 228 additions and 367 deletions.
59 changes: 59 additions & 0 deletions .experimenter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"search-term-groups": {
"description": "A feature allowing the grouping of URLs around the search term that it came from.",
"hasExposure": true,
"exposureDescription": "",
"variables": {
"enabled": {
"description": "If true, the feature shows up on the homescreen and on the new tab screen.",
"type": "boolean"
}
}
},
"default-browser-message": {
"description": "A small feature allowing experiments on the placement of a default browser message.",
"hasExposure": true,
"exposureDescription": "",
"variables": {
"message-location": {
"description": "Where is the message to be put.",
"enum": [
"homescreen-banner",
"settings",
"app-menu-item"
],
"type": "string"
}
}
},
"nimbus-validation": {
"description": "A feature that does not correspond to an application feature suitable for showing that Nimbus is working. This should never be used in production.",
"hasExposure": true,
"exposureDescription": "",
"variables": {
"settings-icon": {
"description": "The drawable displayed in the app menu for Settings",
"type": "string"
},
"settings-punctuation": {
"description": "The emoji displayed in the Settings screen title.",
"type": "string"
},
"settings-title": {
"description": "The title of displayed in the Settings screen and app menu.",
"type": "string"
}
}
},
"homescreen": {
"description": "The homescreen that the user goes to when they press home or new tab.",
"hasExposure": true,
"exposureDescription": "",
"variables": {
"sections-enabled": {
"description": "This property provides a lookup table of whether or not the given section should be enabled. If the section is enabled, it should be toggleable in the settings screen, and on by default.",
"type": "json"
}
}
}
}
23 changes: 22 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,28 @@ android.applicationVariants.all { variant ->

// Generate Kotlin code for the Fenix Glean metrics.
apply plugin: "org.mozilla.telemetry.glean-gradle-plugin"

apply plugin: "org.mozilla.components.nimbus-gradle-plugin"

nimbus {
// The path to the Nimbus feature manifest file
manifestFile = "nimbus.fml.yaml"
// The fully qualified class name for the generated features.
// If the classname begins with a '.' this is taken as a suffix to the app's package name
destinationClass = ".nimbus.FxNimbus"
// Map from the variant name to the channel as experimenter and nimbus understand it.
// If nimbus's channels were accurately set up well for this project, then this
// shouldn't be needed.
channels = [
debug: "developer",
nightly: "nightly",
beta: "beta",
release: "release",
]
// This is generated by the FML and should be checked into git.
// It will be fetched by Experimenter (the Nimbus experiment website)
// and used to inform experiment configuration.
experimenterManifest = ".experimenter.json"
}
configurations {
// There's an interaction between Gradle's resolution of dependencies with different types
// (@jar, @aar) for `implementation` and `testImplementation` and with Android Studio's built-in
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/org/mozilla/fenix/FenixApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ import org.mozilla.fenix.components.Core
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricServiceType
import org.mozilla.fenix.components.metrics.MozillaProductDetector
import org.mozilla.fenix.components.metrics.SecurePrefsTelemetry
import org.mozilla.fenix.components.toolbar.ToolbarPosition
import org.mozilla.fenix.ext.isCustomEngine
import org.mozilla.fenix.ext.isKnownSearchDomain
Expand Down Expand Up @@ -273,8 +272,6 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
System.currentTimeMillis() - Core.HISTORY_METADATA_MAX_AGE_IN_MS
)
}

SecurePrefsTelemetry(this@FenixApplication, components.analytics.experiments).startTests()
}
// Account manager initialization needs to happen on the main thread.
GlobalScope.launch(Dispatchers.Main) {
Expand Down
10 changes: 4 additions & 6 deletions app/src/main/java/org/mozilla/fenix/components/Analytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import org.mozilla.fenix.ReleaseChannel
import org.mozilla.fenix.components.metrics.AdjustMetricsService
import org.mozilla.fenix.components.metrics.GleanMetricsService
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.experiments.NimbusFeatures
import org.mozilla.fenix.experiments.createNimbus
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.nimbus.FxNimbus
import org.mozilla.fenix.perf.lazyMonitored
import org.mozilla.geckoview.BuildConfig.MOZ_APP_BUILDID
import org.mozilla.geckoview.BuildConfig.MOZ_APP_VENDOR
Expand Down Expand Up @@ -109,11 +109,9 @@ class Analytics(
}

val experiments: NimbusApi by lazyMonitored {
createNimbus(context, BuildConfig.NIMBUS_ENDPOINT)
}

val features: NimbusFeatures by lazyMonitored {
NimbusFeatures(context)
createNimbus(context, BuildConfig.NIMBUS_ENDPOINT).also { api ->
FxNimbus.api = api
}
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ import mozilla.components.support.ktx.android.content.getColorFromAttr
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifAnyChanged
import org.mozilla.fenix.R
import org.mozilla.fenix.components.accounts.FenixAccountManager
import org.mozilla.fenix.experiments.ExperimentBranch
import org.mozilla.fenix.experiments.FeatureId
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.withExperiment
import org.mozilla.fenix.nimbus.FxNimbus
import org.mozilla.fenix.nimbus.MessageSurfaceId
import org.mozilla.fenix.theme.ThemeManager
import org.mozilla.fenix.utils.BrowsersCache

Expand Down Expand Up @@ -361,6 +360,7 @@ open class DefaultToolbarMenu(

@VisibleForTesting(otherwise = PRIVATE)
val coreMenuItems by lazy {
val defaultBrowserItem = getSetDefaultBrowserItem()
val menuItems =
listOfNotNull(
if (shouldUseBottomToolbar) null else menuToolbar,
Expand All @@ -372,8 +372,8 @@ open class DefaultToolbarMenu(
extensionsItem,
syncMenuItem,
BrowserMenuDivider(),
getSetDefaultBrowserItem(),
getSetDefaultBrowserItem()?.let { BrowserMenuDivider() },
defaultBrowserItem,
defaultBrowserItem?.let { BrowserMenuDivider() },
findInPageItem,
desktopSiteItem,
customizeReaderView.apply { visible = ::shouldShowReaderViewCustomization },
Expand Down Expand Up @@ -446,23 +446,17 @@ open class DefaultToolbarMenu(
}
}

private fun getSetDefaultBrowserItem(): BrowserMenuImageText? {
val experiments = context.components.analytics.experiments
val browsers = BrowsersCache.all(context)

return experiments.withExperiment(FeatureId.DEFAULT_BROWSER) { experimentBranch ->
if (experimentBranch == ExperimentBranch.DEFAULT_BROWSER_TOOLBAR_MENU &&
!browsers.isFirefoxDefaultBrowser
private fun getSetDefaultBrowserItem(): BrowserMenuImageText? =
if (BrowsersCache.all(context).isFirefoxDefaultBrowser) {
null
} else if (FxNimbus.features.defaultBrowserMessage.value().messageLocation == MessageSurfaceId.APP_MENU_ITEM) {
BrowserMenuImageText(
label = context.getString(R.string.preferences_set_as_default_browser),
imageResource = R.mipmap.ic_launcher
) {
return@withExperiment BrowserMenuImageText(
label = context.getString(R.string.preferences_set_as_default_browser),
imageResource = R.mipmap.ic_launcher
) {
onItemTapped.invoke(ToolbarMenu.Item.SetDefaultBrowser)
}
} else {
null
onItemTapped.invoke(ToolbarMenu.Item.SetDefaultBrowser)
}
} else {
null
}
}
}
35 changes: 0 additions & 35 deletions app/src/main/java/org/mozilla/fenix/experiments/Experiments.kt

This file was deleted.

119 changes: 0 additions & 119 deletions app/src/main/java/org/mozilla/fenix/experiments/NimbusFeatures.kt

This file was deleted.

Loading

0 comments on commit 82a6f8c

Please sign in to comment.