Supress lock and logout when showing fileswitcher on Android (#1626)

* Supress lock and logout when showing fileswitcher on Android

* convert suppress bool to delay long
- move HandleVaultTimeoutAsync to vaultTimeoutService
This commit is contained in:
Jake Fink 2022-01-19 09:09:30 -05:00 committed by GitHub
parent 2791d4b8ec
commit 6f3999016f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 38 deletions

View File

@ -176,6 +176,8 @@ namespace Bit.App
if (Device.RuntimePlatform == Device.Android)
{
await _vaultTimeoutService.CheckVaultTimeoutAsync();
// Reset delay on every start
_vaultTimeoutService.DelayLockAndLogoutMs = null;
}
_messagingService.Send("startEventTimer");
}
@ -208,7 +210,7 @@ namespace Bit.App
private async Task SleptAsync()
{
await HandleVaultTimeoutAsync();
await _vaultTimeoutService.CheckVaultTimeoutAsync();
_messagingService.Send("stopEventTimer");
}
@ -279,33 +281,6 @@ namespace Bit.App
}
}
private async Task HandleVaultTimeoutAsync()
{
if (await _vaultTimeoutService.IsLockedAsync())
{
return;
}
var authed = await _userService.IsAuthenticatedAsync();
if (!authed)
{
return;
}
var vaultTimeout = await _storageService.GetAsync<int?>(Constants.VaultTimeoutKey);
vaultTimeout = vaultTimeout.GetValueOrDefault(-1);
if (vaultTimeout == 0)
{
var action = await _storageService.GetAsync<string>(Constants.VaultTimeoutActionKey);
if (action == "logOut")
{
await _vaultTimeoutService.LogOutAsync();
}
else
{
await _vaultTimeoutService.LockAsync(true);
}
}
}
private async Task ClearCacheIfNeededAsync()
{
var lastClear = await _storageService.GetAsync<DateTime?>(Constants.LastFileCacheClearKey);

View File

@ -18,6 +18,7 @@ namespace Bit.App.Pages
private readonly ICipherService _cipherService;
private readonly ICryptoService _cryptoService;
private readonly IUserService _userService;
private readonly IVaultTimeoutService _timeoutService;
private readonly IPlatformUtilsService _platformUtilsService;
private CipherView _cipher;
private Cipher _cipherDomain;
@ -33,6 +34,7 @@ namespace Bit.App.Pages
_cryptoService = ServiceContainer.Resolve<ICryptoService>("cryptoService");
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
_userService = ServiceContainer.Resolve<IUserService>("userService");
_timeoutService = ServiceContainer.Resolve<IVaultTimeoutService>("vaultTimeoutService");
Attachments = new ExtendedObservableCollection<AttachmentView>();
DeleteAttachmentCommand = new Command<AttachmentView>(DeleteAsync);
PageTitle = AppResources.Attachments;
@ -135,6 +137,11 @@ namespace Bit.App.Pages
public async Task ChooseFileAsync()
{
// Prevent Android from locking if vault timeout set to "immediate"
if (Device.RuntimePlatform == Device.Android)
{
_timeoutService.DelayLockAndLogoutMs = 60000;
}
await _deviceActionService.SelectFileAsync();
}

View File

@ -8,6 +8,7 @@ namespace Bit.Core.Abstractions
{
EncString PinProtectedKey { get; set; }
bool BiometricLocked { get; set; }
long? DelayLockAndLogoutMs { get; set; }
Task CheckVaultTimeoutAsync();
Task ClearAsync();

View File

@ -58,6 +58,7 @@ namespace Bit.Core.Services
public EncString PinProtectedKey { get; set; } = null;
public bool BiometricLocked { get; set; } = true;
public long? DelayLockAndLogoutMs { get; set; }
public async Task<bool> IsLockedAsync()
{
@ -93,25 +94,39 @@ namespace Bit.Core.Services
{
return;
}
if (vaultTimeoutMinutes == 0 && !DelayLockAndLogoutMs.HasValue)
{
await LockOrLogout();
}
var lastActiveTime = await _storageService.GetAsync<long?>(Constants.LastActiveTimeKey);
if (lastActiveTime == null)
{
return;
}
var diffMs = _platformUtilsService.GetActiveTime() - lastActiveTime;
if (DelayLockAndLogoutMs.HasValue && diffMs < DelayLockAndLogoutMs)
{
return;
}
var vaultTimeoutMs = vaultTimeoutMinutes * 60000;
if (diffMs >= vaultTimeoutMs)
{
// Pivot based on saved action
var action = await _storageService.GetAsync<string>(Constants.VaultTimeoutActionKey);
if (action == "logOut")
{
await LogOutAsync();
}
else
{
await LockAsync(true);
}
await LockOrLogout();
}
}
private async Task LockOrLogout()
{
// Pivot based on saved action
var action = await _storageService.GetAsync<string>(Constants.VaultTimeoutActionKey);
if (action == "logOut")
{
await LogOutAsync();
}
else
{
await LockAsync(true);
}
}