From e8c776fe49e8538d98cbac03fc278d385c759776 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 3 Jun 2019 11:08:33 -0400 Subject: [PATCH] implement blacklisted uris options for autofill --- src/Android/Autofill/AutofillService.cs | 11 +++++++++-- src/Android/Autofill/Parser.cs | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/Android/Autofill/AutofillService.cs b/src/Android/Autofill/AutofillService.cs index 4eae82719..893e22314 100644 --- a/src/Android/Autofill/AutofillService.cs +++ b/src/Android/Autofill/AutofillService.cs @@ -24,7 +24,8 @@ namespace Bit.Droid.Autofill private ILockService _lockService; 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; if(structure == null) @@ -35,7 +36,13 @@ namespace Bit.Droid.Autofill var parser = new Parser(structure, ApplicationContext); parser.Parse(); - if(!parser.ShouldAutofill) + if(_storageService == null) + { + _storageService = ServiceContainer.Resolve("storageService"); + } + + var shouldAutofill = await parser.ShouldAutofillAsync(_storageService); + if(!shouldAutofill) { return; } diff --git a/src/Android/Autofill/Parser.cs b/src/Android/Autofill/Parser.cs index 228bb7817..221629c07 100644 --- a/src/Android/Autofill/Parser.cs +++ b/src/Android/Autofill/Parser.cs @@ -3,6 +3,8 @@ using Android.App.Assist; using System.Collections.Generic; using Bit.Core; using Android.Content; +using Bit.Core.Abstractions; +using System.Threading.Tasks; namespace Bit.Droid.Autofill { @@ -77,8 +79,20 @@ namespace Bit.Droid.Autofill } } - public bool ShouldAutofill => !string.IsNullOrWhiteSpace(Uri) && - !AutofillHelpers.BlacklistedUris.Contains(Uri) && FieldCollection != null && FieldCollection.Fillable; + public async Task ShouldAutofillAsync(IStorageService storageService) + { + var fillable = !string.IsNullOrWhiteSpace(Uri) && !AutofillHelpers.BlacklistedUris.Contains(Uri) && + FieldCollection != null && FieldCollection.Fillable; + if(fillable) + { + var blacklistedUris = await storageService.GetAsync>(Constants.AutofillBlacklistedUrisKey); + if(blacklistedUris != null && blacklistedUris.Count > 0) + { + fillable = !new HashSet(blacklistedUris).Contains(Uri); + } + } + return fillable; + } public void Parse() {