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

App and OS deprecation: Milestone 1 #4967

Merged
merged 13 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -1,10 +1,13 @@
package org.oppia.android.domain.platformparameter

import android.content.Context
import dagger.Module
import dagger.Provides
import org.oppia.android.app.utility.getVersionCode
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.ENABLE_APP_AND_OS_DEPRECATION_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_CONTINUE_BUTTON_ANIMATION_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
Expand All @@ -14,6 +17,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.EnableAppAndOsDeprecation
import org.oppia.android.util.platformparameter.EnableContinueButtonAnimation
import org.oppia.android.util.platformparameter.EnableDownloadsSupport
import org.oppia.android.util.platformparameter.EnableEditAccountsOptionsUi
Expand All @@ -23,7 +27,14 @@ import org.oppia.android.util.platformparameter.EnableLanguageSelectionUi
import org.oppia.android.util.platformparameter.EnableLearnerStudyAnalytics
import org.oppia.android.util.platformparameter.EnablePerformanceMetricsCollection
import org.oppia.android.util.platformparameter.EnableSpotlightUi
import org.oppia.android.util.platformparameter.FORCED_APP_UPDATE_VERSION_CODE
import org.oppia.android.util.platformparameter.ForcedAppUpdateVersionCode
import org.oppia.android.util.platformparameter.LEARNER_STUDY_ANALYTICS
import org.oppia.android.util.platformparameter.LOWEST_SUPPORTED_API_LEVEL
import org.oppia.android.util.platformparameter.LOWEST_SUPPORTED_API_LEVEL_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.LowestSupportedApiLevel
import org.oppia.android.util.platformparameter.OPTIONAL_APP_UPDATE_VERSION_CODE
import org.oppia.android.util.platformparameter.OptionalAppUpdateVersionCode
import org.oppia.android.util.platformparameter.PERFORMANCE_METRICS_COLLECTION_HIGH_FREQUENCY_TIME_INTERVAL_IN_MINUTES
import org.oppia.android.util.platformparameter.PERFORMANCE_METRICS_COLLECTION_HIGH_FREQUENCY_TIME_INTERVAL_IN_MINUTES_DEFAULT_VAL
import org.oppia.android.util.platformparameter.PERFORMANCE_METRICS_COLLECTION_LOW_FREQUENCY_TIME_INTERVAL_IN_MINUTES
Expand Down Expand Up @@ -189,4 +200,50 @@ class PlatformParameterAlphaKenyaModule {
ENABLE_SPOTLIGHT_UI_DEFAULT_VALUE
)
}

@Provides
@EnableAppAndOsDeprecation
fun provideEnableAppAndOsDeprecation(): PlatformParameterValue<Boolean> {
return PlatformParameterValue.createDefaultParameter(
ENABLE_APP_AND_OS_DEPRECATION_DEFAULT_VALUE
)
}

@Provides
@OptionalAppUpdateVersionCode
fun provideOptionalAppUpdateVersionCode(
platformParameterSingleton: PlatformParameterSingleton,
context: Context
): PlatformParameterValue<Int> {
return platformParameterSingleton.getIntegerPlatformParameter(
OPTIONAL_APP_UPDATE_VERSION_CODE
) ?: PlatformParameterValue.createDefaultParameter(
context.getVersionCode()
)
}

@Provides
@ForcedAppUpdateVersionCode
fun provideForcedAppUpdateVersionCode(
platformParameterSingleton: PlatformParameterSingleton,
context: Context
): PlatformParameterValue<Int> {
return platformParameterSingleton.getIntegerPlatformParameter(
FORCED_APP_UPDATE_VERSION_CODE
) ?: PlatformParameterValue.createDefaultParameter(
context.getVersionCode()
)
}

