Make chrome/webview send password field focus events

This commit is contained in:
Matthew Wong 2015-11-04 21:46:43 -05:00 committed by Matthew Wong
parent 4a6901b309
commit f2a4b944d8

View file

@ -136,7 +136,7 @@ public class AutofillService extends AccessibilityService {
} }
final String appName = (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "").toString(); final String appName = (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "").toString();
setMatchingPasswords(appName, info.getPackageName().toString()); getMatchingPassword(appName, info.getPackageName().toString());
if (items.isEmpty()) { if (items.isEmpty()) {
return; return;
} }
@ -144,22 +144,26 @@ public class AutofillService extends AccessibilityService {
showDialog(appName); showDialog(appName);
} }
private boolean searchWebView(AccessibilityNodeInfo source) { private void searchWebView(AccessibilityNodeInfo source) {
for (int i = 0; i < source.getChildCount(); i++) { ArrayDeque<AccessibilityNodeInfo> q = new ArrayDeque<>();
AccessibilityNodeInfo u = source.getChild(i); q.add(source);
if (u == null) { while (!q.isEmpty()) {
continue; AccessibilityNodeInfo u = q.remove();
}
// this is not likely to always work
if (u.getContentDescription() != null && u.getContentDescription().equals("Web View")) { if (u.getContentDescription() != null && u.getContentDescription().equals("Web View")) {
return true; if (!u.equals(source)) {
u.recycle();
}
return;
} }
if (searchWebView(u)) { for (int i = 0; i < u.getChildCount(); i++) {
return true; if (u.getChild(i) != null) {
q.add(u.getChild(i));
}
}
if (!u.equals(source)) {
u.recycle();
} }
u.recycle();
} }
return false;
} }
// dismiss the dialog if the window has changed // dismiss the dialog if the window has changed
@ -180,7 +184,7 @@ public class AutofillService extends AccessibilityService {
} }
} }
private void setMatchingPasswords(String appName, String packageName) { private void getMatchingPassword(String appName, String packageName) {
// 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 = getSharedPreferences("autofill", Context.MODE_PRIVATE); SharedPreferences prefs = getSharedPreferences("autofill", Context.MODE_PRIVATE);
@ -190,10 +194,7 @@ public class AutofillService extends AccessibilityService {
if (!PasswordRepository.isInitialized()) { if (!PasswordRepository.isInitialized()) {
PasswordRepository.initialize(this); PasswordRepository.initialize(this);
} }
items = new ArrayList<>(); items = recursiveFilter(appName, null);
for (File file : searchPasswords(PasswordRepository.getRepositoryDirectory(this), appName)) {
items.add(PasswordItem.newPassword(file.getName(), file, PasswordRepository.getRepositoryDirectory(this)));
}
break; break;
case "/never": case "/never":
items.clear(); items.clear();
@ -209,24 +210,17 @@ public class AutofillService extends AccessibilityService {
} }
} }
private ArrayList<File> searchPasswords(File path, String appName) { private ArrayList<PasswordItem> recursiveFilter(String filter, File dir) {
ArrayList<File> passList ArrayList<PasswordItem> items = new ArrayList<>();
= PasswordRepository.getFilesList(path); ArrayList<PasswordItem> passwordItems = dir == null ?
PasswordRepository.getPasswords(PasswordRepository.getRepositoryDirectory(this)) :
if (passList.size() == 0) return new ArrayList<>(); PasswordRepository.getPasswords(dir, PasswordRepository.getRepositoryDirectory(this));
for (PasswordItem item : passwordItems) {
ArrayList<File> items = new ArrayList<>(); if (item.getType() == PasswordItem.TYPE_CATEGORY) {
items.addAll(recursiveFilter(filter, item.getFile()));
for (File file : passList) { }
if (file.isFile()) { if (item.toString().toLowerCase().contains(filter.toLowerCase())) {
if (file.toString().toLowerCase().contains(appName.toLowerCase())) { items.add(item);
items.add(file);
}
} else {
// ignore .git directory
if (file.getName().equals(".git"))
continue;
items.addAll(searchPasswords(file, appName));
} }
} }
return items; return items;