Skip to content

Commit

Permalink
Introduce initial ExposureNotificationClient mock for deviceForTester…
Browse files Browse the repository at this point in the history
…s build flavor (corona-warn-app#321)
  • Loading branch information
pocmo committed Jun 18, 2020
1 parent c341644 commit 7043609
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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())
}
}
Original file line number Diff line number Diff line change
@@ -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<Boolean> {
Log.w(TAG, "isEnabled()")

return Tasks.forResult(enabled)
}

override fun provideDiagnosisKeys(
p0: MutableList<File>?,
p1: ExposureConfiguration?,
p2: String?
): Task<Void> {
Log.w(TAG, "provideDiagnosisKeys()")

return Tasks.forResult(null)
}

override fun getExposureSummary(p0: String?): Task<ExposureSummary> {
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<Void> {
Log.w(TAG, "start()")

enabled = true

return Tasks.forResult(null)
}

override fun stop(): Task<Void> {
Log.w(TAG, "stop()")

enabled = false

return Tasks.forResult(null)
}

override fun getExposureInformation(p0: String?): Task<MutableList<ExposureInformation>> {
Log.w(TAG, "getExposureInformation()")

return Tasks.forResult(null)
}

override fun getApiKey(): ApiKey<Api.ApiOptions.NoOptions> {
throw NotImplementedError()
}

override fun getTemporaryExposureKeyHistory(): Task<MutableList<TemporaryExposureKey>> {
Log.w(TAG, "getTemporaryExposureKeyHistory()")

return Tasks.forResult(mutableListOf())
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
}

/****************************************************
Expand Down

0 comments on commit 7043609

Please sign in to comment.