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

Active tracing days count can be negative (EXPOSUREAPP-1844) #828 (#1029)


* Refactored method

* Normalized interval pairs.

* Perfoming additional check for from date

* Removed changes from build.gradle

* Fixed lint errors

Co-authored-by: default avatarJakob Möller <jakob.moeller@sap.com>
parent f1d98958
No related branches found
No related tags found
No related merge requests found
...@@ -188,22 +188,19 @@ object TimeVariables { ...@@ -188,22 +188,19 @@ object TimeVariables {
// 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
var enIsDisabled = false val enIsDisabled = try {
!InternalExposureNotificationClient.asyncIsEnabled()
try {
enIsDisabled = !InternalExposureNotificationClient.asyncIsEnabled()
} catch (e: ApiException) { } catch (e: ApiException) {
e.report(ExceptionCategory.EXPOSURENOTIFICATION) e.report(ExceptionCategory.EXPOSURENOTIFICATION)
false
} }
if (enIsDisabled) { if (enIsDisabled) {
val current = System.currentTimeMillis() val current = System.currentTimeMillis()
var lastTimeTracingWasNotActivated = val lastTimeTracingWasNotActivated = minOf(
LocalData.lastNonActiveTracingTimestamp() ?: current LocalData.lastNonActiveTracingTimestamp() ?: current,
current - tracingActiveMS
if (lastTimeTracingWasNotActivated < (current - getTimeRangeFromRetentionPeriod())) { )
lastTimeTracingWasNotActivated = current - getTimeRangeFromRetentionPeriod()
}
inactiveTracingIntervals.add(Pair(lastTimeTracingWasNotActivated, current)) inactiveTracingIntervals.add(Pair(lastTimeTracingWasNotActivated, current))
} }
......
...@@ -61,14 +61,12 @@ class TracingIntervalRepository(private val tracingIntervalDao: TracingIntervalD ...@@ -61,14 +61,12 @@ class TracingIntervalRepository(private val tracingIntervalDao: TracingIntervalD
} }
suspend fun getIntervals(): List<Pair<Long, Long>> { suspend fun getIntervals(): List<Pair<Long, Long>> {
deleteOutdatedInterval() val retentionTimestamp = System.currentTimeMillis() - TimeVariables.getDefaultRetentionPeriodInMS()
return tracingIntervalDao.getAllIntervals().map { tracingIntervalDao.deleteOutdatedIntervals(retentionTimestamp)
Pair(it.from, it.to)
}.also {
Timber.d("Intervals: $it")
}
}
private suspend fun deleteOutdatedInterval() = tracingIntervalDao return tracingIntervalDao
.deleteOutdatedIntervals(System.currentTimeMillis() - TimeVariables.getDefaultRetentionPeriodInMS()) .getAllIntervals()
.map { Pair(maxOf(it.from, retentionTimestamp), it.to) }
.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