1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-12-25 16:47:55 +01:00

ClearExtensionCiphersCache

This commit is contained in:
Kyle Spearrin 2018-12-10 11:48:35 -05:00
parent a8c18cf83a
commit 3b9f4433ad
9 changed files with 43 additions and 4 deletions

View File

@ -70,5 +70,6 @@ namespace Bit.Android.Services
var adapter = manager.DefaultAdapter; var adapter = manager.DefaultAdapter;
return adapter != null && adapter.IsEnabled; return adapter != null && adapter.IsEnabled;
} }
public bool IsExtension => false;
} }
} }

View File

@ -18,6 +18,7 @@ namespace Bit.App.Abstractions
string IdentityUrl { get; set; } string IdentityUrl { get; set; }
string IconsUrl { get; set; } string IconsUrl { get; set; }
bool ClearCiphersCache { get; set; } bool ClearCiphersCache { get; set; }
bool ClearExtensionCiphersCache { get; set; }
bool OrganizationGivesPremium { get; set; } bool OrganizationGivesPremium { get; set; }
} }
} }

View File

@ -10,5 +10,6 @@
bool HasCamera { get; } bool HasCamera { get; }
bool AutofillServiceSupported { get; } bool AutofillServiceSupported { get; }
bool HasFaceIdSupport { get; } bool HasFaceIdSupport { get; }
bool IsExtension { get; }
} }
} }

View File

@ -47,6 +47,7 @@
public const string IconsUrl = "other:iconsUrl"; public const string IconsUrl = "other:iconsUrl";
public const string FailedPinAttempts = "other:failedPinAttempts"; public const string FailedPinAttempts = "other:failedPinAttempts";
public const string ClearCiphersCache = "other:clearCiphersCache"; public const string ClearCiphersCache = "other:clearCiphersCache";
public const string ClearExtensionCiphersCache = "other:clearExtensionCiphersCache";
public const string OrgGivesPremium = "other:orgGivesPremium"; public const string OrgGivesPremium = "other:orgGivesPremium";
public const int SelectFileRequestCode = 42; public const int SelectFileRequestCode = 42;

View File

