diff --git a/src/Android/Services/DeviceActionService.cs b/src/Android/Services/DeviceActionService.cs index c45c8f7a3..3ed9392b1 100644 --- a/src/Android/Services/DeviceActionService.cs +++ b/src/Android/Services/DeviceActionService.cs @@ -11,6 +11,13 @@ namespace Bit.Android.Services { public class DeviceActionService : IDeviceActionService { + private readonly IAppSettingsService _appSettingsService; + + public DeviceActionService(IAppSettingsService appSettingsService) + { + _appSettingsService = appSettingsService; + } + public void CopyToClipboard(string text) { var clipboardManager = (ClipboardManager)Forms.Context.GetSystemService(Context.ClipboardService); @@ -86,6 +93,7 @@ namespace Bit.Android.Services try { DeleteDir(CrossCurrentActivity.Current.Activity.CacheDir); + _appSettingsService.LastCacheClear = DateTime.UtcNow; } catch(Exception) { } } diff --git a/src/App/Abstractions/Services/IAppSettingsService.cs b/src/App/Abstractions/Services/IAppSettingsService.cs index ac96407c7..ad0a7a878 100644 --- a/src/App/Abstractions/Services/IAppSettingsService.cs +++ b/src/App/Abstractions/Services/IAppSettingsService.cs @@ -6,6 +6,7 @@ namespace Bit.App.Abstractions { bool Locked { get; set; } DateTime LastActivity { get; set; } + DateTime LastCacheClear { get; set; } bool AutofillPersistNotification { get; set; } bool AutofillPasswordField { get; set; } string SecurityStamp { get; set; } diff --git a/src/App/App.cs b/src/App/App.cs index 003224a8c..081288aca 100644 --- a/src/App/App.cs +++ b/src/App/App.cs @@ -113,7 +113,11 @@ namespace Bit.App await Task.Run(() => FullSyncAsync()).ConfigureAwait(false); } - await Task.Run(() => _deviceActionService.ClearCache()).ConfigureAwait(false); + if((DateTime.UtcNow - _appSettingsService.LastCacheClear).TotalDays >= 1) + { + await Task.Run(() => _deviceActionService.ClearCache()).ConfigureAwait(false); + } + Debug.WriteLine("OnStart"); } @@ -156,6 +160,13 @@ namespace Bit.App { await Task.Run(() => FullSyncAsync()).ConfigureAwait(false); } + + var now = DateTime.UtcNow; + if((now - _appSettingsService.LastCacheClear).TotalDays >= 1 + && (now - _appSettingsService.LastActivity).TotalHours >= 1) + { + await Task.Run(() => _deviceActionService.ClearCache()).ConfigureAwait(false); + } } private void SetMainPageFromAutofill() diff --git a/src/App/Constants.cs b/src/App/Constants.cs index 6f4a541c6..684c8c7e4 100644 --- a/src/App/Constants.cs +++ b/src/App/Constants.cs @@ -28,6 +28,7 @@ public const string SecurityStamp = "other:securityStamp"; public const string LastActivityDate = "other:lastActivityDate"; + public const string LastCacheClearDate = "other:cacheClearDate"; public const string Locked = "other:locked"; public const string LastLoginEmail = "other:lastLoginEmail"; public const string LastSync = "other:lastSync"; diff --git a/src/App/Services/AppSettingsService.cs b/src/App/Services/AppSettingsService.cs index 312f753c5..424f85808 100644 --- a/src/App/Services/AppSettingsService.cs +++ b/src/App/Services/AppSettingsService.cs @@ -38,6 +38,18 @@ namespace Bit.App.Services } } + public DateTime LastCacheClear + { + get + { + return _settings.GetValueOrDefault(Constants.LastCacheClearDate, DateTime.MinValue); + } + set + { + _settings.AddOrUpdateValue(Constants.LastCacheClearDate, value); + } + } + public bool AutofillPersistNotification { get diff --git a/src/iOS/Services/DeviceActionService.cs b/src/iOS/Services/DeviceActionService.cs index 23e1b3d28..af0129953 100644 --- a/src/iOS/Services/DeviceActionService.cs +++ b/src/iOS/Services/DeviceActionService.cs @@ -8,6 +8,13 @@ namespace Bit.iOS.Services { public class DeviceActionService : IDeviceActionService { + private readonly IAppSettingsService _appSettingsService; + + public DeviceActionService(IAppSettingsService appSettingsService) + { + _appSettingsService = appSettingsService; + } + public void CopyToClipboard(string text) { UIPasteboard clipboard = UIPasteboard.General; @@ -44,6 +51,8 @@ namespace Bit.iOS.Services NSFileManager.DefaultManager.Remove(item, out itemError); } } + + _appSettingsService.LastCacheClear = DateTime.UtcNow; } private UIViewController GetVisibleViewController(UIViewController controller = null)