diff --git a/src/App/App.cs b/src/App/App.cs index 55517d8cf..2d4642132 100644 --- a/src/App/App.cs +++ b/src/App/App.cs @@ -99,7 +99,7 @@ namespace Bit.App if(Device.OS == TargetPlatform.Android) { - _settings.AddOrUpdateValue(Constants.LastBackgroundedDate, DateTime.UtcNow); + _settings.AddOrUpdateValue(Constants.LastActivityDate, DateTime.UtcNow); } } diff --git a/src/App/Constants.cs b/src/App/Constants.cs index 82fb41fa6..9b4c1fe59 100644 --- a/src/App/Constants.cs +++ b/src/App/Constants.cs @@ -22,7 +22,7 @@ public const string ExtensionActivated = "extension:activated"; public const string FirstVaultLoad = "other:firstVaultLoad"; - public const string LastBackgroundedDate = "other:lastBackgroundedDate"; + public const string LastActivityDate = "other:lastActivityDate"; public const string Locked = "other:locked"; public const string LastLoginEmail = "other:lastLoginEmail"; public const string LastSync = "other:lastSync"; diff --git a/src/App/Controls/ExtendedContentPage.cs b/src/App/Controls/ExtendedContentPage.cs index 0a22df632..b66f794c8 100644 --- a/src/App/Controls/ExtendedContentPage.cs +++ b/src/App/Controls/ExtendedContentPage.cs @@ -1,4 +1,6 @@ using Bit.App.Abstractions; +using Plugin.Settings.Abstractions; +using System; using Xamarin.Forms; using XLabs.Ioc; @@ -7,12 +9,18 @@ namespace Bit.App.Controls public class ExtendedContentPage : ContentPage { private ISyncService _syncService; + private IGoogleAnalyticsService _googleAnalyticsService; + private ISettings _settings; private bool _syncIndicator; + private bool _updateActivity; - public ExtendedContentPage(bool syncIndicator = false) + public ExtendedContentPage(bool syncIndicator = false, bool updateActivity = true) { _syncIndicator = syncIndicator; + _updateActivity = updateActivity; _syncService = Resolver.Resolve(); + _googleAnalyticsService = Resolver.Resolve(); + _settings = Resolver.Resolve(); BackgroundColor = Color.FromHex("efeff4"); @@ -37,8 +45,12 @@ namespace Bit.App.Controls IsBusy = _syncService.SyncInProgress; } - var googleAnalyticsService = Resolver.Resolve(); - googleAnalyticsService.TrackPage(GetType().Name); + if(_updateActivity) + { + _settings.AddOrUpdateValue(Constants.LastActivityDate, DateTime.UtcNow); + } + + _googleAnalyticsService.TrackPage(GetType().Name); base.OnAppearing(); } diff --git a/src/App/Pages/HomePage.cs b/src/App/Pages/HomePage.cs index 290bef5d5..4c986feed 100644 --- a/src/App/Pages/HomePage.cs +++ b/src/App/Pages/HomePage.cs @@ -17,6 +17,7 @@ namespace Bit.App.Pages private readonly ISettings _settings; public HomePage() + : base(updateActivity: false) { _authService = Resolver.Resolve(); _userDialogs = Resolver.Resolve(); diff --git a/src/App/Pages/LoginPage.cs b/src/App/Pages/LoginPage.cs index cd63a3a17..daeaf4f66 100644 --- a/src/App/Pages/LoginPage.cs +++ b/src/App/Pages/LoginPage.cs @@ -26,6 +26,7 @@ namespace Bit.App.Pages private readonly string _email; public LoginPage(string email = null) + : base(updateActivity: false) { _email = email; _cryptoService = Resolver.Resolve(); diff --git a/src/App/Pages/LoginTwoFactorPage.cs b/src/App/Pages/LoginTwoFactorPage.cs index 8a0a6cb82..e1fc0717b 100644 --- a/src/App/Pages/LoginTwoFactorPage.cs +++ b/src/App/Pages/LoginTwoFactorPage.cs @@ -22,6 +22,7 @@ namespace Bit.App.Pages private ISyncService _syncService; public LoginTwoFactorPage() + : base(updateActivity: false) { _cryptoService = Resolver.Resolve(); _authService = Resolver.Resolve(); diff --git a/src/App/Pages/PasswordHintPage.cs b/src/App/Pages/PasswordHintPage.cs index 8904e55e7..35bde30aa 100644 --- a/src/App/Pages/PasswordHintPage.cs +++ b/src/App/Pages/PasswordHintPage.cs @@ -18,6 +18,7 @@ namespace Bit.App.Pages private IAccountsApiRepository _accountApiRepository; public PasswordHintPage() + : base(updateActivity: false) { _userDialogs = Resolver.Resolve(); _accountApiRepository = Resolver.Resolve(); diff --git a/src/App/Pages/RegisterPage.cs b/src/App/Pages/RegisterPage.cs index 55424e0dc..0e829fad9 100644 --- a/src/App/Pages/RegisterPage.cs +++ b/src/App/Pages/RegisterPage.cs @@ -20,6 +20,7 @@ namespace Bit.App.Pages private HomePage _homePage; public RegisterPage(HomePage homePage) + : base(updateActivity: false) { _homePage = homePage; _cryptoService = Resolver.Resolve(); diff --git a/src/App/Services/LockService.cs b/src/App/Services/LockService.cs index cf89251fa..92e463598 100644 --- a/src/App/Services/LockService.cs +++ b/src/App/Services/LockService.cs @@ -40,9 +40,9 @@ namespace Bit.App.Services return LockType.None; } - // Has it been longer than lockSeconds since the last time the app was backgrounded? + // Has it been longer than lockSeconds since the last time the app was used? var now = DateTime.UtcNow; - var lastBackground = _settings.GetValueOrDefault(Constants.LastBackgroundedDate, now.AddYears(-1)); + var lastBackground = _settings.GetValueOrDefault(Constants.LastActivityDate, now.AddYears(-1)); if((now - lastBackground).TotalSeconds < lockSeconds) { return LockType.None; diff --git a/src/iOS.Extension/LoadingViewController.cs b/src/iOS.Extension/LoadingViewController.cs index b6cfe35eb..9bbc7f7ea 100644 --- a/src/iOS.Extension/LoadingViewController.cs +++ b/src/iOS.Extension/LoadingViewController.cs @@ -30,6 +30,7 @@ namespace Bit.iOS.Extension private readonly JsonSerializerSettings _jsonSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; private IGoogleAnalyticsService _googleAnalyticsService; + private ISettings _settings; public LoadingViewController(IntPtr handle) : base(handle) { } @@ -45,12 +46,12 @@ namespace Bit.iOS.Extension View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f); _context.ExtContext = ExtensionContext; _googleAnalyticsService = Resolver.Resolve(); + _settings = Resolver.Resolve(); if(!_setupHockeyApp) { var appIdService = Resolver.Resolve(); - var crashManagerDelegate = new HockeyAppCrashManagerDelegate( - appIdService, Resolver.Resolve()); + var crashManagerDelegate = new HockeyAppCrashManagerDelegate(appIdService, Resolver.Resolve()); var manager = HockeyApp.iOS.BITHockeyManager.SharedHockeyManager; manager.Configure("51f96ae568ba45f699a18ad9f63046c3", crashManagerDelegate); manager.CrashManager.CrashManagerStatus = HockeyApp.iOS.BITCrashManagerStatus.AutoSend; @@ -92,7 +93,8 @@ namespace Bit.iOS.Extension var authService = Resolver.Resolve(); if(!authService.IsAuthenticated) { - var alert = Dialogs.CreateAlert(null, "You must log into the main bitwarden app before you can use the extension.", AppResources.Ok, (a) => + var alert = Dialogs.CreateAlert(null, + "You must log into the main bitwarden app before you can use the extension.", AppResources.Ok, (a) => { CompleteRequest(null); }); @@ -176,6 +178,7 @@ namespace Bit.iOS.Extension private void ContinueOn() { Debug.WriteLine("BW Log, Segue to setup, site add or list."); + _settings.AddOrUpdateValue(App.Constants.LastActivityDate, DateTime.UtcNow); if(_context.ProviderType == Constants.UTTypeAppExtensionSaveLoginAction) { @@ -240,6 +243,7 @@ namespace Bit.iOS.Extension if(itemData != null) { + _settings.AddOrUpdateValue(App.Constants.LastActivityDate, DateTime.UtcNow); _googleAnalyticsService.TrackExtensionEvent("AutoFilled", _context.ProviderType); } else @@ -249,7 +253,8 @@ namespace Bit.iOS.Extension _googleAnalyticsService.Dispatch(() => { - NSRunLoop.Main.BeginInvokeOnMainThread(() => { + NSRunLoop.Main.BeginInvokeOnMainThread(() => + { ExtensionContext.CompleteRequest(returningItems, null); }); }); diff --git a/src/iOS.Extension/SiteListViewController.cs b/src/iOS.Extension/SiteListViewController.cs index 578ce2f10..920b94068 100644 --- a/src/iOS.Extension/SiteListViewController.cs +++ b/src/iOS.Extension/SiteListViewController.cs @@ -174,8 +174,6 @@ namespace Bit.iOS.Extension return; } - Resolver.Resolve().AddOrUpdateValue(App.Constants.LastBackgroundedDate, DateTime.UtcNow); - var item = _tableItems.ElementAt(indexPath.Row); if(item == null) { diff --git a/src/iOS/AppDelegate.cs b/src/iOS/AppDelegate.cs index feea6ae1c..2c650805f 100644 --- a/src/iOS/AppDelegate.cs +++ b/src/iOS/AppDelegate.cs @@ -141,7 +141,7 @@ namespace Bit.iOS UIApplication.SharedApplication.SetStatusBarHidden(true, false); // Log the date/time we last backgrounded - Settings.AddOrUpdateValue(App.Constants.LastBackgroundedDate, DateTime.UtcNow); + Settings.AddOrUpdateValue(App.Constants.LastActivityDate, DateTime.UtcNow); // Dispatch Google Analytics SendGoogleAnalyticsHitsInBackground();