mirror of
https://github.com/bitwarden/android.git
synced 2024-11-01 07:35:52 +03:00
Migrate EnvironmentUrlsKey to pref storage (#725)
This commit is contained in:
parent
bbd8615cda
commit
89f26bbc6b
2 changed files with 27 additions and 4 deletions
|
@ -30,8 +30,15 @@ namespace Bit.App.Services
|
||||||
Constants.MigratedFromV1AutofillPromptShown,
|
Constants.MigratedFromV1AutofillPromptShown,
|
||||||
Constants.TriedV1Resync,
|
Constants.TriedV1Resync,
|
||||||
Constants.ClearCiphersCacheKey,
|
Constants.ClearCiphersCacheKey,
|
||||||
|
Constants.EnvironmentUrlsKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private readonly HashSet<string> _migrateToPreferences = new HashSet<string>
|
||||||
|
{
|
||||||
|
Constants.EnvironmentUrlsKey,
|
||||||
|
};
|
||||||
|
private readonly HashSet<string> _haveMigratedToPreferences = new HashSet<string>();
|
||||||
|
|
||||||
public MobileStorageService(
|
public MobileStorageService(
|
||||||
IStorageService preferenceStorageService,
|
IStorageService preferenceStorageService,
|
||||||
IStorageService liteDbStorageService)
|
IStorageService liteDbStorageService)
|
||||||
|
@ -40,13 +47,28 @@ namespace Bit.App.Services
|
||||||
_liteDbStorageService = liteDbStorageService;
|
_liteDbStorageService = liteDbStorageService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<T> GetAsync<T>(string key)
|
public async Task<T> GetAsync<T>(string key)
|
||||||
{
|
{
|
||||||
if(_preferenceStorageKeys.Contains(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)
|
public Task SaveAsync<T>(string key, T obj)
|
||||||
|
|
|
@ -13,7 +13,8 @@ namespace Bit.App.Services
|
||||||
private readonly string _sharedName;
|
private readonly string _sharedName;
|
||||||
private readonly JsonSerializerSettings _jsonSettings = new JsonSerializerSettings
|
private readonly JsonSerializerSettings _jsonSettings = new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||||
|
NullValueHandling = NullValueHandling.Ignore
|
||||||
};
|
};
|
||||||
|
|
||||||
public PreferencesStorageService(string sharedName)
|
public PreferencesStorageService(string sharedName)
|
||||||
|
|
Loading…
Reference in a new issue