only show autofills if a fillable login form

This commit is contained in:
Kyle Spearrin 2017-11-17 17:46:55 -05:00
parent abf75cffd9
commit da199deed1
3 changed files with 26 additions and 17 deletions

View file

@ -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;

View file

@ -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;

View file

@ -8,6 +8,8 @@ namespace Bit.Android.Autofill
{
public class FieldCollection
{
private List<Field> _passwordFields;
public HashSet<int> Ids { get; private set; } = new HashSet<int>();
public List<AutofillId> AutofillIds { get; private set; } = new List<AutofillId>();
public SaveDataType SaveType { get; private set; } = SaveDataType.Generic;
@ -19,6 +21,27 @@ namespace Bit.Android.Autofill
public IDictionary<string, List<Field>> HintToFieldsMap { get; private set; } =
new Dictionary<string, List<Field>>();
public List<Field> 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;