1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-04 08:50:18 +01:00

implement blacklisted uris options for autofill

This commit is contained in:
Kyle Spearrin 2019-06-03 11:08:33 -04:00
parent 999c9667c8
commit e8c776fe49
2 changed files with 25 additions and 4 deletions

View File

@ -24,7 +24,8 @@ namespace Bit.Droid.Autofill
private ILockService _lockService; private ILockService _lockService;
private IStorageService _storageService; private IStorageService _storageService;
public async override void OnFillRequest(FillRequest request, CancellationSignal cancellationSignal, FillCallback callback) public async override void OnFillRequest(FillRequest request, CancellationSignal cancellationSignal,
FillCallback callback)
{ {
var structure = request.FillContexts?.LastOrDefault()?.Structure; var structure = request.FillContexts?.LastOrDefault()?.Structure;
if(structure == null) if(structure == null)
@ -35,7 +36,13 @@ namespace Bit.Droid.Autofill
var parser = new Parser(structure, ApplicationContext); var parser = new Parser(structure, ApplicationContext);
parser.Parse(); parser.Parse();
if(!parser.ShouldAutofill) if(_storageService == null)
{
_storageService = ServiceContainer.Resolve<IStorageService>("storageService");
}
var shouldAutofill = await parser.ShouldAutofillAsync(_storageService);
if(!shouldAutofill)
{ {
return; return;
} }

View File

@ -3,6 +3,8 @@ using Android.App.Assist;
using System.Collections.Generic; using System.Collections.Generic;
using Bit.Core; using Bit.Core;
using Android.Content; using Android.Content;
using Bit.Core.Abstractions;
using System.Threading.Tasks;
namespace Bit.Droid.Autofill namespace Bit.Droid.Autofill
{ {
@ -77,8 +79,20 @@ namespace Bit.Droid.Autofill
} }
} }
public bool ShouldAutofill => !string.IsNullOrWhiteSpace(Uri) && public async Task<bool> ShouldAutofillAsync(IStorageService storageService)
!AutofillHelpers.BlacklistedUris.Contains(Uri) && FieldCollection != null && FieldCollection.Fillable; {
var fillable = !string.IsNullOrWhiteSpace(Uri) && !AutofillHelpers.BlacklistedUris.Contains(Uri) &&
FieldCollection != null && FieldCollection.Fillable;
if(fillable)
{
var blacklistedUris = await storageService.GetAsync<List<string>>(Constants.AutofillBlacklistedUrisKey);
if(blacklistedUris != null && blacklistedUris.Count > 0)
{
fillable = !new HashSet<string>(blacklistedUris).Contains(Uri);
}
}
return fillable;
}
public void Parse() public void Parse()
{ {