1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-09-28 03:57:43 +02:00

Track activity more accurately throughout the app & extension so that lock screen is not presented prematurly.

This commit is contained in:
Kyle Spearrin 2016-08-08 19:00:36 -04:00
parent 36629b0855
commit d3b1fed9b7
12 changed files with 34 additions and 14 deletions

View File

@ -99,7 +99,7 @@ namespace Bit.App
if(Device.OS == TargetPlatform.Android) if(Device.OS == TargetPlatform.Android)
{ {
_settings.AddOrUpdateValue(Constants.LastBackgroundedDate, DateTime.UtcNow); _settings.AddOrUpdateValue(Constants.LastActivityDate, DateTime.UtcNow);
} }
} }

View File

@ -22,7 +22,7 @@
public const string ExtensionActivated = "extension:activated"; public const string ExtensionActivated = "extension:activated";
public const string FirstVaultLoad = "other:firstVaultLoad"; 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 Locked = "other:locked";
public const string LastLoginEmail = "other:lastLoginEmail"; public const string LastLoginEmail = "other:lastLoginEmail";
public const string LastSync = "other:lastSync"; public const string LastSync = "other:lastSync";

View File

@ -1,4 +1,6 @@
using Bit.App.Abstractions; using Bit.App.Abstractions;
using Plugin.Settings.Abstractions;
using System;
using Xamarin.Forms; using Xamarin.Forms;
using XLabs.Ioc; using XLabs.Ioc;
@ -7,12 +9,18 @@ namespace Bit.App.Controls
public class ExtendedContentPage : ContentPage public class ExtendedContentPage : ContentPage
{ {
private ISyncService _syncService; private ISyncService _syncService;
private IGoogleAnalyticsService _googleAnalyticsService;
private ISettings _settings;
private bool _syncIndicator; private bool _syncIndicator;
private bool _updateActivity;
public ExtendedContentPage(bool syncIndicator = false) public ExtendedContentPage(bool syncIndicator = false, bool updateActivity = true)
{ {
_syncIndicator = syncIndicator; _syncIndicator = syncIndicator;
_updateActivity = updateActivity;
_syncService = Resolver.Resolve<ISyncService>(); _syncService = Resolver.Resolve<ISyncService>();
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
_settings = Resolver.Resolve<ISettings>();
BackgroundColor = Color.FromHex("efeff4"); BackgroundColor = Color.FromHex("efeff4");
@ -37,8 +45,12 @@ namespace Bit.App.Controls
IsBusy = _syncService.SyncInProgress; IsBusy = _syncService.SyncInProgress;
} }
var googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>(); if(_updateActivity)
googleAnalyticsService.TrackPage(GetType().Name); {
_settings.AddOrUpdateValue(Constants.LastActivityDate, DateTime.UtcNow);
}
_googleAnalyticsService.TrackPage(GetType().Name);
base.OnAppearing(); base.OnAppearing();
} }

View File

