change heuristic to decide what is a username field: treat every field before a password field as username field. Even though this seems to make less sense, it works better with several apps; decode field references for AutoFill; display item in preferences for Autofill (#9)
This commit is contained in:
@@ -96,6 +96,8 @@
|
||||
<string name="QuickUnlock_prefs_key">QuickUnlock_prefs_key</string>
|
||||
<string name="FileHandling_prefs_key">FileHandling_prefs_key</string>
|
||||
<string name="keyboardswitch_prefs_key">keyboardswitch_prefs_key</string>
|
||||
<string name="AutoFill_prefs_key">AutoFill_prefs_key</string>
|
||||
|
||||
|
||||
<string name="OfflineMode_key">OfflineMode_key</string>
|
||||
|
||||
|
||||
@@ -371,6 +371,7 @@
|
||||
<string name="ShowSeparateNotifications_summary">Show separate notifications for copying username and password to clipboard and activating the keyboard.</string>
|
||||
|
||||
<string name="AccServiceAutoFill_prefs">AutoFill Accessibility-Service</string>
|
||||
<string name="AutoFill_prefs">AutoFill Service</string>
|
||||
|
||||
<string name="ShowKp2aKeyboardNotification_title">KP2A keyboard notification</string>
|
||||
<string name="ShowKp2aKeyboardNotification_summary">Make full entry accessible through the KP2A keyboard (recommended).</string>
|
||||
@@ -576,6 +577,9 @@
|
||||
<string name="plugin_disabled">disabled</string>
|
||||
<string name="plugin_web">Find plug-ins online</string>
|
||||
<string name="plugin_scopes">Scopes</string>
|
||||
|
||||
|
||||
<string name="not_enabled">not enabled</string>
|
||||
|
||||
<string name="query_credentials_for_url">%1$s is requesting credentials for %2$s.</string>
|
||||
<string name="query_credentials">%1$s is requesting credentials. Please select an entry.</string>
|
||||
|
||||
@@ -380,6 +380,12 @@
|
||||
android:data="https://philippc.github.io/keepass2android/AccServiceAutoFill.html" />
|
||||
</Preference>
|
||||
|
||||
<Preference
|
||||
android:key="@string/AutoFill_prefs_key"
|
||||
android:title="@string/AutoFill_prefs">
|
||||
|
||||
</Preference>
|
||||
|
||||
</PreferenceScreen>
|
||||
<PreferenceScreen
|
||||
android:key="@string/QuickUnlock_prefs_key"
|
||||
|
||||
@@ -112,22 +112,23 @@ namespace keepass2android.services.AutofillBase
|
||||
|
||||
if (forFill)
|
||||
{
|
||||
foreach (var pf in passwordFields)
|
||||
AutofillFields.Add(new AutofillFieldMetadata(pf, new[] { View.AutofillHintPassword }));
|
||||
foreach (var uf in usernameFields)
|
||||
AutofillFields.Add(new AutofillFieldMetadata(uf, new[] { View.AutofillHintUsername }));
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var pf in passwordFields)
|
||||
ClientFormData.Add(new FilledAutofillField(pf, new[] { View.AutofillHintPassword }));
|
||||
AutofillFields.Add(new AutofillFieldMetadata(pf, new[] { View.AutofillHintPassword }));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var uf in usernameFields)
|
||||
ClientFormData.Add(new FilledAutofillField(uf, new[] { View.AutofillHintUsername }));
|
||||
foreach (var pf in passwordFields)
|
||||
ClientFormData.Add(new FilledAutofillField(pf, new[] { View.AutofillHintPassword }));
|
||||
}
|
||||
|
||||
|
||||
|
||||
String packageName = Structure.ActivityComponent.PackageName;
|
||||
|
||||
String packageName = Structure.ActivityComponent.PackageName;
|
||||
if (!string.IsNullOrEmpty(webDomain))
|
||||
{
|
||||
bool valid = Kp2aDigitalAssetLinksDataSource.Instance.IsValid(mContext, webDomain, packageName);
|
||||
|
||||
@@ -40,8 +40,6 @@ namespace keepass2android.services.AutofillBase.model
|
||||
}
|
||||
}
|
||||
|
||||
public bool Protected { get; set; }
|
||||
|
||||
|
||||
public FilledAutofillField()
|
||||
{}
|
||||
|
||||
@@ -53,14 +53,13 @@ namespace keepass2android.services.Kp2aAutofill
|
||||
FilledAutofillFieldCollection fieldCollection = new FilledAutofillFieldCollection();
|
||||
var pwEntry = pwEntryOutput.Entry;
|
||||
|
||||
foreach (string key in pwEntry.Strings.GetKeys())
|
||||
foreach (string key in pwEntryOutput.OutputStrings.GetKeys())
|
||||
{
|
||||
FilledAutofillField field =
|
||||
new FilledAutofillField
|
||||
{
|
||||
AutofillHints = new[] {GetCanonicalHintFromKp2aField(pwEntry, key)},
|
||||
TextValue = pwEntry.Strings.ReadSafe(key),
|
||||
Protected = pwEntry.Strings.Get(key).IsProtected
|
||||
AutofillHints = new[] {GetCanonicalHintFromKp2aField(key)},
|
||||
TextValue = pwEntryOutput.OutputStrings.ReadSafe(key)
|
||||
};
|
||||
fieldCollection.Add(field);
|
||||
}
|
||||
@@ -71,8 +70,7 @@ namespace keepass2android.services.Kp2aAutofill
|
||||
new FilledAutofillField
|
||||
{
|
||||
AutofillHints = new[] {View.AutofillHintCreditCardExpirationDate},
|
||||
DateValue = (long) (1000 * TimeUtil.SerializeUnix(expTime)),
|
||||
Protected = false
|
||||
DateValue = (long) (1000 * TimeUtil.SerializeUnix(expTime))
|
||||
};
|
||||
fieldCollection.Add(field);
|
||||
|
||||
@@ -80,8 +78,7 @@ namespace keepass2android.services.Kp2aAutofill
|
||||
new FilledAutofillField
|
||||
{
|
||||
AutofillHints = new[] {View.AutofillHintCreditCardExpirationDay},
|
||||
TextValue = expTime.Day.ToString(),
|
||||
Protected = false
|
||||
TextValue = expTime.Day.ToString()
|
||||
};
|
||||
fieldCollection.Add(field);
|
||||
|
||||
@@ -89,8 +86,7 @@ namespace keepass2android.services.Kp2aAutofill
|
||||
new FilledAutofillField
|
||||
{
|
||||
AutofillHints = new[] {View.AutofillHintCreditCardExpirationMonth},
|
||||
TextValue = expTime.Month.ToString(),
|
||||
Protected = false
|
||||
TextValue = expTime.Month.ToString()
|
||||
};
|
||||
fieldCollection.Add(field);
|
||||
|
||||
@@ -98,8 +94,7 @@ namespace keepass2android.services.Kp2aAutofill
|
||||
new FilledAutofillField
|
||||
{
|
||||
AutofillHints = new[] {View.AutofillHintCreditCardExpirationYear},
|
||||
TextValue = expTime.Year.ToString(),
|
||||
Protected = false
|
||||
TextValue = expTime.Year.ToString()
|
||||
};
|
||||
fieldCollection.Add(field);
|
||||
}
|
||||
@@ -148,7 +143,7 @@ namespace keepass2android.services.Kp2aAutofill
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string GetCanonicalHintFromKp2aField(PwEntry pwEntry, string key)
|
||||
private static string GetCanonicalHintFromKp2aField(string key)
|
||||
{
|
||||
if (!keyToHint.TryGetValue(key, out string result))
|
||||
result = key;
|
||||
|
||||
@@ -30,9 +30,11 @@ using Android.Graphics.Drawables;
|
||||
using Android.OS;
|
||||
using Android.Widget;
|
||||
using Android.Preferences;
|
||||
using Android.Provider;
|
||||
using Android.Runtime;
|
||||
using Android.Util;
|
||||
using Android.Views;
|
||||
using Android.Views.Autofill;
|
||||
using Java.IO;
|
||||
using KeePassLib.Cryptography.Cipher;
|
||||
using KeePassLib.Keys;
|
||||
@@ -347,6 +349,13 @@ namespace keepass2android
|
||||
App.Kp2a.UpdateOngoingNotification();
|
||||
}
|
||||
|
||||
public override void OnResume()
|
||||
{
|
||||
base.OnResume();
|
||||
|
||||
UpdateAutofillPref();
|
||||
}
|
||||
|
||||
|
||||
public override void OnCreate(Bundle savedInstanceState)
|
||||
{
|
||||
@@ -359,6 +368,10 @@ namespace keepass2android
|
||||
FindPreference(GetString(Resource.String.ShowUnlockedNotification_key)).PreferenceChange += OnShowUnlockedNotificationChanged;
|
||||
FindPreference(GetString(Resource.String.DebugLog_key)).PreferenceChange += OnDebugLogChanged;
|
||||
FindPreference(GetString(Resource.String.DebugLog_send_key)).PreferenceClick += OnSendDebug;
|
||||
|
||||
UpdateAutofillPref();
|
||||
|
||||
|
||||
PrepareNoDonatePreference(Activity, FindPreference(GetString(Resource.String.NoDonateOption_key)));
|
||||
PrepareNoDonationReminderPreference(Activity, ((PreferenceScreen)FindPreference(GetString(Resource.String.display_prefs_key))), FindPreference(GetString(Resource.String.NoDonationReminder_key)));
|
||||
|
||||
@@ -450,7 +463,32 @@ namespace keepass2android
|
||||
|
||||
}
|
||||
|
||||
private void OnSendDebug(object sender, Preference.PreferenceClickEventArgs e)
|
||||
private void UpdateAutofillPref()
|
||||
{
|
||||
var autofillPref = FindPreference(GetString(Resource.String.AutoFill_prefs_key));
|
||||
if ((Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.O) ||
|
||||
!((AutofillManager) Activity.GetSystemService(Java.Lang.Class.FromType(typeof(AutofillManager))))
|
||||
.IsAutofillSupported)
|
||||
{
|
||||
var passwordAccessScreen =
|
||||
(PreferenceScreen) FindPreference(Activity.GetString(Resource.String.password_access_prefs_key));
|
||||
passwordAccessScreen.RemovePreference(autofillPref);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (((AutofillManager) Activity.GetSystemService(Java.Lang.Class.FromType(typeof(AutofillManager))))
|
||||
.HasEnabledAutofillServices)
|
||||
autofillPref.Summary = Activity.GetString(Resource.String.plugin_enabled);
|
||||
else
|
||||
{
|
||||
autofillPref.Summary = Activity.GetString(Resource.String.not_enabled);
|
||||
}
|
||||
autofillPref.Intent = new Intent(Settings.ActionRequestSetAutofillService);
|
||||
autofillPref.Intent.SetData(Android.Net.Uri.Parse("package:" + Activity.PackageName));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSendDebug(object sender, Preference.PreferenceClickEventArgs e)
|
||||
{
|
||||
Kp2aLog.SendLog(this.Activity);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user