From dd334858ffe8a5baa19424d46f2bb681cb4bd7e6 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 1 Feb 2018 21:20:35 -0500 Subject: [PATCH] add timeout on timers --- src/App/Pages/ScanPage.cs | 9 +++++---- src/App/Pages/Tools/ToolsAccessibilityServicePage.cs | 9 +++++---- src/App/Pages/Tools/ToolsAutofillServicePage.cs | 9 +++++---- src/App/Pages/Vault/VaultViewCipherPage.cs | 9 +++++---- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/App/Pages/ScanPage.cs b/src/App/Pages/ScanPage.cs index fbb190550..4dc844f23 100644 --- a/src/App/Pages/ScanPage.cs +++ b/src/App/Pages/ScanPage.cs @@ -11,7 +11,8 @@ namespace Bit.App.Pages { private readonly ZXingScannerView _zxing; private readonly OverlayGrid _overlay; - private bool _pageDisappeared = true; + private DateTime? _timerStarted = null; + private TimeSpan _timerMaxLength = TimeSpan.FromMinutes(3); public ScanPage(Action callback) : base(updateActivity: false, requireAuth: false) @@ -79,12 +80,12 @@ namespace Bit.App.Pages protected override void OnAppearing() { - _pageDisappeared = false; base.OnAppearing(); _zxing.IsScanning = true; + _timerStarted = DateTime.Now; Device.StartTimer(new TimeSpan(0, 0, 2), () => { - if(_pageDisappeared) + if(_timerStarted == null || (DateTime.Now - _timerStarted) > _timerMaxLength) { return false; } @@ -96,7 +97,7 @@ namespace Bit.App.Pages protected override void OnDisappearing() { - _pageDisappeared = true; + _timerStarted = null; _zxing.IsScanning = false; base.OnDisappearing(); } diff --git a/src/App/Pages/Tools/ToolsAccessibilityServicePage.cs b/src/App/Pages/Tools/ToolsAccessibilityServicePage.cs index 1f6180623..16c295aef 100644 --- a/src/App/Pages/Tools/ToolsAccessibilityServicePage.cs +++ b/src/App/Pages/Tools/ToolsAccessibilityServicePage.cs @@ -13,7 +13,8 @@ namespace Bit.App.Pages private readonly IGoogleAnalyticsService _googleAnalyticsService; private readonly IAppInfoService _appInfoService; private readonly IDeviceActionService _deviceActionService; - private bool _pageDisappeared = false; + private DateTime? _timerStarted = null; + private TimeSpan _timerMaxLength = TimeSpan.FromMinutes(5); public ToolsAccessibilityServicePage() { @@ -175,12 +176,12 @@ namespace Bit.App.Pages protected override void OnAppearing() { - _pageDisappeared = false; UpdateEnabled(); + _timerStarted = DateTime.Now; Device.StartTimer(new TimeSpan(0, 0, 3), () => { System.Diagnostics.Debug.WriteLine("Check timer on accessibility"); - if(_pageDisappeared) + if(_timerStarted == null || (DateTime.Now - _timerStarted) > _timerMaxLength) { return false; } @@ -194,7 +195,7 @@ namespace Bit.App.Pages protected override void OnDisappearing() { - _pageDisappeared = true; + _timerStarted = null; base.OnDisappearing(); } diff --git a/src/App/Pages/Tools/ToolsAutofillServicePage.cs b/src/App/Pages/Tools/ToolsAutofillServicePage.cs index 7c9accb45..2ba19616e 100644 --- a/src/App/Pages/Tools/ToolsAutofillServicePage.cs +++ b/src/App/Pages/Tools/ToolsAutofillServicePage.cs @@ -13,7 +13,8 @@ namespace Bit.App.Pages private readonly IGoogleAnalyticsService _googleAnalyticsService; private readonly IAppInfoService _appInfoService; private readonly IDeviceActionService _deviceActionService; - private bool _pageDisappeared = false; + private DateTime? _timerStarted = null; + private TimeSpan _timerMaxLength = TimeSpan.FromMinutes(5); public ToolsAutofillServicePage() { @@ -126,12 +127,12 @@ namespace Bit.App.Pages protected override void OnAppearing() { - _pageDisappeared = false; UpdateEnabled(); + _timerStarted = DateTime.Now; Device.StartTimer(new TimeSpan(0, 0, 2), () => { System.Diagnostics.Debug.WriteLine("Check timer on autofill"); - if(_pageDisappeared) + if(_timerStarted == null || (DateTime.Now - _timerStarted) > _timerMaxLength) { return false; } @@ -145,7 +146,7 @@ namespace Bit.App.Pages protected override void OnDisappearing() { - _pageDisappeared = true; + _timerStarted = null; base.OnDisappearing(); } diff --git a/src/App/Pages/Vault/VaultViewCipherPage.cs b/src/App/Pages/Vault/VaultViewCipherPage.cs index ce9e68c71..150d33d55 100644 --- a/src/App/Pages/Vault/VaultViewCipherPage.cs +++ b/src/App/Pages/Vault/VaultViewCipherPage.cs @@ -21,7 +21,8 @@ namespace Bit.App.Pages private readonly ICipherService _cipherService; private readonly IDeviceActionService _deviceActionService; private readonly ITokenService _tokenService; - private bool _pageDisappeared = true; + private DateTime? _timerStarted = null; + private TimeSpan _timerMaxLength = TimeSpan.FromMinutes(5); public VaultViewCipherPage(CipherType type, string cipherId) { @@ -273,7 +274,6 @@ namespace Bit.App.Pages protected async override void OnAppearing() { - _pageDisappeared = false; NotesCell.Tapped += NotesCell_Tapped; EditItem?.InitEvents(); @@ -291,7 +291,7 @@ namespace Bit.App.Pages protected override void OnDisappearing() { - _pageDisappeared = true; + _timerStarted = null; NotesCell.Tapped -= NotesCell_Tapped; EditItem?.Dispose(); CleanupAttachmentCells(); @@ -382,9 +382,10 @@ namespace Bit.App.Pages if(!string.IsNullOrWhiteSpace(Model.LoginTotpCode)) { TotpTick(totpKey); + _timerStarted = DateTime.Now; Device.StartTimer(new TimeSpan(0, 0, 1), () => { - if(_pageDisappeared) + if(_timerStarted == null || (DateTime.Now - _timerStarted) > _timerMaxLength) { return false; }