@Provides
@LowestSupportedApiLevel
fun provideLowestSupportedApiLevel(
platformParameterSingleton: PlatformParameterSingleton
): PlatformParameterValue<Int> {
return platformParameterSingleton.getIntegerPlatformParameter(
LOWEST_SUPPORTED_API_LEVEL
) ?: PlatformParameterValue.createDefaultParameter(
LOWEST_SUPPORTED_API_LEVEL_DEFAULT_VALUE
)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.oppia.android.domain.platformparameter

import android.content.Context
import dagger.Module
import dagger.Provides
import org.oppia.android.app.utility.getVersionCode
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.ENABLE_APP_AND_OS_DEPRECATION_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.ENABLE_CONTINUE_BUTTON_ANIMATION_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
Expand All @@ -14,6 +17,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.EnableAppAndOsDeprecation
import org.oppia.android.util.platformparameter.EnableContinueButtonAnimation
import org.oppia.android.util.platformparameter.EnableDownloadsSupport
import org.oppia.android.util.platformparameter.EnableEditAccountsOptionsUi
Expand All @@ -23,8 +27,15 @@ import org.oppia.android.util.platformparameter.EnableLanguageSelectionUi
import org.oppia.android.util.platformparameter.EnableLearnerStudyAnalytics
import org.oppia.android.util.platformparameter.EnablePerformanceMetricsCollection
import org.oppia.android.util.platformparameter.EnableSpotlightUi
import org.oppia.android.util.platformparameter.FORCED_APP_UPDATE_VERSION_CODE
import org.oppia.android.util.platformparameter.ForcedAppUpdateVersionCode
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.LOWEST_SUPPORTED_API_LEVEL
import org.oppia.android.util.platformparameter.LOWEST_SUPPORTED_API_LEVEL_DEFAULT_VALUE
import org.oppia.android.util.platformparameter.LowestSupportedApiLevel
import org.oppia.android.util.platformparameter.OPTIONAL_APP_UPDATE_VERSION_CODE
import org.oppia.android.util.platformparameter.OptionalAppUpdateVersionCode
import org.oppia.android.util.platformparameter.PERFORMANCE_METRICS_COLLECTION_HIGH_FREQUENCY_TIME_INTERVAL_IN_MINUTES
import org.oppia.android.util.platformparameter.PERFORMANCE_METRICS_COLLECTION_HIGH_FREQUENCY_TIME_INTERVAL_IN_MINUTES_DEFAULT_VAL
import org.oppia.android.util.platformparameter.PERFORMANCE_METRICS_COLLECTION_LOW_FREQUENCY_TIME_INTERVAL_IN_MINUTES
Expand Down Expand Up @@ -185,4 +196,50 @@ class PlatformParameterModule {
ENABLE_CONTINUE_BUTTON_ANIMATION_DEFAULT_VALUE
)
}

@Provides
@EnableAppAndOsDeprecation
fun provideEnableAppAndOsDeprecation(): PlatformParameterValue<Boolean> {
return PlatformParameterValue.createDefaultParameter(
ENABLE_APP_AND_OS_DEPRECATION_DEFAULT_VALUE
)
}

@Provides
@OptionalAppUpdateVersionCode
fun provideOptionalAppUpdateVersionCode(
platformParameterSingleton: PlatformParameterSingleton,
context: Context
): PlatformParameterValue<Int> {
return platformParameterSingleton.getIntegerPlatformParameter(
OPTIONAL_APP_UPDATE_VERSION_CODE
) ?: PlatformParameterValue.createDefaultParameter(
context.getVersionCode()
)
}

@Provides
@ForcedAppUpdateVersionCode
fun provideForcedAppUpdateVersionCode(
platformParameterSingleton: PlatformParameterSingleton,
context: Context
): PlatformParameterValue<Int> {
return platformParameterSingleton.getIntegerPlatformParameter(
FORCED_APP_UPDATE_VERSION_CODE
) ?: PlatformParameterValue.createDefaultParameter(
context.getVersionCode()
)
}

