From 88f6b60b97b1a08e437213fde1db3efdfda125a3 Mon Sep 17 00:00:00 2001 From: mp-bw <59324545+mp-bw@users.noreply.github.com> Date: Fri, 1 Apr 2022 12:07:14 -0400 Subject: [PATCH] Crash fixes (#1869) * Crash fixes * added HasAutofillService to DeviceActionService --- src/Android/Services/BiometricService.cs | 19 +++++++++---------- src/Android/Services/DeviceActionService.cs | 7 ++++++- src/App/Abstractions/IDeviceActionService.cs | 1 + .../Settings/AutofillServicesPageViewModel.cs | 3 ++- .../Vault/AutofillCiphersPageViewModel.cs | 4 ++-- src/Core/Services/TokenService.cs | 8 ++++---- src/iOS.Core/Services/DeviceActionService.cs | 5 +++++ 7 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/Android/Services/BiometricService.cs b/src/Android/Services/BiometricService.cs index aa23477ba..c55673f19 100644 --- a/src/Android/Services/BiometricService.cs +++ b/src/Android/Services/BiometricService.cs @@ -43,23 +43,22 @@ namespace Bit.Droid.Services public Task ValidateIntegrityAsync(string bioIntegrityKey = null) { - // bioIntegrityKey used in iOS only if (Build.VERSION.SdkInt < BuildVersionCodes.M) { return Task.FromResult(true); } - _keystore.Load(null); - IKey key = _keystore.GetKey(KeyName, null); - Cipher cipher = Cipher.GetInstance(Transformation); - - if (key == null || cipher == null) - { - return Task.FromResult(true); - } - try { + _keystore.Load(null); + var key = _keystore.GetKey(KeyName, null); + var cipher = Cipher.GetInstance(Transformation); + + if (key == null || cipher == null) + { + return Task.FromResult(true); + } + cipher.Init(CipherMode.EncryptMode, key); } catch (KeyPermanentlyInvalidatedException e) diff --git a/src/Android/Services/DeviceActionService.cs b/src/Android/Services/DeviceActionService.cs index 11ef29774..37d90d0d4 100644 --- a/src/Android/Services/DeviceActionService.cs +++ b/src/Android/Services/DeviceActionService.cs @@ -674,7 +674,7 @@ namespace Bit.Droid.Services else { var data = new Intent(); - if (cipher == null) + if (cipher?.Login == null) { data.PutExtra("canceled", "true"); } @@ -734,6 +734,11 @@ namespace Bit.Droid.Services return Accessibility.AccessibilityHelpers.OverlayPermitted(); } + public bool HasAutofillService() + { + return true; + } + public void OpenAccessibilityOverlayPermissionSettings() { var activity = (MainActivity)CrossCurrentActivity.Current.Activity; diff --git a/src/App/Abstractions/IDeviceActionService.cs b/src/App/Abstractions/IDeviceActionService.cs index ad267f7ab..350f791db 100644 --- a/src/App/Abstractions/IDeviceActionService.cs +++ b/src/App/Abstractions/IDeviceActionService.cs @@ -35,6 +35,7 @@ namespace Bit.App.Abstractions void Background(); bool AutofillAccessibilityServiceRunning(); bool AutofillAccessibilityOverlayPermitted(); + bool HasAutofillService(); bool AutofillServiceEnabled(); void DisableAutofillService(); bool AutofillServicesEnabled(); diff --git a/src/App/Pages/Settings/AutofillServicesPageViewModel.cs b/src/App/Pages/Settings/AutofillServicesPageViewModel.cs index ecd89b6af..52b3cf4c3 100644 --- a/src/App/Pages/Settings/AutofillServicesPageViewModel.cs +++ b/src/App/Pages/Settings/AutofillServicesPageViewModel.cs @@ -192,7 +192,8 @@ namespace Bit.App.Pages public void UpdateEnabled() { - AutofillServiceToggled = _deviceActionService.AutofillServiceEnabled(); + AutofillServiceToggled = + _deviceActionService.HasAutofillService() && _deviceActionService.AutofillServiceEnabled(); AccessibilityToggled = _deviceActionService.AutofillAccessibilityServiceRunning(); DrawOverToggled = _deviceActionService.AutofillAccessibilityOverlayPermitted(); } diff --git a/src/App/Pages/Vault/AutofillCiphersPageViewModel.cs b/src/App/Pages/Vault/AutofillCiphersPageViewModel.cs index b90a144a2..360b5d225 100644 --- a/src/App/Pages/Vault/AutofillCiphersPageViewModel.cs +++ b/src/App/Pages/Vault/AutofillCiphersPageViewModel.cs @@ -66,9 +66,9 @@ namespace Bit.App.Pages public void Init(AppOptions appOptions) { _appOptions = appOptions; - Uri = appOptions.Uri; + Uri = appOptions?.Uri; string name = null; - if (Uri.StartsWith(Constants.AndroidAppProtocol)) + if (Uri?.StartsWith(Constants.AndroidAppProtocol) ?? false) { name = Uri.Substring(Constants.AndroidAppProtocol.Length); } diff --git a/src/Core/Services/TokenService.cs b/src/Core/Services/TokenService.cs index c30d33479..dcf3ad17e 100644 --- a/src/Core/Services/TokenService.cs +++ b/src/Core/Services/TokenService.cs @@ -208,10 +208,10 @@ namespace Bit.Core.Services if (_accessTokenForDecoding == null) { await GetTokenAsync(); - } - if (_accessTokenForDecoding == null) - { - return false; + if (_accessTokenForDecoding == null) + { + return false; + } } var decoded = DecodeToken(); if (decoded?["amr"] == null) diff --git a/src/iOS.Core/Services/DeviceActionService.cs b/src/iOS.Core/Services/DeviceActionService.cs index 5699e5f9b..28b12703a 100644 --- a/src/iOS.Core/Services/DeviceActionService.cs +++ b/src/iOS.Core/Services/DeviceActionService.cs @@ -392,6 +392,11 @@ namespace Bit.iOS.Core.Services throw new NotImplementedException(); } + public bool HasAutofillService() + { + return false; + } + public bool AutofillServiceEnabled() { throw new NotImplementedException();