You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation
<!--
- Explain what your PR does. If this PR fixes an existing bug, please
include
- "Fixes #bugnum:" in the explanation so that GitHub can auto-close the
issue
- when this PR is merged.
-->
When merged, this PR will;
- Modify the Platform Parameter and Feature Flags documentation to
reflect changes introduced by the Technical Analytics Milestones 1, 2
and 3 PRs.
## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [x] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).
## For UI-specific PRs only
<!-- Delete these section if this PR does not include UI-related
changes. -->
If your PR includes UI-related changes, then:
- Add screenshots for portrait/landscape for both a tablet & phone of
the before & after UI changes
- For the screenshots above, include both English and pseudo-localized
(RTL) screenshots (see [RTL
guide](https://github.com/oppia/oppia-android/wiki/RTL-Guidelines))
- Add a video showing the full UX flow with a screen reader enabled (see
[accessibility
guide](https://github.com/oppia/oppia-android/wiki/Accessibility-A11y-Guide))
- For PRs introducing new UI elements or color changes, both light and
dark mode screenshots must be included
- Add a screenshot demonstrating that you ran affected Espresso tests
locally & that they're passing
---------
Co-authored-by: Adhiambo Peres <[email protected]>
-[How to create a Platform Parameter](#how-to-create-a-platform-parameter)
5
-
-[How to consume a Platform Parameter](#how-to-consume-a-platform-parameter)
5
+
-[How to create a Feature Flag](#how-to-create-a-feature-flag)
6
+
-[How to consume a Platform Parameter or Feature Flag](#how-to-consume-a-platform-parameter-or-feature-flag)
7
+
-[Ensuring your Feature Flags are logged on each app session](#ensuring-your-feature-flags-are-logged-on-each-app-session)
6
8
-[How to write tests related Platform Parameter](#how-to-write-tests-related-platform-parameter)
7
9
-[1. We actually don't test for platform parameter(s)](#1-we-actually-dont-test-for-platform-parameters)
8
10
-[2. We test for different values of platform parameter(s)](#2-we-test-for-different-values-of-platform-parameters)
@@ -14,13 +16,13 @@ In order to release these types of features in a smooth manner, we need to be ab
14
16
15
17
## How to create a Platform Parameter
16
18
1. Create the Constants
17
-
-If the Platform Parameter you intend to create is related to a particular feature, so first check that do there exist a file in the `utility\src\main\java\org\oppia\android\util\platformparameter`which contains other Platform Parameters related to the same feature. If there is no such then create a new Kotlin file along with its name corresponding to the feature.
18
-
-After searching/making a "constants" file related to a feature, we need to define three things:
19
+
- Platform parameters are typically stored inside `utility\src\main\java\org\oppia\android\util\platformparameter`in the `PlatformParameterConstants.kt`.
20
+
-To create a new platform parameter, we need to define three things:
19
21
1. Qualifier Annotation which will help us to distinguish our Platform Parameter from others.
20
22
21
23
<br>
22
24
23
-
```
25
+
```kotlin
24
26
/**
25
27
* Qualifier for the platform parameter that defines the time period in hours, after which the
26
28
* [PlatformParameterSyncUpWorker] will run again.
@@ -33,7 +35,7 @@ In order to release these types of features in a smooth manner, we need to be ab
33
35
34
36
<br>
35
37
36
-
```
38
+
```kotlin
37
39
/**
38
40
* Name of the platform parameter that defines the time period in hours, after which the
39
41
* [PlatformParameterSyncUpWorker] will run again.
@@ -45,7 +47,7 @@ In order to release these types of features in a smooth manner, we need to be ab
45
47
46
48
<br>
47
49
48
-
```
50
+
```kotlin
49
51
/**
50
52
* Default value of the platform parameter that defines the time period in hours, after which the
51
53
* [PlatformParameterSyncUpWorker] will run again.
@@ -59,7 +61,7 @@ In order to release these types of features in a smooth manner, we need to be ab
59
61
60
62
<br>
61
63
62
-
```
64
+
```kotlin
63
65
/* Dagger module that provides values for individual Platform Parameters. */
64
66
@Module
65
67
classPlatformParameterModule {
@@ -83,29 +85,145 @@ Note: If the Platform Parameter that you are creating will only be a Compile Tim
83
85
-Note that permission will be required before accessing the FeatureGating console in the Oppia backend.
84
86
85
87
86
-
## How to consume a Platform Parameter
87
-
To consume a Platform Parameter in any file, we need to inject the specific `PlatformParameterValue\<T\>` instance along with the Qualifier Annotation defined for that Parameter. For eg - we are injecting the `SyncUpTimePeriodInHours` platform parameter in `PlatformParameterSyncUpWorkManagerInitializer`
88
+
## How to create a FeatureFlag
89
+
1. Create the Constant
90
+
-Feature flags, like platform parameters, are stored inside `utility\src\main\java\org\oppia\android\util\platformparameter` in the `FeatureFlagConstants.kt` file.
91
+
-To add new feature flags, we need to define three things:
92
+
1. QualifierAnnotation which will help us to distinguish our PlatformParameter from others. Each feature flag should be prepended with an `Enable` prefix to distinguish it from platform parameters.
93
+
94
+
<br>
88
95
89
-
```
96
+
```kotlin
97
+
/**
98
+
* Qualifier for the [EnableAppAndOsDeprecation] feature flag that controls whether to enable
99
+
* app and OS deprecation or not.
100
+
*/
101
+
@Qualifier
102
+
annotationclassEnableAppAndOsDeprecation
103
+
```
104
+
105
+
2. The name of the FeatureFlaginString format. This should also be prefixed with `android_enable_` to distinguish it from other feature flags on the Oppia-Web gating console.
106
+
107
+
<br>
108
+
109
+
```kotlin
110
+
/** Name of the feature flag that controls whether to enable app and os deprecation. */
-FeatureFlags are still a special type of PlatformParameterand are provided in a similar manner. For providing your FeatureFlagin the App, we need to first make a @Provides annotated method in the `PlatformParameterModule(domain\src\main\java\org\oppia\android\domain\platformparameter\PlatformParameterModule.kt)`
127
+
-Since feature flags can only be booleans, Thereturn type forthis @Provides annotated method will be equal to `PlatformPrameterValue<Boolean>`. Any other type will cause the platform parameter sync to fail. For eg- here we provide `EnableAppAndOsDeprecation` feature flag.
128
+
129
+
<br>
130
+
131
+
```kotlin
132
+
/* Dagger module that provides values for individual Platform Parameters. */
-All feature flags should be added to the feature flags console to allow them to be remotely enabled or disabled.
151
+
-Add the name and the value of our PlatformParameter. This change will make our Compile-TimePlatformParameter to be a Run-TimePlatformParameter. This means that we can control its value from backend.
152
+
-Note that permission will be required before accessing the FeatureGating console in the Oppia backend.
153
+
154
+
## How to consume a PlatformParameterorFeatureFlag
155
+
To consume a PlatformParameterin any file, we need to inject the specific `PlatformParameterValue<T>` instance along with the QualifierAnnotation defined for that Parameter. For eg - we are injecting the `SyncUpTimePeriodInHours` platform parameter and the `EnableAppAndOSDeprecation` feature flag in `PlatformParameterSyncUpWorkManagerInitializer`
// now we can use the value in the "time" variable, which will be an integer.
166
+
// Now we can use the value in the "time" variable, which will be an integer.
167
+
168
+
val appAndOsDeprecationEnabled = enableAppAndOsDeprecation.value
169
+
// This value can then be used to gate some features as desired.
98
170
}
99
171
}
100
172
```
101
173
102
-
## How to write tests related Platform Parameter
174
+
## Ensuring your Feature Flags are logged on each app session
175
+
As a requirement, all feature flags should be logged at the beginning of each app session. This is done automatically via the `FeatureFlagsLogger.kt` inside `domain/src/main/java/org/oppia/android/domain/oppialogger/analytics/` but some configuration is required. To ensure any newly added feature flags are logged as part of this requirement, follow the steps below;
176
+
177
+
### 1. Import the feature flag to the FeatureFlagsLogger
178
+
To get the value of the feature flag for logging, we need to consume the created feature flag as shown in the example below to ensure the value is present;
179
+
180
+
```kotlin
181
+
/**
182
+
* Convenience logger for feature flags.
183
+
*
184
+
* This logger is meant to be used for feature flag-related logging on every app launch. It is
185
+
* primarily used within the ApplicationLifecycleObserver to log the status of feature flags in a
### 2. Add an entry to the list of loggable feature flags
199
+
The FeatureFlagsLogger contains a variable `featureFlagItemMap`, which is a map of feature flags to be logged and their names. Any newly added feature flags should also be added here to ensure that they are logged as well.
200
+
201
+
```kotlin
202
+
/**
203
+
* A variable containing a list of all the feature flags in the app.
204
+
*
205
+
* @return a list of key-value pairs of [String] and [PlatformParameterValue]
APP_AND_OS_DEPRECATION to enableAppAndOsDeprecation
210
+
)
211
+
```
212
+
213
+
### 3. Update the Feature Flags Logger test
214
+
Besides the feature-flag logger, the `FeatureFlagLoggerTest` located at `domain/src/test/java/org/oppia/android/domain/oppialogger/analytics/FeatureFlagsLoggerTest.kt` will also need to be updated to reflect the newly added feature flag(s). There are two tests that will need to be changed.
215
+
216
+
- The first test that should be updated is the `testLogFeatureFlags_correctNumberOfFeatureFlagsIsLogged` test. For this, only the constant `expectedFeatureFlagCount` will need to be updated. If a new feature flag was added, increment the count and if one was removed, decrement the count.
217
+
218
+
- The second test that will need to be updated is the `testLogFeatureFlags_allFeatureFlagNamesAreLogged`. This is a parameterized test that iterates through each currently existing feature flag to ensure each one of them is logged as expected. To update this test and ensure it passes after a feature flag change, modify the `RunParameterized()` section and either add the expected values for the new flag or remove the expected values for a removed feature flag.
219
+
220
+
## How to write tests related to Platform Parameters
103
221
Before writing a test we must understand the purpose of the platform parameter in our class/classes (that needs to be tested). After verifying this we can divide testing procedures into following groups -
104
222
105
223
### 1. We actually don't test for platform parameter(s)
106
224
We just need specific platform parameter(s) in the dagger graph because our class needs it, but our test cases are not actually verifying the behaviour of class based on different values of the platform parameter. These are the simplest cases to write tests for. We will only need to create a `TestModule` inside the Test class and then include this into the @Component for the `TestApplicationComponent`. For eg -
0 commit comments