This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for merging application data to prevent crashes
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/src/main/java/dev/medzik/librepass/android/UpdateMerge.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters