1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-06-26 10:36:21 +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)
{
_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 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";

View File

@ -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<ISyncService>();
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
_settings = Resolver.Resolve<ISettings>();
BackgroundColor = Color.FromHex("efeff4");
@ -37,8 +45,12 @@ namespace Bit.App.Controls
IsBusy = _syncService.SyncInProgress;
}
var googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
googleAnalyticsService.TrackPage(GetType().Name);
if(_updateActivity)
{
_settings.AddOrUpdateValue(Constants.LastActivityDate, DateTime.UtcNow);
}
_googleAnalyticsService.TrackPage(GetType().Name);
base.OnAppearing();
}

View File

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

View File

@ -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<ICryptoService>();

View File

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

View File

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

View File

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

View File

@ -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;

View File

@ -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<IGoogleAnalyticsService>();
_settings = Resolver.Resolve<ISettings>();
if(!_setupHockeyApp)
{
var appIdService = Resolver.Resolve<IAppIdService>();
var crashManagerDelegate = new HockeyAppCrashManagerDelegate(
appIdService, Resolver.Resolve<IAuthService>());
var crashManagerDelegate = new HockeyAppCrashManagerDelegate(appIdService, Resolver.Resolve<IAuthService>());
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<IAuthService>();
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);
});
});

View File

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

View File

@ -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();