Skip to content
Snippets Groups Projects
Unverified Commit be9384c3 authored by Philipp Woessner's avatar Philipp Woessner Committed by GitHub
Browse files

Prevent automatic risk calculation in manual mode on app start (#795)

* added a check for manual mode when updating on app start

* added logging for conditions

* added comments
parent 12e89f68
No related branches found
No related tags found
No related merge requests found
......@@ -62,28 +62,55 @@ class TracingViewModel : ViewModel() {
fun refreshRiskLevel() {
viewModelScope.launch {
try {
// get the current date and the date the diagnosis keys were fetched the last time
val currentDate = DateTime(Instant.now(), DateTimeZone.getDefault())
val lastFetch = DateTime(
LocalData.lastTimeDiagnosisKeysFromServerFetch(),
DateTimeZone.getDefault()
)
val keysWereNotRetrievedToday = LocalData.lastTimeDiagnosisKeysFromServerFetch() == null ||
currentDate.withTimeAtStartOfDay() != lastFetch.withTimeAtStartOfDay()
val isNetworkEnabled = ConnectivityHelper.isNetworkEnabled(CoronaWarnApplication.getAppContext())
if (keysWereNotRetrievedToday && isNetworkEnabled) {
// check if the keys were not already retrieved today
val keysWereNotRetrievedToday =
LocalData.lastTimeDiagnosisKeysFromServerFetch() == null ||
currentDate.withTimeAtStartOfDay() != lastFetch.withTimeAtStartOfDay()
// check if the network is enabled to make the server fetch
val isNetworkEnabled =
ConnectivityHelper.isNetworkEnabled(CoronaWarnApplication.getAppContext())
// only fetch the diagnosis keys if background jobs are enabled, so that in manual
// model the keys are only fetched on button press of the user
val isBackgroundJobEnabled =
ConnectivityHelper.isBackgroundJobEnabled(CoronaWarnApplication.getAppContext())
Timber.v("Keys were not retrieved today $keysWereNotRetrievedToday")
Timber.v("Network is enabled $isNetworkEnabled")
Timber.v("Background jobs are enabled $isBackgroundJobEnabled")
if (keysWereNotRetrievedToday && isNetworkEnabled && isBackgroundJobEnabled) {
TracingRepository.isRefreshing.value = true
// start the fetching and submitting of the diagnosis keys
RetrieveDiagnosisKeysTransaction.start()
refreshLastTimeDiagnosisKeysFetchedDate()
TimerHelper.checkManualKeyRetrievalTimer()
}
} catch (e: TransactionException) {
e.cause?.report(INTERNAL)
} catch (e: Exception) {
e.report(INTERNAL)
}
// refresh the risk level
try {
RiskLevelTransaction.start()
} catch (e: TransactionException) {
e.cause?.report(INTERNAL)
} catch (e: Exception) {
e.report(INTERNAL)
}
TracingRepository.isRefreshing.value = false
}
}
......
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