Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

replace JodaTime in AppConfig (EXPOSUREAPP-13141) #5210

Merged
merged 27 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ee8c269
replace JodaTime in analytics
jurajkusnier May 18, 2022
435ff35
detekt
jurajkusnier May 18, 2022
51f076c
Merge branch 'release/2.23.x' into feature/13114-replace_joda_time_an…
BMItr May 18, 2022
ec9b847
Merge branch 'release/2.23.x' into feature/13114-replace_joda_time_an…
marcauberer May 18, 2022
5036bb4
Merge branch 'release/2.23.x' into feature/13114-replace_joda_time_an…
jurajkusnier May 19, 2022
40e9bc2
Merge branch 'release/2.23.x' into feature/13114-replace_joda_time_an…
mtwalli May 19, 2022
c478130
remove unused code
jurajkusnier May 19, 2022
f924ebb
update app config
jurajkusnier May 19, 2022
105ceeb
ktlint
jurajkusnier May 19, 2022
cf6fe9b
detekt
jurajkusnier May 19, 2022
2592d0b
Merge branch 'release/2.23.x' into feature/13114-replace_joda_time_an…
mtwalli May 20, 2022
7b8e8c5
Merge branch 'release/2.23.x' into feature/13114-replace_joda_time_an…
jurajkusnier May 20, 2022
5fa5d49
Merge branch 'release/2.23.x' into feature/13114-replace_joda_time_an…
jurajkusnier May 23, 2022
8648483
Merge branch 'release/2.23.x' into feature/13114-replace_joda_time_an…
mtwalli May 23, 2022
fa188d3
Merge branch 'release/2.23.x' into feature/13114-replace_joda_time_an…
jurajkusnier May 23, 2022
d076b6b
fix tests
jurajkusnier May 23, 2022
2fd9f4e
Merge branch 'feature/13114-replace_joda_time_analytics' into feature…
jurajkusnier May 23, 2022
ba79f5d
merge
jurajkusnier May 23, 2022
edd954a
remove comment
jurajkusnier May 24, 2022
2b0478b
Merge branch 'release/2.24.x' into feature/13141-joda_app_config
jurajkusnier May 25, 2022
b8b911d
Merge branch 'release/2.24.x' into feature/13141-joda_app_config
marcauberer May 26, 2022
01b837d
Merge branch 'release/2.24.x' into feature/13141-joda_app_config
mtwalli May 27, 2022
3c4d455
Merge branch 'release/2.24.x' into feature/13141-joda_app_config
jurajkusnier May 30, 2022
e3b40a5
remove utc from AppConfigServer
jurajkusnier May 30, 2022
cd9f40c
update ConfigDataContainerTest
jurajkusnier May 30, 2022
82c41e9
Merge branch 'release/2.24.x' into feature/13141-joda_app_config
jurajkusnier May 30, 2022
7e70f92
Merge branch 'release/2.24.x' into feature/13141-joda_app_config
jurajkusnier May 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import de.rki.coronawarnapp.util.ui.observe2
import de.rki.coronawarnapp.util.ui.viewBinding
import de.rki.coronawarnapp.util.viewmodel.CWAViewModelFactoryProvider
import de.rki.coronawarnapp.util.viewmodel.cwaViewModels
import org.joda.time.DateTimeZone
import org.joda.time.format.ISODateTimeFormat
import java.time.format.DateTimeFormatter
import javax.inject.Inject

@SuppressLint("SetTextI18n")
Expand All @@ -25,19 +24,18 @@ class AppConfigTestFragment : Fragment(R.layout.fragment_test_appconfig), AutoIn

private val binding: FragmentTestAppconfigBinding by viewBinding()

private val timeFormatter = ISODateTimeFormat.dateTime()
.withZone(DateTimeZone.forID("Europe/Berlin"))
private val timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd - HH:mm:ss")

@Suppress("DEPRECATION")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

