mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-08-31 22:35:17 +00:00
split setwebmatchingpassword and setappmatchingpassword for clarity
This commit is contained in:
@@ -198,10 +198,11 @@ public class AutofillService extends AccessibilityService {
|
|||||||
|
|
||||||
isWeb = false;
|
isWeb = false;
|
||||||
|
|
||||||
setMatchingPasswords(appName, packageName, false);
|
setAppMatchingPasswords(appName, packageName);
|
||||||
} else {
|
} else {
|
||||||
// now we may have found a title but webViewURL could be null
|
// 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;
|
appName = packageName;
|
||||||
isWeb = true;
|
isWeb = true;
|
||||||
}
|
}
|
||||||
@@ -256,36 +257,56 @@ public class AutofillService extends AccessibilityService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO split this into 2 functions for isWeb and !isWeb
|
private String setWebMatchingPasswords(String webViewTitle, String webViewURL) {
|
||||||
private String setMatchingPasswords(String appName, String packageName, boolean isWeb) {
|
|
||||||
// Return the URL needed to open the corresponding Settings.
|
// 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"
|
// 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";
|
String defValue = settings.getBoolean("autofill_default", true) ? "/first" : "/never";
|
||||||
SharedPreferences prefs;
|
SharedPreferences prefs;
|
||||||
String preference;
|
String preference;
|
||||||
|
|
||||||
// for websites unlike apps there can be blank preference of "" which
|
prefs = getSharedPreferences("autofill_web", Context.MODE_PRIVATE);
|
||||||
// means use default, so ignore it.
|
preference = defValue;
|
||||||
if (!isWeb) {
|
if (webViewURL != null) {
|
||||||
prefs = getSharedPreferences("autofill", Context.MODE_PRIVATE);
|
Map<String, ?> prefsMap = prefs.getAll();
|
||||||
preference = prefs.getString(packageName, defValue);
|
for (String key : prefsMap.keySet()) {
|
||||||
} else {
|
// for websites unlike apps there can be blank preference of "" which
|
||||||
prefs = getSharedPreferences("autofill_web", Context.MODE_PRIVATE);
|
// means use default, so ignore it.
|
||||||
preference = defValue;
|
if ((webViewURL.toLowerCase().contains(key.toLowerCase()) || key.toLowerCase().contains(webViewURL.toLowerCase()))
|
||||||
if (webViewURL != null) {
|
&& !prefs.getString(key, null).equals("")) {
|
||||||
Map<String, ?> prefsMap = prefs.getAll();
|
preference = prefs.getString(key, null);
|
||||||
for (String key : prefsMap.keySet()) {
|
settingsURL = key;
|
||||||
if ((webViewURL.toLowerCase().contains(key.toLowerCase()) || key.toLowerCase().contains(webViewURL.toLowerCase()))
|
|
||||||
&& !prefs.getString(key, null).equals("")) {
|
|
||||||
preference = prefs.getString(key, null);
|
|
||||||
settingsURL = key;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (preference) {
|
||||||
|
case "/first":
|
||||||
|
if (!PasswordRepository.isInitialized()) {
|
||||||
|
PasswordRepository.initialize(this);
|
||||||
|
}
|
||||||
|
items = searchPasswords(PasswordRepository.getRepositoryDirectory(this), webViewTitle);
|
||||||
|
break;
|
||||||
|
case "/never":
|
||||||
|
items = new ArrayList<>();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
getPreferredPasswords(preference);
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
switch (preference) {
|
||||||
case "/first":
|
case "/first":
|
||||||
if (!PasswordRepository.isInitialized()) {
|
if (!PasswordRepository.isInitialized()) {
|
||||||
@@ -299,8 +320,6 @@ public class AutofillService extends AccessibilityService {
|
|||||||
default:
|
default:
|
||||||
getPreferredPasswords(preference);
|
getPreferredPasswords(preference);
|
||||||
}
|
}
|
||||||
|
|
||||||
return settingsURL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put the newline separated list of passwords from the SharedPreferences
|
// Put the newline separated list of passwords from the SharedPreferences
|
||||||
|
Reference in New Issue
Block a user