From 50c241ab634ef5d7c85bc227178d9a37ca173068 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Thu, 19 Nov 2020 18:40:11 +0100 Subject: [PATCH] EN: Fixed rare case of incorrectly reporting more exposures than happened --- .../core/ui/ExposureNotificationsAppPreferencesFragment.kt | 2 +- .../main/res/xml/preferences_exposure_notifications_app.xml | 2 +- .../gms/nearby/exposurenotification/ExposureDatabase.kt | 4 +++- .../gms/nearby/exposurenotification/MeasuredExposure.kt | 6 +++--- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsAppPreferencesFragment.kt b/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsAppPreferencesFragment.kt index 35ce9a44..cbe9e888 100644 --- a/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsAppPreferencesFragment.kt +++ b/play-services-nearby-core-ui/src/main/kotlin/org/microg/gms/nearby/core/ui/ExposureNotificationsAppPreferencesFragment.kt @@ -73,7 +73,7 @@ class ExposureNotificationsAppPreferencesFragment : PreferenceFragmentCompat() { val encountersLine = if (merged.isEmpty()) { getString(R.string.pref_exposure_app_last_report_summary_encounters_no) } else { - database.findAllMeasuredExposures(config.first).merge().map { + merged.map { val riskScore = it.getRiskScore(config.second.orDefault()) "ยท " + getString(R.string.pref_exposure_app_last_report_summary_encounters_line, DateUtils.formatDateRange(requireContext(), it.timestamp, it.timestamp + it.durationInMinutes * 60 * 1000L, DateUtils.FORMAT_SHOW_TIME or DateUtils.FORMAT_SHOW_DATE), riskScore) }.joinToString("
").let { getString(R.string.pref_exposure_app_last_report_summary_encounters_prefix, merged.size) + "
$it
" + getString(R.string.pref_exposure_app_last_report_summary_encounters_suffix) + "" } diff --git a/play-services-nearby-core-ui/src/main/res/xml/preferences_exposure_notifications_app.xml b/play-services-nearby-core-ui/src/main/res/xml/preferences_exposure_notifications_app.xml index c08872ef..d8d030b7 100644 --- a/play-services-nearby-core-ui/src/main/res/xml/preferences_exposure_notifications_app.xml +++ b/play-services-nearby-core-ui/src/main/res/xml/preferences_exposure_notifications_app.xml @@ -13,7 +13,7 @@ android:title="@string/open_app" /> - riskLogged) { + if (key.transmissionRiskLevel > riskLogged || key.rollingStartIntervalNumber > startLogged) { riskLogged = key.transmissionRiskLevel + startLogged = key.rollingStartIntervalNumber Log.d(TAG, "First key with risk ${key.transmissionRiskLevel}: ${ByteString.of(*key.keyData).hex()} starts ${key.rollingStartIntervalNumber}") } if ((key.rollingStartIntervalNumber + key.rollingPeriod).toLong() * ROLLING_WINDOW_LENGTH_MS + ALLOWED_KEY_OFFSET_MS < oldestRpi) { diff --git a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/MeasuredExposure.kt b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/MeasuredExposure.kt index d6dfe5a6..77c5c277 100644 --- a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/MeasuredExposure.kt +++ b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/MeasuredExposure.kt @@ -21,8 +21,8 @@ fun List.merge(): List { val result = arrayListOf() for (key in keys) { var merged: MergedExposure? = null - for (exposure in filter { it.key == key }.sortedBy { it.timestamp }) { - if (merged != null && merged.timestamp + MergedExposure.MAXIMUM_DURATION + ROLLING_WINDOW_LENGTH_MS > exposure.timestamp) { + for (exposure in filter { it.key == key }.distinctBy { it.timestamp }.sortedBy { it.timestamp }) { + if (merged != null && merged.timestamp + MergedExposure.MAXIMUM_DURATION > exposure.timestamp) { merged += exposure } else { if (merged != null) { @@ -30,7 +30,7 @@ fun List.merge(): List { } merged = MergedExposure(key, exposure.timestamp, exposure.txPower, exposure.confidence, listOf(MergedSubExposure(exposure.attenuation, exposure.duration))) } - if (merged.durationInMinutes > 30) { + if (merged.durationInMinutes >= 30) { result.add(merged) merged = null }