diff --git a/src/Android/Services/DeviceInfoService.cs b/src/Android/Services/DeviceInfoService.cs index 3f56fb4a5..7b17ee062 100644 --- a/src/Android/Services/DeviceInfoService.cs +++ b/src/Android/Services/DeviceInfoService.cs @@ -70,5 +70,6 @@ namespace Bit.Android.Services var adapter = manager.DefaultAdapter; return adapter != null && adapter.IsEnabled; } + public bool IsExtension => false; } } diff --git a/src/App/Abstractions/Services/IAppSettingsService.cs b/src/App/Abstractions/Services/IAppSettingsService.cs index 2249b019c..e3b48db45 100644 --- a/src/App/Abstractions/Services/IAppSettingsService.cs +++ b/src/App/Abstractions/Services/IAppSettingsService.cs @@ -18,6 +18,7 @@ namespace Bit.App.Abstractions string IdentityUrl { get; set; } string IconsUrl { get; set; } bool ClearCiphersCache { get; set; } + bool ClearExtensionCiphersCache { get; set; } bool OrganizationGivesPremium { get; set; } } } \ No newline at end of file diff --git a/src/App/Abstractions/Services/IDeviceInfoService.cs b/src/App/Abstractions/Services/IDeviceInfoService.cs index 56276013b..1b6958575 100644 --- a/src/App/Abstractions/Services/IDeviceInfoService.cs +++ b/src/App/Abstractions/Services/IDeviceInfoService.cs @@ -10,5 +10,6 @@ bool HasCamera { get; } bool AutofillServiceSupported { get; } bool HasFaceIdSupport { get; } + bool IsExtension { get; } } } diff --git a/src/App/Constants.cs b/src/App/Constants.cs index a9dffa1d7..bf6286591 100644 --- a/src/App/Constants.cs +++ b/src/App/Constants.cs @@ -47,6 +47,7 @@ public const string IconsUrl = "other:iconsUrl"; public const string FailedPinAttempts = "other:failedPinAttempts"; public const string ClearCiphersCache = "other:clearCiphersCache"; + public const string ClearExtensionCiphersCache = "other:clearExtensionCiphersCache"; public const string OrgGivesPremium = "other:orgGivesPremium"; public const int SelectFileRequestCode = 42; diff --git a/src/App/Services/AppSettingsService.cs b/src/App/Services/AppSettingsService.cs index c02c66a07..3d609d225 100644 --- a/src/App/Services/AppSettingsService.cs +++ b/src/App/Services/AppSettingsService.cs @@ -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 { get diff --git a/src/App/Services/CipherService.cs b/src/App/Services/CipherService.cs index de82a9179..d8aae7576 100644 --- a/src/App/Services/CipherService.cs +++ b/src/App/Services/CipherService.cs @@ -27,6 +27,7 @@ namespace Bit.App.Services private readonly ISettingsService _settingsService; private readonly ICryptoService _cryptoService; private readonly IAppSettingsService _appSettingsService; + private readonly IDeviceInfoService _deviceInfoService; public CipherService( ICipherRepository cipherRepository, @@ -36,7 +37,8 @@ namespace Bit.App.Services ICipherApiRepository cipherApiRepository, ISettingsService settingsService, ICryptoService cryptoService, - IAppSettingsService appSettingsService) + IAppSettingsService appSettingsService, + IDeviceInfoService deviceInfoService) { _cipherRepository = cipherRepository; _cipherCollectionRepository = cipherCollectionRepository; @@ -46,6 +48,7 @@ namespace Bit.App.Services _settingsService = settingsService; _cryptoService = cryptoService; _appSettingsService = appSettingsService; + _deviceInfoService = deviceInfoService; } public async Task GetByIdAsync(string id) @@ -63,12 +66,18 @@ namespace Bit.App.Services public async Task> GetAllAsync() { - if(_appSettingsService.ClearCiphersCache) + if(!_deviceInfoService.IsExtension && _appSettingsService.ClearCiphersCache) { CachedCiphers = null; _appSettingsService.ClearCiphersCache = false; } + if(_deviceInfoService.IsExtension && _appSettingsService.ClearExtensionCiphersCache) + { + CachedCiphers = null; + _appSettingsService.ClearExtensionCiphersCache = false; + } + if(CachedCiphers != null) { return CachedCiphers; @@ -272,6 +281,7 @@ namespace Bit.App.Services await _cipherRepository.UpsertAsync(cipher); CachedCiphers = null; _appSettingsService.ClearCiphersCache = true; + _appSettingsService.ClearExtensionCiphersCache = true; if(sendMessage && Application.Current != null) { MessagingCenter.Send(Application.Current, "UpsertedCipher", @@ -308,6 +318,7 @@ namespace Bit.App.Services await _cipherRepository.DeleteAsync(id); CachedCiphers = null; _appSettingsService.ClearCiphersCache = true; + _appSettingsService.ClearExtensionCiphersCache = true; } public async Task DownloadAndDecryptAttachmentAsync(string url, CipherString key, string orgId = null) @@ -383,6 +394,7 @@ namespace Bit.App.Services } CachedCiphers = null; _appSettingsService.ClearCiphersCache = true; + _appSettingsService.ClearExtensionCiphersCache = true; } public async Task DeleteAttachmentAsync(Cipher cipher, string attachmentId) @@ -406,6 +418,7 @@ namespace Bit.App.Services await _attachmentRepository.DeleteAsync(attachmentId); CachedCiphers = null; _appSettingsService.ClearCiphersCache = true; + _appSettingsService.ClearExtensionCiphersCache = true; } private Tuple InfoFromMobileAppUri(string mobileAppUriString) diff --git a/src/iOS.Autofill/CredentialProviderViewController.cs b/src/iOS.Autofill/CredentialProviderViewController.cs index d3fc3b6ae..8fe2bfec5 100644 --- a/src/iOS.Autofill/CredentialProviderViewController.cs +++ b/src/iOS.Autofill/CredentialProviderViewController.cs @@ -327,7 +327,7 @@ namespace Bit.iOS.Autofill container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); - container.RegisterSingleton(); + container.RegisterInstance(new DeviceInfoService(true)); container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); diff --git a/src/iOS.Core/Services/DeviceInfoService.cs b/src/iOS.Core/Services/DeviceInfoService.cs index b194da9d3..e51ff1f0a 100644 --- a/src/iOS.Core/Services/DeviceInfoService.cs +++ b/src/iOS.Core/Services/DeviceInfoService.cs @@ -7,6 +7,15 @@ namespace Bit.iOS.Core.Services { public class DeviceInfoService : IDeviceInfoService { + public DeviceInfoService() + : this(false) + { } + + public DeviceInfoService(bool isExtension) + { + IsExtension = isExtension; + } + public string Type => Xamarin.Forms.Device.iOS; public string Model => UIDevice.CurrentDevice.Model; public int Version @@ -45,5 +54,6 @@ namespace Bit.iOS.Core.Services return context.BiometryType == LABiometryType.FaceId; } } + public bool IsExtension { get; private set; } } } diff --git a/src/iOS.Extension/LoadingViewController.cs b/src/iOS.Extension/LoadingViewController.cs index 7a2e0f59d..d33996598 100644 --- a/src/iOS.Extension/LoadingViewController.cs +++ b/src/iOS.Extension/LoadingViewController.cs @@ -285,7 +285,7 @@ namespace Bit.iOS.Extension container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); - container.RegisterSingleton(); + container.RegisterInstance(new DeviceInfoService(true)); container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton();