Lock Screen Fixes

- Move settings to AppSettingsService
- Update activity on page disappaearing
- Always check if app is currently locked before updating last activity
date
This commit is contained in:
Kyle Spearrin 2017-04-28 11:07:26 -04:00
parent be47bb7263
commit 01736ca685
13 changed files with 102 additions and 23 deletions

View file

@ -73,7 +73,8 @@ namespace Bit.Android
Resolver.Resolve<ILockService>(),
Resolver.Resolve<IGoogleAnalyticsService>(),
Resolver.Resolve<ILocalizeService>(),
Resolver.Resolve<IAppInfoService>()));
Resolver.Resolve<IAppInfoService>(),
Resolver.Resolve<IAppSettingsService>()));
MessagingCenter.Subscribe<Xamarin.Forms.Application>(Xamarin.Forms.Application.Current, "RateApp", (sender) =>
{

View file

@ -211,6 +211,7 @@ namespace Bit.Android
.RegisterType<ITokenService, TokenService>(new ContainerControlledLifetimeManager())
.RegisterType<ISettingsService, SettingsService>(new ContainerControlledLifetimeManager())
.RegisterType<IMemoryService, MemoryService>(new ContainerControlledLifetimeManager())
.RegisterType<IAppSettingsService, AppSettingsService>(new ContainerControlledLifetimeManager())
// Repositories
.RegisterType<IFolderRepository, FolderRepository>(new ContainerControlledLifetimeManager())
.RegisterType<IFolderApiRepository, FolderApiRepository>(new ContainerControlledLifetimeManager())

View file

@ -0,0 +1,10 @@
using System;
namespace Bit.App.Abstractions
{
public interface IAppSettingsService
{
bool Locked { get; set; }
DateTime LastActivity { get; set; }
}
}

View file

@ -1,9 +1,11 @@
using Bit.App.Enums;
using System;
namespace Bit.App.Abstractions
{
public interface ILockService
{
void UpdateLastActivity(DateTime? activityDate = null);
LockType GetLockType(bool forceLock);
}
}

View file

@ -33,6 +33,7 @@ namespace Bit.App
private readonly IGoogleAnalyticsService _googleAnalyticsService;
private readonly ILocalizeService _localizeService;
private readonly IAppInfoService _appInfoService;
private readonly IAppSettingsService _appSettingsService;
public App(
string uri,
@ -46,7 +47,8 @@ namespace Bit.App
ILockService lockService,
IGoogleAnalyticsService googleAnalyticsService,
ILocalizeService localizeService,
IAppInfoService appInfoService)
IAppInfoService appInfoService,
IAppSettingsService appSettingsService)
{
_uri = uri;
_databaseService = databaseService;
@ -60,6 +62,7 @@ namespace Bit.App
_googleAnalyticsService = googleAnalyticsService;
_localizeService = localizeService;
_appInfoService = appInfoService;
_appSettingsService = appSettingsService;
SetCulture();
SetStyles();
@ -123,7 +126,7 @@ namespace Bit.App
if(Device.OS == TargetPlatform.Android && !TopPageIsLock())
{
_settings.AddOrUpdateValue(Constants.LastActivityDate, DateTime.UtcNow);
_lockService.UpdateLastActivity();
}
}
@ -248,7 +251,7 @@ namespace Bit.App
return;
}
_settings.AddOrUpdateValue(Constants.Locked, true);
_appSettingsService.Locked = true;
switch(lockType)
{
case Enums.LockType.Fingerprint:

View file

@ -39,6 +39,7 @@
<Compile Include="Abstractions\Repositories\IAccountsApiRepository.cs" />
<Compile Include="Abstractions\Repositories\IDeviceApiRepository.cs" />
<Compile Include="Abstractions\Repositories\ISettingsRepository.cs" />
<Compile Include="Abstractions\Services\IAppSettingsService.cs" />
<Compile Include="Abstractions\Services\IMemoryService.cs" />
<Compile Include="Abstractions\Services\ISettingsService.cs" />
<Compile Include="Abstractions\Services\ITokenService.cs" />
@ -203,6 +204,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>AppResources.zh-Hans.resx</DependentUpon>
</Compile>
<Compile Include="Services\AppSettingsService.cs" />
<Compile Include="Services\SettingsService.cs" />
<Compile Include="Services\TokenService.cs" />
<Compile Include="Services\AppIdService.cs" />

View file

@ -10,7 +10,7 @@ namespace Bit.App.Controls
{
private ISyncService _syncService;
private IGoogleAnalyticsService _googleAnalyticsService;
private ISettings _settings;
private ILockService _lockService;
private bool _syncIndicator;
private bool _updateActivity;
@ -20,7 +20,7 @@ namespace Bit.App.Controls
_updateActivity = updateActivity;
_syncService = Resolver.Resolve<ISyncService>();
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
_settings = Resolver.Resolve<ISettings>();
_lockService = Resolver.Resolve<ILockService>();
BackgroundColor = Color.FromHex("efeff4");
@ -45,11 +45,6 @@ namespace Bit.App.Controls
IsBusy = _syncService.SyncInProgress;
}
if(_updateActivity)
{
_settings.AddOrUpdateValue(Constants.LastActivityDate, DateTime.UtcNow);
}
_googleAnalyticsService.TrackPage(GetType().Name);
base.OnAppearing();
}
@ -61,6 +56,11 @@ namespace Bit.App.Controls
IsBusy = false;
}
if(_updateActivity)
{
_lockService.UpdateLastActivity();
}
base.OnDisappearing();
}
}

