2017-11-15 00:46:40 +03:00
|
|
|
|
using static Android.App.Assist.AssistStructure;
|
|
|
|
|
using Android.App.Assist;
|
2017-11-18 01:15:42 +03:00
|
|
|
|
using Bit.App;
|
2017-11-15 00:46:40 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.Android.Autofill
|
|
|
|
|
{
|
2017-11-15 07:13:55 +03:00
|
|
|
|
public class Parser
|
2017-11-15 00:46:40 +03:00
|
|
|
|
{
|
|
|
|
|
private readonly AssistStructure _structure;
|
2017-11-15 07:13:55 +03:00
|
|
|
|
private string _uri;
|
2017-11-15 00:46:40 +03:00
|
|
|
|
|
2017-11-15 07:13:55 +03:00
|
|
|
|
public Parser(AssistStructure structure)
|
2017-11-15 00:46:40 +03:00
|
|
|
|
{
|
|
|
|
|
_structure = structure;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-15 07:13:55 +03:00
|
|
|
|
public FieldCollection FieldCollection { get; private set; } = new FieldCollection();
|
|
|
|
|
public string Uri
|
|
|
|
|
{
|
|
|
|
|
get => _uri;
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-11-17 18:09:27 +03:00
|
|
|
|
if(string.IsNullOrWhiteSpace(value))
|
|
|
|
|
{
|
|
|
|
|
_uri = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-18 01:15:42 +03:00
|
|
|
|
_uri = string.Concat(Constants.AndroidAppProtocol, value);
|
2017-11-15 07:13:55 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-15 00:46:40 +03:00
|
|
|
|
|
2017-11-18 01:15:42 +03:00
|
|
|
|
public void Parse()
|
2017-11-15 00:46:40 +03:00
|
|
|
|
{
|
|
|
|
|
for(var i = 0; i < _structure.WindowNodeCount; i++)
|
|
|
|
|
{
|
|
|
|
|
var node = _structure.GetWindowNodeAt(i);
|
2017-11-18 01:15:42 +03:00
|
|
|
|
ParseNode(node.RootViewNode);
|
2017-11-15 00:46:40 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-18 01:15:42 +03:00
|
|
|
|
private void ParseNode(ViewNode node)
|
2017-11-15 00:46:40 +03:00
|
|
|
|
{
|
2017-11-17 05:58:04 +03:00
|
|
|
|
var hints = node.GetAutofillHints();
|
|
|
|
|
var isEditText = node.ClassName == "android.widget.EditText";
|
|
|
|
|
if(isEditText || (hints?.Length ?? 0) > 0)
|
2017-11-15 00:46:40 +03:00
|
|
|
|
{
|
2017-11-17 22:38:56 +03:00
|
|
|
|
if(Uri == null)
|
|
|
|
|
{
|
|
|
|
|
Uri = node.IdPackage;
|
|
|
|
|
}
|
2017-11-18 01:15:42 +03:00
|
|
|
|
FieldCollection.Add(new Field(node));
|
2017-11-15 00:46:40 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-17 05:58:04 +03:00
|
|
|
|
for(var i = 0; i < node.ChildCount; i++)
|
2017-11-15 00:46:40 +03:00
|
|
|
|
{
|
2017-11-18 01:15:42 +03:00
|
|
|
|
ParseNode(node.GetChildAt(i));
|
2017-11-15 00:46:40 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|