using System; using System.Collections.Generic; using System.Threading.Tasks; using Bit.Core; using Bit.Core.Abstractions; namespace Bit.App.Services { public class MobileStorageService : IStorageService, IDisposable { private readonly IStorageService _preferencesStorageService; private readonly IStorageService _liteDbStorageService; private readonly HashSet _preferenceStorageKeys = new HashSet { Constants.StateVersionKey, Constants.PreAuthEnvironmentUrlsKey, Constants.AutofillTileAdded, Constants.AddSitePromptShownKey, Constants.PushInitialPromptShownKey, Constants.LastFileCacheClearKey, Constants.PushLastRegistrationDateKey, Constants.PushRegisteredTokenKey, Constants.PushCurrentTokenKey, Constants.LastBuildKey, Constants.ClearCiphersCacheKey, Constants.BiometricIntegrityKey, Constants.iOSAutoFillClearCiphersCacheKey, Constants.iOSAutoFillBiometricIntegrityKey, Constants.iOSExtensionClearCiphersCacheKey, Constants.iOSExtensionBiometricIntegrityKey, Constants.iOSShareExtensionClearCiphersCacheKey, Constants.iOSShareExtensionBiometricIntegrityKey, Constants.RememberedEmailKey, Constants.RememberedOrgIdentifierKey, }; public MobileStorageService( IStorageService preferenceStorageService, IStorageService liteDbStorageService) { _preferencesStorageService = preferenceStorageService; _liteDbStorageService = liteDbStorageService; } public async Task GetAsync(string key) { if (_preferenceStorageKeys.Contains(key)) { return await _preferencesStorageService.GetAsync(key); } return await _liteDbStorageService.GetAsync(key); } public Task SaveAsync(string key, T obj) { if (_preferenceStorageKeys.Contains(key)) { return _preferencesStorageService.SaveAsync(key, obj); } return _liteDbStorageService.SaveAsync(key, obj); } public Task RemoveAsync(string key) { if (_preferenceStorageKeys.Contains(key)) { return _preferencesStorageService.RemoveAsync(key); } return _liteDbStorageService.RemoveAsync(key); } public void Dispose() { if (_liteDbStorageService is IDisposable disposableLiteDbService) { disposableLiteDbService.Dispose(); } if (_preferencesStorageService is IDisposable disposablePrefService) { disposablePrefService.Dispose(); } } } }