Skip to content

Commit

Permalink
[PM-3446] User without MP, item with MP does not show on Android keyb…
Browse files Browse the repository at this point in the history
…oard for autofill (bitwarden#2764)

* [PM-3446] Check if user has mp and allow autofill to use items with mp re-prompt
  • Loading branch information
andrebispo5 authored Sep 26, 2023
1 parent 828043e commit 218a30b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/Android/Autofill/AutofillHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Bit.Core.Abstractions;
using SaveFlags = Android.Service.Autofill.SaveFlags;
using Bit.Droid.Utilities;
using Bit.Core.Services;

namespace Bit.Droid.Autofill
{
Expand Down Expand Up @@ -152,23 +153,24 @@ public static class AutofillHelpers
"androidapp://com.oneplus.applocker",
};

public static async Task<List<FilledItem>> GetFillItemsAsync(Parser parser, ICipherService cipherService)
public static async Task<List<FilledItem>> GetFillItemsAsync(Parser parser, ICipherService cipherService, IUserVerificationService userVerificationService)
{
var userHasMasterPassword = await userVerificationService.HasMasterPasswordAsync();
if (parser.FieldCollection.FillableForLogin)
{
var ciphers = await cipherService.GetAllDecryptedByUrlAsync(parser.Uri);
if (ciphers.Item1.Any() || ciphers.Item2.Any())
{
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<FilledItem>();
}
Expand Down
10 changes: 5 additions & 5 deletions src/Android/Autofill/AutofillService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Bit.Core;
using Bit.Core.Abstractions;
using Bit.Core.Enums;
using Bit.Core.Services;
using Bit.Core.Utilities;

namespace Bit.Droid.Autofill
Expand All @@ -26,6 +27,7 @@ public class AutofillService : Android.Service.Autofill.AutofillService
private IPolicyService _policyService;
private IStateService _stateService;
private LazyResolve<ILogger> _logger = new LazyResolve<ILogger>("logger");
private IUserVerificationService _userVerificationService;

public async override void OnFillRequest(FillRequest request, CancellationSignal cancellationSignal,
FillCallback callback)
Expand Down Expand Up @@ -64,11 +66,9 @@ public async override void OnFillRequest(FillRequest request, CancellationSignal
var locked = await _vaultTimeoutService.IsLockedAsync();
if (!locked)
{
if (_cipherService == null)
{
_cipherService = ServiceContainer.Resolve<ICipherService>("cipherService");
}
items = await AutofillHelpers.GetFillItemsAsync(parser, _cipherService);
_cipherService ??= ServiceContainer.Resolve<ICipherService>();
_userVerificationService ??= ServiceContainer.Resolve<IUserVerificationService>();
items = await AutofillHelpers.GetFillItemsAsync(parser, _cipherService, _userVerificationService);
}

// build response
Expand Down

0 comments on commit 218a30b

Please sign in to comment.