From 49996ef8a845140bf42cf1e5a00a7ffc8924071d Mon Sep 17 00:00:00 2001 From: Matthias Urhahn <matthias.urhahn@sap.com> Date: Thu, 19 Nov 2020 13:16:21 +0100 Subject: [PATCH] Fix unexpected token confusing our exposure detection tracking logic. --- .../receiver/ExposureStateUpdateReceiver.kt | 25 ++++++++----------- .../ExposureStateUpdateReceiverTest.kt | 4 +-- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/receiver/ExposureStateUpdateReceiver.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/receiver/ExposureStateUpdateReceiver.kt index 5fb17c90d..72a049c16 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/receiver/ExposureStateUpdateReceiver.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/receiver/ExposureStateUpdateReceiver.kt @@ -29,11 +29,8 @@ import javax.inject.Inject * new keys are processed. Then the [ExposureStateUpdateReceiver] will receive the corresponding action in its * [onReceive] function. * - * Inside this receiver no further action or calculation will be done but it is rather used to inform the - * [de.rki.coronawarnapp.transaction.RetrieveDiagnosisKeysTransaction] that the processing of the diagnosis keys is - * finished and the Exposure Summary can be retrieved in order to calculate a risk level to show to the user. - * - * @see de.rki.coronawarnapp.transaction.RetrieveDiagnosisKeysTransaction + * Inside this receiver no further action or calculation will be done but it is rather used to start + * a worker that launches the RiskLevelTask which then makes use of the new data this notifies us of. * */ class ExposureStateUpdateReceiver : BroadcastReceiver() { @@ -54,15 +51,13 @@ class ExposureStateUpdateReceiver : BroadcastReceiver() { scope.launch(context = scope.coroutineContext) { try { - val token = intent.requireToken() - - trackDetection(token, action) + intent.getStringExtra(EXTRA_TOKEN)?.let { + Timber.tag(TAG).w("Received unknown token from ENF: %s", it) + } - val data = Data - .Builder() - .putString(EXTRA_TOKEN, token) - .build() + trackDetection(action) + val data = Data.Builder().build() OneTimeWorkRequest .Builder(ExposureStateUpdateWorker::class.java) .setInputData(data) @@ -78,13 +73,13 @@ class ExposureStateUpdateReceiver : BroadcastReceiver() { } } - private fun trackDetection(token: String, action: String?) { + private fun trackDetection(action: String?) { when (action) { ACTION_EXPOSURE_STATE_UPDATED -> { - exposureDetectionTracker.finishExposureDetection(token, Result.UPDATED_STATE) + exposureDetectionTracker.finishExposureDetection(identifier = null, result = Result.UPDATED_STATE) } ACTION_EXPOSURE_NOT_FOUND -> { - exposureDetectionTracker.finishExposureDetection(token, Result.NO_MATCHES) + exposureDetectionTracker.finishExposureDetection(identifier = null, result = Result.NO_MATCHES) } else -> throw UnknownBroadcastException(action) } diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/receiver/ExposureStateUpdateReceiverTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/receiver/ExposureStateUpdateReceiverTest.kt index 9a703be68..4bd4076ca 100644 --- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/receiver/ExposureStateUpdateReceiverTest.kt +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/receiver/ExposureStateUpdateReceiverTest.kt @@ -84,7 +84,7 @@ class ExposureStateUpdateReceiverTest : BaseTest() { scope.advanceUntilIdle() verifySequence { - exposureDetectionTracker.finishExposureDetection("token", TrackedExposureDetection.Result.UPDATED_STATE) + exposureDetectionTracker.finishExposureDetection(null, TrackedExposureDetection.Result.UPDATED_STATE) workManager.enqueue(any<WorkRequest>()) } } @@ -97,7 +97,7 @@ class ExposureStateUpdateReceiverTest : BaseTest() { scope.advanceUntilIdle() verifySequence { - exposureDetectionTracker.finishExposureDetection("token", TrackedExposureDetection.Result.NO_MATCHES) + exposureDetectionTracker.finishExposureDetection(null, TrackedExposureDetection.Result.NO_MATCHES) workManager.enqueue(any<WorkRequest>()) } } -- GitLab