summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorMatthew Wong <matt2566@hotmail.com>2016-03-07 20:42:33 -0500
committerMatthew Wong <matt2566@hotmail.com>2016-03-07 20:42:33 -0500
commit1e970e10431bb31d9a5367851b93bba211c46b81 (patch)
tree683c2aa578e62a85c42218ad86d2b40f506bf650 /app/src/main
parentc9725d71868384193e470938850571a9f3cbde66 (diff)
split setwebmatchingpassword and setappmatchingpassword for clarity
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java63
1 files changed, 41 insertions, 22 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java
index 4cd91abd..b18b610f 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java
@@ -198,10 +198,11 @@ public class AutofillService extends AccessibilityService {
isWeb = false;
- setMatchingPasswords(appName, packageName, false);
+ setAppMatchingPasswords(appName, packageName);
} else {
// now we may have found a title but webViewURL could be null
- packageName = setMatchingPasswords(webViewTitle, webViewURL, true);
+ // we set packagename so that we can find the website setting entry
+ packageName = setWebMatchingPasswords(webViewTitle, webViewURL);
appName = packageName;
isWeb = true;
}
@@ -256,32 +257,26 @@ public class AutofillService extends AccessibilityService {
}
}
- // TODO split this into 2 functions for isWeb and !isWeb
- private String setMatchingPasswords(String appName, String packageName, boolean isWeb) {
+ private String setWebMatchingPasswords(String webViewTitle, String webViewURL) {
// Return the URL needed to open the corresponding Settings.
- String settingsURL = packageName;
+ String settingsURL = webViewURL;
// if autofill_default is checked and prefs.getString DNE, 'Automatically match with password'/"first" otherwise "never"
String defValue = settings.getBoolean("autofill_default", true) ? "/first" : "/never";
SharedPreferences prefs;
String preference;
- // for websites unlike apps there can be blank preference of "" which
- // means use default, so ignore it.
- if (!isWeb) {
- prefs = getSharedPreferences("autofill", Context.MODE_PRIVATE);
- preference = prefs.getString(packageName, defValue);
- } else {
- prefs = getSharedPreferences("autofill_web", Context.MODE_PRIVATE);
- preference = defValue;
- if (webViewURL != null) {
- Map<String, ?> prefsMap = prefs.getAll();
- for (String key : prefsMap.keySet()) {
- if ((webViewURL.toLowerCase().contains(key.toLowerCase()) || key.toLowerCase().contains(webViewURL.toLowerCase()))
- && !prefs.getString(key, null).equals("")) {
- preference = prefs.getString(key, null);
- settingsURL = key;
- }
+ prefs = getSharedPreferences("autofill_web", Context.MODE_PRIVATE);
+ preference = defValue;
+ if (webViewURL != null) {
+ Map<String, ?> prefsMap = prefs.getAll();
+ for (String key : prefsMap.keySet()) {
+ // for websites unlike apps there can be blank preference of "" which
+ // means use default, so ignore it.
+ if ((webViewURL.toLowerCase().contains(key.toLowerCase()) || key.toLowerCase().contains(webViewURL.toLowerCase()))
+ && !prefs.getString(key, null).equals("")) {
+ preference = prefs.getString(key, null);
+ settingsURL = key;
}
}
}
@@ -291,7 +286,7 @@ public class AutofillService extends AccessibilityService {
if (!PasswordRepository.isInitialized()) {
PasswordRepository.initialize(this);
}
- items = searchPasswords(PasswordRepository.getRepositoryDirectory(this), appName);
+ items = searchPasswords(PasswordRepository.getRepositoryDirectory(this), webViewTitle);
break;
case "/never":
items = new ArrayList<>();
@@ -303,6 +298,30 @@ public class AutofillService extends AccessibilityService {
return settingsURL;
}
+ private void setAppMatchingPasswords(String appName, String packageName) {
+ // if autofill_default is checked and prefs.getString DNE, 'Automatically match with password'/"first" otherwise "never"
+ String defValue = settings.getBoolean("autofill_default", true) ? "/first" : "/never";
+ SharedPreferences prefs;
+ String preference;
+
+ prefs = getSharedPreferences("autofill", Context.MODE_PRIVATE);
+ preference = prefs.getString(packageName, defValue);
+
+ switch (preference) {
+ case "/first":
+ if (!PasswordRepository.isInitialized()) {
+ PasswordRepository.initialize(this);
+ }
+ items = searchPasswords(PasswordRepository.getRepositoryDirectory(this), appName);
+ break;
+ case "/never":
+ items = new ArrayList<>();
+ break;
+ default:
+ getPreferredPasswords(preference);
+ }
+ }
+
// Put the newline separated list of passwords from the SharedPreferences
// file into the items list.
private void getPreferredPasswords(String preference) {