Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Migration to google ENF client v2 (window mode) (EXPOSUREAPP-3456) #1677

Merged
merged 68 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
c41b781
temporary Params from current ENFv2 Draft - neccassary to work, but w…
BMItr Nov 2, 2020
fd7d3aa
Merge branch 'release/1.8.x' into feature/3456-enfv2-main-branch
BMItr Nov 3, 2020
8c51dcc
Merge remote-tracking branch 'origin/release/1.8.x' into feature/3456…
chris-cwa Nov 5, 2020
2f0eeeb
Merge remote-tracking branch 'origin/release/1.8.x' into feature/3456…
chris-cwa Nov 9, 2020
d2f89e7
Determine Risk Level for Exposure Windows & Aggregation (EXPOSUREAPP-…
kolyaopahle Nov 10, 2020
e51c803
Merge remote-tracking branch 'origin/release/1.8.x' into feature/3456…
chris-cwa Nov 11, 2020
3687be8
Parse test JSON files and init unit tests with respective parameters …
AlexanderAlferov Nov 12, 2020
a5630be
Enhance enf client (EXPOSUREAPP-3540) (#1584)
BMItr Nov 12, 2020
dcf361a
ENFClient v2 - ExposureDetectionTracker without identifier (EXPOSUREA…
BMItr Nov 16, 2020
fdfe57c
Initial switch to new app config version (EXPOSUREAPP-3414) (#1602)
kolyaopahle Nov 16, 2020
43ca791
Merge remote-tracking branch 'origin/release/1.8.x' into feature/3456…
chris-cwa Nov 17, 2020
fb77079
ENFv2 -Cleanup deprecations and corresponding tests (EXPOSUREAPP-3456…
BMItr Nov 17, 2020
cd319d2
Merge remote-tracking branch 'origin/release/1.8.x' into feature/3456…
chris-cwa Nov 17, 2020
02e1b5a
Merge branch 'release/1.8.x' into feature/3456-enfv2-main-branch
chris-cwa Nov 17, 2020
e46a5d8
ENFv2 - Adjustments for new tech spec (EXPOSUREAPP-3853) (#1647)
BMItr Nov 18, 2020
94ca573
Fixed asset appconfig resolution for v2 config
kolyaopahle Nov 18, 2020
c2b01a3
Fixed unittests for DefaultAppConfigSource
kolyaopahle Nov 18, 2020
940efa1
Merge pull request #1654 from corona-warn-app/fix/3456-wrong-default-…
kolyaopahle Nov 18, 2020
bc59d9c
Started to address some comments from the sneak preview PR
kolyaopahle Nov 18, 2020
a96bb27
Removed enf v1 exposure summary and tokens (EXPOSUREAPP-3538) (#1644)
chris-cwa Nov 18, 2020
689ef69
Merge branch 'feature/3456-enfv2-main-branch'
kolyaopahle Nov 18, 2020
65eac7b
Ide removed something it shouldn't have
kolyaopahle Nov 18, 2020
ddff543
Adjusted quota limit for exposure window mode
BMItr Nov 18, 2020
014de69
Merge remote-tracking branch 'origin/release/1.8.x' into feature/3456…
chris-cwa Nov 18, 2020
d5772bb
use 1.8.x variants
chris-cwa Nov 18, 2020
802f4d6
fixed some test imports
chris-cwa Nov 18, 2020
d87d8b3
fixed types
chris-cwa Nov 18, 2020
ea62e49
flow for aggregated result
chris-cwa Nov 18, 2020
92a675d
flow for windows
chris-cwa Nov 18, 2020
4756b0c
flow a pair
chris-cwa Nov 18, 2020
6f28aef
Adjusted misleading fun names
BMItr Nov 18, 2020
feeabf0
fix multiple instances for ExposureResultStore
BMItr Nov 18, 2020
5a08408
Merge branch 'feature/3456-enfv2-main-branch' into fix/3456-sneak-pre…
kolyaopahle Nov 19, 2020
541651a
Adjusted to new test cases (#1665)
AlexanderAlferov Nov 19, 2020
b74cec8
Reverted gradle changes
kolyaopahle Nov 19, 2020
2b93781
Merge branch 'release/1.8.x' into feature/3456-enfv2-main-branch
d4rken Nov 19, 2020
bad8ab7
Fix test regression.
d4rken Nov 19, 2020
49996ef
Fix unexpected token confusing our exposure detection tracking logic.
d4rken Nov 19, 2020
5bafefd
Fixed failing tests
kolyaopahle Nov 19, 2020
6df5dd8
Merge branch 'feature/3456-enfv2-main-branch' into fix/3456-sneak-pre…
kolyaopahle Nov 19, 2020
bf75427
Merge pull request #1667 from corona-warn-app/fix/3456-enfv2-main-bra…
kolyaopahle Nov 19, 2020
4764903
Merge branch 'feature/3456-enfv2-main-branch' into fix/3456-sneak-pre…
kolyaopahle Nov 19, 2020
4f11a1a
Fixed lint issues from main merge
kolyaopahle Nov 19, 2020
a237b72
Merge pull request #1656 from corona-warn-app/fix/3456-sneak-preview-…
kolyaopahle Nov 19, 2020
0965985
Adressed some of the new comments
kolyaopahle Nov 19, 2020
07ae619
linting
kolyaopahle Nov 19, 2020
895a58e
check if rawConfig contains riskCalculationParameters
kolyaopahle Nov 19, 2020
a152169
switched typical to minimum attenuation in risk calculation
kolyaopahle Nov 19, 2020
967fd5d
Inject enf client and exposure result store (#1672)
chris-cwa Nov 19, 2020
082a2c2
Merge branch 'release/1.8.x' into feature/3456-enfv2-main-branch
BMItr Nov 19, 2020
df8d005
ENFv2 - Refactor testmenu to use exposure window (EXPOSUREAPP-3845) (…
BMItr Nov 19, 2020
e1ab86b
fix failing CI tests for enfv2 main brach
BMItr Nov 19, 2020
7e863f3
sometimes less is more
BMItr Nov 19, 2020
04cd061
Merge branch 'release/1.8.x' into feature/3456-enfv2-main-branch
chris-cwa Nov 20, 2020
2492a68
Remove unused function that caused build errors.
d4rken Nov 20, 2020
51e7feb
added unsupportedENFVersionException, requireAtLeast, adjusted Tests
BMItr Nov 20, 2020
63824df
changed requiredENFVersion to V16 in DefaultDiagnosisKeyProvider
BMItr Nov 20, 2020
56571ad
- unused
chris-cwa Nov 20, 2020
4731a31
updated test api fragment to display exposure windows (#1678)
chris-cwa Nov 20, 2020
efb6deb
renamed method
chris-cwa Nov 20, 2020
6ddb44a
Merge branch 'feature/3456-enfv2-main-branch' of https://github.com/c…
chris-cwa Nov 20, 2020
35e77fb
Refactor ENF version check (#1680)
d4rken Nov 20, 2020
c92fbc7
Changed ApplicationConfigurationInvalidException to NormalizedTimePer…
kolyaopahle Nov 20, 2020
d44fb1a
Merge remote-tracking branch 'origin/feature/3456-enfv2-main-branch' …
kolyaopahle Nov 20, 2020
c6e5072
Fixed auto formatting error
kolyaopahle Nov 20, 2020
322500c
Resolve ENFv2 PR comments (#1681)
d4rken Nov 20, 2020
0361f4b
Move calculation unrelated functions into the risk level task to awai…
d4rken Nov 20, 2020
fa8315d
Merge branch 'release/1.8.x' into feature/3456-enfv2-main-branch
d4rken Nov 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2
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.material.snackbar.Snackbar
import com.google.gson.Gson
Expand All @@ -32,25 +31,24 @@ import de.rki.coronawarnapp.exception.ExceptionCategory
import de.rki.coronawarnapp.exception.ExceptionCategory.INTERNAL
import de.rki.coronawarnapp.exception.TransactionException
import de.rki.coronawarnapp.exception.reporting.report
import de.rki.coronawarnapp.nearby.InternalExposureNotificationClient
import de.rki.coronawarnapp.nearby.ENFClient
import de.rki.coronawarnapp.nearby.InternalExposureNotificationPermissionHelper
import de.rki.coronawarnapp.receiver.ExposureStateUpdateReceiver
import de.rki.coronawarnapp.risk.ExposureResultStore
import de.rki.coronawarnapp.risk.TimeVariables
import de.rki.coronawarnapp.server.protocols.AppleLegacyKeyExchange
import de.rki.coronawarnapp.sharing.ExposureSharingService
import de.rki.coronawarnapp.storage.AppDatabase
import de.rki.coronawarnapp.storage.ExposureSummaryRepository
import de.rki.coronawarnapp.storage.LocalData
import de.rki.coronawarnapp.storage.tracing.TracingIntervalRepository
import de.rki.coronawarnapp.test.menu.ui.TestMenuItem
import de.rki.coronawarnapp.util.KeyFileHelper
import de.rki.coronawarnapp.util.di.AppInjector
import de.rki.coronawarnapp.util.di.AutoInject
import de.rki.coronawarnapp.util.ui.observe2
import de.rki.coronawarnapp.util.ui.viewBindingLazy
import de.rki.coronawarnapp.util.viewmodel.CWAViewModelFactoryProvider
import de.rki.coronawarnapp.util.viewmodel.cwaViewModels
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.joda.time.DateTime
Expand All @@ -66,6 +64,8 @@ class TestForAPIFragment : Fragment(R.layout.fragment_test_for_a_p_i),
InternalExposureNotificationPermissionHelper.Callback, AutoInject {

@Inject lateinit var viewModelFactory: CWAViewModelFactoryProvider.Factory
@Inject lateinit var enfClient: ENFClient
@Inject lateinit var exposureResultStore: ExposureResultStore
private val vm: TestForApiFragmentViewModel by cwaViewModels { viewModelFactory }

companion object {
Expand All @@ -85,19 +85,13 @@ class TestForAPIFragment : Fragment(R.layout.fragment_test_for_a_p_i),
}
}

private val enfClient by lazy {
AppInjector.component.enfClient
}

private var myExposureKeysJSON: String? = null
private var myExposureKeys: List<TemporaryExposureKey>? = mutableListOf()
private var otherExposureKey: AppleLegacyKeyExchange.Key? = null
private var otherExposureKeyList = mutableListOf<AppleLegacyKeyExchange.Key>()

private lateinit var internalExposureNotificationPermissionHelper: InternalExposureNotificationPermissionHelper

private var token: String? = null

private lateinit var qrPager: ViewPager2
private lateinit var qrPagerAdapter: RecyclerView.Adapter<QRPagerAdapter.QRViewHolder>

Expand All @@ -108,8 +102,6 @@ class TestForAPIFragment : Fragment(R.layout.fragment_test_for_a_p_i),
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

token = UUID.randomUUID().toString()

internalExposureNotificationPermissionHelper =
InternalExposureNotificationPermissionHelper(this, this)

Expand All @@ -127,7 +119,6 @@ class TestForAPIFragment : Fragment(R.layout.fragment_test_for_a_p_i),
binding.apply {
buttonApiTestStart.setOnClickListener { start() }
buttonApiGetExposureKeys.setOnClickListener { getExposureKeys() }
buttonApiGetCheckExposure.setOnClickListener { checkExposure() }

buttonApiScanQrCode.setOnClickListener {
IntentIntegrator.forSupportFragment(this@TestForAPIFragment)
Expand Down Expand Up @@ -168,8 +159,7 @@ class TestForAPIFragment : Fragment(R.layout.fragment_test_for_a_p_i),

buttonRetrieveExposureSummary.setOnClickListener {
vm.launch {
val summary = ExposureSummaryRepository.getExposureSummaryRepository()
.getExposureSummaryEntities().toString()
val summary = exposureResultStore.entities.first().exposureWindows.toString()

withContext(Dispatchers.Main) {
showToast(summary)
Expand Down Expand Up @@ -206,12 +196,6 @@ class TestForAPIFragment : Fragment(R.layout.fragment_test_for_a_p_i),
}
}

override fun onResume() {
super.onResume()

updateExposureSummaryDisplay(null)
}

private val prettyKey = { key: AppleLegacyKeyExchange.Key ->
StringBuilder()
.append("\nKey data: ${key.keyData}")
Expand Down Expand Up @@ -274,9 +258,6 @@ class TestForAPIFragment : Fragment(R.layout.fragment_test_for_a_p_i),
if (null == otherExposureKey) {
showToast("No other keys provided. Please fill the EditText with the JSON containing keys")
} else {
token = UUID.randomUUID().toString()
LocalData.googleApiToken(token)

val appleKeyList = mutableListOf<AppleLegacyKeyExchange.Key>()

for (key in otherExposureKeyList) {
Expand All @@ -298,75 +279,28 @@ class TestForAPIFragment : Fragment(R.layout.fragment_test_for_a_p_i),

val dir = File(
File(requireContext().getExternalFilesDir(null), "key-export"),
token ?: ""
UUID.randomUUID().toString()
)
dir.mkdirs()

var googleFileList: List<File>
lifecycleScope.launch {
googleFileList = KeyFileHelper.asyncCreateExportFiles(appleFiles, dir)

Timber.i("Provide ${googleFileList.count()} files with ${appleKeyList.size} keys with token $token")
Timber.i("Provide ${googleFileList.count()} files with ${appleKeyList.size} keys")
try {
// only testing implementation: this is used to wait for the broadcastreceiver of the OS / EN API
enfClient.provideDiagnosisKeys(
googleFileList,
AppInjector.component.appConfigProvider.getAppConfig().exposureDetectionConfiguration,
token!!
googleFileList
)
showToast("Provided ${appleKeyList.size} keys to Google API with token $token")
showToast("Provided ${appleKeyList.size} keys to Google API")
} catch (e: Exception) {
e.report(ExceptionCategory.EXPOSURENOTIFICATION)
}
}
}
}

private fun checkExposure() {
Timber.d("Check Exposure with token $token")

lifecycleScope.launch {
try {
val exposureSummary =
InternalExposureNotificationClient.asyncGetExposureSummary(token!!)
updateExposureSummaryDisplay(exposureSummary)
showToast("Updated Exposure Summary with token $token")
Timber.d("Received exposure with token $token from QR Code")
Timber.i(exposureSummary.toString())
} catch (e: Exception) {
e.report(ExceptionCategory.EXPOSURENOTIFICATION)
}
}
}

private fun updateExposureSummaryDisplay(exposureSummary: ExposureSummary?) {

binding.labelExposureSummaryMatchedKeyCount.text = getString(
R.string.test_api_body_matchedKeyCount,
(exposureSummary?.matchedKeyCount ?: "-").toString()
)

binding.labelExposureSummaryDaysSinceLastExposure.text = getString(
R.string.test_api_body_daysSinceLastExposure,
(exposureSummary?.daysSinceLastExposure ?: "-").toString()
)

binding.labelExposureSummaryMaximumRiskScore.text = getString(
R.string.test_api_body_maximumRiskScore,
(exposureSummary?.maximumRiskScore ?: "-").toString()
)

binding.labelExposureSummarySummationRiskScore.text = getString(
R.string.test_api_body_summation_risk,
(exposureSummary?.summationRiskScore ?: "-").toString()
)

binding.labelExposureSummaryAttenuation.text = getString(
R.string.test_api_body_attenuation,
(exposureSummary?.attenuationDurationsInMinutes?.joinToString() ?: "-").toString()
)
}

private fun updateKeysDisplay() {

val myKeys =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package de.rki.coronawarnapp.test.risklevel.ui

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.navArgs
import com.google.zxing.integration.android.IntentIntegrator
import com.google.zxing.integration.android.IntentResult
import de.rki.coronawarnapp.R
import de.rki.coronawarnapp.databinding.FragmentTestRiskLevelCalculationBinding
import de.rki.coronawarnapp.server.protocols.AppleLegacyKeyExchange
import de.rki.coronawarnapp.sharing.ExposureSharingService
import de.rki.coronawarnapp.test.menu.ui.TestMenuItem
import de.rki.coronawarnapp.ui.viewmodel.SettingsViewModel
import de.rki.coronawarnapp.util.di.AutoInject
import de.rki.coronawarnapp.util.ui.observe2
import de.rki.coronawarnapp.util.ui.viewBindingLazy
import de.rki.coronawarnapp.util.viewmodel.CWAViewModelFactoryProvider
import de.rki.coronawarnapp.util.viewmodel.cwaViewModelsAssisted
import timber.log.Timber
import javax.inject.Inject

@Suppress("LongMethod")
Expand Down Expand Up @@ -55,7 +49,6 @@ class TestRiskLevelCalculationFragment : Fragment(R.layout.fragment_test_risk_le
}

binding.buttonRetrieveDiagnosisKeys.setOnClickListener { vm.retrieveDiagnosisKeys() }
binding.buttonProvideKeyViaQr.setOnClickListener { vm.scanLocalQRCodeAndProvide() }
binding.buttonCalculateRiskLevel.setOnClickListener { vm.calculateRiskLevel() }
binding.buttonClearDiagnosisKeyCache.setOnClickListener { vm.clearKeyCache() }

Expand All @@ -67,66 +60,32 @@ class TestRiskLevelCalculationFragment : Fragment(R.layout.fragment_test_risk_le
).show()
}

vm.riskScoreState.observe2(this) { state ->
binding.labelRiskScore.text = state.riskScoreMsg
binding.labelBackendParameters.text = state.backendParameters
binding.labelExposureSummary.text = state.exposureSummary
binding.labelFormula.text = state.formula
binding.labelExposureInfo.text = state.exposureInfo
vm.additionalRiskCalcInfo.observe2(this) {
binding.labelRiskAdditionalInfo.text = it
}
vm.startENFObserver()

vm.apiKeysProvidedEvent.observe2(this) { event ->
Toast.makeText(
requireContext(),
"Provided ${event.keyCount} keys to Google API with token ${event.token}",
Toast.LENGTH_SHORT
).show()
vm.aggregatedRiskResult.observe2(this) {
binding.labelAggregatedRiskResult.text = it
}

vm.startLocalQRCodeScanEvent.observe2(this) {
IntentIntegrator.forSupportFragment(this)
.setOrientationLocked(false)
.setBeepEnabled(false)
.initiateScan()
vm.exposureWindowCountString.observe2(this) {
binding.labelExposureWindowCount.text = it
}
}

override fun onResume() {
super.onResume()
vm.calculateRiskLevel()
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
val result: IntentResult =
IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
?: return super.onActivityResult(requestCode, resultCode, data)

if (result.contents == null) {
Toast.makeText(requireContext(), "Cancelled", Toast.LENGTH_LONG).show()
return
vm.exposureWindows.observe2(this) {
binding.labelExposureWindows.text = it
}

ExposureSharingService.getOthersKeys(result.contents) { key: AppleLegacyKeyExchange.Key? ->
Timber.i("Keys scanned: %s", key)
if (key == null) {
Toast.makeText(
requireContext(), "No Key data found in QR code", Toast.LENGTH_SHORT
).show()
return@getOthersKeys Unit
}

val text = binding.transmissionNumber.text.toString()
val number = if (!text.isBlank()) Integer.valueOf(text) else 5
vm.provideDiagnosisKey(number, key)
vm.backendParameters.observe2(this) {
binding.labelBackendParameters.text = it
}
}

companion object {
val TAG: String = TestRiskLevelCalculationFragment::class.simpleName!!
val MENU_ITEM = TestMenuItem(
title = "Risklevel Calculation",
description = "Risklevel calculation related test options.",
title = "ENF v2 Calculation",
description = "Window Mode related overview.",
targetId = R.id.test_risklevel_calculation_fragment
)
}
Expand Down
Loading