From 29b92f4a6d1dacac3e0a1154972e2659b3a536be Mon Sep 17 00:00:00 2001 From: Matthew Wong Date: Wed, 12 Aug 2015 21:17:15 -0400 Subject: Make service compatible with latest PasswordRepository changes --- .../zeapo/pwdstore/autofill/AutofillService.java | 42 +++------------------- 1 file changed, 4 insertions(+), 38 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 2a80a449..bb3b17f2 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java @@ -22,7 +22,6 @@ import android.view.accessibility.AccessibilityWindowInfo; import android.widget.Toast; import com.zeapo.pwdstore.R; -import com.zeapo.pwdstore.UserPreference; import com.zeapo.pwdstore.utils.PasswordItem; import com.zeapo.pwdstore.utils.PasswordRepository; @@ -139,7 +138,7 @@ public class AutofillService extends AccessibilityService { String path = PasswordRepository.getWorkTree() + "/" + preference + ".gpg"; File file = new File(path); items = new ArrayList<>(); - items.add(PasswordItem.newPassword(file.getName(), file)); + items.add(PasswordItem.newPassword(file.getName(), file, PasswordRepository.getRepositoryDirectory(this))); } if (items.isEmpty()) { return; @@ -178,11 +177,11 @@ public class AutofillService extends AccessibilityService { private ArrayList recursiveFilter(String filter, File dir) { ArrayList items = new ArrayList<>(); if (!PasswordRepository.isInitialized()) { - initialize(); + PasswordRepository.initialize(this); } ArrayList passwordItems = dir == null ? - PasswordRepository.getPasswords() : - PasswordRepository.getPasswords(dir); + 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())); @@ -194,39 +193,6 @@ public class AutofillService extends AccessibilityService { return items; } - // just like PasswordRepository.initialize(). - private void initialize() { - File dir = null; - SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - - if (settings.getBoolean("git_external", false)) { - if (settings.getString("git_external_repo", null) != null) { - dir = new File(settings.getString("git_external_repo", null)); - } - } else { - dir = new File(getFilesDir() + "/store"); - } - // temp for debug - if (dir == null) { - Intent intent = new Intent(this, UserPreference.class); - intent.putExtra("operation", "git_external"); - startActivity(intent); - return; - } - - // uninitialize the repo if the dir does not exist or is absolutely empty - if (!dir.exists() || !dir.isDirectory() || FileUtils.listFiles(dir, null, false).isEmpty()) { - settings.edit().putBoolean("repository_initialized", false).apply(); - } - - if (!PasswordRepository.getPasswords(dir).isEmpty()) { - settings.edit().putBoolean("repository_initialized", true).apply(); - } - - // create the repository static variable in PasswordRepository - PasswordRepository.getRepository(new File(dir.getAbsolutePath() + "/.git")); - } - @Override public void onInterrupt() { -- cgit v1.2.3