From 2e556f9b8c8ccaf1f752de4e1c02b78c452d96d4 Mon Sep 17 00:00:00 2001 From: Philipp Woessner <64482866+pwoessner@users.noreply.github.com> Date: Tue, 21 Jul 2020 16:06:05 +0200 Subject: [PATCH] reset singleton instances when the user resets the app (#901) --- .../java/de/rki/coronawarnapp/storage/AppDatabase.kt | 7 +++++++ .../coronawarnapp/storage/ExposureSummaryRepository.kt | 4 ++++ .../rki/coronawarnapp/storage/RiskLevelRepository.kt | 10 ++++++++++ .../storage/keycache/KeyCacheRepository.kt | 4 ++++ .../storage/tracing/TracingIntervalRepository.kt | 4 ++++ .../de/rki/coronawarnapp/util/DataRetentionHelper.kt | 3 +++ 6 files changed, 32 insertions(+) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/AppDatabase.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/AppDatabase.kt index 632fef208..df9ff7296 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/AppDatabase.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/AppDatabase.kt @@ -8,8 +8,10 @@ import androidx.room.RoomDatabase import androidx.room.TypeConverters import de.rki.coronawarnapp.storage.keycache.KeyCacheDao import de.rki.coronawarnapp.storage.keycache.KeyCacheEntity +import de.rki.coronawarnapp.storage.keycache.KeyCacheRepository import de.rki.coronawarnapp.storage.tracing.TracingIntervalDao import de.rki.coronawarnapp.storage.tracing.TracingIntervalEntity +import de.rki.coronawarnapp.storage.tracing.TracingIntervalRepository import de.rki.coronawarnapp.util.Converters import de.rki.coronawarnapp.util.security.SecurityHelper import net.sqlcipher.database.SupportFactory @@ -48,6 +50,11 @@ abstract class AppDatabase : RoomDatabase() { SQLiteDatabase.deleteDatabase(dbFile) } resetInstance() + + // reset also the repo instances + KeyCacheRepository.resetInstance() + TracingIntervalRepository.resetInstance() + ExposureSummaryRepository.resetInstance() } private fun buildDatabase(context: Context): AppDatabase { diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/ExposureSummaryRepository.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/ExposureSummaryRepository.kt index de6c051e3..60eb7bae1 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/ExposureSummaryRepository.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/ExposureSummaryRepository.kt @@ -14,6 +14,10 @@ class ExposureSummaryRepository(private val exposureSummaryDao: ExposureSummaryD instance ?: ExposureSummaryRepository(exposureSummaryDao).also { instance = it } } + fun resetInstance() = synchronized(this) { + instance = null + } + fun getExposureSummaryRepository(): ExposureSummaryRepository { return getInstance( AppDatabase.getInstance(CoronaWarnApplication.getAppContext()) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/RiskLevelRepository.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/RiskLevelRepository.kt index 17c0a5ef5..4fcb0f09b 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/RiskLevelRepository.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/RiskLevelRepository.kt @@ -30,6 +30,16 @@ object RiskLevelRepository { setLastSuccessfullyCalculatedScore(riskLevel) } + /** + * Resets the data in the [RiskLevelRepository] + * + * @see de.rki.coronawarnapp.util.DataRetentionHelper + * + */ + fun reset() { + riskLevelScore.postValue(RiskLevelConstants.UNKNOWN_RISK_INITIAL) + } + /** * Set the current risk level from the last calculated risk level. * This is necessary if the app has no connectivity and the risk level transaction diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/keycache/KeyCacheRepository.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/keycache/KeyCacheRepository.kt index 243a5b300..9e3ce0003 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/keycache/KeyCacheRepository.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/keycache/KeyCacheRepository.kt @@ -37,6 +37,10 @@ class KeyCacheRepository(private val keyCacheDao: KeyCacheDao) { .also { instance = it } } + fun resetInstance() = synchronized(this) { + instance = null + } + fun getDateRepository(context: Context): KeyCacheRepository { return getInstance( AppDatabase.getInstance(context.applicationContext) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/tracing/TracingIntervalRepository.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/tracing/TracingIntervalRepository.kt index 2b6ea7515..478e580bf 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/tracing/TracingIntervalRepository.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/storage/tracing/TracingIntervalRepository.kt @@ -39,6 +39,10 @@ class TracingIntervalRepository(private val tracingIntervalDao: TracingIntervalD .also { instance = it } } + fun resetInstance() = synchronized(this) { + instance = null + } + fun getDateRepository(context: Context): TracingIntervalRepository { return getInstance( AppDatabase.getInstance(context.applicationContext) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/DataRetentionHelper.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/DataRetentionHelper.kt index 2ffe2d1e6..463435867 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/DataRetentionHelper.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/DataRetentionHelper.kt @@ -23,6 +23,7 @@ import android.annotation.SuppressLint import android.content.Context import de.rki.coronawarnapp.storage.AppDatabase import de.rki.coronawarnapp.storage.FileStorageHelper +import de.rki.coronawarnapp.storage.RiskLevelRepository import de.rki.coronawarnapp.util.security.SecurityHelper import timber.log.Timber @@ -43,6 +44,8 @@ object DataRetentionHelper { AppDatabase.reset(context) // Shared Preferences Reset SecurityHelper.resetSharedPrefs() + // Reset the current risk level stored in LiveData + RiskLevelRepository.reset() // Export File Reset FileStorageHelper.getAllFilesInKeyExportDirectory().forEach { it.delete() } Timber.w("CWA LOCAL DATA DELETION COMPLETED.") -- GitLab