parse fallback package id from first node title

This commit is contained in:
Kyle Spearrin 2019-08-01 16:39:01 -04:00
parent 67c6cf6b8c
commit b7819838b8

View file

@ -97,11 +97,20 @@ namespace Bit.Droid.Autofill
public void Parse() public void Parse()
{ {
string titlePackageId = null;
for(var i = 0; i < _structure.WindowNodeCount; i++) for(var i = 0; i < _structure.WindowNodeCount; i++)
{ {
var node = _structure.GetWindowNodeAt(i); var node = _structure.GetWindowNodeAt(i);
if(i == 0)
{
titlePackageId = GetTitlePackageId(node);
}
ParseNode(node.RootViewNode); ParseNode(node.RootViewNode);
} }
if(string.IsNullOrWhiteSpace(PackageName) && string.IsNullOrWhiteSpace(Website))
{
PackageName = titlePackageId;
}
if(!AutofillHelpers.TrustedBrowsers.Contains(PackageName) && if(!AutofillHelpers.TrustedBrowsers.Contains(PackageName) &&
!AutofillHelpers.CompatBrowsers.Contains(PackageName)) !AutofillHelpers.CompatBrowsers.Contains(PackageName))
{ {
@ -146,5 +155,22 @@ namespace Bit.Droid.Autofill
Website = string.Format("{0}://{1}", scheme, node.WebDomain); Website = string.Format("{0}://{1}", scheme, node.WebDomain);
} }
} }
private string GetTitlePackageId(WindowNode node)
{
if(node != null && !string.IsNullOrWhiteSpace(node.Title))
{
var slashPosition = node.Title.IndexOf('/');
if(slashPosition > -1)
{
var packageId = node.Title.Substring(0, slashPosition);
if(packageId.Contains("."))
{
return packageId;
}
}
}
return null;
}
} }
} }