Skip to content

Commit

Permalink
Add feature flag for gating NPS Survey (#5302)
Browse files Browse the repository at this point in the history
<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation
Add feature flag for gating NPS Survey

<!--
- 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.
  -->

## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [ ] 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: ...".)
- [ ] 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
  • Loading branch information
adhiamboperes authored Jan 26, 2024
1 parent 1892b15 commit 6f17b17
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.data.DataProvider
import org.oppia.android.util.data.DataProviders
import org.oppia.android.util.data.DataProviders.Companion.transform
import org.oppia.android.util.platformparameter.EnableNpsSurvey
import org.oppia.android.util.platformparameter.PlatformParameterValue
import org.oppia.android.util.system.OppiaClock
import org.oppia.android.util.threading.BackgroundDispatcher
import java.util.UUID
Expand Down Expand Up @@ -57,7 +59,8 @@ class ExplorationActiveTimeController @Inject constructor(
private val dataProviders: DataProviders,
private val oppiaLogger: OppiaLogger,
private val exceptionsController: ExceptionsController,
@BackgroundDispatcher private val backgroundCoroutineDispatcher: CoroutineDispatcher
@BackgroundDispatcher private val backgroundCoroutineDispatcher: CoroutineDispatcher,
@EnableNpsSurvey private val enableNpsSurvey: PlatformParameterValue<Boolean>
) : ExplorationProgressListener, ApplicationLifecycleListener {
private var isAppInForeground: Boolean = false
private var explorationStarted: Boolean = false
Expand All @@ -82,27 +85,35 @@ class ExplorationActiveTimeController @Inject constructor(

override fun onExplorationStarted(profileId: ProfileId, topicId: String) {
this.explorationStarted = true
startSessionTimer(
profileId = profileId,
topicId = topicId,
isAppInForeground = getIsAppInForeground(),
explorationStarted = true
)
if (enableNpsSurvey.value) {
startSessionTimer(
profileId = profileId,
topicId = topicId,
isAppInForeground = getIsAppInForeground(),
explorationStarted = true
)
}
}

override fun onExplorationEnded() {
this.explorationStarted = false
stopSessionTimerAsync(getIsExplorationStarted())
if (enableNpsSurvey.value) {
stopSessionTimerAsync(getIsExplorationStarted())
}
}

override fun onAppInForeground() {
this.isAppInForeground = true
resumeSessionTimer(getIsExplorationStarted())
if (enableNpsSurvey.value) {
resumeSessionTimer(getIsExplorationStarted())
}
}

override fun onAppInBackground() {
this.isAppInForeground = false
pauseSessionTimerAsync()
if (enableNpsSurvey.value) {
pauseSessionTimerAsync()
}
}

private fun getIsAppInForeground() = this.isAppInForeground
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import org.oppia.android.util.platformparameter.ENABLE_DOWNLOADS_SUPPORT_DEFAULT
import org.oppia.android.util.platformparameter.ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_EXTRA_TOPIC_TABS_UI_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_INTERACTION_CONFIG_CHANGE_STATE_RETENTION_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_NPS_SURVEY
import org.oppia.android.util.platformparameter.ENABLE_NPS_SURVEY_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION
import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_SPOTLIGHT_UI_DEFAULT_VALUE
Expand All @@ -27,6 +29,7 @@ import org.oppia.android.util.platformparameter.EnableFastLanguageSwitchingInLes
import org.oppia.android.util.platformparameter.EnableInteractionConfigChangeStateRetention
import org.oppia.android.util.platformparameter.EnableLearnerStudyAnalytics
import org.oppia.android.util.platformparameter.EnableLoggingLearnerStudyIds
import org.oppia.android.util.platformparameter.EnableNpsSurvey
import org.oppia.android.util.platformparameter.EnablePerformanceMetricsCollection
import org.oppia.android.util.platformparameter.EnableSpotlightUi
import org.oppia.android.util.platformparameter.FAST_LANGUAGE_SWITCHING_IN_LESSON
Expand Down Expand Up @@ -307,4 +310,15 @@ class PlatformParameterAlphaKenyaModule {
NPS_SURVEY_MINIMUM_AGGREGATE_LEARNING_TIME_IN_A_TOPIC_IN_MINUTES_DEFAULT_VALUE
)
}

@Provides
@EnableNpsSurvey
fun provideEnableNpsSurvey(
platformParameterSingleton: PlatformParameterSingleton
): PlatformParameterValue<Boolean> {
return platformParameterSingleton.getBooleanPlatformParameter(ENABLE_NPS_SURVEY)
?: PlatformParameterValue.createDefaultParameter(
ENABLE_NPS_SURVEY_DEFAULT_VALUE
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import org.oppia.android.util.platformparameter.ENABLE_DOWNLOADS_SUPPORT_DEFAULT
import org.oppia.android.util.platformparameter.ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_EXTRA_TOPIC_TABS_UI_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_INTERACTION_CONFIG_CHANGE_STATE_RETENTION_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_NPS_SURVEY
import org.oppia.android.util.platformparameter.ENABLE_NPS_SURVEY_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION
import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.EXTRA_TOPIC_TABS_UI
Expand All @@ -26,6 +28,7 @@ import org.oppia.android.util.platformparameter.EnableFastLanguageSwitchingInLes
import org.oppia.android.util.platformparameter.EnableInteractionConfigChangeStateRetention
import org.oppia.android.util.platformparameter.EnableLearnerStudyAnalytics
import org.oppia.android.util.platformparameter.EnableLoggingLearnerStudyIds
import org.oppia.android.util.platformparameter.EnableNpsSurvey
import org.oppia.android.util.platformparameter.EnablePerformanceMetricsCollection
import org.oppia.android.util.platformparameter.EnableSpotlightUi
import org.oppia.android.util.platformparameter.FAST_LANGUAGE_SWITCHING_IN_LESSON
Expand Down Expand Up @@ -302,4 +305,15 @@ class PlatformParameterAlphaModule {
NPS_SURVEY_MINIMUM_AGGREGATE_LEARNING_TIME_IN_A_TOPIC_IN_MINUTES_DEFAULT_VALUE
)
}

@Provides
@EnableNpsSurvey
fun provideEnableNpsSurvey(
platformParameterSingleton: PlatformParameterSingleton
): PlatformParameterValue<Boolean> {
return platformParameterSingleton.getBooleanPlatformParameter(ENABLE_NPS_SURVEY)
?: PlatformParameterValue.createDefaultParameter(
ENABLE_NPS_SURVEY_DEFAULT_VALUE
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import org.oppia.android.util.platformparameter.ENABLE_DOWNLOADS_SUPPORT_DEFAULT
import org.oppia.android.util.platformparameter.ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_EXTRA_TOPIC_TABS_UI_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_INTERACTION_CONFIG_CHANGE_STATE_RETENTION_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_NPS_SURVEY
import org.oppia.android.util.platformparameter.ENABLE_NPS_SURVEY_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION
import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_SPOTLIGHT_UI_DEFAULT_VALUE
Expand All @@ -27,6 +29,7 @@ import org.oppia.android.util.platformparameter.EnableFastLanguageSwitchingInLes
import org.oppia.android.util.platformparameter.EnableInteractionConfigChangeStateRetention
import org.oppia.android.util.platformparameter.EnableLearnerStudyAnalytics
import org.oppia.android.util.platformparameter.EnableLoggingLearnerStudyIds
import org.oppia.android.util.platformparameter.EnableNpsSurvey
import org.oppia.android.util.platformparameter.EnablePerformanceMetricsCollection
import org.oppia.android.util.platformparameter.EnableSpotlightUi
import org.oppia.android.util.platformparameter.FAST_LANGUAGE_SWITCHING_IN_LESSON
Expand Down Expand Up @@ -304,4 +307,15 @@ class PlatformParameterModule {
NPS_SURVEY_MINIMUM_AGGREGATE_LEARNING_TIME_IN_A_TOPIC_IN_MINUTES_DEFAULT_VALUE
)
}

@Provides
@EnableNpsSurvey
fun provideEnableNpsSurvey(
platformParameterSingleton: PlatformParameterSingleton
): PlatformParameterValue<Boolean> {
return platformParameterSingleton.getBooleanPlatformParameter(ENABLE_NPS_SURVEY)
?: PlatformParameterValue.createDefaultParameter(
ENABLE_NPS_SURVEY_DEFAULT_VALUE
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import org.oppia.android.util.logging.SyncStatusModule
import org.oppia.android.util.networking.NetworkConnectionUtilDebugModule
import org.oppia.android.util.platformparameter.EnableLearnerStudyAnalytics
import org.oppia.android.util.platformparameter.EnableLoggingLearnerStudyIds
import org.oppia.android.util.platformparameter.EnableNpsSurvey
import org.oppia.android.util.platformparameter.PlatformParameterValue
import org.robolectric.Shadows
import org.robolectric.annotation.Config
Expand Down Expand Up @@ -856,6 +857,12 @@ class AudioPlayerControllerTest {
defaultValue = enableFeature
)
}

@Provides
@EnableNpsSurvey
fun provideEnableNpsSurvey(): PlatformParameterValue<Boolean> {
return PlatformParameterValue.createDefaultParameter(defaultValue = true)
}
}

// TODO(#89): Move this to a common test application component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import dagger.BindsInstance
import dagger.Component
import dagger.Module
import dagger.Provides
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.oppia.android.app.model.ProfileId
Expand Down Expand Up @@ -96,6 +97,11 @@ class ExplorationActiveTimeControllerTest {
private val firstTestProfile = ProfileId.newBuilder().setInternalId(0).build()
private val secondTestProfile = ProfileId.newBuilder().setInternalId(1).build()

@Before
fun setUp() {
TestPlatformParameterModule.forceEnableNpsSurvey(true)
}

@Test
fun testSessionTimer_explorationStartedCallbackReceived_startsSessionTimer() {
setUpTestApplicationComponent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ import org.oppia.android.util.logging.SyncStatusModule
import org.oppia.android.util.networking.NetworkConnectionUtilDebugModule
import org.oppia.android.util.platformparameter.EnableLearnerStudyAnalytics
import org.oppia.android.util.platformparameter.EnableLoggingLearnerStudyIds
import org.oppia.android.util.platformparameter.EnableNpsSurvey
import org.oppia.android.util.platformparameter.PlatformParameterValue
import org.robolectric.annotation.Config
import org.robolectric.annotation.LooperMode
Expand Down Expand Up @@ -3189,6 +3190,12 @@ class ExplorationProgressControllerTest {
// Enable study IDs by default in tests.
return PlatformParameterValue.createDefaultParameter(defaultValue = true)
}

@Provides
@EnableNpsSurvey
fun provideEnableNpsSurvey(): PlatformParameterValue<Boolean> {
return PlatformParameterValue.createDefaultParameter(defaultValue = true)
}
}

// TODO(#89): Move this to a common test application component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.junit.runner.RunWith
import org.oppia.android.domain.exploration.testing.ExplorationStorageTestModule
import org.oppia.android.domain.oppialogger.LogStorageModule
import org.oppia.android.testing.TestLogReportingModule
import org.oppia.android.testing.platformparameter.TestPlatformParameterModule
import org.oppia.android.testing.robolectric.RobolectricModule
import org.oppia.android.testing.threading.TestDispatcherModule
import org.oppia.android.testing.time.FakeOppiaClockModule
Expand Down Expand Up @@ -92,7 +93,8 @@ class ExplorationProgressModuleTest {
TestModule::class, TestLogModule::class, RobolectricModule::class,
FakeOppiaClockModule::class, ExplorationProgressModule::class, TestDispatcherModule::class,
LocaleProdModule::class, TestLogReportingModule::class, LogStorageModule::class,
NetworkConnectionUtilDebugModule::class, ExplorationStorageTestModule::class
NetworkConnectionUtilDebugModule::class, ExplorationStorageTestModule::class,
TestPlatformParameterModule::class
]
)
interface TestApplicationComponent : DataProvidersInjector {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class SurveyGatingControllerTest {

@Before
fun setUp() {
TestPlatformParameterModule.forceEnableNpsSurvey(true)
setUpTestApplicationComponent()
profileTestHelper.initializeProfiles()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.oppia.android.util.platformparameter.ENABLE_DOWNLOADS_SUPPORT_DEFAULT
import org.oppia.android.util.platformparameter.ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_EXTRA_TOPIC_TABS_UI_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_INTERACTION_CONFIG_CHANGE_STATE_RETENTION_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_NPS_SURVEY_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.EnableAppAndOsDeprecation
import org.oppia.android.util.platformparameter.EnableDownloadsSupport
Expand All @@ -22,6 +23,7 @@ import org.oppia.android.util.platformparameter.EnableFastLanguageSwitchingInLes
import org.oppia.android.util.platformparameter.EnableInteractionConfigChangeStateRetention
import org.oppia.android.util.platformparameter.EnableLearnerStudyAnalytics
import org.oppia.android.util.platformparameter.EnableLoggingLearnerStudyIds
import org.oppia.android.util.platformparameter.EnableNpsSurvey
import org.oppia.android.util.platformparameter.EnablePerformanceMetricsCollection
import org.oppia.android.util.platformparameter.EnableSpotlightUi
import org.oppia.android.util.platformparameter.FAST_LANGUAGE_SWITCHING_IN_LESSON_DEFAULT_VALUE
Expand Down Expand Up @@ -263,6 +265,12 @@ class TestPlatformParameterModule {
return PlatformParameterValue.createDefaultParameter(minimumLearningTime)
}

@Provides
@EnableNpsSurvey
fun provideEnableNpsSurvey(): PlatformParameterValue<Boolean> {
return PlatformParameterValue.createDefaultParameter(enableNpsSurvey)
}

companion object {
private var enableDownloadsSupport = ENABLE_DOWNLOADS_SUPPORT_DEFAULT_VALUE
private var enableEditAccountsOptionsUi = ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE
Expand All @@ -280,6 +288,7 @@ class TestPlatformParameterModule {
private var minimumLearningTime =
NPS_SURVEY_MINIMUM_AGGREGATE_LEARNING_TIME_IN_A_TOPIC_IN_MINUTES_DEFAULT_VALUE
private var gracePeriodInDays = NPS_SURVEY_GRACE_PERIOD_IN_DAYS_DEFAULT_VALUE
private var enableNpsSurvey = ENABLE_NPS_SURVEY_DEFAULT_VALUE

@VisibleForTesting(otherwise = VisibleForTesting.NONE)
fun forceEnableDownloadsSupport(value: Boolean) {
Expand Down Expand Up @@ -334,6 +343,12 @@ class TestPlatformParameterModule {
enableSpotlightUi = value
}

/** Enables forcing [EnableNpsSurvey] feature flag from tests. */
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
fun forceEnableNpsSurvey(value: Boolean) {
enableNpsSurvey = value
}

@VisibleForTesting(otherwise = VisibleForTesting.NONE)
fun reset() {
enableDownloadsSupport = ENABLE_DOWNLOADS_SUPPORT_DEFAULT_VALUE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,13 @@ const val APP_AND_OS_DEPRECATION = "android_enable_app_and_os_deprecation"
* Default value for the feature flag corresponding to [EnableAppAndOsDeprecation].
*/
const val ENABLE_APP_AND_OS_DEPRECATION_DEFAULT_VALUE = false

/** Qualifier for the feature flag that toggles the the NPS Survey. */
@Qualifier
annotation class EnableNpsSurvey

/** Name of the feature flag that toggles the NPS Survey. */
const val ENABLE_NPS_SURVEY = "enable_nps_survey"

/** Default value of the feature flag corresponding to [EnableNpsSurvey]. */
const val ENABLE_NPS_SURVEY_DEFAULT_VALUE = false

0 comments on commit 6f17b17

Please sign in to comment.