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( var passwordField = fieldCollection.Fields.FirstOrDefault(
f => f.InputType.HasFlag(InputTypes.TextVariationPassword)); f => f.InputType.HasFlag(InputTypes.TextVariationPassword));
if(passwordField == null)
{
passwordField = fieldCollection.Fields.FirstOrDefault(
f => f.IdEntry?.ToLower().Contains("password") ?? false);
}
if(passwordField == null) if(passwordField == null)
{ {
return false; return false;

View file

@ -11,17 +11,20 @@ namespace Bit.Android.Autofill
public class Field public class Field
{ {
private List<string> _hints; private List<string> _hints;
private string[] _autofillOptions;
public Field(ViewNode view) public Field(ViewNode node)
{ {
_autofillOptions = view.GetAutofillOptions(); Id = node.Id;
Id = view.Id; IdEntry = node.IdEntry;
AutofillId = view.AutofillId; AutofillId = node.AutofillId;
AutofillType = view.AutofillType; AutofillType = node.AutofillType;
InputType = view.InputType; InputType = node.InputType;
Focused = view.IsFocused; Focused = node.IsFocused;
Hints = AutofillHelpers.FilterForSupportedHints(view.GetAutofillHints())?.ToList() ?? new List<string>(); 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; public SaveDataType SaveType { get; set; } = SaveDataType.Generic;
@ -35,22 +38,26 @@ namespace Bit.Android.Autofill
} }
} }
public int Id { get; private set; } public int Id { get; private set; }
public string IdEntry { get; set; }
public AutofillId AutofillId { get; private set; } public AutofillId AutofillId { get; private set; }
public AutofillType AutofillType { get; private set; } public AutofillType AutofillType { get; private set; }
public InputTypes InputType { get; private set; } public InputTypes InputType { get; private set; }
public bool Focused { 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) 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++)
{ {
return i; if(AutofillOptions[i].Equals(value))
{
return i;
}
} }
} }

View file

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

View file

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