From ff1957880781a9b2fd6774722c2c19f5d70fb488 Mon Sep 17 00:00:00 2001 From: Matt Portune <59324545+mportune-bw@users.noreply.github.com> Date: Fri, 9 Jul 2021 11:48:03 -0400 Subject: [PATCH] Fix for password unlock for autofill and share-to-send on Android (#1453) --- src/Android/Autofill/AutofillService.cs | 1 + src/App/Pages/Send/SendAddEditPage.xaml.cs | 17 +++++++++++++++++ src/App/Pages/Send/SendAddEditPageViewModel.cs | 10 +++++++++- src/App/Pages/Vault/AddEditPage.xaml.cs | 7 +++++++ src/App/Pages/Vault/AutofillCiphersPage.xaml.cs | 7 +++++++ 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Android/Autofill/AutofillService.cs b/src/Android/Autofill/AutofillService.cs index 7ac0c67b7..4b55b005d 100644 --- a/src/Android/Autofill/AutofillService.cs +++ b/src/Android/Autofill/AutofillService.cs @@ -57,6 +57,7 @@ namespace Bit.Droid.Autofill } List items = null; + await _vaultTimeoutService.CheckVaultTimeoutAsync(); var locked = await _vaultTimeoutService.IsLockedAsync(); if (!locked) { diff --git a/src/App/Pages/Send/SendAddEditPage.xaml.cs b/src/App/Pages/Send/SendAddEditPage.xaml.cs index 394d2767b..3f17e60bb 100644 --- a/src/App/Pages/Send/SendAddEditPage.xaml.cs +++ b/src/App/Pages/Send/SendAddEditPage.xaml.cs @@ -16,6 +16,7 @@ namespace Bit.App.Pages public partial class SendAddEditPage : BaseContentPage { private readonly IBroadcasterService _broadcasterService; + private readonly IVaultTimeoutService _vaultTimeoutService; private AppOptions _appOptions; private SendAddEditPageViewModel _vm; @@ -26,6 +27,7 @@ namespace Bit.App.Pages SendType? type = null) { _broadcasterService = ServiceContainer.Resolve("broadcasterService"); + _vaultTimeoutService = ServiceContainer.Resolve("vaultTimeoutService"); _appOptions = appOptions; InitializeComponent(); _vm = BindingContext as SendAddEditPageViewModel; @@ -79,6 +81,11 @@ namespace Bit.App.Pages protected override async void OnAppearing() { base.OnAppearing(); + await _vaultTimeoutService.CheckVaultTimeoutAsync(); + if (await _vaultTimeoutService.IsLockedAsync()) + { + return; + } await _vm.InitAsync(); _broadcasterService.Subscribe(nameof(SendAddEditPage), message => { @@ -109,6 +116,16 @@ namespace Bit.App.Pages }); } + protected override bool OnBackButtonPressed() + { + if (_vm.IsAddFromShare && Device.RuntimePlatform == Device.Android) + { + _appOptions.CreateSend = null; + _vm.CloseMainApp(); + } + return base.OnBackButtonPressed(); + } + protected override void OnDisappearing() { base.OnDisappearing(); diff --git a/src/App/Pages/Send/SendAddEditPageViewModel.cs b/src/App/Pages/Send/SendAddEditPageViewModel.cs index 73aea806d..e8e724702 100644 --- a/src/App/Pages/Send/SendAddEditPageViewModel.cs +++ b/src/App/Pages/Send/SendAddEditPageViewModel.cs @@ -398,7 +398,7 @@ namespace Bit.App.Pages if (IsAddFromShare && Device.RuntimePlatform == Device.Android) { - _deviceActionService.CloseMainApp(); + CloseMainApp(); } else { @@ -429,6 +429,14 @@ namespace Bit.App.Pages return false; } + public void CloseMainApp() + { + if (Device.RuntimePlatform == Device.Android) + { + _deviceActionService.CloseMainApp(); + } + } + public async Task RemovePasswordAsync() { return await AppHelpers.RemoveSendPasswordAsync(SendId); diff --git a/src/App/Pages/Vault/AddEditPage.xaml.cs b/src/App/Pages/Vault/AddEditPage.xaml.cs index e475a875a..5809d86bf 100644 --- a/src/App/Pages/Vault/AddEditPage.xaml.cs +++ b/src/App/Pages/Vault/AddEditPage.xaml.cs @@ -20,6 +20,7 @@ namespace Bit.App.Pages private readonly AppOptions _appOptions; private readonly IStorageService _storageService; private readonly IDeviceActionService _deviceActionService; + private readonly IVaultTimeoutService _vaultTimeoutService; private AddEditPageViewModel _vm; private bool _fromAutofill; @@ -38,6 +39,7 @@ namespace Bit.App.Pages { _storageService = ServiceContainer.Resolve("storageService"); _deviceActionService = ServiceContainer.Resolve("deviceActionService"); + _vaultTimeoutService = ServiceContainer.Resolve("vaultTimeoutService"); _appOptions = appOptions; _fromAutofill = fromAutofill; FromAutofillFramework = _appOptions?.FromAutofillFramework ?? false; @@ -145,6 +147,11 @@ namespace Bit.App.Pages protected override async void OnAppearing() { base.OnAppearing(); + await _vaultTimeoutService.CheckVaultTimeoutAsync(); + if (await _vaultTimeoutService.IsLockedAsync()) + { + return; + } await LoadOnAppearedAsync(_scrollView, true, async () => { var success = await _vm.LoadAsync(_appOptions); diff --git a/src/App/Pages/Vault/AutofillCiphersPage.xaml.cs b/src/App/Pages/Vault/AutofillCiphersPage.xaml.cs index c8f9c9634..bbaa2f026 100644 --- a/src/App/Pages/Vault/AutofillCiphersPage.xaml.cs +++ b/src/App/Pages/Vault/AutofillCiphersPage.xaml.cs @@ -15,6 +15,7 @@ namespace Bit.App.Pages { private readonly AppOptions _appOptions; private readonly IPlatformUtilsService _platformUtilsService; + private readonly IVaultTimeoutService _vaultTimeoutService; private AutofillCiphersPageViewModel _vm; @@ -27,11 +28,17 @@ namespace Bit.App.Pages _vm.Init(appOptions); _platformUtilsService = ServiceContainer.Resolve("platformUtilsService"); + _vaultTimeoutService = ServiceContainer.Resolve("vaultTimeoutService"); } protected async override void OnAppearing() { base.OnAppearing(); + await _vaultTimeoutService.CheckVaultTimeoutAsync(); + if (await _vaultTimeoutService.IsLockedAsync()) + { + return; + } await LoadOnAppearedAsync(_mainLayout, false, async () => { try