diff options
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java | 63 |
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) { |