1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-26 05:03:39 +00:00
Files
mobile/src/App/Services/MobileStorageService.cs
Todd Martin ebf65ecb96 Set push token state values to be user-specific (#2200)
* Changed the current push token and last registration time to be user-based

* Fixed compile error.

* Fixed interface implementation.

* Fixed compile error for Android.

* Refactored to handle getting active user ID within state service

* Refactored methods allow existing logic to handle getting the active user.

* Updated to reconcile options.

* Updated naming and fixed issue with UserId.

* Removed space between constants.
2022-12-14 16:07:04 -05:00

85 lines
2.8 KiB
C#

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<string> _preferenceStorageKeys = new HashSet<string>
{
Constants.StateVersionKey,
Constants.PreAuthEnvironmentUrlsKey,
Constants.AutofillTileAdded,
Constants.AddSitePromptShownKey,
Constants.PushInitialPromptShownKey,
Constants.LastFileCacheClearKey,
Constants.PushRegisteredTokenKey,
Constants.LastBuildKey,
Constants.ClearCiphersCacheKey,
Constants.BiometricIntegrityKey,
Constants.iOSExtensionActiveUserIdKey,
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<T> GetAsync<T>(string key)
{
if (_preferenceStorageKeys.Contains(key))
{
return await _preferencesStorageService.GetAsync<T>(key);
}
return await _liteDbStorageService.GetAsync<T>(key);
}
public Task SaveAsync<T>(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();
}
}
}
}