better detection based on IdEntry sniffing

This commit is contained in:
Kyle Spearrin 2017-11-16 16:09:57 -05:00
parent 0e020924ff
commit d84627aa2c
4 changed files with 34 additions and 21 deletions

View file

@ -38,6 +38,12 @@ namespace Bit.Android.Autofill
{
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);
}
if(passwordField == null)
{
return false;

View file

@ -11,17 +11,20 @@ namespace Bit.Android.Autofill
public class Field
{
private List<string> _hints;
private string[] _autofillOptions;
public Field(ViewNode view)
public Field(ViewNode node)
{
_autofillOptions = view.GetAutofillOptions();
Id = view.Id;
AutofillId = view.AutofillId;
AutofillType = view.AutofillType;
InputType = view.InputType;
Focused = view.IsFocused;
Hints = AutofillHelpers.FilterForSupportedHints(view.GetAutofillHints())?.ToList() ?? new List<string>();
Id = node.Id;
IdEntry = node.IdEntry;
AutofillId = node.AutofillId;
AutofillType = node.AutofillType;
InputType = node.InputType;
Focused = node.IsFocused;
Selected = node.IsSelected;
Clickable = node.IsClickable;
Visible = node.Visibility == ViewStates.Visible;
Hints = AutofillHelpers.FilterForSupportedHints(node.GetAutofillHints());
AutofillOptions = node.GetAutofillOptions()?.ToList();
}
public SaveDataType SaveType { get; set; } = SaveDataType.Generic;
@ -35,24 +38,28 @@ namespace Bit.Android.Autofill
}
}
public int Id { get; private set; }
public string IdEntry { get; set; }
public AutofillId AutofillId { get; private set; }
public AutofillType AutofillType { get; private set; }
public InputTypes InputType { get; private set; }
public bool Focused { get; private set; }
public bool Selected { get; private set; }
public bool Clickable { get; private set; }
public bool Visible { get; private set; }
public List<string> AutofillOptions { get; set; }
/**
* When the {@link ViewNode} is a list that the user needs to choose a string from (i.e. a
* spinner), this is called to return the index of a specific item in the list.
*/
public int GetAutofillOptionIndex(string value)
{
for(var i = 0; i < _autofillOptions.Length; i++)
if(AutofillOptions != null)
{
if(_autofillOptions[i].Equals(value))
for(var i = 0; i < AutofillOptions.Count; i++)
{
if(AutofillOptions[i].Equals(value))
{
return i;
}
}
}
return -1;
}

View file

@ -24,9 +24,9 @@ namespace Bit.Android.Autofill
return;
}
SaveType |= field.SaveType;
Ids.Add(field.Id);
Fields.Add(field);
SaveType |= field.SaveType;
AutofillIds.Add(field.AutofillId);
IdToFieldMap.Add(field.Id, field);

View file

@ -9,10 +9,10 @@ namespace Bit.Android.Autofill
public FilledField() { }
public FilledField(ViewNode viewNode)
public FilledField(ViewNode node)
{
_hints = AutofillHelpers.FilterForSupportedHints(viewNode.GetAutofillHints());
var autofillValue = viewNode.AutofillValue;
_hints = AutofillHelpers.FilterForSupportedHints(node.GetAutofillHints());
var autofillValue = node.AutofillValue;
if(autofillValue == null)
{
return;
@ -20,7 +20,7 @@ namespace Bit.Android.Autofill
if(autofillValue.IsList)
{
var autofillOptions = viewNode.GetAutofillOptions();
var autofillOptions = node.GetAutofillOptions();
int index = autofillValue.ListValue;
if(autofillOptions != null && autofillOptions.Length > 0)
{