Initialize the repository automatically, don't require the app to do it after a restart

This commit is contained in:
Matthew Wong 2015-07-28 12:36:09 -04:00
parent 7182db30b7
commit 4b15ea3ae9
2 changed files with 37 additions and 3 deletions

View file

@ -61,6 +61,7 @@ public class AutofillService extends AccessibilityService {
@Override @Override
public void onAccessibilityEvent(AccessibilityEvent event) { public void onAccessibilityEvent(AccessibilityEvent event) {
// if returning to the source app from a successful AutofillActivity
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
&& event.getPackageName().equals(packageName) && unlockOK) { && event.getPackageName().equals(packageName) && unlockOK) {
decryptAndVerify(); decryptAndVerify();
@ -78,6 +79,7 @@ public class AutofillService extends AccessibilityService {
if (dialog != null && dialog.isShowing()) { if (dialog != null && dialog.isShowing()) {
dialog.dismiss(); dialog.dismiss();
} }
// ignore the ACTION_FOCUS from decryptAndVerify
if (ignoreActionFocus) { if (ignoreActionFocus) {
ignoreActionFocus = false; ignoreActionFocus = false;
return; return;
@ -107,7 +109,6 @@ public class AutofillService extends AccessibilityService {
}); });
dialog = builder.create(); dialog = builder.create();
dialog.setIcon(R.drawable.ic_launcher); dialog.setIcon(R.drawable.ic_launcher);
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
@ -120,7 +121,7 @@ public class AutofillService extends AccessibilityService {
private ArrayList<PasswordItem> recursiveFilter(String filter, File dir) { private ArrayList<PasswordItem> recursiveFilter(String filter, File dir) {
ArrayList<PasswordItem> items = new ArrayList<>(); ArrayList<PasswordItem> items = new ArrayList<>();
if (!PasswordRepository.isInitialized()) { if (!PasswordRepository.isInitialized()) {
return items; initialize();
} }
ArrayList<PasswordItem> passwordItems = dir == null ? ArrayList<PasswordItem> passwordItems = dir == null ?
PasswordRepository.getPasswords() : PasswordRepository.getPasswords() :
@ -136,6 +137,39 @@ public class AutofillService extends AccessibilityService {
return items; 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 @Override
public void onInterrupt() { public void onInterrupt() {

View file

@ -155,5 +155,5 @@
<string name="category_string">"Category: "</string> <string name="category_string">"Category: "</string>
<!-- Autofill --> <!-- Autofill -->
<string name="autofill_description">Auto-fills login fields.</string> <string name="autofill_description">Auto-fills password fields in apps. Only works for Android versions 4.3 and up. Does not rely on the clipboard for Android versions 5.0 and up.</string>
</resources> </resources>