@Provides
@LowestSupportedApiLevel
fun provideLowestSupportedApiLevel(
platformParameterSingleton: PlatformParameterSingleton
): PlatformParameterValue<Int> {
return platformParameterSingleton.getIntegerPlatformParameter(
LOWEST_SUPPORTED_API_LEVEL
) ?: PlatformParameterValue.createDefaultParameter(
LOWEST_SUPPORTED_API_LEVEL_DEFAULT_VALUE
)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.oppia.android.domain.platformparameter

import android.app.Application
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import androidx.test.core.content.pm.ApplicationInfoBuilder
import androidx.test.core.content.pm.PackageInfoBuilder
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import dagger.BindsInstance
Expand All @@ -11,6 +14,7 @@ import dagger.Provides
import org.junit.Test
import org.junit.runner.RunWith
import org.oppia.android.app.model.PlatformParameter
import org.oppia.android.app.utility.getVersionCode
import org.oppia.android.testing.platformparameter.TEST_BOOLEAN_PARAM_DEFAULT_VALUE
import org.oppia.android.testing.platformparameter.TEST_BOOLEAN_PARAM_NAME
import org.oppia.android.testing.platformparameter.TEST_BOOLEAN_PARAM_SERVER_VALUE
Expand All @@ -24,8 +28,13 @@ import org.oppia.android.testing.platformparameter.TestBooleanParam
import org.oppia.android.testing.platformparameter.TestIntegerParam
import org.oppia.android.testing.platformparameter.TestPlatformParameterModule
import org.oppia.android.testing.platformparameter.TestStringParam
import org.oppia.android.util.platformparameter.EnableAppAndOsDeprecation
import org.oppia.android.util.platformparameter.ForcedAppUpdateVersionCode
import org.oppia.android.util.platformparameter.LowestSupportedApiLevel
import org.oppia.android.util.platformparameter.OptionalAppUpdateVersionCode
import org.oppia.android.util.platformparameter.PlatformParameterSingleton
import org.oppia.android.util.platformparameter.PlatformParameterValue
import org.robolectric.Shadows
import org.robolectric.annotation.Config
import org.robolectric.annotation.LooperMode
import javax.inject.Inject
Expand All @@ -44,6 +53,9 @@ class PlatformParameterModuleTest {
@Inject
lateinit var platformParameterSingleton: PlatformParameterSingleton

@Inject
lateinit var context: Context

@field:[Inject TestStringParam]
lateinit var stringPlatformParameterProvider: Provider<PlatformParameterValue<String>>

Expand All @@ -53,6 +65,18 @@ class PlatformParameterModuleTest {
@field:[Inject TestBooleanParam]
lateinit var booleanPlatformParameterProvider: Provider<PlatformParameterValue<Boolean>>

@field:[Inject EnableAppAndOsDeprecation]
lateinit var enableAppAndOsDeprecationProvider: Provider<PlatformParameterValue<Boolean>>

@field:[Inject OptionalAppUpdateVersionCode]
lateinit var optionalAppUpdateVersionCodeProvider: Provider<PlatformParameterValue<Int>>

@field:[Inject ForcedAppUpdateVersionCode]
lateinit var forcedAppUpdateVersionCodeProvider: Provider<PlatformParameterValue<Int>>

@field:[Inject LowestSupportedApiLevel]
lateinit var lowestSupportedApiLevelProvider: Provider<PlatformParameterValue<Int>>

private val platformParameterMapWithValues by lazy {
val mockStringPlatformParameter = PlatformParameter.newBuilder()
.setString(TEST_STRING_PARAM_SERVER_VALUE).build()
Expand Down Expand Up @@ -137,18 +161,71 @@ class PlatformParameterModuleTest {
.isEqualTo(TEST_BOOLEAN_PARAM_SERVER_VALUE)
}

@Test
fun testModule_injectEnableAppAndOsDeprecation_hasCorrectDefaultValue() {
setUpTestApplicationComponent(platformParameterMapWithValues)
assertThat(enableAppAndOsDeprecationProvider.get().value)
.isEqualTo(TEST_ENABLE_APP_AND_OS_DEPRECATION_DEFAULT_VALUE)
}

@Test
fun testModule_injectOptionalAppUpdateVersionCode_hasCorrectAppVersionCode() {
setUpTestApplicationComponent(platformParameterMapWithValues)
assertThat(optionalAppUpdateVersionCodeProvider.get().value)
.isEqualTo(context.getVersionCode())
assertThat(optionalAppUpdateVersionCodeProvider.get().value)
.isEqualTo(TEST_APP_VERSION_CODE)
}

@Test
fun testModule_injectForcedAppUpdateVersionCode_hasCorrectAppVersionCode() {
setUpTestApplicationComponent(platformParameterMapWithValues)
assertThat(forcedAppUpdateVersionCodeProvider.get().value)
.isEqualTo(context.getVersionCode())
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
assertThat(forcedAppUpdateVersionCodeProvider.get().value)
.isEqualTo(TEST_APP_VERSION_CODE)
}

@Test
fun testModule_injectLowestSupportedApiLevel_hasCorrectMinimumApiLevel() {
setUpTestApplicationComponent(platformParameterMapWithValues)
assertThat(lowestSupportedApiLevelProvider.get().value)
.isEqualTo(TEST_LOWEST_SUPPORTED_API_LEVEL)
}

private fun registerTestApplication() {
val packageManager = Shadows.shadowOf(context.packageManager)
val applicationInfo =
ApplicationInfoBuilder.newBuilder()
.setPackageName(context.packageName)
.build()
val packageInfo =
PackageInfoBuilder.newBuilder()
.setPackageName(context.packageName)
.setApplicationInfo(applicationInfo)
.build()
packageInfo.versionName = TEST_APP_VERSION_NAME
packageInfo.longVersionCode = TEST_APP_VERSION_CODE
packageManager.installPackage(packageInfo)
}

private fun setUpTestApplicationComponent(platformParameterMap: Map<String, PlatformParameter>) {
ApplicationProvider.getApplicationContext<TestApplication>().inject(this)
platformParameterSingleton.setPlatformParameterMap(platformParameterMap)
registerTestApplication()
}

@Module
class TestModule {
@Provides
@Singleton
fun providePlatformParameterSingleton(
platformParameterSingletonImpl: PlatformParameterSingletonImpl
): PlatformParameterSingleton = platformParameterSingletonImpl

@Provides
fun provideContext(application: Application): Context {
return application
}
}

// TODO(#89): Move this to a common test application component.
Expand Down Expand Up @@ -180,4 +257,11 @@ class PlatformParameterModuleTest {
component.inject(platformParameterModuleTest)
}
}

private companion object {
private const val TEST_APP_VERSION_NAME = "oppia-android-test-0123456789"
private const val TEST_APP_VERSION_CODE = 125L
private const val TEST_LOWEST_SUPPORTED_API_LEVEL = 19
private const val TEST_ENABLE_APP_AND_OS_DEPRECATION_DEFAULT_VALUE = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ kt_android_library(
":dagger",
":test_constants",
"//utility",
"//utility/src/main/java/org/oppia/android/util/extensions:context_extensions",
],
)

Expand Down
Loading