From b7819838b8572942c94795687a1813612d9779c5 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 1 Aug 2019 16:39:01 -0400 Subject: [PATCH] parse fallback package id from first node title --- src/Android/Autofill/Parser.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Android/Autofill/Parser.cs b/src/Android/Autofill/Parser.cs index 3c11d0697..f46758184 100644 --- a/src/Android/Autofill/Parser.cs +++ b/src/Android/Autofill/Parser.cs @@ -97,11 +97,20 @@ namespace Bit.Droid.Autofill public void Parse() { + string titlePackageId = null; for(var i = 0; i < _structure.WindowNodeCount; i++) { var node = _structure.GetWindowNodeAt(i); + if(i == 0) + { + titlePackageId = GetTitlePackageId(node); + } ParseNode(node.RootViewNode); } + if(string.IsNullOrWhiteSpace(PackageName) && string.IsNullOrWhiteSpace(Website)) + { + PackageName = titlePackageId; + } if(!AutofillHelpers.TrustedBrowsers.Contains(PackageName) && !AutofillHelpers.CompatBrowsers.Contains(PackageName)) { @@ -146,5 +155,22 @@ namespace Bit.Droid.Autofill 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; + } } }