mirror of
https://github.com/bitwarden/mobile
synced 2025-12-05 23:53:33 +00:00
Merge branch 'master' into feature-accountswitch
This commit is contained in:
@@ -188,6 +188,8 @@ namespace Bit.App
|
||||
if (Device.RuntimePlatform == Device.Android)
|
||||
{
|
||||
await _vaultTimeoutService.CheckVaultTimeoutAsync();
|
||||
// Reset delay on every start
|
||||
_vaultTimeoutService.DelayLockAndLogoutMs = null;
|
||||
}
|
||||
_messagingService.Send("startEventTimer");
|
||||
}
|
||||
@@ -220,7 +222,7 @@ namespace Bit.App
|
||||
|
||||
private async Task SleptAsync()
|
||||
{
|
||||
await HandleVaultTimeoutAsync();
|
||||
await _vaultTimeoutService.CheckVaultTimeoutAsync();
|
||||
_messagingService.Send("stopEventTimer");
|
||||
}
|
||||
|
||||
@@ -318,33 +320,6 @@ namespace Bit.App
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleVaultTimeoutAsync()
|
||||
{
|
||||
if (await _vaultTimeoutService.IsLockedAsync())
|
||||
{
|
||||
return;
|
||||
}
|
||||
var authed = await _stateService.IsAuthenticatedAsync();
|
||||
if (!authed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var vaultTimeout = await _stateService.GetVaultTimeoutAsync();
|
||||
vaultTimeout = vaultTimeout.GetValueOrDefault(-1);
|
||||
if (vaultTimeout == 0)
|
||||
{
|
||||
var action = await _stateService.GetVaultTimeoutActionAsync();
|
||||
if (action == "logOut")
|
||||
{
|
||||
await _vaultTimeoutService.LogOutAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
await _vaultTimeoutService.LockAsync(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ClearCacheIfNeededAsync()
|
||||
{
|
||||
var lastClear = await _stateService.GetLastFileCacheClearAsync();
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace Bit.App.Pages
|
||||
private readonly ICipherService _cipherService;
|
||||
private readonly ICryptoService _cryptoService;
|
||||
private readonly IStateService _stateService;
|
||||
private readonly IVaultTimeoutService _vaultTimeoutService;
|
||||
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");
|
||||
_stateService = ServiceContainer.Resolve<IStateService>("stateService");
|
||||
_vaultTimeoutService = 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)
|
||||
{
|
||||
_vaultTimeoutService.DelayLockAndLogoutMs = 60000;
|
||||
}
|
||||
await _deviceActionService.SelectFileAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace Bit.Core.Abstractions
|
||||
{
|
||||
public interface IVaultTimeoutService
|
||||
{
|
||||
long? DelayLockAndLogoutMs { get; set; }
|
||||
|
||||
Task CheckVaultTimeoutAsync();
|
||||
Task<bool> ShouldTimeoutAsync(string userId = null);
|
||||
Task ExecuteTimeoutActionAsync(string userId = null);
|
||||
|
||||
@@ -52,6 +52,8 @@ namespace Bit.Core.Services
|
||||
_loggedOutCallback = loggedOutCallback;
|
||||
}
|
||||
|
||||
public long? DelayLockAndLogoutMs { get; set; }
|
||||
|
||||
public async Task<bool> IsLockedAsync(string userId = null)
|
||||
{
|
||||
var hasKey = await _cryptoService.HasKeyAsync(userId);
|
||||
@@ -95,12 +97,20 @@ namespace Bit.Core.Services
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (vaultTimeoutMinutes == 0 && !DelayLockAndLogoutMs.HasValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
var lastActiveTime = await _stateService.GetLastActiveTimeAsync(userId);
|
||||
if (lastActiveTime == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var diffMs = _platformUtilsService.GetActiveTime() - lastActiveTime;
|
||||
if (DelayLockAndLogoutMs.HasValue && diffMs < DelayLockAndLogoutMs)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var vaultTimeoutMs = vaultTimeoutMinutes * 60000;
|
||||
return diffMs >= vaultTimeoutMs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user