From da199deed1b716e4c5151661e19af4bd18c7aad2 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 17 Nov 2017 17:46:55 -0500 Subject: [PATCH] only show autofills if a fillable login form --- src/Android/Autofill/AutofillService.cs | 2 +- src/Android/Autofill/CipherFilledItem.cs | 9 +------ src/Android/Autofill/FieldCollection.cs | 32 ++++++++++++++++++------ 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/Android/Autofill/AutofillService.cs b/src/Android/Autofill/AutofillService.cs index cadf5dcee..46b577fbf 100644 --- a/src/Android/Autofill/AutofillService.cs +++ b/src/Android/Autofill/AutofillService.cs @@ -33,7 +33,7 @@ namespace Bit.Android.Autofill var parser = new Parser(structure); parser.Parse(); - if(!parser.FieldCollection.Fields.Any() || string.IsNullOrWhiteSpace(parser.Uri) || + if(!parser.FieldCollection.FillableForLogin || string.IsNullOrWhiteSpace(parser.Uri) || parser.Uri == "androidapp://com.x8bit.bitwarden" || parser.Uri == "androidapp://android") { return; diff --git a/src/Android/Autofill/CipherFilledItem.cs b/src/Android/Autofill/CipherFilledItem.cs index 56f4731c2..73fec5d68 100644 --- a/src/Android/Autofill/CipherFilledItem.cs +++ b/src/Android/Autofill/CipherFilledItem.cs @@ -61,14 +61,7 @@ namespace Bit.Android.Autofill if(Type == CipherType.Login) { - var passwordField = fieldCollection.Fields.FirstOrDefault( - f => f.InputType.HasFlag(InputTypes.TextVariationPassword)); - if(passwordField == null) - { - passwordField = fieldCollection.Fields.FirstOrDefault( - f => f.IdEntry?.ToLower().Contains("password") ?? false); - } - + var passwordField = fieldCollection.PasswordFields.FirstOrDefault(); if(passwordField == null) { return false; diff --git a/src/Android/Autofill/FieldCollection.cs b/src/Android/Autofill/FieldCollection.cs index 46c667c89..637846d84 100644 --- a/src/Android/Autofill/FieldCollection.cs +++ b/src/Android/Autofill/FieldCollection.cs @@ -8,6 +8,8 @@ namespace Bit.Android.Autofill { public class FieldCollection { + private List _passwordFields; + public HashSet Ids { get; private set; } = new HashSet(); public List AutofillIds { get; private set; } = new List(); public SaveDataType SaveType { get; private set; } = SaveDataType.Generic; @@ -19,6 +21,27 @@ namespace Bit.Android.Autofill public IDictionary> HintToFieldsMap { get; private set; } = new Dictionary>(); + public List PasswordFields + { + get + { + if(_passwordFields != null) + { + return _passwordFields; + } + + _passwordFields = Fields.Where(f => f.InputType.HasFlag(InputTypes.TextVariationPassword)).ToList(); + if(!_passwordFields.Any()) + { + _passwordFields = Fields.Where(f => f.IdEntry?.ToLower().Contains("password") ?? false).ToList(); + } + + return _passwordFields; + } + } + + public bool FillableForLogin => PasswordFields.Any(); + public void Add(Field field) { if(Ids.Contains(field.Id)) @@ -59,14 +82,7 @@ namespace Bit.Android.Autofill return null; } - var passwordField = Fields.FirstOrDefault( - f => f.InputType.HasFlag(InputTypes.TextVariationPassword) && !string.IsNullOrWhiteSpace(f.TextValue)); - if(passwordField == null) - { - passwordField = Fields.FirstOrDefault( - f => (f.IdEntry?.ToLower().Contains("password") ?? false) && !string.IsNullOrWhiteSpace(f.TextValue)); - } - + var passwordField = PasswordFields.FirstOrDefault(f => !string.IsNullOrWhiteSpace(f.TextValue)); if(passwordField == null) { return null;