1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-16 16:23:29 +00:00

Migrate EnvironmentUrlsKey to pref storage (#725)

This commit is contained in:
Kyle Spearrin
2020-02-10 11:32:58 -05:00
committed by GitHub
parent bbd8615cda
commit 89f26bbc6b
2 changed files with 27 additions and 4 deletions

View File

@@ -30,8 +30,15 @@ namespace Bit.App.Services
Constants.MigratedFromV1AutofillPromptShown,
Constants.TriedV1Resync,
Constants.ClearCiphersCacheKey,
Constants.EnvironmentUrlsKey,
};
private readonly HashSet<string> _migrateToPreferences = new HashSet<string>
{
Constants.EnvironmentUrlsKey,
};
private readonly HashSet<string> _haveMigratedToPreferences = new HashSet<string>();
public MobileStorageService(
IStorageService preferenceStorageService,
IStorageService liteDbStorageService)
@@ -40,13 +47,28 @@ namespace Bit.App.Services
_liteDbStorageService = liteDbStorageService;
}
public Task<T> GetAsync<T>(string key)
public async Task<T> GetAsync<T>(string key)
{
if(_preferenceStorageKeys.Contains(key))
{
return _preferencesStorageService.GetAsync<T>(key);
var prefValue = await _preferencesStorageService.GetAsync<T>(key);
if(prefValue != null || !_migrateToPreferences.Contains(key) ||
_haveMigratedToPreferences.Contains(key))
{
return prefValue;
}
}
return _liteDbStorageService.GetAsync<T>(key);
var liteDbValue = await _liteDbStorageService.GetAsync<T>(key);
if(_migrateToPreferences.Contains(key))
{
if(liteDbValue != null)
{
await _preferencesStorageService.SaveAsync(key, liteDbValue);
await _liteDbStorageService.RemoveAsync(key);
}
_haveMigratedToPreferences.Add(key);
}
return liteDbValue;
}
public Task SaveAsync<T>(string key, T obj)