add more autofill compat support

This commit is contained in:
Kyle Spearrin 2018-09-06 00:17:26 -04:00
parent 43dad1df63
commit 10ecdfbe31
3 changed files with 67 additions and 14 deletions

View file

@ -17,6 +17,24 @@ namespace Bit.Android.Autofill
{ {
private static int _pendingIntentId = 0; private static int _pendingIntentId = 0;
// These browser work natively with the autofill framework
public static HashSet<string> TrustedBrowsers = new HashSet<string>
{
"org.mozilla.focus","org.mozilla.klar","com.duckduckgo.mobile.android"
};
// These browsers work using the compatibility shim for the autofill framework
public static HashSet<string> CompatBrowsers = new HashSet<string>
{
"org.mozilla.firefox","org.mozilla.firefox_beta","com.microsoft.emmx","com.android.chrome",
"com.chrome.beta","com.android.browser","com.brave.browser","com.opera.browser",
"com.opera.browser.beta","com.opera.mini.native","com.chrome.dev","com.chrome.canary",
"com.google.android.apps.chrome","com.google.android.apps.chrome_dev","com.yandex.browser",
"com.sec.android.app.sbrowser","com.sec.android.app.sbrowser.beta","org.codeaurora.swe.browser",
"com.amazon.cloud9","mark.via.gp","org.bromite.bromite","org.chromium.chrome","com.kiwibrowser.browser",
"com.ecosia.android", "com.opera.mini.native.beta","org.mozilla.fennec_aurora"
};
public static async Task<List<FilledItem>> GetFillItemsAsync(Parser parser, ICipherService service) public static async Task<List<FilledItem>> GetFillItemsAsync(Parser parser, ICipherService service)
{ {
var items = new List<FilledItem>(); var items = new List<FilledItem>();
@ -62,7 +80,7 @@ namespace Bit.Android.Autofill
} }
responseBuilder.AddDataset(BuildVaultDataset(context, parser.FieldCollection, parser.Uri, locked)); responseBuilder.AddDataset(BuildVaultDataset(context, parser.FieldCollection, parser.Uri, locked));
AddSaveInfo(responseBuilder, parser.FieldCollection); AddSaveInfo(parser, responseBuilder, parser.FieldCollection);
responseBuilder.SetIgnoredIds(parser.FieldCollection.IgnoreAutofillIds.ToArray()); responseBuilder.SetIgnoredIds(parser.FieldCollection.IgnoreAutofillIds.ToArray());
return responseBuilder.Build(); return responseBuilder.Build();
} }
@ -126,8 +144,16 @@ namespace Bit.Android.Autofill
return view; return view;
} }
public static void AddSaveInfo(FillResponse.Builder responseBuilder, FieldCollection fields) public static void AddSaveInfo(Parser parser, FillResponse.Builder responseBuilder, FieldCollection fields)
{ {
// Docs state that password fields cannot be reliably saved in Compat mode since they will show as
// masked values.
var compatBrowser = CompatBrowsers.Contains(parser.PackageName);
if(compatBrowser && fields.SaveType == SaveDataType.Password)
{
return;
}
var requiredIds = fields.GetRequiredSaveFields(); var requiredIds = fields.GetRequiredSaveFields();
if(fields.SaveType == SaveDataType.Generic || requiredIds.Length == 0) if(fields.SaveType == SaveDataType.Generic || requiredIds.Length == 0)
{ {
@ -140,6 +166,10 @@ namespace Bit.Android.Autofill
{ {
saveBuilder.SetOptionalIds(optionalIds); saveBuilder.SetOptionalIds(optionalIds);
} }
if(compatBrowser)
{
saveBuilder.SetFlags(SaveFlags.SaveOnAllViewsInvisible);
}
responseBuilder.SetSaveInfo(saveBuilder.Build()); responseBuilder.SetSaveInfo(saveBuilder.Build());
} }
} }

View file

@ -7,17 +7,6 @@ namespace Bit.Android.Autofill
{ {
public class Parser public class Parser
{ {
public static HashSet<string> TrustedBrowsers = new HashSet<string>
{
"org.mozilla.focus","org.mozilla.firefox","org.mozilla.firefox_beta","com.microsoft.emmx",
"com.android.chrome","com.chrome.beta","com.android.browser","com.brave.browser","com.opera.browser",
"com.opera.browser.beta","com.opera.mini.native","com.chrome.dev","com.chrome.canary",
"com.google.android.apps.chrome","com.google.android.apps.chrome_dev","com.yandex.browser",
"com.sec.android.app.sbrowser","com.sec.android.app.sbrowser.beta","org.codeaurora.swe.browser",
"com.amazon.cloud9","org.mozilla.klar","com.duckduckgo.mobile.android","mark.via.gp","org.bromite.bromite",
"org.chromium.chrome", "com.kiwibrowser.browser", "com.ecosia.android", "com.opera.mini.native.beta",
"org.mozilla.fennec_aurora"
};
public static HashSet<string> ExcludedPackageIds = new HashSet<string> public static HashSet<string> ExcludedPackageIds = new HashSet<string>
{ {
@ -95,7 +84,8 @@ namespace Bit.Android.Autofill
ParseNode(node.RootViewNode); ParseNode(node.RootViewNode);
} }
if(!TrustedBrowsers.Contains(PackageName)) if(!AutofillHelpers.TrustedBrowsers.Contains(PackageName) &&
!AutofillHelpers.CompatBrowsers.Contains(PackageName))
{ {
WebDomain = null; WebDomain = null;
} }

View file

@ -42,4 +42,37 @@
<compatibility-package <compatibility-package
android:name="org.mozilla.firefox_beta" android:name="org.mozilla.firefox_beta"
android:maxLongVersionCode="10000000000"/> android:maxLongVersionCode="10000000000"/>
<compatibility-package
android:name="com.brave.browser"
android:maxLongVersionCode="10000000000"/>
<compatibility-package
android:name="com.google.android.apps.chrome"
android:maxLongVersionCode="10000000000"/>
<compatibility-package
android:name="com.google.android.apps.chrome_dev"
android:maxLongVersionCode="10000000000"/>
<compatibility-package
android:name="com.yandex.browser"
android:maxLongVersionCode="10000000000"/>
<compatibility-package
android:name="org.codeaurora.swe.browser"
android:maxLongVersionCode="10000000000"/>
<compatibility-package
android:name="com.amazon.cloud9"
android:maxLongVersionCode="10000000000"/>
<compatibility-package
android:name="mark.via.gp"
android:maxLongVersionCode="10000000000"/>
<compatibility-package
android:name="org.bromite.bromite"
android:maxLongVersionCode="10000000000"/>
<compatibility-package
android:name="org.chromium.chrome"
android:maxLongVersionCode="10000000000"/>
<compatibility-package
android:name="com.kiwibrowser.browser"
android:maxLongVersionCode="10000000000"/>
<compatibility-package
android:name="com.ecosia.android"
android:maxLongVersionCode="10000000000"/>
</autofill-service> </autofill-service>