View file

@ -6,6 +6,7 @@ using Xamarin.Forms;
using XLabs.Ioc;
using Plugin.Fingerprint.Abstractions;
using Plugin.Settings.Abstractions;
using Bit.App.Abstractions;
namespace Bit.App.Pages
{
@ -13,6 +14,7 @@ namespace Bit.App.Pages
{
private readonly IFingerprint _fingerprint;
private readonly ISettings _settings;
private readonly IAppSettingsService _appSettings;
private readonly bool _checkFingerprintImmediately;
public LockFingerprintPage(bool checkFingerprintImmediately)
@ -20,6 +22,7 @@ namespace Bit.App.Pages
_checkFingerprintImmediately = checkFingerprintImmediately;
_fingerprint = Resolver.Resolve<IFingerprint>();
_settings = Resolver.Resolve<ISettings>();
_appSettings = Resolver.Resolve<IAppSettingsService>();
Init();
}
@ -79,7 +82,7 @@ namespace Bit.App.Pages
var result = await _fingerprint.AuthenticateAsync(AppResources.FingerprintDirection);
if(result.Authenticated)
{
_settings.AddOrUpdateValue(Constants.Locked, false);
_appSettings.Locked = false;
await Navigation.PopModalAsync();
}
else if(result.Status == FingerprintAuthenticationResultStatus.FallbackRequested)

View file

@ -152,7 +152,6 @@ namespace Bit.App.Pages
return;
}
_userDialogs.ShowLoading(AppResources.Deleting, MaskType.Black);
var deleteTask = await _folderService.DeleteAsync(_folderId);
_userDialogs.HideLoading();

View file

@ -0,0 +1,41 @@
using System;
using Bit.App.Abstractions;
using Plugin.Settings.Abstractions;
namespace Bit.App.Services
{
public class AppSettingsService : IAppSettingsService
{
private readonly ISettings _settings;
public AppSettingsService(
ISettings settings)
{
_settings = settings;
}
public bool Locked
{
get
{
return _settings.GetValueOrDefault(Constants.Locked, false);
}
set
{
_settings.AddOrUpdateValue(Constants.Locked, value);
}
}
public DateTime LastActivity
{
get
{
return _settings.GetValueOrDefault(Constants.LastActivityDate, DateTime.MinValue);
}
set
{
_settings.AddOrUpdateValue(Constants.LastActivityDate, value);
}
}
}
}

View file

@ -9,19 +9,32 @@ namespace Bit.App.Services
public class LockService : ILockService
{
private readonly ISettings _settings;
private readonly IAppSettingsService _appSettings;
private readonly IAuthService _authService;
private readonly IFingerprint _fingerprint;
public LockService(
ISettings settings,
IAppSettingsService appSettings,
IAuthService authService,
IFingerprint fingerprint)
{
_settings = settings;
_appSettings = appSettings;
_authService = authService;
_fingerprint = fingerprint;
}
public void UpdateLastActivity(DateTime? activityDate = null)
{
if(_appSettings.Locked)
{
return;
}
_appSettings.LastActivity = activityDate.GetValueOrDefault(DateTime.UtcNow);
}
public LockType GetLockType(bool forceLock)
{
// Only lock if they are logged in
@ -31,7 +44,7 @@ namespace Bit.App.Services
}
// Are we forcing a lock? (i.e. clicking a button to lock the app manually, immediately)
if(!forceLock && !_settings.GetValueOrDefault(Constants.Locked, false))
if(!forceLock && !_appSettings.Locked)
{
// Lock seconds tells if they want to lock the app or not
var lockSeconds = _settings.GetValueOrDefault(Constants.SettingLockSeconds, 60 * 15);
@ -42,8 +55,7 @@ namespace Bit.App.Services
// Has it been longer than lockSeconds since the last time the app was used?
var now = DateTime.UtcNow;
var lastBackground = _settings.GetValueOrDefault(Constants.LastActivityDate, now.AddYears(-1));
if((now - lastBackground).TotalSeconds < lockSeconds)
if((now - _appSettings.LastActivity).TotalSeconds < lockSeconds)
{
return LockType.None;
}

View file

@ -30,7 +30,7 @@ namespace Bit.iOS.Extension
private readonly JsonSerializerSettings _jsonSettings =
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
private IGoogleAnalyticsService _googleAnalyticsService;
private ISettings _settings;
private ILockService _lockService;
public LoadingViewController(IntPtr handle) : base(handle)
{ }
@ -44,7 +44,7 @@ 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>();
_lockService = Resolver.Resolve<ILockService>();
if(!_setupHockeyApp)
{
@ -175,7 +175,7 @@ namespace Bit.iOS.Extension
private void ContinueOn()
{
Debug.WriteLine("BW Log, Segue to setup, login add or list.");
_settings.AddOrUpdateValue(App.Constants.LastActivityDate, DateTime.UtcNow);
_lockService.UpdateLastActivity();
if(_context.ProviderType == Constants.UTTypeAppExtensionSaveLoginAction)
{
@ -240,7 +240,7 @@ namespace Bit.iOS.Extension
if(itemData != null)
{
_settings.AddOrUpdateValue(App.Constants.LastActivityDate, DateTime.UtcNow);
_lockService.UpdateLastActivity();
_googleAnalyticsService.TrackExtensionEvent("AutoFilled", _context.ProviderType);
}
else
@ -283,6 +283,7 @@ namespace Bit.iOS.Extension
.RegisterType<ITokenService, TokenService>(new ContainerControlledLifetimeManager())
.RegisterType<ISettingsService, SettingsService>(new ContainerControlledLifetimeManager())
.RegisterType<IDeviceInfoService, DeviceInfoService>(new ContainerControlledLifetimeManager())
.RegisterType<IAppSettingsService, AppSettingsService>(new ContainerControlledLifetimeManager())
// Repositories
.RegisterType<IFolderRepository, FolderRepository>(new ContainerControlledLifetimeManager())
.RegisterType<IFolderApiRepository, FolderApiRepository>(new ContainerControlledLifetimeManager())

View file

@ -33,6 +33,7 @@ namespace Bit.iOS
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
private GaiCompletionHandler _dispatchHandler = null;
private ILockService _lockService;
public ISettings Settings { get; set; }
@ -45,6 +46,7 @@ namespace Bit.iOS
SetIoc();
}
_lockService = Resolver.Resolve<ILockService>();
var appIdService = Resolver.Resolve<IAppIdService>();
var crashManagerDelegate = new HockeyAppCrashManagerDelegate(
appIdService, Resolver.Resolve<IAuthService>());
@ -65,10 +67,11 @@ namespace Bit.iOS
Resolver.Resolve<ISyncService>(),
Resolver.Resolve<IFingerprint>(),
Resolver.Resolve<ISettings>(),
Resolver.Resolve<ILockService>(),
_lockService,
Resolver.Resolve<IGoogleAnalyticsService>(),
Resolver.Resolve<ILocalizeService>(),
Resolver.Resolve<IAppInfoService>()));
Resolver.Resolve<IAppInfoService>(),
Resolver.Resolve<IAppSettingsService>()));
// Appearance stuff
@ -143,7 +146,7 @@ namespace Bit.iOS
UIApplication.SharedApplication.SetStatusBarHidden(true, false);
// Log the date/time we last backgrounded
Settings.AddOrUpdateValue(App.Constants.LastActivityDate, DateTime.UtcNow);
_lockService.UpdateLastActivity();
// Dispatch Google Analytics
SendGoogleAnalyticsHitsInBackground();
@ -268,6 +271,7 @@ namespace Bit.iOS
.RegisterType<IHttpService, HttpService>(new ContainerControlledLifetimeManager())
.RegisterType<ITokenService, TokenService>(new ContainerControlledLifetimeManager())
.RegisterType<ISettingsService, SettingsService>(new ContainerControlledLifetimeManager())
.RegisterType<IAppSettingsService, AppSettingsService>(new ContainerControlledLifetimeManager())
// Repositories
.RegisterType<IFolderRepository, FolderRepository>(new ContainerControlledLifetimeManager())
.RegisterType<IFolderApiRepository, FolderApiRepository>(new ContainerControlledLifetimeManager())