From a016feba35c05ce482b67e01b51b93ef1d39ef70 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Wed, 9 Sep 2020 00:50:16 +0200 Subject: [PATCH] EN: Don't create TEK without need --- ...xposureNotificationsPreferencesFragment.kt | 7 +++- .../exposurenotification/ExposureDatabase.kt | 32 +++++++++---------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/play-services-core/src/main/kotlin/org/microg/gms/ui/ExposureNotificationsPreferencesFragment.kt b/play-services-core/src/main/kotlin/org/microg/gms/ui/ExposureNotificationsPreferencesFragment.kt index e8666daf..3c69b22a 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/ui/ExposureNotificationsPreferencesFragment.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/ui/ExposureNotificationsPreferencesFragment.kt @@ -96,7 +96,12 @@ class ExposureNotificationsPreferencesFragment : PreferenceFragmentCompat() { } } collectedRpis.summary = getString(R.string.pref_exposure_collected_rpis_summary, lastHourKeys) - advertisingId.summary = currentId.toString() + if (currentId != null) { + advertisingId.isVisible = true + advertisingId.summary = currentId.toString() + } else { + advertisingId.isVisible = false + } exposureApps.removeAll() if (apps.isEmpty()) { exposureApps.addPreference(exposureAppsNone) diff --git a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureDatabase.kt b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureDatabase.kt index 94e6c86e..a227d13d 100644 --- a/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureDatabase.kt +++ b/play-services-nearby-core/src/main/kotlin/org/microg/gms/nearby/exposurenotification/ExposureDatabase.kt @@ -499,29 +499,29 @@ class ExposureDatabase private constructor(private val context: Context) : SQLit } } - private val currentTemporaryExposureKey: TemporaryExposureKey - get() = writableDatabase.let { database -> - database.beginTransaction() - try { - var key = findOwnKeyAt(currentRollingStartNumber.toInt(), database) - if (key == null) { - key = generateCurrentTemporaryExposureKey() - storeOwnKey(key, database) - } - database.setTransactionSuccessful() - key - } finally { - database.endTransaction() + private fun ensureTemporaryExposureKey(): TemporaryExposureKey = writableDatabase.let { database -> + database.beginTransaction() + try { + var key = findOwnKeyAt(currentRollingStartNumber.toInt(), database) + if (key == null) { + key = generateCurrentTemporaryExposureKey() + storeOwnKey(key, database) } + database.setTransactionSuccessful() + key + } finally { + database.endTransaction() } + } - val currentRpiId: UUID + val currentRpiId: UUID? get() { - val buffer = ByteBuffer.wrap(currentTemporaryExposureKey.generateRpiId(currentIntervalNumber.toInt())) + val key = findOwnKeyAt(currentRollingStartNumber.toInt()) ?: return null + val buffer = ByteBuffer.wrap(key.generateRpiId(currentIntervalNumber.toInt())) return UUID(buffer.long, buffer.long) } - fun generateCurrentPayload(metadata: ByteArray) = currentTemporaryExposureKey.generatePayload(currentIntervalNumber.toInt(), metadata) + fun generateCurrentPayload(metadata: ByteArray) = ensureTemporaryExposureKey().generatePayload(currentIntervalNumber.toInt(), metadata) override fun getWritableDatabase(): SQLiteDatabase { if (this != instance) {