From d84627aa2c7dbf201f70e20c095e57c01eb9c434 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 16 Nov 2017 16:09:57 -0500 Subject: [PATCH] better detection based on IdEntry sniffing --- src/Android/Autofill/CipherFilledItem.cs | 6 ++++ src/Android/Autofill/Field.cs | 39 ++++++++++++++---------- src/Android/Autofill/FieldCollection.cs | 2 +- src/Android/Autofill/FilledField.cs | 8 ++--- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/Android/Autofill/CipherFilledItem.cs b/src/Android/Autofill/CipherFilledItem.cs index 2af844f38..f3e60abe0 100644 --- a/src/Android/Autofill/CipherFilledItem.cs +++ b/src/Android/Autofill/CipherFilledItem.cs @@ -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; diff --git a/src/Android/Autofill/Field.cs b/src/Android/Autofill/Field.cs index f8b8dd8e4..198aa61c6 100644 --- a/src/Android/Autofill/Field.cs +++ b/src/Android/Autofill/Field.cs @@ -11,17 +11,20 @@ namespace Bit.Android.Autofill public class Field { private List _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(); + 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,22 +38,26 @@ 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 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++) { - return i; + if(AutofillOptions[i].Equals(value)) + { + return i; + } } } diff --git a/src/Android/Autofill/FieldCollection.cs b/src/Android/Autofill/FieldCollection.cs index dd611143c..632b294f0 100644 --- a/src/Android/Autofill/FieldCollection.cs +++ b/src/Android/Autofill/FieldCollection.cs @@ -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); diff --git a/src/Android/Autofill/FilledField.cs b/src/Android/Autofill/FilledField.cs index 3eae8e729..7b7a5076f 100644 --- a/src/Android/Autofill/FilledField.cs +++ b/src/Android/Autofill/FilledField.cs @@ -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) {