From 473e93ea161bc8e6c802272d91040c40de0f180c Mon Sep 17 00:00:00 2001 From: Matt Portune <59324545+mportune-bw@users.noreply.github.com> Date: Sun, 7 Jun 2020 00:15:51 -0400 Subject: [PATCH] Fix for deadlock in iOS autofill & share extensions (#960) --- .../CredentialProviderViewController.cs | 32 +++++++++---------- src/iOS.Autofill/SetupViewController.cs | 1 + src/iOS.Extension/LoadingViewController.cs | 16 +++++----- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/iOS.Autofill/CredentialProviderViewController.cs b/src/iOS.Autofill/CredentialProviderViewController.cs index 8caa4f79b..d24d38ff9 100644 --- a/src/iOS.Autofill/CredentialProviderViewController.cs +++ b/src/iOS.Autofill/CredentialProviderViewController.cs @@ -41,7 +41,7 @@ namespace Bit.iOS.Autofill }; } - public override void PrepareCredentialList(ASCredentialServiceIdentifier[] serviceIdentifiers) + public override async void PrepareCredentialList(ASCredentialServiceIdentifier[] serviceIdentifiers) { InitAppIfNeeded(); _context.ServiceIdentifiers = serviceIdentifiers; @@ -54,11 +54,11 @@ namespace Bit.iOS.Autofill } _context.UrlString = uri; } - if (!IsAuthed()) + if (! await IsAuthed()) { LaunchLoginFlow(); } - else if (IsLocked()) + else if (await IsLocked()) { PerformSegue("lockPasswordSegue", this); } @@ -75,10 +75,10 @@ namespace Bit.iOS.Autofill } } - public override void ProvideCredentialWithoutUserInteraction(ASPasswordCredentialIdentity credentialIdentity) + public override async void ProvideCredentialWithoutUserInteraction(ASPasswordCredentialIdentity credentialIdentity) { InitAppIfNeeded(); - if (!IsAuthed() || IsLocked()) + if (! await IsAuthed() || await IsLocked()) { var err = new NSError(new NSString("ASExtensionErrorDomain"), Convert.ToInt32(ASExtensionErrorCode.UserInteractionRequired), null); @@ -86,13 +86,13 @@ namespace Bit.iOS.Autofill return; } _context.CredentialIdentity = credentialIdentity; - ProvideCredentialAsync().GetAwaiter().GetResult(); + await ProvideCredentialAsync(); } - public override void PrepareInterfaceToProvideCredential(ASPasswordCredentialIdentity credentialIdentity) + public override async void PrepareInterfaceToProvideCredential(ASPasswordCredentialIdentity credentialIdentity) { InitAppIfNeeded(); - if (!IsAuthed()) + if (! await IsAuthed()) { LaunchLoginFlow(); return; @@ -101,11 +101,11 @@ namespace Bit.iOS.Autofill CheckLock(async () => await ProvideCredentialAsync()); } - public override void PrepareInterfaceForExtensionConfiguration() + public override async void PrepareInterfaceForExtensionConfiguration() { InitAppIfNeeded(); _context.Configuring = true; - if (!IsAuthed()) + if (! await IsAuthed()) { LaunchLoginFlow(); return; @@ -237,9 +237,9 @@ namespace Bit.iOS.Autofill CompleteRequest(decCipher.Id, decCipher.Login.Username, decCipher.Login.Password, totpCode); } - private void CheckLock(Action notLockedAction) + private async void CheckLock(Action notLockedAction) { - if (IsLocked()) + if (await IsLocked()) { PerformSegue("lockPasswordSegue", this); } @@ -249,16 +249,16 @@ namespace Bit.iOS.Autofill } } - private bool IsLocked() + private Task IsLocked() { var vaultTimeoutService = ServiceContainer.Resolve("vaultTimeoutService"); - return vaultTimeoutService.IsLockedAsync().GetAwaiter().GetResult(); + return vaultTimeoutService.IsLockedAsync(); } - private bool IsAuthed() + private Task IsAuthed() { var userService = ServiceContainer.Resolve("userService"); - return userService.IsAuthenticatedAsync().GetAwaiter().GetResult(); + return userService.IsAuthenticatedAsync(); } private void InitApp() diff --git a/src/iOS.Autofill/SetupViewController.cs b/src/iOS.Autofill/SetupViewController.cs index 11844ee98..a7444d1ef 100644 --- a/src/iOS.Autofill/SetupViewController.cs +++ b/src/iOS.Autofill/SetupViewController.cs @@ -25,6 +25,7 @@ namespace Bit.iOS.Autofill ActivatedLabel.Text = AppResources.AutofillActivated; ActivatedLabel.Font = UIFont.FromDescriptor(descriptor, descriptor.PointSize * 1.3f); + ActivatedLabel.TextColor = ThemeHelpers.SuccessColor; BackButton.Title = AppResources.Back; base.ViewDidLoad(); diff --git a/src/iOS.Extension/LoadingViewController.cs b/src/iOS.Extension/LoadingViewController.cs index 1ac977de1..02cac22b3 100644 --- a/src/iOS.Extension/LoadingViewController.cs +++ b/src/iOS.Extension/LoadingViewController.cs @@ -6,9 +6,9 @@ using Bit.iOS.Core; using Bit.iOS.Extension.Models; using MobileCoreServices; using Bit.iOS.Core.Utilities; -using Bit.App.Resources; using Bit.iOS.Core.Controllers; using System.Collections.Generic; +using System.Threading.Tasks; using Bit.iOS.Core.Models; using Bit.Core.Utilities; using Bit.Core.Abstractions; @@ -63,7 +63,7 @@ namespace Bit.iOS.Extension } } - public override void ViewDidAppear(bool animated) + public override async void ViewDidAppear(bool animated) { base.ViewDidAppear(animated); if (_context.ProviderType == Constants.UTTypeAppExtensionSetup) @@ -71,12 +71,12 @@ namespace Bit.iOS.Extension PerformSegue("setupSegue", this); return; } - if (!IsAuthed()) + if (! await IsAuthed()) { LaunchLoginFlow(); return; } - else if (IsLocked()) + else if (await IsLocked()) { PerformSegue("lockPasswordSegue", this); } @@ -408,16 +408,16 @@ namespace Bit.iOS.Extension iOSCoreHelpers.SubscribeBroadcastReceiver(this, _nfcSession, _nfcDelegate); } - private bool IsLocked() + private Task IsLocked() { var vaultTimeoutService = ServiceContainer.Resolve("vaultTimeoutService"); - return vaultTimeoutService.IsLockedAsync().GetAwaiter().GetResult(); + return vaultTimeoutService.IsLockedAsync(); } - private bool IsAuthed() + private Task IsAuthed() { var userService = ServiceContainer.Resolve("userService"); - return userService.IsAuthenticatedAsync().GetAwaiter().GetResult(); + return userService.IsAuthenticatedAsync(); } private void LaunchLoginFlow()