From 5ac913005a27e7e1dff8000afc55e56313a93d88 Mon Sep 17 00:00:00 2001 From: Adhiambo Peres <59600948+adhiamboperes@users.noreply.github.com> Date: Tue, 16 Jan 2024 11:47:48 +0300 Subject: [PATCH] Add feature flag for gating NPS Survey --- .../analytics/ApplicationLifecycleObserver.kt | 13 ++++++++++--- .../PlatformParameterAlphaKenyaModule.kt | 14 ++++++++++++++ .../PlatformParameterAlphaModule.kt | 14 ++++++++++++++ .../platformparameter/PlatformParameterModule.kt | 14 ++++++++++++++ .../ExplorationActiveTimeControllerTest.kt | 6 ++++++ .../TestPlatformParameterModule.kt | 15 +++++++++++++++ .../platformparameter/FeatureFlagConstants.kt | 10 ++++++++++ 7 files changed, 83 insertions(+), 3 deletions(-) diff --git a/domain/src/main/java/org/oppia/android/domain/oppialogger/analytics/ApplicationLifecycleObserver.kt b/domain/src/main/java/org/oppia/android/domain/oppialogger/analytics/ApplicationLifecycleObserver.kt index 8a4504b4372..4c8073f50cf 100644 --- a/domain/src/main/java/org/oppia/android/domain/oppialogger/analytics/ApplicationLifecycleObserver.kt +++ b/domain/src/main/java/org/oppia/android/domain/oppialogger/analytics/ApplicationLifecycleObserver.kt @@ -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 @@ -44,7 +45,9 @@ class ApplicationLifecycleObserver @Inject constructor( @BackgroundDispatcher private val backgroundDispatcher: CoroutineDispatcher, @EnablePerformanceMetricsCollection private val enablePerformanceMetricsCollection: PlatformParameterValue, - private val applicationLifecycleListeners: Set<@JvmSuppressWildcards ApplicationLifecycleListener> + private val applicationLifecycleListeners: + Set<@JvmSuppressWildcards ApplicationLifecycleListener>, + @EnableNpsSurvey private val enableNpsSurvey: PlatformParameterValue, ) : ApplicationStartupListener, LifecycleObserver, Application.ActivityLifecycleCallbacks { /** @@ -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() @@ -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) diff --git a/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterAlphaKenyaModule.kt b/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterAlphaKenyaModule.kt index 01b0f2e8036..6a9820e4c47 100644 --- a/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterAlphaKenyaModule.kt +++ b/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterAlphaKenyaModule.kt @@ -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 @@ -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 @@ -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 { + return platformParameterSingleton.getBooleanPlatformParameter(ENABLE_NPS_SURVEY) + ?: PlatformParameterValue.createDefaultParameter( + ENABLE_NPS_SURVEY_DEFAULT_VALUE + ) + } } diff --git a/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterAlphaModule.kt b/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterAlphaModule.kt index 1805833253d..83c1909dde0 100644 --- a/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterAlphaModule.kt +++ b/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterAlphaModule.kt @@ -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 @@ -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 @@ -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 { + return platformParameterSingleton.getBooleanPlatformParameter(ENABLE_NPS_SURVEY) + ?: PlatformParameterValue.createDefaultParameter( + ENABLE_NPS_SURVEY_DEFAULT_VALUE + ) + } } diff --git a/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterModule.kt b/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterModule.kt index c1de688e0f9..17e63902dde 100644 --- a/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterModule.kt +++ b/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterModule.kt @@ -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 @@ -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 @@ -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 { + return platformParameterSingleton.getBooleanPlatformParameter(ENABLE_NPS_SURVEY) + ?: PlatformParameterValue.createDefaultParameter( + ENABLE_NPS_SURVEY_DEFAULT_VALUE + ) + } } diff --git a/domain/src/test/java/org/oppia/android/domain/exploration/ExplorationActiveTimeControllerTest.kt b/domain/src/test/java/org/oppia/android/domain/exploration/ExplorationActiveTimeControllerTest.kt index 39414c42791..d012e057068 100644 --- a/domain/src/test/java/org/oppia/android/domain/exploration/ExplorationActiveTimeControllerTest.kt +++ b/domain/src/test/java/org/oppia/android/domain/exploration/ExplorationActiveTimeControllerTest.kt @@ -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 @@ -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() diff --git a/testing/src/main/java/org/oppia/android/testing/platformparameter/TestPlatformParameterModule.kt b/testing/src/main/java/org/oppia/android/testing/platformparameter/TestPlatformParameterModule.kt index 6874912d8ec..1d0f9f02bfc 100644 --- a/testing/src/main/java/org/oppia/android/testing/platformparameter/TestPlatformParameterModule.kt +++ b/testing/src/main/java/org/oppia/android/testing/platformparameter/TestPlatformParameterModule.kt @@ -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 @@ -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 @@ -263,6 +265,12 @@ class TestPlatformParameterModule { return PlatformParameterValue.createDefaultParameter(minimumLearningTime) } + @Provides + @EnableNpsSurvey + fun provideEnableNpsSurvey(): PlatformParameterValue { + return PlatformParameterValue.createDefaultParameter(enableNpsSurvey) + } + companion object { private var enableDownloadsSupport = ENABLE_DOWNLOADS_SUPPORT_DEFAULT_VALUE private var enableEditAccountsOptionsUi = ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE @@ -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) { @@ -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 diff --git a/utility/src/main/java/org/oppia/android/util/platformparameter/FeatureFlagConstants.kt b/utility/src/main/java/org/oppia/android/util/platformparameter/FeatureFlagConstants.kt index bf366a43954..15299321da7 100644 --- a/utility/src/main/java/org/oppia/android/util/platformparameter/FeatureFlagConstants.kt +++ b/utility/src/main/java/org/oppia/android/util/platformparameter/FeatureFlagConstants.kt @@ -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