catch cancelled lookup

allow URL to change after lookup (as long as host remains)
add debugging
This commit is contained in:
Philipp Crocoll 2015-10-09 22:52:06 +02:00
parent 95fe89f020
commit 641aa5a8b4
2 changed files with 36 additions and 19 deletions

View File

@ -73,7 +73,7 @@ namespace keepass2android.AutoFillPlugin
var emptyPasswordFields = GetNodeOrChildren(root, n => { return IsPasswordField(n); }).ToList();
if (emptyPasswordFields.Any())
{
if ((LookupCredentialsActivity.LastReceivedCredentials != null) && (LookupCredentialsActivity.LastReceivedCredentials.Url == url))
if ((LookupCredentialsActivity.LastReceivedCredentials != null) && IsSame(LookupCredentialsActivity.LastReceivedCredentials.Url, url))
{
Android.Util.Log.Debug ("KP2AAS", "Filling credentials for " + url);
@ -82,10 +82,11 @@ namespace keepass2android.AutoFillPlugin
else
{
Android.Util.Log.Debug ("KP2AAS", "Notif for " + url );
if (LookupCredentialsActivity.LastReceivedCredentials != null) {
if (LookupCredentialsActivity.LastReceivedCredentials != null)
{
Android.Util.Log.Debug ("KP2AAS", LookupCredentialsActivity.LastReceivedCredentials.Url);
Android.Util.Log.Debug ("KP2AAS", url);}
Android.Util.Log.Debug ("KP2AAS", url);
}
AskFillPassword(url, usernameEdit, emptyPasswordFields);
cancelNotification = false;
@ -114,6 +115,13 @@ namespace keepass2android.AutoFillPlugin
}
private bool IsSame(string url1, string url2)
{
if (url1.StartsWith ("androidapp://"))
return url1 == url2;
return KeePassLib.Utility.UrlUtil.GetHost (url1) == KeePassLib.Utility.UrlUtil.GetHost (url2);
}
private static bool IsPasswordField(AccessibilityNodeInfo n)
{
//if (n.Password) Android.Util.Log.Debug(_logTag, "pwdx with " + (n.Text == null ? "null" : n.Text));

View File

@ -32,23 +32,32 @@ namespace keepass2android.AutoFillPlugin
{
base.OnActivityResult(requestCode, resultCode, data);
var jsonOutput = new Org.Json.JSONObject(data.GetStringExtra(Strings.ExtraEntryOutputData));
Dictionary<string, string> output = new Dictionary<string, string>();
for (var iter = jsonOutput.Keys(); iter.HasNext;)
{
string key = iter.Next().ToString();
string value = jsonOutput.Get(key).ToString();
output[key] = value;
}
try
{
var jsonOutput = new Org.Json.JSONObject(data.GetStringExtra(Strings.ExtraEntryOutputData));
Dictionary<string, string> output = new Dictionary<string, string>();
for (var iter = jsonOutput.Keys(); iter.HasNext;)
{
string key = iter.Next().ToString();
string value = jsonOutput.Get(key).ToString();
output[key] = value;
}
string user = "", password = "";
output.TryGetValue(KeePassLib.PwDefs.UserNameField, out user);
output.TryGetValue(KeePassLib.PwDefs.PasswordField, out password);
Android.Util.Log.Debug ("KP2AAS", "Received credentials for " + _lastQueriedUrl);
LastReceivedCredentials = new Credentials() { User = user, Password = password, Url = _lastQueriedUrl };
string user = "", password = "";
output.TryGetValue(KeePassLib.PwDefs.UserNameField, out user);
output.TryGetValue(KeePassLib.PwDefs.PasswordField, out password);
Android.Util.Log.Debug ("KP2AAS", "Received credentials for " + _lastQueriedUrl);
LastReceivedCredentials = new Credentials() { User = user, Password = password, Url = _lastQueriedUrl };
}
catch(Exception e) {
Android.Util.Log.Debug ("KP2AAS", "Exception while receiving credentials: " + e.ToString());
}
finally {
Finish();
Finish ();
}
}
public static Credentials LastReceivedCredentials;