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(); var emptyPasswordFields = GetNodeOrChildren(root, n => { return IsPasswordField(n); }).ToList();
if (emptyPasswordFields.Any()) 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); Android.Util.Log.Debug ("KP2AAS", "Filling credentials for " + url);
@ -82,10 +82,11 @@ namespace keepass2android.AutoFillPlugin
else else
{ {
Android.Util.Log.Debug ("KP2AAS", "Notif for " + url ); 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", LookupCredentialsActivity.LastReceivedCredentials.Url);
Android.Util.Log.Debug ("KP2AAS", url);
Android.Util.Log.Debug ("KP2AAS", url);} }
AskFillPassword(url, usernameEdit, emptyPasswordFields); AskFillPassword(url, usernameEdit, emptyPasswordFields);
cancelNotification = false; 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) private static bool IsPasswordField(AccessibilityNodeInfo n)
{ {
//if (n.Password) Android.Util.Log.Debug(_logTag, "pwdx with " + (n.Text == null ? "null" : n.Text)); //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); base.OnActivityResult(requestCode, resultCode, data);
var jsonOutput = new Org.Json.JSONObject(data.GetStringExtra(Strings.ExtraEntryOutputData)); try
Dictionary<string, string> output = new Dictionary<string, string>(); {
for (var iter = jsonOutput.Keys(); iter.HasNext;)
{ var jsonOutput = new Org.Json.JSONObject(data.GetStringExtra(Strings.ExtraEntryOutputData));
string key = iter.Next().ToString(); Dictionary<string, string> output = new Dictionary<string, string>();
string value = jsonOutput.Get(key).ToString(); for (var iter = jsonOutput.Keys(); iter.HasNext;)
output[key] = value; {
} string key = iter.Next().ToString();
string value = jsonOutput.Get(key).ToString();
output[key] = value;
}
string user = "", password = ""; string user = "", password = "";
output.TryGetValue(KeePassLib.PwDefs.UserNameField, out user); output.TryGetValue(KeePassLib.PwDefs.UserNameField, out user);
output.TryGetValue(KeePassLib.PwDefs.PasswordField, out password); output.TryGetValue(KeePassLib.PwDefs.PasswordField, out password);
Android.Util.Log.Debug ("KP2AAS", "Received credentials for " + _lastQueriedUrl); Android.Util.Log.Debug ("KP2AAS", "Received credentials for " + _lastQueriedUrl);
LastReceivedCredentials = new Credentials() { User = user, Password = password, Url = _lastQueriedUrl }; LastReceivedCredentials = new Credentials() { User = user, Password = password, Url = _lastQueriedUrl };
}
Finish(); catch(Exception e) {
Android.Util.Log.Debug ("KP2AAS", "Exception while receiving credentials: " + e.ToString());
}
finally {
Finish ();
}
} }
public static Credentials LastReceivedCredentials; public static Credentials LastReceivedCredentials;