From f2a4b944d8250a06430a91f4e2268c6c8956646a Mon Sep 17 00:00:00 2001 From: Matthew Wong Date: Wed, 4 Nov 2015 21:46:43 -0500 Subject: Make chrome/webview send password field focus events --- .../zeapo/pwdstore/autofill/AutofillService.java | 66 ++++++++++------------ 1 file changed, 30 insertions(+), 36 deletions(-) (limited to 'app/src/main/java') 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 894fb62b..beed28ec 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java @@ -136,7 +136,7 @@ public class AutofillService extends AccessibilityService { } final String appName = (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "").toString(); - setMatchingPasswords(appName, info.getPackageName().toString()); + getMatchingPassword(appName, info.getPackageName().toString()); if (items.isEmpty()) { return; } @@ -144,22 +144,26 @@ public class AutofillService extends AccessibilityService { showDialog(appName); } - private boolean searchWebView(AccessibilityNodeInfo source) { - for (int i = 0; i < source.getChildCount(); i++) { - AccessibilityNodeInfo u = source.getChild(i); - if (u == null) { - continue; - } - // this is not likely to always work + private void searchWebView(AccessibilityNodeInfo source) { + ArrayDeque q = new ArrayDeque<>(); + q.add(source); + while (!q.isEmpty()) { + AccessibilityNodeInfo u = q.remove(); if (u.getContentDescription() != null && u.getContentDescription().equals("Web View")) { - return true; + if (!u.equals(source)) { + u.recycle(); + } + return; } - if (searchWebView(u)) { - return true; + for (int i = 0; i < u.getChildCount(); i++) { + 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 @@ -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" String defValue = settings.getBoolean("autofill_default", true) ? "/first" : "/never"; SharedPreferences prefs = getSharedPreferences("autofill", Context.MODE_PRIVATE); @@ -190,10 +194,7 @@ public class AutofillService extends AccessibilityService { if (!PasswordRepository.isInitialized()) { PasswordRepository.initialize(this); } - items = new ArrayList<>(); - for (File file : searchPasswords(PasswordRepository.getRepositoryDirectory(this), appName)) { - items.add(PasswordItem.newPassword(file.getName(), file, PasswordRepository.getRepositoryDirectory(this))); - } + items = recursiveFilter(appName, null); break; case "/never": items.clear(); @@ -209,24 +210,17 @@ public class AutofillService extends AccessibilityService { } } - private ArrayList searchPasswords(File path, String appName) { - ArrayList passList - = PasswordRepository.getFilesList(path); - - if (passList.size() == 0) return new ArrayList<>(); - - ArrayList items = new ArrayList<>(); - - for (File file : passList) { - if (file.isFile()) { - if (file.toString().toLowerCase().contains(appName.toLowerCase())) { - items.add(file); - } - } else { - // ignore .git directory - if (file.getName().equals(".git")) - continue; - items.addAll(searchPasswords(file, appName)); + private ArrayList recursiveFilter(String filter, File dir) { + ArrayList items = new ArrayList<>(); + ArrayList passwordItems = dir == null ? + PasswordRepository.getPasswords(PasswordRepository.getRepositoryDirectory(this)) : + PasswordRepository.getPasswords(dir, PasswordRepository.getRepositoryDirectory(this)); + for (PasswordItem item : passwordItems) { + if (item.getType() == PasswordItem.TYPE_CATEGORY) { + items.addAll(recursiveFilter(filter, item.getFile())); + } + if (item.toString().toLowerCase().contains(filter.toLowerCase())) { + items.add(item); } } return items; -- cgit v1.2.3