From 87a7676b5019dd33e0a78c83f85be721b1944134 Mon Sep 17 00:00:00 2001 From: Kenneth Murerwa Date: Wed, 29 Nov 2023 23:10:49 +0300 Subject: [PATCH] Technical Analytics: Milestone 1 - Add Feature Flag Statuses and Ability To Sync Them to Cache Store (#5203) ## Explanation When merged, this PR will: - Create a new `FeatureFlagConstants.kt` file to contain all feature flags. - Create feature flag sync status trackers for each existing feature flag. - Modify the `PlatformParameterSyncUpWorker` to allow status trackers of all feature flags to be synced and cached in the PersistentCacheStore. - Merge the `TestBooleanPlatformParameter`, `TestStringPlatformParameter` and the `TestIntegerPlatformParameter` files into the `TestPlatformParameterConstants` file. - Add syncing with the web for the `EnableDownloadsSupport`, `EnableEditAccountsOptionsUi`, `EnableSpotlightUi`, `EnableExtraTopicTabsUi`, `EnableInteractionConfigChangeStateRetention`, and `EnableAppAndOsDeprecation` feature flags. - Write tests for the changes made. ## Essential Checklist - [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 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 <59600948+adhiamboperes@users.noreply.github.com> Co-authored-by: Ben Henning --- .../PlatformParameterAlphaKenyaModule.kt | 55 ++++-- .../PlatformParameterAlphaModule.kt | 57 +++++-- .../PlatformParameterModule.kt | 58 +++++-- .../PlatformParameterSingletonImpl.kt | 12 +- .../syncup/PlatformParameterSyncUpWorker.kt | 3 + .../domain/audio/AudioPlayerControllerTest.kt | 12 +- .../PlatformParameterSyncUpWorkerTest.kt | 84 ++++++++++ .../ProfileManagementControllerTest.kt | 12 +- model/src/main/proto/platform_parameter.proto | 13 ++ scripts/assets/test_file_exemptions.textproto | 5 +- .../testing/platformparameter/BUILD.bazel | 4 +- .../TestBooleanPlatformParameter.kt | 24 --- .../TestIntegerPlatformParameter.kt | 24 --- .../TestPlatformParameterConstants.kt | 68 ++++++++ .../TestStringPlatformParameter.kt | 24 --- .../platformparameter/FeatureFlagConstants.kt | 157 ++++++++++++++++++ .../PlatformParameterConstants.kt | 123 -------------- .../PlatformParameterValue.kt | 11 +- .../util/logging/EventBundleCreatorTest.kt | 6 +- .../KenyaAlphaEventBundleCreatorTest.kt | 6 +- 20 files changed, 486 insertions(+), 272 deletions(-) delete mode 100644 testing/src/main/java/org/oppia/android/testing/platformparameter/TestBooleanPlatformParameter.kt delete mode 100644 testing/src/main/java/org/oppia/android/testing/platformparameter/TestIntegerPlatformParameter.kt create mode 100644 testing/src/main/java/org/oppia/android/testing/platformparameter/TestPlatformParameterConstants.kt delete mode 100644 testing/src/main/java/org/oppia/android/testing/platformparameter/TestStringPlatformParameter.kt create mode 100644 utility/src/main/java/org/oppia/android/util/platformparameter/FeatureFlagConstants.kt 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 6adc922bc11..376f5abf36e 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 @@ -4,9 +4,12 @@ import android.content.Context import dagger.Module import dagger.Provides import org.oppia.android.app.utility.getVersionCode +import org.oppia.android.util.platformparameter.APP_AND_OS_DEPRECATION import org.oppia.android.util.platformparameter.CACHE_LATEX_RENDERING import org.oppia.android.util.platformparameter.CACHE_LATEX_RENDERING_DEFAULT_VALUE import org.oppia.android.util.platformparameter.CacheLatexRendering +import org.oppia.android.util.platformparameter.DOWNLOADS_SUPPORT +import org.oppia.android.util.platformparameter.EDIT_ACCOUNTS_OPTIONS_UI import org.oppia.android.util.platformparameter.ENABLE_APP_AND_OS_DEPRECATION_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_DOWNLOADS_SUPPORT_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE @@ -16,6 +19,7 @@ import org.oppia.android.util.platformparameter.ENABLE_LANGUAGE_SELECTION_UI_DEF 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 +import org.oppia.android.util.platformparameter.EXTRA_TOPIC_TABS_UI import org.oppia.android.util.platformparameter.EnableAppAndOsDeprecation import org.oppia.android.util.platformparameter.EnableDownloadsSupport import org.oppia.android.util.platformparameter.EnableEditAccountsOptionsUi @@ -30,6 +34,7 @@ import org.oppia.android.util.platformparameter.EnableSpotlightUi import org.oppia.android.util.platformparameter.FAST_LANGUAGE_SWITCHING_IN_LESSON import org.oppia.android.util.platformparameter.FORCED_APP_UPDATE_VERSION_CODE import org.oppia.android.util.platformparameter.ForcedAppUpdateVersionCode +import org.oppia.android.util.platformparameter.INTERACTION_CONFIG_CHANGE_STATE_RETENTION import org.oppia.android.util.platformparameter.LEARNER_STUDY_ANALYTICS import org.oppia.android.util.platformparameter.LOGGING_LEARNER_STUDY_IDS import org.oppia.android.util.platformparameter.LOWEST_SUPPORTED_API_LEVEL @@ -56,6 +61,7 @@ import org.oppia.android.util.platformparameter.PlatformParameterSingleton import org.oppia.android.util.platformparameter.PlatformParameterValue import org.oppia.android.util.platformparameter.SPLASH_SCREEN_WELCOME_MSG import org.oppia.android.util.platformparameter.SPLASH_SCREEN_WELCOME_MSG_DEFAULT_VALUE +import org.oppia.android.util.platformparameter.SPOTLIGHT_UI import org.oppia.android.util.platformparameter.SYNC_UP_WORKER_TIME_PERIOD_IN_HOURS import org.oppia.android.util.platformparameter.SYNC_UP_WORKER_TIME_PERIOD_IN_HOURS_DEFAULT_VALUE import org.oppia.android.util.platformparameter.SplashScreenWelcomeMsg @@ -70,8 +76,12 @@ import org.oppia.android.util.platformparameter.SyncUpWorkerTimePeriodHours class PlatformParameterAlphaKenyaModule { @Provides @EnableDownloadsSupport - fun provideEnableDownloadsSupport(): PlatformParameterValue = - PlatformParameterValue.createDefaultParameter(ENABLE_DOWNLOADS_SUPPORT_DEFAULT_VALUE) + fun provideEnableDownloadsSupport( + platformParameterSingleton: PlatformParameterSingleton + ): PlatformParameterValue { + return platformParameterSingleton.getBooleanPlatformParameter(DOWNLOADS_SUPPORT) + ?: PlatformParameterValue.createDefaultParameter(ENABLE_DOWNLOADS_SUPPORT_DEFAULT_VALUE) + } @Provides @SplashScreenWelcomeMsg @@ -104,8 +114,12 @@ class PlatformParameterAlphaKenyaModule { @Provides @EnableEditAccountsOptionsUi - fun provideEnableEditAccountsOptionsUi(): PlatformParameterValue { - return PlatformParameterValue.createDefaultParameter( + fun provideEnableEditAccountsOptionsUi( + platformParameterSingleton: PlatformParameterSingleton + ): PlatformParameterValue { + return platformParameterSingleton.getBooleanPlatformParameter( + EDIT_ACCOUNTS_OPTIONS_UI + ) ?: PlatformParameterValue.createDefaultParameter( ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE ) } @@ -199,32 +213,45 @@ class PlatformParameterAlphaKenyaModule { @Provides @EnableExtraTopicTabsUi - fun provideEnableExtraTopicTabsUi(): PlatformParameterValue { - return PlatformParameterValue.createDefaultParameter( + fun provideEnableExtraTopicTabsUi( + platformParameterSingleton: PlatformParameterSingleton + ): PlatformParameterValue { + return platformParameterSingleton.getBooleanPlatformParameter( + EXTRA_TOPIC_TABS_UI + ) ?: PlatformParameterValue.createDefaultParameter( ENABLE_EXTRA_TOPIC_TABS_UI_DEFAULT_VALUE ) } @Provides @EnableInteractionConfigChangeStateRetention - fun provideEnableInteractionConfigChangeStateRetention(): PlatformParameterValue { - return PlatformParameterValue.createDefaultParameter( + fun provideEnableInteractionConfigChangeStateRetention( + platformParameterSingleton: PlatformParameterSingleton + ): PlatformParameterValue { + return platformParameterSingleton.getBooleanPlatformParameter( + INTERACTION_CONFIG_CHANGE_STATE_RETENTION + ) ?: PlatformParameterValue.createDefaultParameter( ENABLE_INTERACTION_CONFIG_CHANGE_STATE_RETENTION_DEFAULT_VALUE ) } @Provides @EnableSpotlightUi - fun enableSpotlightUi(): PlatformParameterValue { - return PlatformParameterValue.createDefaultParameter( - ENABLE_SPOTLIGHT_UI_DEFAULT_VALUE - ) + fun provideEnableSpotlightUi( + platformParameterSingleton: PlatformParameterSingleton + ): PlatformParameterValue { + return platformParameterSingleton.getBooleanPlatformParameter(SPOTLIGHT_UI) + ?: PlatformParameterValue.createDefaultParameter(ENABLE_SPOTLIGHT_UI_DEFAULT_VALUE) } @Provides @EnableAppAndOsDeprecation - fun provideEnableAppAndOsDeprecation(): PlatformParameterValue { - return PlatformParameterValue.createDefaultParameter( + fun provideEnableAppAndOsDeprecation( + platformParameterSingleton: PlatformParameterSingleton + ): PlatformParameterValue { + return platformParameterSingleton.getBooleanPlatformParameter( + APP_AND_OS_DEPRECATION + ) ?: PlatformParameterValue.createDefaultParameter( ENABLE_APP_AND_OS_DEPRECATION_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 7ca4dcc66b0..6574762dae5 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 @@ -4,9 +4,12 @@ import android.content.Context import dagger.Module import dagger.Provides import org.oppia.android.app.utility.getVersionCode +import org.oppia.android.util.platformparameter.APP_AND_OS_DEPRECATION import org.oppia.android.util.platformparameter.CACHE_LATEX_RENDERING import org.oppia.android.util.platformparameter.CACHE_LATEX_RENDERING_DEFAULT_VALUE import org.oppia.android.util.platformparameter.CacheLatexRendering +import org.oppia.android.util.platformparameter.DOWNLOADS_SUPPORT +import org.oppia.android.util.platformparameter.EDIT_ACCOUNTS_OPTIONS_UI import org.oppia.android.util.platformparameter.ENABLE_APP_AND_OS_DEPRECATION_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_DOWNLOADS_SUPPORT_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE @@ -15,6 +18,7 @@ import org.oppia.android.util.platformparameter.ENABLE_INTERACTION_CONFIG_CHANGE import org.oppia.android.util.platformparameter.ENABLE_LANGUAGE_SELECTION_UI_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 import org.oppia.android.util.platformparameter.EnableAppAndOsDeprecation import org.oppia.android.util.platformparameter.EnableDownloadsSupport import org.oppia.android.util.platformparameter.EnableEditAccountsOptionsUi @@ -30,6 +34,7 @@ import org.oppia.android.util.platformparameter.FAST_LANGUAGE_SWITCHING_IN_LESSO import org.oppia.android.util.platformparameter.FAST_LANGUAGE_SWITCHING_IN_LESSON_DEFAULT_VALUE import org.oppia.android.util.platformparameter.FORCED_APP_UPDATE_VERSION_CODE import org.oppia.android.util.platformparameter.ForcedAppUpdateVersionCode +import org.oppia.android.util.platformparameter.INTERACTION_CONFIG_CHANGE_STATE_RETENTION import org.oppia.android.util.platformparameter.LEARNER_STUDY_ANALYTICS import org.oppia.android.util.platformparameter.LOGGING_LEARNER_STUDY_IDS import org.oppia.android.util.platformparameter.LOGGING_LEARNER_STUDY_IDS_DEFAULT_VALUE @@ -57,6 +62,7 @@ import org.oppia.android.util.platformparameter.PlatformParameterSingleton import org.oppia.android.util.platformparameter.PlatformParameterValue import org.oppia.android.util.platformparameter.SPLASH_SCREEN_WELCOME_MSG import org.oppia.android.util.platformparameter.SPLASH_SCREEN_WELCOME_MSG_DEFAULT_VALUE +import org.oppia.android.util.platformparameter.SPOTLIGHT_UI import org.oppia.android.util.platformparameter.SYNC_UP_WORKER_TIME_PERIOD_IN_HOURS import org.oppia.android.util.platformparameter.SYNC_UP_WORKER_TIME_PERIOD_IN_HOURS_DEFAULT_VALUE import org.oppia.android.util.platformparameter.SplashScreenWelcomeMsg @@ -67,8 +73,12 @@ import org.oppia.android.util.platformparameter.SyncUpWorkerTimePeriodHours class PlatformParameterAlphaModule { @Provides @EnableDownloadsSupport - fun provideEnableDownloadsSupport(): PlatformParameterValue = - PlatformParameterValue.createDefaultParameter(ENABLE_DOWNLOADS_SUPPORT_DEFAULT_VALUE) + fun provideEnableDownloadsSupport( + platformParameterSingleton: PlatformParameterSingleton + ): PlatformParameterValue { + return platformParameterSingleton.getBooleanPlatformParameter(DOWNLOADS_SUPPORT) + ?: PlatformParameterValue.createDefaultParameter(ENABLE_DOWNLOADS_SUPPORT_DEFAULT_VALUE) + } @Provides @SplashScreenWelcomeMsg @@ -101,8 +111,12 @@ class PlatformParameterAlphaModule { @Provides @EnableEditAccountsOptionsUi - fun provideEnableEditAccountsOptionsUi(): PlatformParameterValue { - return PlatformParameterValue.createDefaultParameter( + fun provideEnableEditAccountsOptionsUi( + platformParameterSingleton: PlatformParameterSingleton + ): PlatformParameterValue { + return platformParameterSingleton.getBooleanPlatformParameter( + EDIT_ACCOUNTS_OPTIONS_UI + ) ?: PlatformParameterValue.createDefaultParameter( ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE ) } @@ -195,31 +209,46 @@ class PlatformParameterAlphaModule { @Provides @EnableSpotlightUi - fun provideEnableSpotlightUi(): PlatformParameterValue = - PlatformParameterValue.createDefaultParameter(true) // Enable spotlights for alpha users. + fun provideEnableSpotlightUi( + platformParameterSingleton: PlatformParameterSingleton + ): PlatformParameterValue { + return platformParameterSingleton.getBooleanPlatformParameter(SPOTLIGHT_UI) + ?: PlatformParameterValue.createDefaultParameter(true) // Enable spotlights for alpha users. + } @Provides @EnableExtraTopicTabsUi - fun provideEnableExtraTopicTabsUi(): PlatformParameterValue { - return PlatformParameterValue.createDefaultParameter( + fun provideEnableExtraTopicTabsUi( + platformParameterSingleton: PlatformParameterSingleton + ): PlatformParameterValue { + return platformParameterSingleton.getBooleanPlatformParameter( + EXTRA_TOPIC_TABS_UI + ) ?: PlatformParameterValue.createDefaultParameter( ENABLE_EXTRA_TOPIC_TABS_UI_DEFAULT_VALUE ) } @Provides @EnableInteractionConfigChangeStateRetention - fun provideEnableInteractionConfigChangeStateRetention(): PlatformParameterValue { - return PlatformParameterValue.createDefaultParameter( + fun provideEnableInteractionConfigChangeStateRetention( + platformParameterSingleton: PlatformParameterSingleton + ): PlatformParameterValue { + return platformParameterSingleton.getBooleanPlatformParameter( + INTERACTION_CONFIG_CHANGE_STATE_RETENTION + ) ?: PlatformParameterValue.createDefaultParameter( ENABLE_INTERACTION_CONFIG_CHANGE_STATE_RETENTION_DEFAULT_VALUE ) } @Provides @EnableAppAndOsDeprecation - fun provideEnableAppAndOsDeprecation(): PlatformParameterValue { - return PlatformParameterValue.createDefaultParameter( - ENABLE_APP_AND_OS_DEPRECATION_DEFAULT_VALUE - ) + fun provideEnableAppAndOsDeprecation( + platformParameterSingleton: PlatformParameterSingleton + ): PlatformParameterValue { + return platformParameterSingleton.getBooleanPlatformParameter(APP_AND_OS_DEPRECATION) + ?: PlatformParameterValue.createDefaultParameter( + ENABLE_APP_AND_OS_DEPRECATION_DEFAULT_VALUE + ) } @Provides 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 26e25bd3590..4acd5804929 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 @@ -4,9 +4,12 @@ import android.content.Context import dagger.Module import dagger.Provides import org.oppia.android.app.utility.getVersionCode +import org.oppia.android.util.platformparameter.APP_AND_OS_DEPRECATION import org.oppia.android.util.platformparameter.CACHE_LATEX_RENDERING import org.oppia.android.util.platformparameter.CACHE_LATEX_RENDERING_DEFAULT_VALUE import org.oppia.android.util.platformparameter.CacheLatexRendering +import org.oppia.android.util.platformparameter.DOWNLOADS_SUPPORT +import org.oppia.android.util.platformparameter.EDIT_ACCOUNTS_OPTIONS_UI import org.oppia.android.util.platformparameter.ENABLE_APP_AND_OS_DEPRECATION_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_DOWNLOADS_SUPPORT_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE @@ -16,6 +19,7 @@ import org.oppia.android.util.platformparameter.ENABLE_LANGUAGE_SELECTION_UI_DEF 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 +import org.oppia.android.util.platformparameter.EXTRA_TOPIC_TABS_UI import org.oppia.android.util.platformparameter.EnableAppAndOsDeprecation import org.oppia.android.util.platformparameter.EnableDownloadsSupport import org.oppia.android.util.platformparameter.EnableEditAccountsOptionsUi @@ -31,6 +35,7 @@ import org.oppia.android.util.platformparameter.FAST_LANGUAGE_SWITCHING_IN_LESSO import org.oppia.android.util.platformparameter.FAST_LANGUAGE_SWITCHING_IN_LESSON_DEFAULT_VALUE import org.oppia.android.util.platformparameter.FORCED_APP_UPDATE_VERSION_CODE import org.oppia.android.util.platformparameter.ForcedAppUpdateVersionCode +import org.oppia.android.util.platformparameter.INTERACTION_CONFIG_CHANGE_STATE_RETENTION import org.oppia.android.util.platformparameter.LEARNER_STUDY_ANALYTICS import org.oppia.android.util.platformparameter.LEARNER_STUDY_ANALYTICS_DEFAULT_VALUE import org.oppia.android.util.platformparameter.LOGGING_LEARNER_STUDY_IDS @@ -59,6 +64,7 @@ import org.oppia.android.util.platformparameter.PlatformParameterSingleton import org.oppia.android.util.platformparameter.PlatformParameterValue import org.oppia.android.util.platformparameter.SPLASH_SCREEN_WELCOME_MSG import org.oppia.android.util.platformparameter.SPLASH_SCREEN_WELCOME_MSG_DEFAULT_VALUE +import org.oppia.android.util.platformparameter.SPOTLIGHT_UI import org.oppia.android.util.platformparameter.SYNC_UP_WORKER_TIME_PERIOD_IN_HOURS import org.oppia.android.util.platformparameter.SYNC_UP_WORKER_TIME_PERIOD_IN_HOURS_DEFAULT_VALUE import org.oppia.android.util.platformparameter.SplashScreenWelcomeMsg @@ -69,8 +75,12 @@ import org.oppia.android.util.platformparameter.SyncUpWorkerTimePeriodHours class PlatformParameterModule { @Provides @EnableDownloadsSupport - fun provideEnableDownloadsSupport(): PlatformParameterValue = - PlatformParameterValue.createDefaultParameter(ENABLE_DOWNLOADS_SUPPORT_DEFAULT_VALUE) + fun provideEnableDownloadsSupport( + platformParameterSingleton: PlatformParameterSingleton + ): PlatformParameterValue { + return platformParameterSingleton.getBooleanPlatformParameter(DOWNLOADS_SUPPORT) + ?: PlatformParameterValue.createDefaultParameter(ENABLE_DOWNLOADS_SUPPORT_DEFAULT_VALUE) + } @Provides @SplashScreenWelcomeMsg @@ -103,8 +113,12 @@ class PlatformParameterModule { @Provides @EnableEditAccountsOptionsUi - fun provideEnableEditAccountsOptionsUi(): PlatformParameterValue { - return PlatformParameterValue.createDefaultParameter( + fun provideEnableEditAccountsOptionsUi( + platformParameterSingleton: PlatformParameterSingleton + ): PlatformParameterValue { + return platformParameterSingleton.getBooleanPlatformParameter( + EDIT_ACCOUNTS_OPTIONS_UI + ) ?: PlatformParameterValue.createDefaultParameter( ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE ) } @@ -197,34 +211,46 @@ class PlatformParameterModule { @Provides @EnableSpotlightUi - fun provideEnableSpotlightUi(): PlatformParameterValue { - return PlatformParameterValue.createDefaultParameter( - ENABLE_SPOTLIGHT_UI_DEFAULT_VALUE - ) + fun provideEnableSpotlightUi( + platformParameterSingleton: PlatformParameterSingleton + ): PlatformParameterValue { + return platformParameterSingleton.getBooleanPlatformParameter(SPOTLIGHT_UI) + ?: PlatformParameterValue.createDefaultParameter(ENABLE_SPOTLIGHT_UI_DEFAULT_VALUE) } @Provides @EnableExtraTopicTabsUi - fun provideEnableExtraTopicTabsUi(): PlatformParameterValue { - return PlatformParameterValue.createDefaultParameter( + fun provideEnableExtraTopicTabsUi( + platformParameterSingleton: PlatformParameterSingleton + ): PlatformParameterValue { + return platformParameterSingleton.getBooleanPlatformParameter( + EXTRA_TOPIC_TABS_UI + ) ?: PlatformParameterValue.createDefaultParameter( ENABLE_EXTRA_TOPIC_TABS_UI_DEFAULT_VALUE ) } @Provides @EnableInteractionConfigChangeStateRetention - fun provideEnableInteractionConfigChangeStateRetention(): PlatformParameterValue { - return PlatformParameterValue.createDefaultParameter( + fun provideEnableInteractionConfigChangeStateRetention( + platformParameterSingleton: PlatformParameterSingleton + ): PlatformParameterValue { + return platformParameterSingleton.getBooleanPlatformParameter( + INTERACTION_CONFIG_CHANGE_STATE_RETENTION + ) ?: PlatformParameterValue.createDefaultParameter( ENABLE_INTERACTION_CONFIG_CHANGE_STATE_RETENTION_DEFAULT_VALUE ) } @Provides @EnableAppAndOsDeprecation - fun provideEnableAppAndOsDeprecation(): PlatformParameterValue { - return PlatformParameterValue.createDefaultParameter( - ENABLE_APP_AND_OS_DEPRECATION_DEFAULT_VALUE - ) + fun provideEnableAppAndOsDeprecation( + platformParameterSingleton: PlatformParameterSingleton + ): PlatformParameterValue { + return platformParameterSingleton.getBooleanPlatformParameter(APP_AND_OS_DEPRECATION) + ?: PlatformParameterValue.createDefaultParameter( + ENABLE_APP_AND_OS_DEPRECATION_DEFAULT_VALUE + ) } @Provides diff --git a/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterSingletonImpl.kt b/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterSingletonImpl.kt index b672ad6cdf9..0a72d4b6b44 100644 --- a/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterSingletonImpl.kt +++ b/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterSingletonImpl.kt @@ -24,8 +24,8 @@ class PlatformParameterSingletonImpl @Inject constructor() : PlatformParameterSi val parameter = platformParameterMap[platformParameterName] ?: return null if (!parameter.valueTypeCase.equals(PlatformParameter.ValueTypeCase.STRING)) return null return object : PlatformParameterValue { - override val value: String - get() = parameter.string + override val value = parameter.string + override val syncStatus = parameter.syncStatus } } @@ -36,8 +36,8 @@ class PlatformParameterSingletonImpl @Inject constructor() : PlatformParameterSi val parameter = platformParameterMap[platformParameterName] ?: return null if (!parameter.valueTypeCase.equals(PlatformParameter.ValueTypeCase.INTEGER)) return null return object : PlatformParameterValue { - override val value: Int - get() = parameter.integer + override val value = parameter.integer + override val syncStatus = parameter.syncStatus } } @@ -48,8 +48,8 @@ class PlatformParameterSingletonImpl @Inject constructor() : PlatformParameterSi val parameter = platformParameterMap[platformParameterName] ?: return null if (!parameter.valueTypeCase.equals(PlatformParameter.ValueTypeCase.BOOLEAN)) return null return object : PlatformParameterValue { - override val value: Boolean - get() = parameter.boolean + override val value = parameter.boolean + override val syncStatus = parameter.syncStatus } } } diff --git a/domain/src/main/java/org/oppia/android/domain/platformparameter/syncup/PlatformParameterSyncUpWorker.kt b/domain/src/main/java/org/oppia/android/domain/platformparameter/syncup/PlatformParameterSyncUpWorker.kt index aaf5aad0a0d..164f7fea914 100644 --- a/domain/src/main/java/org/oppia/android/domain/platformparameter/syncup/PlatformParameterSyncUpWorker.kt +++ b/domain/src/main/java/org/oppia/android/domain/platformparameter/syncup/PlatformParameterSyncUpWorker.kt @@ -11,6 +11,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.async import org.oppia.android.app.model.PlatformParameter +import org.oppia.android.app.model.PlatformParameter.SyncStatus import org.oppia.android.app.utility.getVersionName import org.oppia.android.data.backends.gae.api.PlatformParameterService import org.oppia.android.domain.oppialogger.OppiaLogger @@ -82,6 +83,7 @@ class PlatformParameterSyncUpWorker private constructor( private fun parseNetworkResponse(response: Map): List { return response.map { val platformParameter = PlatformParameter.newBuilder().setName(it.key) + .setSyncStatus(SyncStatus.SYNCED_FROM_SERVER) when (val value = it.value) { is String -> platformParameter.string = value is Int -> platformParameter.integer = value @@ -111,6 +113,7 @@ class PlatformParameterSyncUpWorker private constructor( if (response != null) { val responseBody = checkNotNull(response.body()) val platformParameterList = parseNetworkResponse(responseBody) + if (platformParameterList.isEmpty()) { throw IllegalArgumentException(EMPTY_RESPONSE_EXCEPTION_MSG) } diff --git a/domain/src/test/java/org/oppia/android/domain/audio/AudioPlayerControllerTest.kt b/domain/src/test/java/org/oppia/android/domain/audio/AudioPlayerControllerTest.kt index 1730f091d1b..1854ec26330 100644 --- a/domain/src/test/java/org/oppia/android/domain/audio/AudioPlayerControllerTest.kt +++ b/domain/src/test/java/org/oppia/android/domain/audio/AudioPlayerControllerTest.kt @@ -841,9 +841,9 @@ class AudioPlayerControllerTest { fun provideLearnerStudyAnalytics(): PlatformParameterValue { // Snapshot the value so that it doesn't change between injection and use. val enableFeature = enableLearnerStudyAnalytics - return object : PlatformParameterValue { - override val value: Boolean = enableFeature - } + return PlatformParameterValue.createDefaultParameter( + defaultValue = enableFeature + ) } @Provides @@ -852,9 +852,9 @@ class AudioPlayerControllerTest { fun provideLoggingLearnerStudyIds(): PlatformParameterValue { // Snapshot the value so that it doesn't change between injection and use. val enableFeature = enableLearnerStudyAnalytics - return object : PlatformParameterValue { - override val value: Boolean = enableFeature - } + return PlatformParameterValue.createDefaultParameter( + defaultValue = enableFeature + ) } } diff --git a/domain/src/test/java/org/oppia/android/domain/platformparameter/syncup/PlatformParameterSyncUpWorkerTest.kt b/domain/src/test/java/org/oppia/android/domain/platformparameter/syncup/PlatformParameterSyncUpWorkerTest.kt index ad16b301201..82e756c79e6 100644 --- a/domain/src/test/java/org/oppia/android/domain/platformparameter/syncup/PlatformParameterSyncUpWorkerTest.kt +++ b/domain/src/test/java/org/oppia/android/domain/platformparameter/syncup/PlatformParameterSyncUpWorkerTest.kt @@ -25,6 +25,7 @@ import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.oppia.android.app.model.PlatformParameter +import org.oppia.android.app.model.PlatformParameter.SyncStatus import org.oppia.android.data.backends.gae.BaseUrl import org.oppia.android.data.backends.gae.JsonPrefixNetworkInterceptor import org.oppia.android.data.backends.gae.NetworkApiKey @@ -95,21 +96,25 @@ class PlatformParameterSyncUpWorkerTest { private val expectedTestStringParameter = PlatformParameter.newBuilder() .setName(TEST_STRING_PARAM_NAME) .setString(TEST_STRING_PARAM_SERVER_VALUE) + .setSyncStatus(SyncStatus.SYNCED_FROM_SERVER) .build() private val expectedTestIntegerParameter = PlatformParameter.newBuilder() .setName(TEST_INTEGER_PARAM_NAME) .setInteger(TEST_INTEGER_PARAM_SERVER_VALUE) + .setSyncStatus(SyncStatus.SYNCED_FROM_SERVER) .build() private val defaultTestIntegerParameter = PlatformParameter.newBuilder() .setName(TEST_INTEGER_PARAM_NAME) .setInteger(TEST_INTEGER_PARAM_DEFAULT_VALUE) + .setSyncStatus(SyncStatus.NOT_SYNCED_FROM_SERVER) .build() private val expectedTestBooleanParameter = PlatformParameter.newBuilder() .setName(TEST_BOOLEAN_PARAM_NAME) .setBoolean(TEST_BOOLEAN_PARAM_SERVER_VALUE) + .setSyncStatus(SyncStatus.SYNCED_FROM_SERVER) .build() // Not including "expectedTestBooleanParameter" in this list to prove that a refresh took place @@ -322,6 +327,85 @@ class PlatformParameterSyncUpWorkerTest { .containsEntry(TEST_INTEGER_PARAM_NAME, defaultTestIntegerParameter) } + @Test + fun testSyncUpWorker_getFeatureFlags_addSyncStatusFlags_verifyCorrectStatusReturned() { + // Set up versionName to get correct network response from mock platform parameter service. + setUpApplicationForContext(MockPlatformParameterService.appVersionForCorrectResponse) + + // Empty the Platform Parameter Database to simulate the execution of first SyncUp Work request. + platformParameterController.updatePlatformParameterDatabase(listOf()) + + val workManager = WorkManager.getInstance(context) + + val inputData = Data.Builder().putString( + PlatformParameterSyncUpWorker.WORKER_TYPE_KEY, + PlatformParameterSyncUpWorker.PLATFORM_PARAMETER_WORKER + ).build() + + val request: OneTimeWorkRequest = OneTimeWorkRequestBuilder() + .setInputData(inputData) + .build() + + // Enqueue the Work Request to fetch and cache the Platform Parameters from Remote Service. + workManager.enqueue(request) + testCoroutineDispatchers.runCurrent() + + // Retrieve the previously cached Platform Parameters from Cache Store. + monitorFactory.ensureDataProviderExecutes(platformParameterController.getParameterDatabase()) + + // Values retrieved from Cache store will be sent to Platform Parameter Singleton by the + // Controller in the form of a Map, therefore verify the retrieved values from that Map. + val platformParameterMap = platformParameterSingleton.getPlatformParameterMap() + + // Previous String Platform Parameter is still same in the Database. + assertThat(platformParameterMap) + .containsEntry(TEST_STRING_PARAM_NAME, expectedTestStringParameter) + + // SyncStatus of the platform parameter is SYNCED_FROM_SERVER + assertThat(platformParameterMap[TEST_STRING_PARAM_NAME]?.syncStatus) + .isEqualTo(SyncStatus.SYNCED_FROM_SERVER) + } + + @Test + fun testSyncUpWorker_databaseNotEmpty_getEmptyResponse_verifySyncStatusNotUpdated() { + // Set up versionName to get incorrect network response from mock platform parameter service. + setUpApplicationForContext(MockPlatformParameterService.appVersionForEmptyResponse) + + // Fill the Platform Parameter Database with mock values to simulate the execution of a SyncUp + // Work request that is not first. + platformParameterController.updatePlatformParameterDatabase(mockPlatformParameterList) + + val workManager = WorkManager.getInstance(context) + + val inputData = Data.Builder().putString( + PlatformParameterSyncUpWorker.WORKER_TYPE_KEY, + PlatformParameterSyncUpWorker.PLATFORM_PARAMETER_WORKER + ).build() + + val request: OneTimeWorkRequest = OneTimeWorkRequestBuilder() + .setInputData(inputData) + .build() + + // Enqueue the Work Request to fetch and cache the Platform Parameters from Remote Service. + workManager.enqueue(request) + testCoroutineDispatchers.runCurrent() + + // Retrieve the previously cached Platform Parameters from Cache Store. + monitorFactory.ensureDataProviderExecutes(platformParameterController.getParameterDatabase()) + + // Values retrieved from Cache store will be sent to Platform Parameter Singleton by the + // Controller in the form of a Map, therefore verify the retrieved values from that Map. + val platformParameterMap = platformParameterSingleton.getPlatformParameterMap() + + // Previous Integer Platform Parameter is still same in the Database. + assertThat(platformParameterMap) + .containsEntry(TEST_INTEGER_PARAM_NAME, defaultTestIntegerParameter) + + // SyncStatus of the platform parameter is still the same in the database + assertThat(platformParameterMap[TEST_INTEGER_PARAM_NAME]?.syncStatus) + .isEqualTo(SyncStatus.NOT_SYNCED_FROM_SERVER) + } + private fun setUpTestApplicationComponent() { ApplicationProvider.getApplicationContext().inject(this) } diff --git a/domain/src/test/java/org/oppia/android/domain/profile/ProfileManagementControllerTest.kt b/domain/src/test/java/org/oppia/android/domain/profile/ProfileManagementControllerTest.kt index 62733f8119c..e95142771be 100644 --- a/domain/src/test/java/org/oppia/android/domain/profile/ProfileManagementControllerTest.kt +++ b/domain/src/test/java/org/oppia/android/domain/profile/ProfileManagementControllerTest.kt @@ -1356,9 +1356,9 @@ class ProfileManagementControllerTest { fun provideLearnerStudyAnalytics(): PlatformParameterValue { // Snapshot the value so that it doesn't change between injection and use. val enableFeature = enableLearnerStudyAnalytics - return object : PlatformParameterValue { - override val value: Boolean = enableFeature - } + return PlatformParameterValue.createDefaultParameter( + defaultValue = enableFeature + ) } @Provides @@ -1367,9 +1367,9 @@ class ProfileManagementControllerTest { fun provideLoggingLearnerStudyIds(): PlatformParameterValue { // Snapshot the value so that it doesn't change between injection and use. val enableFeature = enableLearnerStudyAnalytics - return object : PlatformParameterValue { - override val value: Boolean = enableFeature - } + return PlatformParameterValue.createDefaultParameter( + defaultValue = enableFeature + ) } } diff --git a/model/src/main/proto/platform_parameter.proto b/model/src/main/proto/platform_parameter.proto index 67f9fd6d772..58e45f8325c 100644 --- a/model/src/main/proto/platform_parameter.proto +++ b/model/src/main/proto/platform_parameter.proto @@ -18,6 +18,19 @@ message PlatformParameter { // Indicates a string-typed platform parameter. string string = 4; } + // Indicates the sync status of the platform parameter. + SyncStatus sync_status = 5; + + enum SyncStatus { + // Indicates that the sync status isn't yet known. + SYNC_STATUS_UNSPECIFIED = 0; + + // Indicates that the parameter isn't yet synced with the remote server. + NOT_SYNCED_FROM_SERVER = 1; + + // Indicates the parameter's value has been synced with the remote server. + SYNCED_FROM_SERVER = 2; + } } // Format of platform parameters stored on disk. It closely resembles the JSON response in cache. diff --git a/scripts/assets/test_file_exemptions.textproto b/scripts/assets/test_file_exemptions.textproto index 382bd7c1efa..dac453e5d9b 100644 --- a/scripts/assets/test_file_exemptions.textproto +++ b/scripts/assets/test_file_exemptions.textproto @@ -798,10 +798,8 @@ exempted_file_path: "testing/src/main/java/org/oppia/android/testing/network/Moc exempted_file_path: "testing/src/main/java/org/oppia/android/testing/network/MockSubtopicService.kt" exempted_file_path: "testing/src/main/java/org/oppia/android/testing/network/MockTopicService.kt" exempted_file_path: "testing/src/main/java/org/oppia/android/testing/network/RetrofitTestModule.kt" -exempted_file_path: "testing/src/main/java/org/oppia/android/testing/platformparameter/TestBooleanPlatformParameter.kt" -exempted_file_path: "testing/src/main/java/org/oppia/android/testing/platformparameter/TestIntegerPlatformParameter.kt" +exempted_file_path: "testing/src/main/java/org/oppia/android/testing/platformparameter/TestPlatformParameterConstants.kt" exempted_file_path: "testing/src/main/java/org/oppia/android/testing/platformparameter/TestPlatformParameterModule.kt" -exempted_file_path: "testing/src/main/java/org/oppia/android/testing/platformparameter/TestStringPlatformParameter.kt" exempted_file_path: "testing/src/main/java/org/oppia/android/testing/robolectric/IsOnRobolectric.kt" exempted_file_path: "testing/src/main/java/org/oppia/android/testing/robolectric/RobolectricModule.kt" exempted_file_path: "testing/src/main/java/org/oppia/android/testing/threading/BackgroundTestDispatcher.kt" @@ -887,6 +885,7 @@ exempted_file_path: "utility/src/main/java/org/oppia/android/util/parser/svg/Svg exempted_file_path: "utility/src/main/java/org/oppia/android/util/parser/svg/SvgDecoder.kt" exempted_file_path: "utility/src/main/java/org/oppia/android/util/parser/svg/SvgPictureDrawable.kt" exempted_file_path: "utility/src/main/java/org/oppia/android/util/parser/svg/TextSvgDrawableTranscoder.kt" +exempted_file_path: "utility/src/main/java/org/oppia/android/util/platformparameter/FeatureFlagConstants.kt" exempted_file_path: "utility/src/main/java/org/oppia/android/util/platformparameter/PlatformParameterConstants.kt" exempted_file_path: "utility/src/main/java/org/oppia/android/util/platformparameter/PlatformParameterValue.kt" exempted_file_path: "utility/src/main/java/org/oppia/android/util/statusbar/StatusBarColor.kt" diff --git a/testing/src/main/java/org/oppia/android/testing/platformparameter/BUILD.bazel b/testing/src/main/java/org/oppia/android/testing/platformparameter/BUILD.bazel index a724de2135e..2ef5618b8fc 100644 --- a/testing/src/main/java/org/oppia/android/testing/platformparameter/BUILD.bazel +++ b/testing/src/main/java/org/oppia/android/testing/platformparameter/BUILD.bazel @@ -10,9 +10,7 @@ kt_android_library( name = "test_constants", testonly = True, srcs = [ - "TestBooleanPlatformParameter.kt", - "TestIntegerPlatformParameter.kt", - "TestStringPlatformParameter.kt", + "TestPlatformParameterConstants.kt", ], visibility = [ "//:oppia_testing_visibility", diff --git a/testing/src/main/java/org/oppia/android/testing/platformparameter/TestBooleanPlatformParameter.kt b/testing/src/main/java/org/oppia/android/testing/platformparameter/TestBooleanPlatformParameter.kt deleted file mode 100644 index de74d381739..00000000000 --- a/testing/src/main/java/org/oppia/android/testing/platformparameter/TestBooleanPlatformParameter.kt +++ /dev/null @@ -1,24 +0,0 @@ -package org.oppia.android.testing.platformparameter - -import javax.inject.Qualifier - -/** - * Qualifier for test boolean platform parameter. Only used in tests related to platform parameter. - */ -@Qualifier -annotation class TestBooleanParam - -/** - * Name for the test boolean platform parameter. Only used in tests related to platform parameter. - */ -const val TEST_BOOLEAN_PARAM_NAME = "test_boolean_param_name" - -/** - * Default value for the test boolean platform parameter. Only used in tests related to platform parameter. - */ -const val TEST_BOOLEAN_PARAM_DEFAULT_VALUE = false - -/** - * Server value for the test boolean platform parameter. Only used in tests related to platform parameter. - */ -const val TEST_BOOLEAN_PARAM_SERVER_VALUE = true diff --git a/testing/src/main/java/org/oppia/android/testing/platformparameter/TestIntegerPlatformParameter.kt b/testing/src/main/java/org/oppia/android/testing/platformparameter/TestIntegerPlatformParameter.kt deleted file mode 100644 index 956d3f1d4e0..00000000000 --- a/testing/src/main/java/org/oppia/android/testing/platformparameter/TestIntegerPlatformParameter.kt +++ /dev/null @@ -1,24 +0,0 @@ -package org.oppia.android.testing.platformparameter - -import javax.inject.Qualifier - -/** - * Qualifier for test integer platform parameter. Only used in tests related to platform parameter. - */ -@Qualifier -annotation class TestIntegerParam - -/** - * Name for the test integer platform parameter. Only used in tests related to platform parameter. - */ -const val TEST_INTEGER_PARAM_NAME = "test_integer_param_name" - -/** - * Default value for the test integer platform parameter. Only used in tests related to platform parameter. - */ -const val TEST_INTEGER_PARAM_DEFAULT_VALUE = 0 - -/** - * Server value for the test integer platform parameter. Only used in tests related to platform parameter. - */ -const val TEST_INTEGER_PARAM_SERVER_VALUE = 1 diff --git a/testing/src/main/java/org/oppia/android/testing/platformparameter/TestPlatformParameterConstants.kt b/testing/src/main/java/org/oppia/android/testing/platformparameter/TestPlatformParameterConstants.kt new file mode 100644 index 00000000000..a904314f795 --- /dev/null +++ b/testing/src/main/java/org/oppia/android/testing/platformparameter/TestPlatformParameterConstants.kt @@ -0,0 +1,68 @@ +package org.oppia.android.testing.platformparameter + +import javax.inject.Qualifier + +/** + * Qualifier for test string platform parameter. Only used in tests related to platform parameter. + */ +@Qualifier +annotation class TestStringParam + +/** + * Name for the test string platform parameter. Only used in tests related to platform parameter. + */ +const val TEST_STRING_PARAM_NAME = "test_string_param_name" + +/** + * Default value for the test string platform parameter. Only used in tests related to platform + * parameter. + */ +const val TEST_STRING_PARAM_DEFAULT_VALUE = "test_string_param_default_value" + +/** + * Server value for the test string platform parameter. Only used in tests related to platform + * parameter. + */ +const val TEST_STRING_PARAM_SERVER_VALUE = "test_string_param_value" + +/** + * Qualifier for test boolean platform parameter. Only used in tests related to platform parameter. + */ +@Qualifier +annotation class TestBooleanParam + +/** + * Name for the test boolean platform parameter. Only used in tests related to platform parameter. + */ +const val TEST_BOOLEAN_PARAM_NAME = "test_boolean_param_name" + +/** + * Default value for the test boolean platform parameter. Only used in tests related to platform parameter. + */ +const val TEST_BOOLEAN_PARAM_DEFAULT_VALUE = false + +/** + * Server value for the test boolean platform parameter. Only used in tests related to platform parameter. + */ +const val TEST_BOOLEAN_PARAM_SERVER_VALUE = true + +/** + * Qualifier for test integer platform parameter. Only used in tests related to platform parameter. + */ +@Qualifier +annotation class TestIntegerParam + +/** + * Name for the test integer platform parameter. Only used in tests related to platform parameter. + */ +const val TEST_INTEGER_PARAM_NAME = "test_integer_param_name" + +/** + * Default value for the test integer platform parameter. Only used in tests related to platform parameter. + */ +const val TEST_INTEGER_PARAM_DEFAULT_VALUE = 0 + +/** + * Server value for the test integer platform parameter. Only used in tests related to platform parameter. + */ +const val TEST_INTEGER_PARAM_SERVER_VALUE = 1 diff --git a/testing/src/main/java/org/oppia/android/testing/platformparameter/TestStringPlatformParameter.kt b/testing/src/main/java/org/oppia/android/testing/platformparameter/TestStringPlatformParameter.kt deleted file mode 100644 index 330623e1ba4..00000000000 --- a/testing/src/main/java/org/oppia/android/testing/platformparameter/TestStringPlatformParameter.kt +++ /dev/null @@ -1,24 +0,0 @@ -package org.oppia.android.testing.platformparameter - -import javax.inject.Qualifier - -/** - * Qualifier for test string platform parameter. Only used in tests related to platform parameter. - */ -@Qualifier -annotation class TestStringParam - -/** - * Name for the test string platform parameter. Only used in tests related to platform parameter. - */ -const val TEST_STRING_PARAM_NAME = "test_string_param_name" - -/** - * Default value for the test string platform parameter. Only used in tests related to platform parameter. - */ -const val TEST_STRING_PARAM_DEFAULT_VALUE = "test_string_param_default_value" - -/** - * Server value for the test string platform parameter. Only used in tests related to platform parameter. - */ -const val TEST_STRING_PARAM_SERVER_VALUE = "test_string_param_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 new file mode 100644 index 00000000000..dd45a5a3ae2 --- /dev/null +++ b/utility/src/main/java/org/oppia/android/util/platformparameter/FeatureFlagConstants.kt @@ -0,0 +1,157 @@ +package org.oppia.android.util.platformparameter + +import javax.inject.Qualifier + +/** + * This file contains all the constants that are associated with individual Feature Flags. + * These constants are: + * - Qualifier Annotation + * - Feature Flag Name - The name begins with Enable_ + * - Feature Flag Default Value + * - Feature Flag Status - A boolean that keeps track of whether the feature flag + * has been synced with Oppia Web. + */ + +/** + * Qualifier for the feature flag that controls whether the user has support for manually + * downloading topics. + */ +@Qualifier annotation class EnableDownloadsSupport + +/** Name of the feature flag that controls whether to enable downloads support. */ +const val DOWNLOADS_SUPPORT = "downloads_support" + +/** Default value for feature flag corresponding to [EnableDownloadsSupport]. */ +const val ENABLE_DOWNLOADS_SUPPORT_DEFAULT_VALUE = false + +/** Qualifier for the feature flag corresponding to enabling the language selection UI. */ +@Qualifier +annotation class EnableLanguageSelectionUi + +/** Default value for the feature flag corresponding to [EnableLanguageSelectionUi]. */ +const val ENABLE_LANGUAGE_SELECTION_UI_DEFAULT_VALUE = true + +/** + * Qualifier for the feature flag corresponding to enabling the extra topic tabs: practice and info. + */ +@Qualifier +annotation class EnableExtraTopicTabsUi + +/** Name of the feature flag that controls whether to enable the extra topics tab UI. */ +const val EXTRA_TOPIC_TABS_UI = "extra_topic_tabs_ui" + +/** Default value for the feature flag corresponding to [EnableExtraTopicTabsUi]. */ +const val ENABLE_EXTRA_TOPIC_TABS_UI_DEFAULT_VALUE = false + +/** + * Qualifier for the feature flag that controls the visibility of [ProfileAndDeviceIdActivity] + * and working of learner study related analytics logging. + */ +@Qualifier +annotation class EnableLearnerStudyAnalytics + +/** + * Name of the feature flag that controls the visibility of [ProfileAndDeviceIdActivity] + * and working of learner study related analytics logging. + */ +const val LEARNER_STUDY_ANALYTICS = "learner_study_analytics" + +/** + * Default value of the feature flag that controls the visibility of [ProfileAndDeviceIdActivity] + * and working of learner study related analytics logging. + */ +const val LEARNER_STUDY_ANALYTICS_DEFAULT_VALUE = false + +/** + * Qualifier for a feature flag that controls whether learners may be allowed (via an + * admin-controlled setting) to use a special in-lesson button for quickly switching between content + * languages. + * + * This is generally expected to only be used in tandem with [EnableLearnerStudyAnalytics]. + */ +@Qualifier annotation class EnableFastLanguageSwitchingInLesson + +/** The feature flag name corresponding to [EnableFastLanguageSwitchingInLesson]. */ +const val FAST_LANGUAGE_SWITCHING_IN_LESSON = "fast_language_switching_in_lesson" + +/** + * The default enabled state for the feature corresponding to [EnableFastLanguageSwitchingInLesson]. + */ +const val FAST_LANGUAGE_SWITCHING_IN_LESSON_DEFAULT_VALUE = false + +/** + * Qualifier for a feature flag that controls whether learner study IDs should be generated and + * logged with outgoing events. + * + * This is generally expected to only be used in tandem with [EnableLearnerStudyAnalytics]. + */ +@Qualifier annotation class EnableLoggingLearnerStudyIds + +/** The feature flag name corresponding to [EnableLoggingLearnerStudyIds]. */ +const val LOGGING_LEARNER_STUDY_IDS = "logging_learner_study_ids" + +/** The default enabled state for the feature corresponding to [EnableLoggingLearnerStudyIds]. */ +const val LOGGING_LEARNER_STUDY_IDS_DEFAULT_VALUE = false + +/** Qualifier for the feature flag corresponding to enabling the edit accounts options. */ +@Qualifier +annotation class EnableEditAccountsOptionsUi + +/** Name of the feature flag that controls whether to enable the edit account options UI. */ +const val EDIT_ACCOUNTS_OPTIONS_UI = "edit_accounts_options_ui" + +/** Default value for the feature flag corresponding to [EnableEditAccountsOptionsUi]. */ +const val ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE = false + +/** Qualifier for the feature flag that controls whether to record performance metrics. */ +@Qualifier +annotation class EnablePerformanceMetricsCollection + +/** Name of the feature flag that controls whether to record performance metrics. */ +const val ENABLE_PERFORMANCE_METRICS_COLLECTION = "enable_performance_metrics_collection" + +/** Default value for whether to record performance metrics. */ +const val ENABLE_PERFORMANCE_METRICS_COLLECTION_DEFAULT_VALUE = false + +/** Qualifier for the feature flag corresponding to enabling the spotlight UI. */ +@Qualifier +annotation class EnableSpotlightUi + +/** Name of the feature flag that controls whether to enable the spotlight UI. */ +const val SPOTLIGHT_UI = "spotlight_ui" + +/** Default value for the feature flag corresponding to [EnableSpotlightUi]. */ +const val ENABLE_SPOTLIGHT_UI_DEFAULT_VALUE = false + +/** + * Qualifier for the feature flag that controls whether input interaction state is correctly + * retained across configuration changes. + */ +@Qualifier +annotation class EnableInteractionConfigChangeStateRetention + +/** + * Name of the feature flag that controls whether input interaction state is correctly retained + * across configuration changes. + */ +const val INTERACTION_CONFIG_CHANGE_STATE_RETENTION = "interaction_config_change_state_retention" + +/** + * Default value for feature flag corresponding to [EnableInteractionConfigChangeStateRetention]. + */ +const val ENABLE_INTERACTION_CONFIG_CHANGE_STATE_RETENTION_DEFAULT_VALUE = false + +/** + * Qualifier for the [EnableAppAndOsDeprecation] feature flag that controls whether to enable + * app and OS deprecation or not. + */ +@Qualifier +annotation class EnableAppAndOsDeprecation + +/** Name of the feature flag that controls whether to enable app and os deprecation. */ +const val APP_AND_OS_DEPRECATION = "app_and_os_deprecation" + +/** + * Default value for the feature flag corresponding to [EnableAppAndOsDeprecation]. + */ +const val ENABLE_APP_AND_OS_DEPRECATION_DEFAULT_VALUE = false diff --git a/utility/src/main/java/org/oppia/android/util/platformparameter/PlatformParameterConstants.kt b/utility/src/main/java/org/oppia/android/util/platformparameter/PlatformParameterConstants.kt index fa0deba044c..46121ebf7d9 100644 --- a/utility/src/main/java/org/oppia/android/util/platformparameter/PlatformParameterConstants.kt +++ b/utility/src/main/java/org/oppia/android/util/platformparameter/PlatformParameterConstants.kt @@ -10,15 +10,6 @@ import javax.inject.Qualifier * - Platform Parameter Default Value */ -/** - * Qualifier for the platform parameter that controls whether the user has support for manually - * downloading topics. - */ -@Qualifier annotation class EnableDownloadsSupport - -/** Default value for feature flag corresponding to [EnableDownloadsSupport]. */ -const val ENABLE_DOWNLOADS_SUPPORT_DEFAULT_VALUE = false - /** * Name of the platform parameter that automatically updates topics when a user toggles the * switch in the [AdministratorControlsFragmentPresenter]. @@ -75,72 +66,6 @@ const val SYNC_UP_WORKER_TIME_PERIOD_IN_HOURS = "sync_up_worker_time_period" */ const val SYNC_UP_WORKER_TIME_PERIOD_IN_HOURS_DEFAULT_VALUE = 12 -/** Qualifier for the feature flag corresponding to enabling the language selection UI. */ -@Qualifier -annotation class EnableLanguageSelectionUi - -/** Default value for the feature flag corresponding to [EnableLanguageSelectionUi]. */ -const val ENABLE_LANGUAGE_SELECTION_UI_DEFAULT_VALUE = true - -/** - * Qualifier for the feature flag corresponding to enabling the extra topic tabs: practice and info. - */ -@Qualifier -annotation class EnableExtraTopicTabsUi - -/** Default value for the feature flag corresponding to [EnableExtraTopicTabsUi]. */ -const val ENABLE_EXTRA_TOPIC_TABS_UI_DEFAULT_VALUE = false - -/** - * Qualifier for the platform parameter that controls the visibility of [ProfileAndDeviceIdActivity] - * and working of learner study related analytics logging. - */ -@Qualifier -annotation class EnableLearnerStudyAnalytics - -/** - * Name of the platform parameter that controls the visibility of [ProfileAndDeviceIdActivity] - * and working of learner study related analytics logging. - */ -const val LEARNER_STUDY_ANALYTICS = "learner_study_analytics" - -/** - * Default value of the platform parameter that controls the visibility of [ProfileAndDeviceIdActivity] - * and working of learner study related analytics logging. - */ -const val LEARNER_STUDY_ANALYTICS_DEFAULT_VALUE = false - -/** - * Qualifier for a feature flag that controls whether learners may be allowed (via an - * admin-controlled setting) to use a special in-lesson button for quickly switching between content - * languages. - * - * This is generally expected to only be used in tandem with [EnableLearnerStudyAnalytics]. - */ -@Qualifier annotation class EnableFastLanguageSwitchingInLesson - -/** The platform parameter name corresponding to [EnableFastLanguageSwitchingInLesson]. */ -const val FAST_LANGUAGE_SWITCHING_IN_LESSON = "fast_language_switching_in_lesson" - -/** - * The default enabled state for the feature corresponding to [EnableFastLanguageSwitchingInLesson]. - */ -const val FAST_LANGUAGE_SWITCHING_IN_LESSON_DEFAULT_VALUE = false - -/** - * Qualifier for a feature flag that controls whether learner study IDs should be generated and - * logged with outgoing events. - * - * This is generally expected to only be used in tandem with [EnableLearnerStudyAnalytics]. - */ -@Qualifier annotation class EnableLoggingLearnerStudyIds - -/** The platform parameter name corresponding to [EnableLoggingLearnerStudyIds]. */ -const val LOGGING_LEARNER_STUDY_IDS = "logging_learner_study_ids" - -/** The default enabled state for the feature corresponding to [EnableLoggingLearnerStudyIds]. */ -const val LOGGING_LEARNER_STUDY_IDS_DEFAULT_VALUE = false - /** * Qualifier for the platform parameter that controls whether to cache LaTeX rendering using Glide. */ @@ -153,23 +78,6 @@ const val CACHE_LATEX_RENDERING = "cache_latex_rendering" /** Default value for whether to cache LaTeX rendering using Glide. */ const val CACHE_LATEX_RENDERING_DEFAULT_VALUE = true -/** Qualifier for the feature flag corresponding to enabling the edit accounts options. */ -@Qualifier -annotation class EnableEditAccountsOptionsUi - -/** Default value for the feature flag corresponding to [EnableEditAccountsOptionsUi]. */ -const val ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE = false - -/** Qualifier for the platform parameter that controls whether to record performance metrics. */ -@Qualifier -annotation class EnablePerformanceMetricsCollection - -/** Name of the platform parameter that controls whether to record performance metrics. */ -const val ENABLE_PERFORMANCE_METRICS_COLLECTION = "enable_performance_metrics_collection" - -/** Default value for whether to record performance metrics. */ -const val ENABLE_PERFORMANCE_METRICS_COLLECTION_DEFAULT_VALUE = false - /** * Qualifier for the platform parameter that controls the time interval in minutes of uploading * previously recorded performance metrics to the remote service. @@ -232,37 +140,6 @@ const val PERFORMANCE_METRICS_COLLECTION_LOW_FREQUENCY_TIME_INTERVAL_IN_MINUTES const val PERFORMANCE_METRICS_COLLECTION_LOW_FREQUENCY_TIME_INTERVAL_IN_MINUTES_DEFAULT_VAL = 1440 -/** Qualifier for the feature flag corresponding to enabling the spotlight UI. */ -@Qualifier -annotation class EnableSpotlightUi - -/** Default value for the feature flag corresponding to [EnableSpotlightUi]. */ -const val ENABLE_SPOTLIGHT_UI_DEFAULT_VALUE = false - -/** - * Qualifier for the platform parameter that controls whether input interaction state is correctly - * retained across configuration changes. - */ -@Qualifier -annotation class EnableInteractionConfigChangeStateRetention - -/** - * Default value for feature flag corresponding to [EnableInteractionConfigChangeStateRetention]. - */ -const val ENABLE_INTERACTION_CONFIG_CHANGE_STATE_RETENTION_DEFAULT_VALUE = false - -/** - * Qualifier for the [EnableAppAndOsDeprecation] feature flag that controls whether to enable - * app and OS deprecation or not. - */ -@Qualifier -annotation class EnableAppAndOsDeprecation - -/** - * 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 contains the version code of the latest available * optional app update, which is used to notify the app that a soft update is available. diff --git a/utility/src/main/java/org/oppia/android/util/platformparameter/PlatformParameterValue.kt b/utility/src/main/java/org/oppia/android/util/platformparameter/PlatformParameterValue.kt index 309574d9660..beefdee92bb 100644 --- a/utility/src/main/java/org/oppia/android/util/platformparameter/PlatformParameterValue.kt +++ b/utility/src/main/java/org/oppia/android/util/platformparameter/PlatformParameterValue.kt @@ -1,6 +1,7 @@ package org.oppia.android.util.platformparameter import org.oppia.android.app.model.PlatformParameter +import org.oppia.android.app.model.PlatformParameter.SyncStatus /** * Generic interface that is used to provide platform parameter values corresponding to the @@ -9,16 +10,20 @@ import org.oppia.android.app.model.PlatformParameter */ interface PlatformParameterValue { val value: T + val syncStatus: SyncStatus companion object { /** * Creates a Platform Parameter Implementation containing the default value for a particular * Platform Parameter */ - fun createDefaultParameter(defaultValue: T): PlatformParameterValue { + fun createDefaultParameter( + defaultValue: T, + defaultSyncStatus: SyncStatus = SyncStatus.NOT_SYNCED_FROM_SERVER + ): PlatformParameterValue { return object : PlatformParameterValue { - override val value: T - get() = defaultValue + override val value = defaultValue + override val syncStatus = defaultSyncStatus } } } diff --git a/utility/src/test/java/org/oppia/android/util/logging/EventBundleCreatorTest.kt b/utility/src/test/java/org/oppia/android/util/logging/EventBundleCreatorTest.kt index d2062e9097f..db424118e1f 100644 --- a/utility/src/test/java/org/oppia/android/util/logging/EventBundleCreatorTest.kt +++ b/utility/src/test/java/org/oppia/android/util/logging/EventBundleCreatorTest.kt @@ -2414,9 +2414,9 @@ class EventBundleCreatorTest { fun provideLoggingLearnerStudyIds(): PlatformParameterValue { // Snapshot the value so that it doesn't change between injection and use. val enableFeature = enableLoggingLearnerStudyIds - return object : PlatformParameterValue { - override val value: Boolean = enableFeature - } + return PlatformParameterValue.createDefaultParameter( + defaultValue = enableFeature + ) } } diff --git a/utility/src/test/java/org/oppia/android/util/logging/KenyaAlphaEventBundleCreatorTest.kt b/utility/src/test/java/org/oppia/android/util/logging/KenyaAlphaEventBundleCreatorTest.kt index 562f16b4337..3ec4c2f5169 100644 --- a/utility/src/test/java/org/oppia/android/util/logging/KenyaAlphaEventBundleCreatorTest.kt +++ b/utility/src/test/java/org/oppia/android/util/logging/KenyaAlphaEventBundleCreatorTest.kt @@ -1581,9 +1581,9 @@ class KenyaAlphaEventBundleCreatorTest { fun provideLoggingLearnerStudyIds(): PlatformParameterValue { // Snapshot the value so that it doesn't change between injection and use. val enableFeature = enableLoggingLearnerStudyIds - return object : PlatformParameterValue { - override val value: Boolean = enableFeature - } + return PlatformParameterValue.createDefaultParameter( + defaultValue = enableFeature + ) } }