@ -209,6 +209,18 @@ namespace Bit.App.Services
} }
} }
public bool ClearExtensionCiphersCache
{
get
{
return _settings.GetValueOrDefault(Constants.ClearExtensionCiphersCache, false);
}
set
{
_settings.AddOrUpdateValue(Constants.ClearExtensionCiphersCache, value);
}
}
public bool OrganizationGivesPremium public bool OrganizationGivesPremium
{ {
get get

View File

@ -27,6 +27,7 @@ namespace Bit.App.Services
private readonly ISettingsService _settingsService; private readonly ISettingsService _settingsService;
private readonly ICryptoService _cryptoService; private readonly ICryptoService _cryptoService;
private readonly IAppSettingsService _appSettingsService; private readonly IAppSettingsService _appSettingsService;
private readonly IDeviceInfoService _deviceInfoService;
public CipherService( public CipherService(
ICipherRepository cipherRepository, ICipherRepository cipherRepository,
@ -36,7 +37,8 @@ namespace Bit.App.Services
ICipherApiRepository cipherApiRepository, ICipherApiRepository cipherApiRepository,
ISettingsService settingsService, ISettingsService settingsService,
ICryptoService cryptoService, ICryptoService cryptoService,
IAppSettingsService appSettingsService) IAppSettingsService appSettingsService,
IDeviceInfoService deviceInfoService)
{ {
_cipherRepository = cipherRepository; _cipherRepository = cipherRepository;
_cipherCollectionRepository = cipherCollectionRepository; _cipherCollectionRepository = cipherCollectionRepository;
@ -46,6 +48,7 @@ namespace Bit.App.Services
_settingsService = settingsService; _settingsService = settingsService;
_cryptoService = cryptoService; _cryptoService = cryptoService;
_appSettingsService = appSettingsService; _appSettingsService = appSettingsService;
_deviceInfoService = deviceInfoService;
} }
public async Task<Cipher> GetByIdAsync(string id) public async Task<Cipher> GetByIdAsync(string id)
@ -63,12 +66,18 @@ namespace Bit.App.Services
public async Task<IEnumerable<Cipher>> GetAllAsync() public async Task<IEnumerable<Cipher>> GetAllAsync()
{ {
if(_appSettingsService.ClearCiphersCache) if(!_deviceInfoService.IsExtension && _appSettingsService.ClearCiphersCache)
{ {
CachedCiphers = null; CachedCiphers = null;
_appSettingsService.ClearCiphersCache = false; _appSettingsService.ClearCiphersCache = false;
} }
if(_deviceInfoService.IsExtension && _appSettingsService.ClearExtensionCiphersCache)
{
CachedCiphers = null;
_appSettingsService.ClearExtensionCiphersCache = false;
}
if(CachedCiphers != null) if(CachedCiphers != null)
{ {
return CachedCiphers; return CachedCiphers;
@ -272,6 +281,7 @@ namespace Bit.App.Services
await _cipherRepository.UpsertAsync(cipher); await _cipherRepository.UpsertAsync(cipher);
CachedCiphers = null; CachedCiphers = null;
_appSettingsService.ClearCiphersCache = true; _appSettingsService.ClearCiphersCache = true;
_appSettingsService.ClearExtensionCiphersCache = true;
if(sendMessage && Application.Current != null) if(sendMessage && Application.Current != null)
{ {
MessagingCenter.Send(Application.Current, "UpsertedCipher", MessagingCenter.Send(Application.Current, "UpsertedCipher",
@ -308,6 +318,7 @@ namespace Bit.App.Services
await _cipherRepository.DeleteAsync(id); await _cipherRepository.DeleteAsync(id);
CachedCiphers = null; CachedCiphers = null;
_appSettingsService.ClearCiphersCache = true; _appSettingsService.ClearCiphersCache = true;
_appSettingsService.ClearExtensionCiphersCache = true;
} }
public async Task<byte[]> DownloadAndDecryptAttachmentAsync(string url, CipherString key, string orgId = null) public async Task<byte[]> DownloadAndDecryptAttachmentAsync(string url, CipherString key, string orgId = null)
@ -383,6 +394,7 @@ namespace Bit.App.Services
} }
CachedCiphers = null; CachedCiphers = null;
_appSettingsService.ClearCiphersCache = true; _appSettingsService.ClearCiphersCache = true;
_appSettingsService.ClearExtensionCiphersCache = true;
} }
public async Task<ApiResult> DeleteAttachmentAsync(Cipher cipher, string attachmentId) public async Task<ApiResult> DeleteAttachmentAsync(Cipher cipher, string attachmentId)
@ -406,6 +418,7 @@ namespace Bit.App.Services
await _attachmentRepository.DeleteAsync(attachmentId); await _attachmentRepository.DeleteAsync(attachmentId);
CachedCiphers = null; CachedCiphers = null;
_appSettingsService.ClearCiphersCache = true; _appSettingsService.ClearCiphersCache = true;
_appSettingsService.ClearExtensionCiphersCache = true;
} }
private Tuple<string, string[]> InfoFromMobileAppUri(string mobileAppUriString) private Tuple<string, string[]> InfoFromMobileAppUri(string mobileAppUriString)

View File

@ -327,7 +327,7 @@ namespace Bit.iOS.Autofill
container.RegisterSingleton<ILockService, LockService>(); container.RegisterSingleton<ILockService, LockService>();
container.RegisterSingleton<IAppInfoService, AppInfoService>(); container.RegisterSingleton<IAppInfoService, AppInfoService>();
container.RegisterSingleton<IGoogleAnalyticsService, GoogleAnalyticsService>(); container.RegisterSingleton<IGoogleAnalyticsService, GoogleAnalyticsService>();
container.RegisterSingleton<IDeviceInfoService, DeviceInfoService>(); container.RegisterInstance<IDeviceInfoService>(new DeviceInfoService(true));
container.RegisterSingleton<ILocalizeService, LocalizeService>(); container.RegisterSingleton<ILocalizeService, LocalizeService>();
container.RegisterSingleton<ILogService, LogService>(); container.RegisterSingleton<ILogService, LogService>();
container.RegisterSingleton<IHttpService, HttpService>(); container.RegisterSingleton<IHttpService, HttpService>();

View File

@ -7,6 +7,15 @@ namespace Bit.iOS.Core.Services
{ {
public class DeviceInfoService : IDeviceInfoService public class DeviceInfoService : IDeviceInfoService
{ {
public DeviceInfoService()
: this(false)
{ }
public DeviceInfoService(bool isExtension)
{
IsExtension = isExtension;
}
public string Type => Xamarin.Forms.Device.iOS; public string Type => Xamarin.Forms.Device.iOS;
public string Model => UIDevice.CurrentDevice.Model; public string Model => UIDevice.CurrentDevice.Model;
public int Version public int Version
@ -45,5 +54,6 @@ namespace Bit.iOS.Core.Services
return context.BiometryType == LABiometryType.FaceId; return context.BiometryType == LABiometryType.FaceId;
} }
} }
public bool IsExtension { get; private set; }
} }
} }

View File

@ -285,7 +285,7 @@ namespace Bit.iOS.Extension
container.RegisterSingleton<ILockService, LockService>(); container.RegisterSingleton<ILockService, LockService>();
container.RegisterSingleton<IAppInfoService, AppInfoService>(); container.RegisterSingleton<IAppInfoService, AppInfoService>();
container.RegisterSingleton<IGoogleAnalyticsService, GoogleAnalyticsService>(); container.RegisterSingleton<IGoogleAnalyticsService, GoogleAnalyticsService>();
container.RegisterSingleton<IDeviceInfoService, DeviceInfoService>(); container.RegisterInstance<IDeviceInfoService>(new DeviceInfoService(true));
container.RegisterSingleton<ILocalizeService, LocalizeService>(); container.RegisterSingleton<ILocalizeService, LocalizeService>();
container.RegisterSingleton<ILogService, LogService>(); container.RegisterSingleton<ILogService, LogService>();
container.RegisterSingleton<IHttpService, HttpService>(); container.RegisterSingleton<IHttpService, HttpService>();