mirror of
https://github.com/bitwarden/android.git
synced 2024-12-27 11:28:28 +03:00
PM-3350 Added check for state migration version before trying to migrate LiteDB values into Prefs when there's no need to and that may be inducing crashes on backgrounded iOS apps.
This commit is contained in:
parent
c74636ffa5
commit
1491872b62
3 changed files with 11 additions and 4 deletions
|
@ -74,6 +74,7 @@ namespace Bit.Core
|
||||||
public const string DefaultFido2CredentialType = "public-key";
|
public const string DefaultFido2CredentialType = "public-key";
|
||||||
public const string DefaultFido2CredentialAlgorithm = "ECDSA";
|
public const string DefaultFido2CredentialAlgorithm = "ECDSA";
|
||||||
public const string DefaultFido2CredentialCurve = "P-256";
|
public const string DefaultFido2CredentialCurve = "P-256";
|
||||||
|
public const int LatestStateVersion = 7;
|
||||||
|
|
||||||
public static readonly string[] AndroidAllClearCipherCacheKeys =
|
public static readonly string[] AndroidAllClearCipherCacheKeys =
|
||||||
{
|
{
|
||||||
|
|
|
@ -82,6 +82,14 @@ namespace Bit.App.Services
|
||||||
|
|
||||||
private async Task<T> TryMigrateLiteDbToPrefsAsync<T>(string key)
|
private async Task<T> TryMigrateLiteDbToPrefsAsync<T>(string key)
|
||||||
{
|
{
|
||||||
|
// Note: this is added to prevent searching a value in LiteDB when the migration has already run and it's in its latest version.
|
||||||
|
// If not, we could get several concurrent calls to the DB asking for values we already know they are not there,
|
||||||
|
// possible causing crashes on backgrounded apps.
|
||||||
|
if (await _preferencesStorageService.GetAsync<int?>(Constants.StateVersionKey) == Constants.LatestStateVersion)
|
||||||
|
{
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
|
||||||
var currentValue = await _liteDbStorageService.GetAsync<T>(key);
|
var currentValue = await _liteDbStorageService.GetAsync<T>(key);
|
||||||
if (currentValue != null)
|
if (currentValue != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,8 +10,6 @@ namespace Bit.Core.Services
|
||||||
{
|
{
|
||||||
public class StateMigrationService : IStateMigrationService
|
public class StateMigrationService : IStateMigrationService
|
||||||
{
|
{
|
||||||
private const int StateVersion = 7;
|
|
||||||
|
|
||||||
private readonly DeviceType _deviceType;
|
private readonly DeviceType _deviceType;
|
||||||
private readonly IStorageService _preferencesStorageService;
|
private readonly IStorageService _preferencesStorageService;
|
||||||
private readonly IStorageService _liteDbStorageService;
|
private readonly IStorageService _liteDbStorageService;
|
||||||
|
@ -58,10 +56,10 @@ namespace Bit.Core.Services
|
||||||
if (lastVersion == 0)
|
if (lastVersion == 0)
|
||||||
{
|
{
|
||||||
// fresh install, set current/latest version for availability going forward
|
// fresh install, set current/latest version for availability going forward
|
||||||
lastVersion = StateVersion;
|
lastVersion = Constants.LatestStateVersion;
|
||||||
await SetLastStateVersionAsync(lastVersion);
|
await SetLastStateVersionAsync(lastVersion);
|
||||||
}
|
}
|
||||||
return lastVersion < StateVersion;
|
return lastVersion < Constants.LatestStateVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task PerformMigrationAsync()
|
private async Task PerformMigrationAsync()
|
||||||
|
|
Loading…
Reference in a new issue