diff --git a/app/src/main/java/dev/medzik/librepass/android/MainActivity.kt b/app/src/main/java/dev/medzik/librepass/android/MainActivity.kt index 81f07a60..08da5fbb 100644 --- a/app/src/main/java/dev/medzik/librepass/android/MainActivity.kt +++ b/app/src/main/java/dev/medzik/librepass/android/MainActivity.kt @@ -30,6 +30,9 @@ class MainActivity : FragmentActivity() { finish() } + // merge application data when application updated + UpdateMerge.update(this) + // init datastore userSecrets = SecretStore.initialize(this) diff --git a/app/src/main/java/dev/medzik/librepass/android/UpdateMerge.kt b/app/src/main/java/dev/medzik/librepass/android/UpdateMerge.kt new file mode 100644 index 00000000..69dbf57b --- /dev/null +++ b/app/src/main/java/dev/medzik/librepass/android/UpdateMerge.kt @@ -0,0 +1,45 @@ +package dev.medzik.librepass.android + +import android.content.Context +import dev.medzik.librepass.android.data.getRepository +import dev.medzik.librepass.android.utils.SecretStore +import dev.medzik.librepass.android.utils.SecretStore.readKey +import dev.medzik.librepass.android.utils.SecretStore.writeKey +import dev.medzik.librepass.android.utils.StoreKey +import kotlinx.coroutines.runBlocking + +object UpdateMerge { + fun update(context: Context) { + if (context.getRepository().credentials.get() == null) + context.writeKey(StoreKey.AppVersionCode, BuildConfig.VERSION_CODE) + + val lastVersionCode = context.readKey(StoreKey.AppVersionCode) + var versionCode = lastVersionCode + + while (versionCode < BuildConfig.VERSION_CODE) { + when (versionCode) { + -1 -> merge4To5(context) + } + + versionCode++ + } + } + + private fun merge4To5(context: Context) { + val repositoryCredentials = context.getRepository().credentials + val credentials = repositoryCredentials.get() + ?: return + + SecretStore.delete(context) + + runBlocking { + repositoryCredentials.update( + credentials.copy( + biometricProtectedPrivateKey = null, + biometricProtectedPrivateKeyIV = null, + biometricEnabled = false + ) + ) + } + } +} diff --git a/app/src/main/java/dev/medzik/librepass/android/utils/Store.kt b/app/src/main/java/dev/medzik/librepass/android/utils/Store.kt index da0add9b..c2ef28c5 100644 --- a/app/src/main/java/dev/medzik/librepass/android/utils/Store.kt +++ b/app/src/main/java/dev/medzik/librepass/android/utils/Store.kt @@ -54,6 +54,11 @@ sealed class StoreKey( stringSetPreferencesKey("custom_servers"), emptySet() ) + + data object AppVersionCode : StoreKey( + intPreferencesKey("app_version_code"), + -1 + ) } enum class ThemeValues {