diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/diagnosiskeys/download/DownloadDiagnosisKeysTask.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/diagnosiskeys/download/DownloadDiagnosisKeysTask.kt index db52d23dcd0803b00a9500e8e4efec8c017b756a..b545c807ec7d29864850a5c770e6ffd08100da77 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/diagnosiskeys/download/DownloadDiagnosisKeysTask.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/diagnosiskeys/download/DownloadDiagnosisKeysTask.kt @@ -8,6 +8,7 @@ import de.rki.coronawarnapp.environment.EnvironmentSetup import de.rki.coronawarnapp.nearby.ENFClient import de.rki.coronawarnapp.nearby.modules.detectiontracker.TrackedExposureDetection import de.rki.coronawarnapp.risk.RollbackItem +import de.rki.coronawarnapp.storage.LocalData import de.rki.coronawarnapp.task.Task import de.rki.coronawarnapp.task.TaskCancellationException import de.rki.coronawarnapp.task.TaskFactory @@ -25,6 +26,7 @@ import java.util.Date import javax.inject.Inject import javax.inject.Provider +@Suppress("ReturnCount") class DownloadDiagnosisKeysTask @Inject constructor( private val enfClient: ENFClient, private val environmentSetup: EnvironmentSetup, @@ -111,6 +113,11 @@ class DownloadDiagnosisKeysTask @Inject constructor( // remember version code of this execution for next time settings.updateLastVersionCodeToCurrent() + if (LocalData.isAllowedToSubmitDiagnosisKeys()) { + Timber.tag(TAG).i("task aborted, positive test result") + return object : Task.Result {} + } + Timber.tag(TAG).d("Attempting submission to ENF") val isSubmissionSuccessful = enfClient.provideDiagnosisKeys( availableKeyFiles, diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/diagnosiskeys/download/DownloadDiagnosisKeysTaskTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/diagnosiskeys/download/DownloadDiagnosisKeysTaskTest.kt index c22593689bdb3fb649c31a47c0c244abc18a0b52..df2e2ce3dae0471911328808e994e452581ab29a 100644 --- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/diagnosiskeys/download/DownloadDiagnosisKeysTaskTest.kt +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/diagnosiskeys/download/DownloadDiagnosisKeysTaskTest.kt @@ -8,6 +8,7 @@ import de.rki.coronawarnapp.environment.BuildConfigWrap import de.rki.coronawarnapp.environment.EnvironmentSetup import de.rki.coronawarnapp.nearby.ENFClient import de.rki.coronawarnapp.nearby.modules.detectiontracker.TrackedExposureDetection +import de.rki.coronawarnapp.storage.LocalData import de.rki.coronawarnapp.util.TimeStamper import io.mockk.MockKAnnotations import io.mockk.Runs @@ -54,6 +55,8 @@ class DownloadDiagnosisKeysTaskTest : BaseTest() { mockkObject(BuildConfigWrap) every { BuildConfigWrap.VERSION_CODE } returns 1080005 + mockkObject(LocalData) + every { LocalData.isAllowedToSubmitDiagnosisKeys() } returns false availableKey1.apply { every { path } returns File("availableKey1") @@ -230,4 +233,20 @@ class DownloadDiagnosisKeysTaskTest : BaseTest() { enfClient.provideDiagnosisKeys(any(), any()) } } + + @Test + fun `we do not submit keys if user got positive test results`() = runBlockingTest { + every { LocalData.isAllowedToSubmitDiagnosisKeys() } returns true + + createInstance().run(DownloadDiagnosisKeysTask.Arguments()) + + coVerifySequence { + enfClient.isTracingEnabled + enfClient.latestTrackedExposureDetection() + } + + coVerify(exactly = 0) { + enfClient.provideDiagnosisKeys(any(), any()) + } + } }