Skip to content
Snippets Groups Projects
Unverified Commit c7c657b3 authored by Alex Paulescu's avatar Alex Paulescu Committed by GitHub
Browse files

Active tracing days no longer negative (EXPOSUREAPP-2366) (#1082)


* Active tracing days no longer negative

* Shortened line length

Co-authored-by: default avatarJakob Möller <jakob.moeller@sap.com>
parent 3db92539
No related branches found
No related tags found
No related merge requests found
...@@ -181,13 +181,17 @@ object TimeVariables { ...@@ -181,13 +181,17 @@ object TimeVariables {
suspend fun getActiveTracingDaysInRetentionPeriod(): Long { suspend fun getActiveTracingDaysInRetentionPeriod(): Long {
// the active tracing time during the retention period - all non active tracing times // the active tracing time during the retention period - all non active tracing times
val tracingActiveMS = getTimeRangeFromRetentionPeriod() val tracingActiveMS = getTimeRangeFromRetentionPeriod()
val retentionPeriodInMS = getDefaultRetentionPeriodInMS()
val lastNonActiveTracingTimestamp = LocalData.lastNonActiveTracingTimestamp()
val current = System.currentTimeMillis()
val retentionTimestamp = current - retentionPeriodInMS
val inactiveTracingIntervals = TracingIntervalRepository val inactiveTracingIntervals = TracingIntervalRepository
.getDateRepository(CoronaWarnApplication.getAppContext()) .getDateRepository(CoronaWarnApplication.getAppContext())
.getIntervals() .getIntervals()
.toMutableList() .toMutableList()
// by default the tracing is assumed to be activated // by default the tracing is assumed to be activated
// if the API is reachable we set the value accordingly // if the API is reachable we set the value accordingly
val enIsDisabled = try { val enIsDisabled = try {
!InternalExposureNotificationClient.asyncIsEnabled() !InternalExposureNotificationClient.asyncIsEnabled()
} catch (e: ApiException) { } catch (e: ApiException) {
...@@ -195,21 +199,22 @@ object TimeVariables { ...@@ -195,21 +199,22 @@ object TimeVariables {
false false
} }
if (enIsDisabled) { // lastNonActiveTracingTimestamp could be null when en is disabled
val current = System.currentTimeMillis() // it only gets updated when you turn the en back on
val lastTimeTracingWasNotActivated = minOf( // if en is disabled and lastNonActiveTracingTimestamp != null, only then we add a pair to
LocalData.lastNonActiveTracingTimestamp() ?: current, // the inactive intervals list to account for the time of inactivity between the last time
current - tracingActiveMS // en was not active and now.
) if (enIsDisabled && lastNonActiveTracingTimestamp != null) {
val lastTimeTracingWasNotActivated = LocalData.lastNonActiveTracingTimestamp() ?: current
inactiveTracingIntervals.add(Pair(lastTimeTracingWasNotActivated, current)) inactiveTracingIntervals.add(Pair(lastTimeTracingWasNotActivated, current))
} }
val inactiveTracingMS = inactiveTracingIntervals
val finalTracingMS = tracingActiveMS - inactiveTracingIntervals .map { it.second - maxOf(it.first, retentionTimestamp) }
.map { it.second - it.first }
.sum() .sum()
return finalTracingMS.roundUpMsToDays() // because we delete periods that are past 14 days but tracingActiveMS counts from first
// ever activation, there are edge cases where tracingActiveMS gets to be > 14 days
return (minOf(tracingActiveMS, retentionPeriodInMS) - inactiveTracingMS).roundUpMsToDays()
} }
/**************************************************** /****************************************************
......
...@@ -66,7 +66,7 @@ class TracingIntervalRepository(private val tracingIntervalDao: TracingIntervalD ...@@ -66,7 +66,7 @@ class TracingIntervalRepository(private val tracingIntervalDao: TracingIntervalD
return tracingIntervalDao return tracingIntervalDao
.getAllIntervals() .getAllIntervals()
.map { Pair(maxOf(it.from, retentionTimestamp), it.to) } .map { Pair(it.from, it.to) }
.also { Timber.d("Intervals: $it") } .also { Timber.d("Intervals: $it") }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment