reset lock delay when returning from activity result (#2539)

This commit is contained in:
mpbw2 2023-05-25 11:43:45 -04:00 committed by GitHub
parent c7fd113f26
commit 0288a6659c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 6 deletions

View File

@ -44,6 +44,7 @@ namespace Bit.Droid
private IAppIdService _appIdService;
private IEventService _eventService;
private IPushNotificationListenerService _pushNotificationListenerService;
private IVaultTimeoutService _vaultTimeoutService;
private ILogger _logger;
private PendingIntent _eventUploadPendingIntent;
private AppOptions _appOptions;
@ -68,6 +69,7 @@ namespace Bit.Droid
_appIdService = ServiceContainer.Resolve<IAppIdService>("appIdService");
_eventService = ServiceContainer.Resolve<IEventService>("eventService");
_pushNotificationListenerService = ServiceContainer.Resolve<IPushNotificationListenerService>();
_vaultTimeoutService = ServiceContainer.Resolve<IVaultTimeoutService>();
_logger = ServiceContainer.Resolve<ILogger>("logger");
TabLayoutResource = Resource.Layout.Tabbar;
@ -232,6 +234,7 @@ namespace Bit.Droid
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
_vaultTimeoutService.ResetTimeoutDelay = true;
if (resultCode == Result.Ok &&
(requestCode == Core.Constants.SelectFileRequestCode || requestCode == Core.Constants.SaveFileRequestCode))
{

View File

@ -297,7 +297,7 @@ namespace Bit.App
{
await _vaultTimeoutService.CheckVaultTimeoutAsync();
// Reset delay on every start
_vaultTimeoutService.DelayLockAndLogoutMs = null;
_vaultTimeoutService.DelayTimeoutMs = null;
}
await _configService.GetAsync();

View File

@ -156,7 +156,7 @@ namespace Bit.App.Pages
// Prevent Android from locking if vault timeout set to "immediate"
if (Device.RuntimePlatform == Device.Android)
{
_vaultTimeoutService.DelayLockAndLogoutMs = 60000;
_vaultTimeoutService.DelayTimeoutMs = 60000;
}
await _fileService.SelectFileAsync();
}

View File

@ -6,7 +6,8 @@ namespace Bit.Core.Abstractions
{
public interface IVaultTimeoutService
{
long? DelayLockAndLogoutMs { get; set; }
long? DelayTimeoutMs { get; set; }
bool ResetTimeoutDelay { get; set; }
Task CheckVaultTimeoutAsync();
Task<bool> ShouldTimeoutAsync(string userId = null);

View File

@ -50,7 +50,8 @@ namespace Bit.Core.Services
_loggedOutCallback = loggedOutCallback;
}
public long? DelayLockAndLogoutMs { get; set; }
public long? DelayTimeoutMs { get; set; }
public bool ResetTimeoutDelay { get; set; }
public async Task<bool> IsLockedAsync(string userId = null)
{
@ -117,7 +118,7 @@ namespace Bit.Core.Services
{
return false;
}
if (vaultTimeoutMinutes == 0 && !DelayLockAndLogoutMs.HasValue)
if (vaultTimeoutMinutes == 0 && !DelayTimeoutMs.HasValue)
{
return true;
}
@ -127,8 +128,13 @@ namespace Bit.Core.Services
return false;
}
var diffMs = _platformUtilsService.GetActiveTime() - lastActiveTime;
if (DelayLockAndLogoutMs.HasValue && diffMs < DelayLockAndLogoutMs)
if (DelayTimeoutMs.HasValue && diffMs < DelayTimeoutMs)
{
if (ResetTimeoutDelay)
{
DelayTimeoutMs = null;
ResetTimeoutDelay = false;
}
return false;
}
var vaultTimeoutMs = vaultTimeoutMinutes * 60000;