Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature flag for gating NPS Survey #5302

Merged
merged 5 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -44,7 +44,8 @@ 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>,
) : ApplicationStartupListener, LifecycleObserver, Application.ActivityLifecycleCallbacks {

/**
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 platform parameter corresponding to [EnableNpsSurvey]. */
const val ENABLE_NPS_SURVEY_DEFAULT_VALUE = false
Loading