2022-04-26 17:21:17 +02:00
|
|
|
|
using System;
|
2019-04-09 02:54:59 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
2022-04-26 17:21:17 +02:00
|
|
|
|
using Bit.Core;
|
|
|
|
|
using Bit.Core.Abstractions;
|
2019-04-09 02:54:59 +02:00
|
|
|
|
|
2019-04-09 23:10:56 +02:00
|
|
|
|
namespace Bit.App.Services
|
2019-04-09 02:54:59 +02:00
|
|
|
|
{
|
2020-05-28 21:44:27 +02:00
|
|
|
|
public class MobileStorageService : IStorageService, IDisposable
|
2019-04-09 02:54:59 +02:00
|
|
|
|
{
|
|
|
|
|
private readonly IStorageService _preferencesStorageService;
|
|
|
|
|
private readonly IStorageService _liteDbStorageService;
|
|
|
|
|
|
|
|
|
|
private readonly HashSet<string> _preferenceStorageKeys = new HashSet<string>
|
|
|
|
|
{
|
2022-02-23 18:40:17 +01:00
|
|
|
|
Constants.StateVersionKey,
|
|
|
|
|
Constants.PreAuthEnvironmentUrlsKey,
|
|
|
|
|
Constants.AutofillTileAdded,
|
|
|
|
|
Constants.AddSitePromptShownKey,
|
2019-05-29 21:50:20 +02:00
|
|
|
|
Constants.PushInitialPromptShownKey,
|
2019-05-30 20:13:02 +02:00
|
|
|
|
Constants.LastFileCacheClearKey,
|
2019-06-03 20:03:24 +02:00
|
|
|
|
Constants.PushLastRegistrationDateKey,
|
|
|
|
|
Constants.PushRegisteredTokenKey,
|
|
|
|
|
Constants.PushCurrentTokenKey,
|
2019-06-04 16:53:05 +02:00
|
|
|
|
Constants.LastBuildKey,
|
2019-07-07 04:49:17 +02:00
|
|
|
|
Constants.ClearCiphersCacheKey,
|
2020-12-01 21:30:23 +01:00
|
|
|
|
Constants.BiometricIntegrityKey,
|
2020-10-13 21:39:36 +02:00
|
|
|
|
Constants.iOSAutoFillClearCiphersCacheKey,
|
2020-12-01 21:30:23 +01:00
|
|
|
|
Constants.iOSAutoFillBiometricIntegrityKey,
|
2020-10-13 21:39:36 +02:00
|
|
|
|
Constants.iOSExtensionClearCiphersCacheKey,
|
2020-12-01 21:30:23 +01:00
|
|
|
|
Constants.iOSExtensionBiometricIntegrityKey,
|
2022-03-17 19:27:01 +01:00
|
|
|
|
Constants.iOSShareExtensionClearCiphersCacheKey,
|
|
|
|
|
Constants.iOSShareExtensionBiometricIntegrityKey,
|
2022-02-23 18:40:17 +01:00
|
|
|
|
Constants.RememberedEmailKey,
|
|
|
|
|
Constants.RememberedOrgIdentifierKey,
|
2019-04-09 02:54:59 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public MobileStorageService(
|
|
|
|
|
IStorageService preferenceStorageService,
|
|
|
|
|
IStorageService liteDbStorageService)
|
|
|
|
|
{
|
|
|
|
|
_preferencesStorageService = preferenceStorageService;
|
|
|
|
|
_liteDbStorageService = liteDbStorageService;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 17:32:58 +01:00
|
|
|
|
public async Task<T> GetAsync<T>(string key)
|
2019-04-09 02:54:59 +02:00
|
|
|
|
{
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (_preferenceStorageKeys.Contains(key))
|
2019-04-09 02:54:59 +02:00
|
|
|
|
{
|
2022-02-23 18:40:17 +01:00
|
|
|
|
return await _preferencesStorageService.GetAsync<T>(key);
|
2019-04-09 02:54:59 +02:00
|
|
|
|
}
|
2022-02-23 18:40:17 +01:00
|
|
|
|
return await _liteDbStorageService.GetAsync<T>(key);
|
2019-04-09 02:54:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task SaveAsync<T>(string key, T obj)
|
|
|
|
|
{
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (_preferenceStorageKeys.Contains(key))
|
2019-04-09 02:54:59 +02:00
|
|
|
|
{
|
|
|
|
|
return _preferencesStorageService.SaveAsync(key, obj);
|
|
|
|
|
}
|
|
|
|
|
return _liteDbStorageService.SaveAsync(key, obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task RemoveAsync(string key)
|
|
|
|
|
{
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (_preferenceStorageKeys.Contains(key))
|
2019-04-09 02:54:59 +02:00
|
|
|
|
{
|
|
|
|
|
return _preferencesStorageService.RemoveAsync(key);
|
|
|
|
|
}
|
|
|
|
|
return _liteDbStorageService.RemoveAsync(key);
|
|
|
|
|
}
|
2020-05-28 21:44:27 +02:00
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
if (_liteDbStorageService is IDisposable disposableLiteDbService)
|
|
|
|
|
{
|
|
|
|
|
disposableLiteDbService.Dispose();
|
|
|
|
|
}
|
|
|
|
|
if (_preferencesStorageService is IDisposable disposablePrefService)
|
|
|
|
|
{
|
|
|
|
|
disposablePrefService.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-09 02:54:59 +02:00
|
|
|
|
}
|
|
|
|
|
}
|