diff --git a/Corona-Warn-App/src/device/java/de/rki/coronawarnapp/nearby/ExposureNotificationClientFactory.kt b/Corona-Warn-App/src/device/java/de/rki/coronawarnapp/nearby/ExposureNotificationClientFactory.kt new file mode 100644 index 00000000000..e808fc11762 --- /dev/null +++ b/Corona-Warn-App/src/device/java/de/rki/coronawarnapp/nearby/ExposureNotificationClientFactory.kt @@ -0,0 +1,11 @@ +package de.rki.coronawarnapp.nearby + +import com.google.android.gms.nearby.Nearby +import com.google.android.gms.nearby.exposurenotification.ExposureNotificationClient +import de.rki.coronawarnapp.CoronaWarnApplication + +object ExposureNotificationClientFactory { + fun createClient(): ExposureNotificationClient { + return Nearby.getExposureNotificationClient(CoronaWarnApplication.getAppContext()) + } +} diff --git a/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/nearby/ExposureNotificationClientFactory.kt b/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/nearby/ExposureNotificationClientFactory.kt new file mode 100644 index 00000000000..97efd3979d2 --- /dev/null +++ b/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/nearby/ExposureNotificationClientFactory.kt @@ -0,0 +1,93 @@ +package de.rki.coronawarnapp.nearby + +import android.util.Log +import com.google.android.gms.common.api.Api +import com.google.android.gms.common.api.internal.ApiKey +import com.google.android.gms.nearby.exposurenotification.ExposureConfiguration +import com.google.android.gms.nearby.exposurenotification.ExposureInformation +import com.google.android.gms.nearby.exposurenotification.ExposureNotificationClient +import com.google.android.gms.nearby.exposurenotification.ExposureSummary +import com.google.android.gms.nearby.exposurenotification.TemporaryExposureKey +import com.google.android.gms.tasks.Task +import com.google.android.gms.tasks.Tasks +import java.io.File + +object ExposureNotificationClientFactory { + fun createClient(): ExposureNotificationClient { + return MockExposureNotificationClient() + } +} + +private class MockExposureNotificationClient : ExposureNotificationClient { + companion object { + private const val TAG = "MockExposureNotificationClient" + } + + private var enabled: Boolean = false + + override fun isEnabled(): Task { + Log.w(TAG, "isEnabled()") + + return Tasks.forResult(enabled) + } + + override fun provideDiagnosisKeys( + p0: MutableList?, + p1: ExposureConfiguration?, + p2: String? + ): Task { + Log.w(TAG, "provideDiagnosisKeys()") + + return Tasks.forResult(null) + } + + override fun getExposureSummary(p0: String?): Task { + Log.w(TAG, "getExposureSummary()") + + val builder = ExposureSummary.ExposureSummaryBuilder() + + builder.setAttenuationDurations(intArrayOf( + 50, + 10, + 5 + )) + builder.setDaysSinceLastExposure(1) + builder.setMatchedKeyCount(1) + builder.setMaximumRiskScore(50) + builder.setSummationRiskScore(70) + + return Tasks.forResult(builder.build()) + } + + override fun start(): Task { + Log.w(TAG, "start()") + + enabled = true + + return Tasks.forResult(null) + } + + override fun stop(): Task { + Log.w(TAG, "stop()") + + enabled = false + + return Tasks.forResult(null) + } + + override fun getExposureInformation(p0: String?): Task> { + Log.w(TAG, "getExposureInformation()") + + return Tasks.forResult(null) + } + + override fun getApiKey(): ApiKey { + throw NotImplementedError() + } + + override fun getTemporaryExposureKeyHistory(): Task> { + Log.w(TAG, "getTemporaryExposureKeyHistory()") + + return Tasks.forResult(mutableListOf()) + } +} diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/nearby/InternalExposureNotificationClient.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/nearby/InternalExposureNotificationClient.kt index efa21ac8785..58e3098d275 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/nearby/InternalExposureNotificationClient.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/nearby/InternalExposureNotificationClient.kt @@ -1,6 +1,5 @@ package de.rki.coronawarnapp.nearby -import com.google.android.gms.nearby.Nearby import com.google.android.gms.nearby.exposurenotification.ExposureConfiguration import com.google.android.gms.nearby.exposurenotification.ExposureConfiguration.ExposureConfigurationBuilder import com.google.android.gms.nearby.exposurenotification.ExposureSummary @@ -24,7 +23,7 @@ object InternalExposureNotificationClient { // reference to the client from the Google framework with the given application context private val exposureNotificationClient by lazy { - Nearby.getExposureNotificationClient(CoronaWarnApplication.getAppContext()) + ExposureNotificationClientFactory.createClient() } /****************************************************