@ -17,6 +17,7 @@ namespace Bit.App.Pages
private readonly ISettings _settings; private readonly ISettings _settings;
public HomePage() public HomePage()
: base(updateActivity: false)
{ {
_authService = Resolver.Resolve<IAuthService>(); _authService = Resolver.Resolve<IAuthService>();
_userDialogs = Resolver.Resolve<IUserDialogs>(); _userDialogs = Resolver.Resolve<IUserDialogs>();

View File

@ -26,6 +26,7 @@ namespace Bit.App.Pages
private readonly string _email; private readonly string _email;
public LoginPage(string email = null) public LoginPage(string email = null)
: base(updateActivity: false)
{ {
_email = email; _email = email;
_cryptoService = Resolver.Resolve<ICryptoService>(); _cryptoService = Resolver.Resolve<ICryptoService>();

View File

@ -22,6 +22,7 @@ namespace Bit.App.Pages
private ISyncService _syncService; private ISyncService _syncService;
public LoginTwoFactorPage() public LoginTwoFactorPage()
: base(updateActivity: false)
{ {
_cryptoService = Resolver.Resolve<ICryptoService>(); _cryptoService = Resolver.Resolve<ICryptoService>();
_authService = Resolver.Resolve<IAuthService>(); _authService = Resolver.Resolve<IAuthService>();

View File

@ -18,6 +18,7 @@ namespace Bit.App.Pages
private IAccountsApiRepository _accountApiRepository; private IAccountsApiRepository _accountApiRepository;
public PasswordHintPage() public PasswordHintPage()
: base(updateActivity: false)
{ {
_userDialogs = Resolver.Resolve<IUserDialogs>(); _userDialogs = Resolver.Resolve<IUserDialogs>();
_accountApiRepository = Resolver.Resolve<IAccountsApiRepository>(); _accountApiRepository = Resolver.Resolve<IAccountsApiRepository>();

View File

@ -20,6 +20,7 @@ namespace Bit.App.Pages
private HomePage _homePage; private HomePage _homePage;
public RegisterPage(HomePage homePage) public RegisterPage(HomePage homePage)
: base(updateActivity: false)
{ {
_homePage = homePage; _homePage = homePage;
_cryptoService = Resolver.Resolve<ICryptoService>(); _cryptoService = Resolver.Resolve<ICryptoService>();

View File

@ -40,9 +40,9 @@ namespace Bit.App.Services
return LockType.None; 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 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) if((now - lastBackground).TotalSeconds < lockSeconds)
{ {
return LockType.None; return LockType.None;

View File

@ -30,6 +30,7 @@ namespace Bit.iOS.Extension
private readonly JsonSerializerSettings _jsonSettings = private readonly JsonSerializerSettings _jsonSettings =
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
private IGoogleAnalyticsService _googleAnalyticsService; private IGoogleAnalyticsService _googleAnalyticsService;
private ISettings _settings;
public LoadingViewController(IntPtr handle) : base(handle) 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); View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f);
_context.ExtContext = ExtensionContext; _context.ExtContext = ExtensionContext;
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>(); _googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
_settings = Resolver.Resolve<ISettings>();
if(!_setupHockeyApp) if(!_setupHockeyApp)
{ {
var appIdService = Resolver.Resolve<IAppIdService>(); var appIdService = Resolver.Resolve<IAppIdService>();
var crashManagerDelegate = new HockeyAppCrashManagerDelegate( var crashManagerDelegate = new HockeyAppCrashManagerDelegate(appIdService, Resolver.Resolve<IAuthService>());
appIdService, Resolver.Resolve<IAuthService>());
var manager = HockeyApp.iOS.BITHockeyManager.SharedHockeyManager; var manager = HockeyApp.iOS.BITHockeyManager.SharedHockeyManager;
manager.Configure("51f96ae568ba45f699a18ad9f63046c3", crashManagerDelegate); manager.Configure("51f96ae568ba45f699a18ad9f63046c3", crashManagerDelegate);
manager.CrashManager.CrashManagerStatus = HockeyApp.iOS.BITCrashManagerStatus.AutoSend; manager.CrashManager.CrashManagerStatus = HockeyApp.iOS.BITCrashManagerStatus.AutoSend;
@ -92,7 +93,8 @@ namespace Bit.iOS.Extension
var authService = Resolver.Resolve<IAuthService>(); var authService = Resolver.Resolve<IAuthService>();
if(!authService.IsAuthenticated) 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); CompleteRequest(null);
}); });
@ -176,6 +178,7 @@ namespace Bit.iOS.Extension
private void ContinueOn() private void ContinueOn()
{ {
Debug.WriteLine("BW Log, Segue to setup, site add or list."); Debug.WriteLine("BW Log, Segue to setup, site add or list.");
_settings.AddOrUpdateValue(App.Constants.LastActivityDate, DateTime.UtcNow);
if(_context.ProviderType == Constants.UTTypeAppExtensionSaveLoginAction) if(_context.ProviderType == Constants.UTTypeAppExtensionSaveLoginAction)
{ {
@ -240,6 +243,7 @@ namespace Bit.iOS.Extension
if(itemData != null) if(itemData != null)
{ {
_settings.AddOrUpdateValue(App.Constants.LastActivityDate, DateTime.UtcNow);
_googleAnalyticsService.TrackExtensionEvent("AutoFilled", _context.ProviderType); _googleAnalyticsService.TrackExtensionEvent("AutoFilled", _context.ProviderType);
} }
else else
@ -249,7 +253,8 @@ namespace Bit.iOS.Extension
_googleAnalyticsService.Dispatch(() => _googleAnalyticsService.Dispatch(() =>
{ {
NSRunLoop.Main.BeginInvokeOnMainThread(() => { NSRunLoop.Main.BeginInvokeOnMainThread(() =>
{
ExtensionContext.CompleteRequest(returningItems, null); ExtensionContext.CompleteRequest(returningItems, null);
}); });
}); });

View File

@ -174,8 +174,6 @@ namespace Bit.iOS.Extension
return; return;
} }
Resolver.Resolve<ISettings>().AddOrUpdateValue(App.Constants.LastBackgroundedDate, DateTime.UtcNow);
var item = _tableItems.ElementAt(indexPath.Row); var item = _tableItems.ElementAt(indexPath.Row);
if(item == null) if(item == null)
{ {

View File

@ -141,7 +141,7 @@ namespace Bit.iOS
UIApplication.SharedApplication.SetStatusBarHidden(true, false); UIApplication.SharedApplication.SetStatusBarHidden(true, false);
// Log the date/time we last backgrounded // Log the date/time we last backgrounded
Settings.AddOrUpdateValue(App.Constants.LastBackgroundedDate, DateTime.UtcNow); Settings.AddOrUpdateValue(App.Constants.LastActivityDate, DateTime.UtcNow);
// Dispatch Google Analytics // Dispatch Google Analytics
SendGoogleAnalyticsHitsInBackground(); SendGoogleAnalyticsHitsInBackground();