Skip to content

Commit

Permalink
Add feature flag for gating NPS Survey
Browse files Browse the repository at this point in the history
  • Loading branch information
adhiamboperes committed Jan 16, 2024
1 parent bb69b22 commit 5ac9130
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.oppia.android.domain.profile.ProfileManagementController
import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.extractCurrentAppScreenName
import org.oppia.android.util.logging.performancemetrics.PerformanceMetricsAssessor.AppIconification.APP_IN_BACKGROUND
import org.oppia.android.util.logging.performancemetrics.PerformanceMetricsAssessor.AppIconification.APP_IN_FOREGROUND
import org.oppia.android.util.platformparameter.EnableNpsSurvey
import org.oppia.android.util.platformparameter.EnablePerformanceMetricsCollection
import org.oppia.android.util.platformparameter.PlatformParameterValue
import org.oppia.android.util.system.OppiaClock
Expand All @@ -44,7 +45,9 @@ class ApplicationLifecycleObserver @Inject constructor(
@BackgroundDispatcher private val backgroundDispatcher: CoroutineDispatcher,
@EnablePerformanceMetricsCollection
private val enablePerformanceMetricsCollection: PlatformParameterValue<Boolean>,
private val applicationLifecycleListeners: Set<@JvmSuppressWildcards ApplicationLifecycleListener>
private val applicationLifecycleListeners:
Set<@JvmSuppressWildcards ApplicationLifecycleListener>,
@EnableNpsSurvey private val enableNpsSurvey: PlatformParameterValue<Boolean>,
) : ApplicationStartupListener, LifecycleObserver, Application.ActivityLifecycleCallbacks {

/**
Expand Down Expand Up @@ -93,7 +96,9 @@ class ApplicationLifecycleObserver @Inject constructor(
/** Occurs when application comes to foreground. */
@OnLifecycleEvent(Lifecycle.Event.ON_START)
fun onAppInForeground() {
applicationLifecycleListeners.forEach(ApplicationLifecycleListener::onAppInForeground)
if (enableNpsSurvey.value) {
applicationLifecycleListeners.forEach(ApplicationLifecycleListener::onAppInForeground)
}
val timeDifferenceMs = oppiaClock.getCurrentTimeMs() - firstTimestamp
if (timeDifferenceMs > inactivityLimitMillis) {
loggingIdentifierController.updateSessionId()
Expand All @@ -108,7 +113,9 @@ class ApplicationLifecycleObserver @Inject constructor(
/** Occurs when application goes to background. */
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
fun onAppInBackground() {
applicationLifecycleListeners.forEach(ApplicationLifecycleListener::onAppInBackground)
if (enableNpsSurvey.value) {
applicationLifecycleListeners.forEach(ApplicationLifecycleListener::onAppInBackground)
}
firstTimestamp = oppiaClock.getCurrentTimeMs()
if (enablePerformanceMetricsCollection.value) {
cpuPerformanceSnapshotter.updateAppIconification(APP_IN_BACKGROUND)
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 @@ -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 @@ -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 platform parameter 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 platform parameter corresponding to [EnableNpsSurvey]. */
const val ENABLE_NPS_SURVEY_DEFAULT_VALUE = false

0 comments on commit 5ac9130

Please sign in to comment.