From 218a30b51082d867ce5ae9cd687c218bcb8edfb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bispo?= Date: Tue, 26 Sep 2023 17:25:47 +0100 Subject: [PATCH] [PM-3446] User without MP, item with MP does not show on Android keyboard for autofill (#2764) * [PM-3446] Check if user has mp and allow autofill to use items with mp re-prompt --- src/Android/Autofill/AutofillHelpers.cs | 8 +++++--- src/Android/Autofill/AutofillService.cs | 10 +++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Android/Autofill/AutofillHelpers.cs b/src/Android/Autofill/AutofillHelpers.cs index 3d12f8c97..86d6cc828 100644 --- a/src/Android/Autofill/AutofillHelpers.cs +++ b/src/Android/Autofill/AutofillHelpers.cs @@ -20,6 +20,7 @@ using AndroidX.AutoFill.Inline.V1; using Bit.Core.Abstractions; using SaveFlags = Android.Service.Autofill.SaveFlags; using Bit.Droid.Utilities; +using Bit.Core.Services; namespace Bit.Droid.Autofill { @@ -152,8 +153,9 @@ namespace Bit.Droid.Autofill "androidapp://com.oneplus.applocker", }; - public static async Task> GetFillItemsAsync(Parser parser, ICipherService cipherService) + public static async Task> GetFillItemsAsync(Parser parser, ICipherService cipherService, IUserVerificationService userVerificationService) { + var userHasMasterPassword = await userVerificationService.HasMasterPasswordAsync(); if (parser.FieldCollection.FillableForLogin) { var ciphers = await cipherService.GetAllDecryptedByUrlAsync(parser.Uri); @@ -161,14 +163,14 @@ namespace Bit.Droid.Autofill { var allCiphers = ciphers.Item1.ToList(); allCiphers.AddRange(ciphers.Item2.ToList()); - var nonPromptCiphers = allCiphers.Where(cipher => cipher.Reprompt == CipherRepromptType.None); + var nonPromptCiphers = allCiphers.Where(cipher => !userHasMasterPassword || cipher.Reprompt == CipherRepromptType.None); return nonPromptCiphers.Select(c => new FilledItem(c)).ToList(); } } else if (parser.FieldCollection.FillableForCard) { var ciphers = await cipherService.GetAllDecryptedAsync(); - return ciphers.Where(c => c.Type == CipherType.Card && c.Reprompt == CipherRepromptType.None).Select(c => new FilledItem(c)).ToList(); + return ciphers.Where(c => c.Type == CipherType.Card && (!userHasMasterPassword || c.Reprompt == CipherRepromptType.None)).Select(c => new FilledItem(c)).ToList(); } return new List(); } diff --git a/src/Android/Autofill/AutofillService.cs b/src/Android/Autofill/AutofillService.cs index 3becfe4ac..15e384839 100644 --- a/src/Android/Autofill/AutofillService.cs +++ b/src/Android/Autofill/AutofillService.cs @@ -11,6 +11,7 @@ using Android.Widget; using Bit.Core; using Bit.Core.Abstractions; using Bit.Core.Enums; +using Bit.Core.Services; using Bit.Core.Utilities; namespace Bit.Droid.Autofill @@ -26,6 +27,7 @@ namespace Bit.Droid.Autofill private IPolicyService _policyService; private IStateService _stateService; private LazyResolve _logger = new LazyResolve("logger"); + private IUserVerificationService _userVerificationService; public async override void OnFillRequest(FillRequest request, CancellationSignal cancellationSignal, FillCallback callback) @@ -64,11 +66,9 @@ namespace Bit.Droid.Autofill var locked = await _vaultTimeoutService.IsLockedAsync(); if (!locked) { - if (_cipherService == null) - { - _cipherService = ServiceContainer.Resolve("cipherService"); - } - items = await AutofillHelpers.GetFillItemsAsync(parser, _cipherService); + _cipherService ??= ServiceContainer.Resolve(); + _userVerificationService ??= ServiceContainer.Resolve(); + items = await AutofillHelpers.GetFillItemsAsync(parser, _cipherService, _userVerificationService); } // build response