vm.currentConfig.observe2(this) { data ->
binding.currentConfiguration.text = data.rawConfig.toString()
binding.lastUpdate.text = timeFormatter.print(data.updatedAt)
binding.lastUpdate.text = timeFormatter.format(data.updatedAt)
binding.timeOffset.text =
"""
${data.localOffset.millis}ms
${data.localOffset.toMillis()}ms
configType=${data.configType}
isDeviceTimeCorrect=${data.isDeviceTimeCorrect}
""".trimIndent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import de.rki.coronawarnapp.util.di.AppContext
import de.rki.coronawarnapp.util.reset.Resettable
import okhttp3.Cache
import okhttp3.OkHttpClient
import org.joda.time.Duration
import java.time.Duration
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.io.File
Expand All @@ -43,10 +43,10 @@ object AppConfigModule {

val configHttpClient = client.newBuilder().apply {
cache(cache)
connectTimeout(HTTP_TIMEOUT_APPCONFIG.millis, TimeUnit.MILLISECONDS)
readTimeout(HTTP_TIMEOUT_APPCONFIG.millis, TimeUnit.MILLISECONDS)
writeTimeout(HTTP_TIMEOUT_APPCONFIG.millis, TimeUnit.MILLISECONDS)
callTimeout(HTTP_TIMEOUT_APPCONFIG.millis, TimeUnit.MILLISECONDS)
connectTimeout(HTTP_TIMEOUT_APPCONFIG.toMillis(), TimeUnit.MILLISECONDS)
readTimeout(HTTP_TIMEOUT_APPCONFIG.toMillis(), TimeUnit.MILLISECONDS)
writeTimeout(HTTP_TIMEOUT_APPCONFIG.toMillis(), TimeUnit.MILLISECONDS)
callTimeout(HTTP_TIMEOUT_APPCONFIG.toMillis(), TimeUnit.MILLISECONDS)
}.build()

return Retrofit.Builder()
Expand Down Expand Up @@ -109,5 +109,5 @@ object AppConfigModule {
}
}

private val HTTP_TIMEOUT_APPCONFIG = Duration.standardSeconds(10)
private val HTTP_TIMEOUT_APPCONFIG = Duration.ofSeconds(10)
private const val DEFAULT_CACHE_SIZE = 2 * 1024 * 1024L // 5MB
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package de.rki.coronawarnapp.appconfig

import de.rki.coronawarnapp.appconfig.mapping.ConfigMapping
import org.joda.time.Duration
import org.joda.time.Instant
import java.time.Duration
import java.time.Instant

interface ConfigData : ConfigMapping {

Expand Down Expand Up @@ -77,6 +77,6 @@ interface ConfigData : ConfigMapping {
}

companion object {
val DEVICE_TIME_GRACE_RANGE: Duration = Duration.standardHours(2)
val DEVICE_TIME_GRACE_RANGE: Duration = Duration.ofHours(2)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.rki.coronawarnapp.appconfig

import de.rki.coronawarnapp.appconfig.mapping.ConfigMapper
import org.joda.time.Duration
import java.time.Duration

interface CoronaTestConfig {
val ratParameters: CoronaRapidAntigenTestParametersContainer
Expand All @@ -11,8 +11,8 @@ interface CoronaTestConfig {
}

data class CoronaRapidAntigenTestParametersContainer(
val hoursToDeemTestOutdated: Duration = Duration.standardHours(DEFAULT_HOURS),
val durationToShowRiskCard: Duration = Duration.standardHours(DEFAULT_HOURS_SINCE_SAMPLE_COLLECTION),
val hoursToDeemTestOutdated: Duration = Duration.ofHours(DEFAULT_HOURS),
val durationToShowRiskCard: Duration = Duration.ofHours(DEFAULT_HOURS_SINCE_SAMPLE_COLLECTION),
) {
companion object {
const val DEFAULT_HOURS: Long = 48
Expand All @@ -21,7 +21,7 @@ data class CoronaRapidAntigenTestParametersContainer(
}

data class CoronaPCRTestParametersContainer(
val durationToShowRiskCard: Duration = Duration.standardHours(DEFAULT_HOURS_SINCE_TEST_REGISTRATION),
val durationToShowRiskCard: Duration = Duration.ofHours(DEFAULT_HOURS_SINCE_TEST_REGISTRATION),
) {
companion object {
const val DEFAULT_HOURS_SINCE_TEST_REGISTRATION = 168L // 7 days x 24 hours
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package de.rki.coronawarnapp.appconfig

import de.rki.coronawarnapp.appconfig.mapping.ConfigMapper
import okio.ByteString
import org.joda.time.Duration
import java.time.Duration

interface CovidCertificateConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package de.rki.coronawarnapp.appconfig

import de.rki.coronawarnapp.appconfig.mapping.ConfigMapper
import de.rki.coronawarnapp.server.protocols.internal.v2.ExposureDetectionParameters
import org.joda.time.Duration
import java.time.Duration

interface ExposureDetectionConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package de.rki.coronawarnapp.appconfig

import de.rki.coronawarnapp.appconfig.mapping.ConfigMapper
import de.rki.coronawarnapp.diagnosiskeys.server.LocationCode
import org.joda.time.Duration
import org.joda.time.LocalDate
import org.joda.time.LocalTime
import java.time.Duration
import java.time.LocalDate
import java.time.LocalTime

interface KeyDownloadConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DeviceTimeHandler @Inject constructor(
// ForegroundState.isInForeground has a day when opening the app.
.sample(5000)
.onEach {
Timber.tag(TAG).v("Current device time offset is: %dms", it.localOffset.millis)
Timber.tag(TAG).v("Current device time offset is: %dms", it.localOffset.toMillis())
if (it.isDeviceTimeCorrect) {
Timber.v("Dismissing any notification, device time is correct again.")
notification.dismiss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import de.rki.coronawarnapp.appconfig.sources.local.LocalAppConfigSource
import de.rki.coronawarnapp.appconfig.sources.remote.RemoteAppConfigSource
import de.rki.coronawarnapp.main.CWASettings
import de.rki.coronawarnapp.util.TimeStamper
import org.joda.time.Duration
import org.joda.time.Instant
import java.time.Duration
import java.time.Instant
import timber.log.Timber
import javax.inject.Inject

Expand All @@ -26,7 +26,7 @@ class AppConfigSource @Inject constructor(
Timber.tag(TAG).d("getConfigData(offlineMode=$offlineMode)")

val localConfig = localAppConfigSource.getConfigData()
val nowUTC = timeStamper.nowUTC
val nowUTC = timeStamper.nowJavaUTC
Timber.tag(TAG).d("nowUTC=%s localConfig.updatedAt=%s", nowUTC, localConfig?.updatedAt)

if (localConfig != null && localConfig.isValid(nowUTC)) {
Expand All @@ -48,7 +48,7 @@ class AppConfigSource @Inject constructor(
if (!remoteConfig.isDeviceTimeCorrect) {
Timber.tag(TAG).w(
"Device time is incorrect, offset=%dmin",
remoteConfig.localOffset.standardMinutes
remoteConfig.localOffset.toMinutes()
)
}
if (remoteConfig.isDeviceTimeCorrect && cwaSettings.wasDeviceTimeIncorrectAcknowledged) {
Expand All @@ -57,7 +57,7 @@ class AppConfigSource @Inject constructor(
}
if (remoteConfig.deviceTimeState == CORRECT && cwaSettings.firstReliableDeviceTime == Instant.EPOCH) {
Timber.tag(TAG).i("Setting firstReliableDeviceTime to NOW (UTC). ")
cwaSettings.firstReliableDeviceTime = timeStamper.nowUTC
cwaSettings.firstReliableDeviceTime = timeStamper.nowJavaUTC
}
if (remoteConfig.deviceTimeState != cwaSettings.lastDeviceTimeStateChangeState) {
Timber.tag(TAG).i(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package de.rki.coronawarnapp.appconfig.internal

import de.rki.coronawarnapp.appconfig.ConfigData
import de.rki.coronawarnapp.appconfig.mapping.ConfigMapping
import org.joda.time.Duration
import org.joda.time.Instant
import java.time.Duration
import java.time.Instant

data class ConfigDataContainer(
val serverTime: Instant,
Expand All @@ -29,6 +29,6 @@ data class ConfigDataContainer(
override fun isValid(nowUTC: Instant): Boolean = if (cacheValidity == Duration.ZERO) {
false
} else {
Duration(nowUTC, updatedAt).abs() <= cacheValidity
Duration.between(nowUTC, updatedAt).abs() <= cacheValidity
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package de.rki.coronawarnapp.appconfig.internal

import com.google.gson.annotations.SerializedName
import org.joda.time.Duration
import org.joda.time.Instant
import java.time.Duration
import java.time.Instant

data class InternalConfigData(
@SerializedName("rawData") val rawData: ByteArray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import de.rki.coronawarnapp.appconfig.CoronaRapidAntigenTestParametersContainer
import de.rki.coronawarnapp.appconfig.CoronaTestConfig
import de.rki.coronawarnapp.appconfig.CoronaTestConfigContainer
import de.rki.coronawarnapp.server.protocols.internal.v2.AppConfigAndroid.ApplicationConfigurationAndroid
import org.joda.time.Duration
import java.time.Duration
import timber.log.Timber
import javax.inject.Inject

Expand All @@ -28,10 +28,10 @@ class CoronaTestConfigMapper @Inject constructor() : CoronaTestConfig.Mapper {
val coronaRapidAntigenTestParameters = if (coronaTestParameters.hasCoronaRapidAntigenTestParameters()) {
val coronaRapidAntigenTestParameters = coronaTestParameters.coronaRapidAntigenTestParameters
CoronaRapidAntigenTestParametersContainer(
hoursToDeemTestOutdated = Duration.standardHours(
hoursToDeemTestOutdated = Duration.ofHours(
coronaRapidAntigenTestParameters.hoursToDeemTestOutdated.toLong()
),
durationToShowRiskCard = Duration.standardHours(
durationToShowRiskCard = Duration.ofHours(
coronaRapidAntigenTestParameters.hoursSinceSampleCollectionToShowRiskCard.toLong()
)
)
Expand All @@ -42,7 +42,7 @@ class CoronaTestConfigMapper @Inject constructor() : CoronaTestConfig.Mapper {

val coronaPCRTestParameters = if (coronaTestParameters.hasCoronaPCRTestParameters()) {
CoronaPCRTestParametersContainer(
durationToShowRiskCard = Duration.standardHours(
durationToShowRiskCard = Duration.ofHours(
coronaTestParameters.coronaPCRTestParameters.hoursSinceTestRegistrationToShowRiskCard.toLong()
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import de.rki.coronawarnapp.server.protocols.internal.v2.AppConfigAndroid
import de.rki.coronawarnapp.server.protocols.internal.v2.DgcParameters
import de.rki.coronawarnapp.util.toOkioByteString
import okio.ByteString
import org.joda.time.Duration
import java.time.Duration
import timber.log.Timber
import javax.inject.Inject

Expand Down Expand Up @@ -40,15 +40,15 @@ class CovidCertificateConfigMapper @Inject constructor() : CovidCertificateConfi
Timber.e("Invalid value for waitAfterPublicKeyRegistration: %s", it)
TestCertificateConfigContainer().waitAfterPublicKeyRegistration
} else {
Duration.standardSeconds(it.toLong())
Duration.ofSeconds(it.toLong())
}
},
waitForRetry = waitForRetryInSeconds.let {
if (it !in 0..60) {
Timber.e("Invalid value for waitForRetryInSeconds: %s", it)
TestCertificateConfigContainer().waitForRetry
} else {
Duration.standardSeconds(it.toLong())
Duration.ofSeconds(it.toLong())
}
}
)
Expand All @@ -60,7 +60,7 @@ class CovidCertificateConfigMapper @Inject constructor() : CovidCertificateConfi
return DEFAULT_EXPIRATION_THRESHOLD
}

return Duration.standardDays(expirationThresholdInDays.toLong())
return Duration.ofDays(expirationThresholdInDays.toLong())
}

private fun DgcParameters.DGCParameters.mapReissueServicePublicKeyDigest(): ByteString = try {
Expand All @@ -78,11 +78,11 @@ class CovidCertificateConfigMapper @Inject constructor() : CovidCertificateConfi
) : CovidCertificateConfig

data class TestCertificateConfigContainer(
override val waitAfterPublicKeyRegistration: Duration = Duration.standardSeconds(10),
override val waitForRetry: Duration = Duration.standardSeconds(10),
override val waitAfterPublicKeyRegistration: Duration = Duration.ofSeconds(10),
override val waitForRetry: Duration = Duration.ofSeconds(10),
) : CovidCertificateConfig.TestCertificate

companion object {
private val DEFAULT_EXPIRATION_THRESHOLD: Duration get() = Duration.standardDays(14)
private val DEFAULT_EXPIRATION_THRESHOLD: Duration get() = Duration.ofDays(14)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import dagger.Reusable
import de.rki.coronawarnapp.appconfig.ExposureDetectionConfig
import de.rki.coronawarnapp.server.protocols.internal.v2.AppConfigAndroid
import de.rki.coronawarnapp.server.protocols.internal.v2.ExposureDetectionParameters.ExposureDetectionParametersAndroid
import org.joda.time.Duration
import java.time.Duration
import javax.inject.Inject

@Reusable
Expand Down Expand Up @@ -36,9 +36,9 @@ class ExposureDetectionConfigMapper @Inject constructor() : ExposureDetectionCon
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
fun ExposureDetectionParametersAndroid?.overAllDetectionTimeout(): Duration =
if (this == null || overallTimeoutInSeconds > 3600 || overallTimeoutInSeconds <= 0) {
Duration.standardMinutes(15)
Duration.ofMinutes(15)
} else {
Duration.standardSeconds(overallTimeoutInSeconds.toLong())
Duration.ofSeconds(overallTimeoutInSeconds.toLong())
}

// If we are outside the valid data range, fallback to default value.
Expand All @@ -54,8 +54,8 @@ fun ExposureDetectionParametersAndroid?.maxExposureDetectionsPerDay(): Int =
fun ExposureDetectionParametersAndroid?.minTimeBetweenExposureDetections(): Duration {
val detectionsPerDay = this.maxExposureDetectionsPerDay()
return if (detectionsPerDay == 0) {
Duration.standardDays(1)
Duration.ofDays(1)
} else {
(24 / detectionsPerDay).let { Duration.standardHours(it.toLong()) }
(24 / detectionsPerDay).let { Duration.ofHours(it.toLong()) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import de.rki.coronawarnapp.appconfig.KeyDownloadConfig
import de.rki.coronawarnapp.diagnosiskeys.server.LocationCode
import de.rki.coronawarnapp.server.protocols.internal.v2.AppConfigAndroid
import de.rki.coronawarnapp.server.protocols.internal.v2.KeyDownloadParameters.KeyDownloadParametersAndroid
import org.joda.time.Duration
import org.joda.time.LocalDate
import org.joda.time.LocalTime
import org.joda.time.format.DateTimeFormat
import java.time.Duration
import java.time.LocalDate
import java.time.LocalTime
import java.time.format.DateTimeFormatter
import timber.log.Timber
import javax.inject.Inject

Expand All @@ -34,17 +34,17 @@ class KeyDownloadParametersMapper @Inject constructor() : KeyDownloadConfig.Mapp
// If we are outside the valid data range, fallback to default value.
private fun KeyDownloadParametersAndroid?.individualTimeout(): Duration =
if (this == null || downloadTimeoutInSeconds > 1800 || downloadTimeoutInSeconds <= 0) {
Duration.standardSeconds(60)
Duration.ofSeconds(60)
} else {
Duration.standardSeconds(downloadTimeoutInSeconds.toLong())
Duration.ofSeconds(downloadTimeoutInSeconds.toLong())
}

// If we are outside the valid data range, fallback to default value.
private fun KeyDownloadParametersAndroid?.overAllTimeout(): Duration =
if (this == null || overallTimeoutInSeconds > 1800 || overallTimeoutInSeconds <= 0) {
Duration.standardMinutes(8)
Duration.ofMinutes(8)
} else {
Duration.standardSeconds(overallTimeoutInSeconds.toLong())
Duration.ofSeconds(overallTimeoutInSeconds.toLong())
}

private fun KeyDownloadParametersAndroid?.mapDayEtags(): List<RevokedKeyPackage.Day> {
Expand Down Expand Up @@ -106,8 +106,8 @@ class KeyDownloadParametersMapper @Inject constructor() : KeyDownloadConfig.Mapp
) : KeyDownloadConfig

companion object {
private val DAY_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd")
private val HOUR_FORMATTER = DateTimeFormat.forPattern("H")
private val DAY_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd")
private val HOUR_FORMATTER = DateTimeFormatter.ofPattern("H")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import de.rki.coronawarnapp.appconfig.ConfigData
import de.rki.coronawarnapp.appconfig.internal.ConfigDataContainer
import de.rki.coronawarnapp.appconfig.mapping.ConfigParser
import de.rki.coronawarnapp.util.di.AppContext
import org.joda.time.Duration
import org.joda.time.Instant
import java.time.Duration
import java.time.Instant
import javax.inject.Inject

@Reusable
Expand Down
Loading