Bug 1824856 - add release-notify-testrail to treeherder. r=gbrown,releng-reviewers...
[gecko.git] / mobile / android / docs / _posts / 2020-05-28-engine-version-feature-flags.md
blobc0807397a5b86d1b8f08635f4ba7bc7d85408bd9
1 ---
2 layout: post
3 title: "🚩 Engine version dependent feature flags"
4 date: 2020-05-28 14:00:00 +0200
5 author: sebastian
6 ---
8 When integrating a completely new feature, for example into [Firefox Preview](https://github.com/mozilla-mobile/fenix), this feature may only work with the latest version of an engine, e.g. the latest version of `browser-engine-gecko-nightly`. Manually maintaining a feature flag that gradually gets enabled in build variants as the required functionality becomes available in more stable engine versions (`browser-engine-gecko-beta`, `browser-engine-gecko`) is cumbersome, error-prone and potentially a multi-week long process.
10 To help build feature flags, that need to incorporate the engine version, every `Engine` exposes a `version` property. This property is an instance of [`EngineVersion`](https://mozac.org/api/mozilla.components.concept.engine.utils/-engine-version/), which makes it easy to match against specific engine versions.
12 ## Example
14 Let's say you are adding a new feature to [Firefox Preview](https://github.com/mozilla-mobile/fenix). This new feature requires brand new functionality that was just introduced in GeckoView Nightly 77.0. Using [`isAtLeast()`](https://mozac.org/api/mozilla.components.concept.engine.utils/-engine-version/is-at-least.html) you can create a feature flag that will enable this feature in all build variants that are using GeckoView 77.0 or higher.
16 ```Kotlin
17 // Enable feature with GeckoView 77+
18 val useNewFeature = components.engine.version.isAtLeast(77)
19 ```
21 This also works for minor and patch versions as well as additional metadata that is appended to the version number.
23 ```Kotlin
24 // Feature requires GeckoView 77.2 or higher.
25 val useNewFeature = components.engine.version.isAtLeast(77, 2)
26 ```
28 If needed you can access the individual parts of the version number manually:
30 ```Kotlin
31 // For GeckoView (Nightly) 77.0a1
32 engine.version.major // 77
33 engine.version.minor // 0
34 engine.version.patch // 0
35 engine.version.metadata // a1
36 ```
38 ### GeckoView vs. WebView
40 Note that for GeckoView versions we are using the `MOZILLA_VERSION` that GeckoView exposes (e.g. `78.0a1`) which can be different from version of the maven dependency (e.g. `78.0.20200528032513`).
42 In `browser-engine-system`, which is using `WebView`, we are parsing the Chrome version from the [User-Agent](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent).
44 ```Kotlin
45 // Mozilla/5.0 (Linux; Android 10) Build/RPP2.200227.014.A1; wv)
46 // AppleWebKit/537.36 (KHTML, like Gecko) Version 4.0
47 // Chrome/82.0.4062.3 Mobile Safari/537.36
49 // On a device with a WebView with the User-Agent above:
50 engine.version.major // 82
51 engine.version.minor // 0
52 engine.version.patch // 4062
53 engine.version.metadata // .3
54 ```