Skip to content

Commit

Permalink
App and OS deprecation: Milestone 1 (#4967)
Browse files Browse the repository at this point in the history
<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation
<!--
- Explain what your PR does. If this PR fixes an existing bug, please
include
- "Fixes #bugnum:" in the explanation so that GitHub can auto-close the
issue
  - when this PR is merged.
  -->
When this PR is merged, it will;
- Add platform parameters for App/OS deprecation, optional app update
version code, forced app update version code and lowest supported API
level.
- Create dependency injection providers for these four new platform
parameters.

## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [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
<!-- Delete these section if this PR does not include UI-related
changes. -->
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))
- Add a screenshot demonstrating that you ran affected Espresso tests
locally & that they're passing

---------

Co-authored-by: Ben Henning <[email protected]>
  • Loading branch information
kkmurerwa and BenHenning authored May 27, 2023
1 parent 086f0d4 commit 711d5f6
Show file tree
Hide file tree
Showing 6 changed files with 317 additions and 1 deletion.
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())
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

0 comments on commit 711d5f6

Please sign in to comment.