diff --git a/src/AutoFillPlugin/Kp2aAccessibilityService.cs b/src/AutoFillPlugin/Kp2aAccessibilityService.cs index dbc84fc2..0a109df3 100644 --- a/src/AutoFillPlugin/Kp2aAccessibilityService.cs +++ b/src/AutoFillPlugin/Kp2aAccessibilityService.cs @@ -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)); diff --git a/src/AutoFillPlugin/LookupCredentialsActivity.cs b/src/AutoFillPlugin/LookupCredentialsActivity.cs index e67eb849..62494366 100644 --- a/src/AutoFillPlugin/LookupCredentialsActivity.cs +++ b/src/AutoFillPlugin/LookupCredentialsActivity.cs @@ -32,23 +32,32 @@ namespace keepass2android.AutoFillPlugin { base.OnActivityResult(requestCode, resultCode, data); - var jsonOutput = new Org.Json.JSONObject(data.GetStringExtra(Strings.ExtraEntryOutputData)); - Dictionary output = new Dictionary(); - 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 output = new Dictionary(); + 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 }; - - Finish(); + 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 (); + } } public static Credentials LastReceivedCredentials;