aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/autofill
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/autofill')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java4
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.java190
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java123
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java103
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java130
5 files changed, 245 insertions, 305 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java
index 0d39e01d..12d1de74 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java
@@ -6,11 +6,9 @@ import android.content.Intent;
import android.content.IntentSender;
import android.content.SharedPreferences;
import android.os.Bundle;
-import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
-
+import androidx.appcompat.app.AppCompatActivity;
import com.zeapo.pwdstore.PasswordStore;
-
import org.eclipse.jgit.util.StringUtils;
import java.util.ArrayList;
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.java
index 3a3b632d..d7095dae 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.java
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.java
@@ -5,18 +5,13 @@ import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Bundle;
-import androidx.annotation.NonNull;
-import androidx.core.content.ContextCompat;
-import androidx.appcompat.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
@@ -24,7 +19,9 @@ import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
-
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AlertDialog;
+import androidx.core.content.ContextCompat;
import com.zeapo.pwdstore.PasswordStore;
import com.zeapo.pwdstore.R;
@@ -84,12 +81,7 @@ public class AutofillFragment extends DialogFragment {
((ListView) view.findViewById(R.id.matched)).setAdapter(adapter);
// delete items by clicking them
((ListView) view.findViewById(R.id.matched)).setOnItemClickListener(
- new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- adapter.remove(adapter.getItem(position));
- }
- });
+ (parent, view1, position, id) -> adapter.remove(adapter.getItem(position)));
// set the existing preference, if any
SharedPreferences prefs;
@@ -116,36 +108,27 @@ public class AutofillFragment extends DialogFragment {
}
// add items with the + button
- View.OnClickListener matchPassword = new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- ((RadioButton) view.findViewById(R.id.match)).toggle();
- Intent intent = new Intent(getActivity(), PasswordStore.class);
- intent.putExtra("matchWith", true);
- startActivityForResult(intent, MATCH_WITH);
- }
+ View.OnClickListener matchPassword = v -> {
+ ((RadioButton) view.findViewById(R.id.match)).toggle();
+ Intent intent = new Intent(getActivity(), PasswordStore.class);
+ intent.putExtra("matchWith", true);
+ startActivityForResult(intent, MATCH_WITH);
};
view.findViewById(R.id.matchButton).setOnClickListener(matchPassword);
// write to preferences when OK clicked
- builder.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
+ builder.setPositiveButton(R.string.dialog_ok, (dialog, which) -> {
- }
});
builder.setNegativeButton(R.string.dialog_cancel, null);
final SharedPreferences.Editor editor = prefs.edit();
if (isWeb) {
- builder.setNeutralButton(R.string.autofill_apps_delete, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (callingActivity.recyclerAdapter != null
- && packageName != null && !packageName.equals("")) {
- editor.remove(packageName);
- callingActivity.recyclerAdapter.removeWebsite(packageName);
- editor.apply();
- }
+ builder.setNeutralButton(R.string.autofill_apps_delete, (dialog, which) -> {
+ if (callingActivity.recyclerAdapter != null
+ && packageName != null && !packageName.equals("")) {
+ editor.remove(packageName);
+ callingActivity.recyclerAdapter.removeWebsite(packageName);
+ editor.apply();
}
});
}
@@ -157,91 +140,88 @@ public class AutofillFragment extends DialogFragment {
public void onStart() {
super.onStart();
AlertDialog ad = (AlertDialog) getDialog();
- if(ad != null) {
+ if (ad != null) {
Button positiveButton = ad.getButton(Dialog.BUTTON_POSITIVE);
- positiveButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- AutofillPreferenceActivity callingActivity = (AutofillPreferenceActivity) getActivity();
- Dialog dialog = getDialog();
-
- SharedPreferences prefs;
- if (!isWeb) {
- prefs = getActivity().getApplicationContext().getSharedPreferences("autofill", Context.MODE_PRIVATE);
- } else {
- prefs = getActivity().getApplicationContext().getSharedPreferences("autofill_web", Context.MODE_PRIVATE);
- }
- SharedPreferences.Editor editor = prefs.edit();
+ positiveButton.setOnClickListener(v -> {
+ AutofillPreferenceActivity callingActivity = (AutofillPreferenceActivity) getActivity();
+ Dialog dialog = getDialog();
+
+ SharedPreferences prefs;
+ if (!isWeb) {
+ prefs = getActivity().getApplicationContext().getSharedPreferences("autofill", Context.MODE_PRIVATE);
+ } else {
+ prefs = getActivity().getApplicationContext().getSharedPreferences("autofill_web", Context.MODE_PRIVATE);
+ }
+ SharedPreferences.Editor editor = prefs.edit();
- String packageName = getArguments().getString("packageName", "");
- if (isWeb) {
- // handle some errors and don't dismiss the dialog
- EditText webURL = (EditText) dialog.findViewById(R.id.webURL);
+ String packageName = getArguments().getString("packageName", "");
+ if (isWeb) {
+ // handle some errors and don't dismiss the dialog
+ EditText webURL = dialog.findViewById(R.id.webURL);
- packageName = webURL.getText().toString();
+ packageName = webURL.getText().toString();
- if (packageName.equals("")) {
- webURL.setError("URL cannot be blank");
- return;
- }
- String oldPackageName = getArguments().getString("packageName", "");
- if (!oldPackageName.equals(packageName) && prefs.getAll().containsKey(packageName)) {
- webURL.setError("URL already exists");
- return;
- }
+ if (packageName.equals("")) {
+ webURL.setError("URL cannot be blank");
+ return;
}
-
- // write to preferences accordingly
- RadioGroup radioGroup = (RadioGroup) dialog.findViewById(R.id.autofill_radiogroup);
- switch (radioGroup.getCheckedRadioButtonId()) {
- case R.id.use_default:
- if (!isWeb) {
- editor.remove(packageName);
- } else {
- editor.putString(packageName, "");
- }
- break;
- case R.id.first:
- editor.putString(packageName, "/first");
- break;
- case R.id.never:
- editor.putString(packageName, "/never");
- break;
- default:
- StringBuilder paths = new StringBuilder();
- for (int i = 0; i < adapter.getCount(); i++) {
- paths.append(adapter.getItem(i));
- if (i != adapter.getCount()) {
- paths.append("\n");
- }
- }
- editor.putString(packageName, paths.toString());
+ String oldPackageName = getArguments().getString("packageName", "");
+ if (!oldPackageName.equals(packageName) && prefs.getAll().containsKey(packageName)) {
+ webURL.setError("URL already exists");
+ return;
}
- editor.apply();
+ }
- // notify the recycler adapter if it is loaded
- if (callingActivity.recyclerAdapter != null) {
- int position;
+ // write to preferences accordingly
+ RadioGroup radioGroup = dialog.findViewById(R.id.autofill_radiogroup);
+ switch (radioGroup.getCheckedRadioButtonId()) {
+ case R.id.use_default:
if (!isWeb) {
- String appName = getArguments().getString("appName", "");
- position = callingActivity.recyclerAdapter.getPosition(appName);
- callingActivity.recyclerAdapter.notifyItemChanged(position);
+ editor.remove(packageName);
} else {
- position = callingActivity.recyclerAdapter.getPosition(packageName);
- String oldPackageName = getArguments().getString("packageName", "");
- if (oldPackageName.equals(packageName)) {
- callingActivity.recyclerAdapter.notifyItemChanged(position);
- } else if (oldPackageName.equals("")){
- callingActivity.recyclerAdapter.addWebsite(packageName);
- } else {
- editor.remove(oldPackageName);
- callingActivity.recyclerAdapter.updateWebsite(oldPackageName, packageName);
+ editor.putString(packageName, "");
+ }
+ break;
+ case R.id.first:
+ editor.putString(packageName, "/first");
+ break;
+ case R.id.never:
+ editor.putString(packageName, "/never");
+ break;
+ default:
+ StringBuilder paths = new StringBuilder();
+ for (int i = 0; i < adapter.getCount(); i++) {
+ paths.append(adapter.getItem(i));
+ if (i != adapter.getCount()) {
+ paths.append("\n");
}
}
- }
+ editor.putString(packageName, paths.toString());
+ }
+ editor.apply();
- dismiss();
+ // notify the recycler adapter if it is loaded
+ if (callingActivity.recyclerAdapter != null) {
+ int position;
+ if (!isWeb) {
+ String appName = getArguments().getString("appName", "");
+ position = callingActivity.recyclerAdapter.getPosition(appName);
+ callingActivity.recyclerAdapter.notifyItemChanged(position);
+ } else {
+ position = callingActivity.recyclerAdapter.getPosition(packageName);
+ String oldPackageName = getArguments().getString("packageName", "");
+ if (oldPackageName.equals(packageName)) {
+ callingActivity.recyclerAdapter.notifyItemChanged(position);
+ } else if (oldPackageName.equals("")) {
+ callingActivity.recyclerAdapter.addWebsite(packageName);
+ } else {
+ editor.remove(oldPackageName);
+ callingActivity.recyclerAdapter.updateWebsite(oldPackageName, packageName);
+ }
+ }
}
+
+ dismiss();
});
}
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java
index b85a31c7..9fba959a 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java
@@ -8,19 +8,18 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.AsyncTask;
import android.os.Bundle;
-import com.google.android.material.floatingactionbutton.FloatingActionButton;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.appcompat.widget.SearchView;
import androidx.core.app.NavUtils;
import androidx.core.app.TaskStackBuilder;
import androidx.core.view.MenuItemCompat;
-import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
-import androidx.appcompat.widget.SearchView;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-
+import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.zeapo.pwdstore.R;
import java.util.ArrayList;
@@ -29,9 +28,8 @@ import java.util.Map;
public class AutofillPreferenceActivity extends AppCompatActivity {
- private RecyclerView recyclerView;
AutofillRecyclerAdapter recyclerAdapter; // let fragment have access
-
+ private RecyclerView recyclerView;
private PackageManager pm;
private boolean recreate; // flag for action on up press; origin autofill dialog? different act
@@ -41,7 +39,7 @@ public class AutofillPreferenceActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.autofill_recycler_view);
- recyclerView = (RecyclerView) findViewById(R.id.autofill_recycler);
+ recyclerView = findViewById(R.id.autofill_recycler);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
@@ -62,64 +60,8 @@ public class AutofillPreferenceActivity extends AppCompatActivity {
setTitle("Autofill Apps");
- final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
- fab.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- showDialog("", "", true);
- }
- });
- }
-
- private class populateTask extends AsyncTask<Void, Void, Void> {
- @Override
- protected void onPreExecute() {
- runOnUiThread(new Runnable() {
- public void run() {
- findViewById(R.id.progress_bar).setVisibility(View.VISIBLE);
- }
- });
- }
-
- @Override
- protected Void doInBackground(Void... params) {
- Intent intent = new Intent(Intent.ACTION_MAIN);
- intent.addCategory(Intent.CATEGORY_LAUNCHER);
- List<ResolveInfo> allAppsResolveInfo = pm.queryIntentActivities(intent, 0);
- List<AutofillRecyclerAdapter.AppInfo> allApps = new ArrayList<>();
-
- for (ResolveInfo app : allAppsResolveInfo) {
- allApps.add(new AutofillRecyclerAdapter.AppInfo(app.activityInfo.packageName
- , app.loadLabel(pm).toString(), false, app.loadIcon(pm)));
- }
-
- SharedPreferences prefs = getSharedPreferences("autofill_web", Context.MODE_PRIVATE);
- Map<String, ?> prefsMap = prefs.getAll();
- for (String key : prefsMap.keySet()) {
- try {
- allApps.add(new AutofillRecyclerAdapter.AppInfo(key, key, true, pm.getApplicationIcon("com.android.browser")));
- } catch (PackageManager.NameNotFoundException e) {
- allApps.add(new AutofillRecyclerAdapter.AppInfo(key, key, true, null));
- }
- }
-
- recyclerAdapter = new AutofillRecyclerAdapter(allApps, pm, AutofillPreferenceActivity.this);
- return null;
- }
-
- @Override
- protected void onPostExecute(Void aVoid) {
- runOnUiThread(new Runnable() {
- public void run() {
- findViewById(R.id.progress_bar).setVisibility(View.GONE);
- recyclerView.setAdapter(recyclerAdapter);
- Bundle extras = getIntent().getExtras();
- if (extras != null) {
- recyclerView.scrollToPosition(recyclerAdapter.getPosition(extras.getString("appName")));
- }
- }
- });
- }
+ final FloatingActionButton fab = findViewById(R.id.fab);
+ fab.setOnClickListener(v -> showDialog("", "", true));
}
@Override
@@ -175,4 +117,49 @@ public class AutofillPreferenceActivity extends AppCompatActivity {
df.setArguments(args);
df.show(getFragmentManager(), "autofill_dialog");
}
+
+ private class populateTask extends AsyncTask<Void, Void, Void> {
+ @Override
+ protected void onPreExecute() {
+ runOnUiThread(() -> findViewById(R.id.progress_bar).setVisibility(View.VISIBLE));
+ }
+
+ @Override
+ protected Void doInBackground(Void... params) {
+ Intent intent = new Intent(Intent.ACTION_MAIN);
+ intent.addCategory(Intent.CATEGORY_LAUNCHER);
+ List<ResolveInfo> allAppsResolveInfo = pm.queryIntentActivities(intent, 0);
+ List<AutofillRecyclerAdapter.AppInfo> allApps = new ArrayList<>();
+
+ for (ResolveInfo app : allAppsResolveInfo) {
+ allApps.add(new AutofillRecyclerAdapter.AppInfo(app.activityInfo.packageName
+ , app.loadLabel(pm).toString(), false, app.loadIcon(pm)));
+ }
+
+ SharedPreferences prefs = getSharedPreferences("autofill_web", Context.MODE_PRIVATE);
+ Map<String, ?> prefsMap = prefs.getAll();
+ for (String key : prefsMap.keySet()) {
+ try {
+ allApps.add(new AutofillRecyclerAdapter.AppInfo(key, key, true, pm.getApplicationIcon("com.android.browser")));
+ } catch (PackageManager.NameNotFoundException e) {
+ allApps.add(new AutofillRecyclerAdapter.AppInfo(key, key, true, null));
+ }
+ }
+
+ recyclerAdapter = new AutofillRecyclerAdapter(allApps, pm, AutofillPreferenceActivity.this);
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ runOnUiThread(() -> {
+ findViewById(R.id.progress_bar).setVisibility(View.GONE);
+ recyclerView.setAdapter(recyclerAdapter);
+ Bundle extras = getIntent().getExtras();
+ if (extras != null) {
+ recyclerView.scrollToPosition(recyclerAdapter.getPosition(extras.getString("appName")));
+ }
+ });
+ }
+ }
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java
index 0c1ec224..bed2aa7e 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java
@@ -4,15 +4,14 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
-import androidx.recyclerview.widget.SortedList;
-import androidx.recyclerview.widget.RecyclerView;
-import androidx.recyclerview.widget.SortedListAdapterCallback;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
-
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.recyclerview.widget.SortedList;
+import androidx.recyclerview.widget.SortedListAdapterCallback;
import com.zeapo.pwdstore.R;
import java.util.ArrayList;
@@ -25,50 +24,6 @@ class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecyclerAdapt
private AutofillPreferenceActivity activity;
private Drawable browserIcon = null;
- class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
- public View view;
- public TextView name;
- TextView secondary;
- public ImageView icon;
- String packageName;
- String appName;
- Boolean isWeb;
-
- ViewHolder(View view) {
- super(view);
- this.view = view;
- name = (TextView) view.findViewById(R.id.app_name);
- secondary = (TextView) view.findViewById(R.id.secondary_text);
- icon = (ImageView) view.findViewById(R.id.app_icon);
- view.setOnClickListener(this);
- }
-
- @Override
- public void onClick(View v) {
- activity.showDialog(packageName, appName, isWeb);
- }
-
- }
-
- static class AppInfo {
- String packageName;
- String appName;
- boolean isWeb;
- public Drawable icon;
-
- AppInfo(String packageName, String appName, boolean isWeb, Drawable icon) {
- this.packageName = packageName;
- this.appName = appName;
- this.isWeb = isWeb;
- this.icon = icon;
- }
-
- @Override
- public boolean equals(Object o) {
- return o != null && o instanceof AppInfo && this.appName.equals(((AppInfo) o).appName);
- }
- }
-
AutofillRecyclerAdapter(List<AppInfo> allApps, final PackageManager pm
, AutofillPreferenceActivity activity) {
SortedList.Callback<AppInfo> callback = new SortedListAdapterCallback<AppInfo>(this) {
@@ -76,17 +31,17 @@ class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecyclerAdapt
// for the limited add/remove usage for websites
@Override
public int compare(AppInfo o1, AppInfo o2) {
- return o1.appName.toLowerCase().compareTo(o2.appName.toLowerCase());
+ return o1.appName.toLowerCase().compareTo(o2.appName.toLowerCase());
}
@Override
public boolean areContentsTheSame(AppInfo oldItem, AppInfo newItem) {
- return oldItem.appName.equals(newItem.appName);
+ return oldItem.appName.equals(newItem.appName);
}
@Override
public boolean areItemsTheSame(AppInfo item1, AppInfo item2) {
- return item1.appName.equals(item2.appName);
+ return item1.appName.equals(item2.appName);
}
};
this.apps = new SortedList<>(AppInfo.class, callback);
@@ -170,7 +125,7 @@ class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecyclerAdapt
}
void updateWebsite(String oldPackageName, String packageName) {
- apps.updateItemAt(getPosition(oldPackageName), new AppInfo (packageName, packageName, true, browserIcon));
+ apps.updateItemAt(getPosition(oldPackageName), new AppInfo(packageName, packageName, true, browserIcon));
allApps.remove(new AppInfo(null, oldPackageName, false, null)); // compare with equals
allApps.add(new AppInfo(null, packageName, false, null));
}
@@ -190,4 +145,48 @@ class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecyclerAdapt
}
apps.endBatchedUpdates();
}
+
+ static class AppInfo {
+ public Drawable icon;
+ String packageName;
+ String appName;
+ boolean isWeb;
+
+ AppInfo(String packageName, String appName, boolean isWeb, Drawable icon) {
+ this.packageName = packageName;
+ this.appName = appName;
+ this.isWeb = isWeb;
+ this.icon = icon;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof AppInfo && this.appName.equals(((AppInfo) o).appName);
+ }
+ }
+
+ class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
+ public View view;
+ public TextView name;
+ public ImageView icon;
+ TextView secondary;
+ String packageName;
+ String appName;
+ Boolean isWeb;
+
+ ViewHolder(View view) {
+ super(view);
+ this.view = view;
+ name = view.findViewById(R.id.app_name);
+ secondary = view.findViewById(R.id.secondary_text);
+ icon = view.findViewById(R.id.app_icon);
+ view.setOnClickListener(this);
+ }
+
+ @Override
+ public void onClick(View v) {
+ activity.showDialog(packageName, appName, isWeb);
+ }
+
+ }
}
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 7a4d59fa..8ad27b4f 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java
@@ -1,12 +1,10 @@
package com.zeapo.pwdstore.autofill;
import android.accessibilityservice.AccessibilityService;
-import android.annotation.TargetApi;
import android.app.PendingIntent;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
@@ -16,18 +14,16 @@ import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.Settings;
-import androidx.appcompat.app.AlertDialog;
import android.util.Log;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityWindowInfo;
import android.widget.Toast;
-
+import androidx.appcompat.app.AlertDialog;
import com.zeapo.pwdstore.PasswordEntry;
import com.zeapo.pwdstore.R;
import com.zeapo.pwdstore.utils.PasswordRepository;
-
import org.apache.commons.io.FileUtils;
import org.openintents.openpgp.IOpenPgpService2;
import org.openintents.openpgp.OpenPgpError;
@@ -62,10 +58,6 @@ public class AutofillService extends AccessibilityService {
private PasswordEntry lastPassword;
private long lastPasswordMaxDate;
- final class Constants {
- static final String TAG = "Keychain";
- }
-
public static AutofillService getInstance() {
return instance;
}
@@ -96,11 +88,6 @@ public class AutofillService extends AccessibilityService {
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
- // TODO there should be a better way of disabling service
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
- return;
- }
-
// remove stored password from cache
if (lastPassword != null && System.currentTimeMillis() > lastPasswordMaxDate) {
lastPassword = null;
@@ -405,20 +392,14 @@ public class AutofillService extends AccessibilityService {
}
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.Theme_AppCompat_Dialog);
- builder.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface d, int which) {
- dialog.dismiss();
- dialog = null;
- }
+ builder.setNegativeButton(R.string.dialog_cancel, (d, which) -> {
+ dialog.dismiss();
+ dialog = null;
});
- builder.setPositiveButton(R.string.autofill_paste, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface d, int which) {
- pasteText(node, password.getUsername());
- dialog.dismiss();
- dialog = null;
- }
+ builder.setPositiveButton(R.string.autofill_paste, (d, which) -> {
+ pasteText(node, password.getUsername());
+ dialog.dismiss();
+ dialog = null;
});
builder.setMessage(getString(R.string.autofill_paste_username, password.getUsername()));
@@ -436,24 +417,19 @@ public class AutofillService extends AccessibilityService {
}
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.Theme_AppCompat_Dialog);
- builder.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface d, int which) {
- dialog.dismiss();
- dialog = null;
- }
+ builder.setNegativeButton(R.string.dialog_cancel, (d, which) -> {
+ dialog.dismiss();
+ dialog = null;
});
- builder.setNeutralButton("Settings", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) { //TODO make icon? gear?
- // the user will have to return to the app themselves.
- Intent intent = new Intent(AutofillService.this, AutofillPreferenceActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
- intent.putExtra("packageName", packageName);
- intent.putExtra("appName", appName);
- intent.putExtra("isWeb", isWeb);
- startActivity(intent);
- }
+ builder.setNeutralButton("Settings", (dialog, which) -> {
+ //TODO make icon? gear?
+ // the user will have to return to the app themselves.
+ Intent intent = new Intent(AutofillService.this, AutofillPreferenceActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ intent.putExtra("packageName", packageName);
+ intent.putExtra("appName", appName);
+ intent.putExtra("isWeb", isWeb);
+ startActivity(intent);
});
// populate the dialog items, always with pick + pick and match. Could
@@ -464,26 +440,23 @@ public class AutofillService extends AccessibilityService {
}
itemNames[items.size()] = getString(R.string.autofill_pick);
itemNames[items.size() + 1] = getString(R.string.autofill_pick_and_match);
- builder.setItems(itemNames, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- lastWhichItem = which;
- if (which < items.size()) {
- bindDecryptAndVerify();
- } else if (which == items.size()) {
- Intent intent = new Intent(AutofillService.this, AutofillActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
- intent.putExtra("pick", true);
- startActivity(intent);
- } else {
- lastWhichItem--; // will add one element to items, so lastWhichItem=items.size()+1
- Intent intent = new Intent(AutofillService.this, AutofillActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
- intent.putExtra("pickMatchWith", true);
- intent.putExtra("packageName", packageName);
- intent.putExtra("isWeb", isWeb);
- startActivity(intent);
- }
+ builder.setItems(itemNames, (dialog, which) -> {
+ lastWhichItem = which;
+ if (which < items.size()) {
+ bindDecryptAndVerify();
+ } else if (which == items.size()) {
+ Intent intent = new Intent(AutofillService.this, AutofillActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ intent.putExtra("pick", true);
+ startActivity(intent);
+ } else {
+ lastWhichItem--; // will add one element to items, so lastWhichItem=items.size()+1
+ Intent intent = new Intent(AutofillService.this, AutofillActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ intent.putExtra("pickMatchWith", true);
+ intent.putExtra("packageName", packageName);
+ intent.putExtra("isWeb", isWeb);
+ startActivity(intent);
}
});
@@ -515,18 +488,6 @@ public class AutofillService extends AccessibilityService {
}
- private class onBoundListener implements OpenPgpServiceConnection.OnBound {
- @Override
- public void onBound(IOpenPgpService2 service) {
- decryptAndVerify();
- }
-
- @Override
- public void onError(Exception e) {
- e.printStackTrace();
- }
- }
-
private void bindDecryptAndVerify() {
if (serviceConnection.getService() == null) {
// the service was disconnected, need to bind again
@@ -600,7 +561,6 @@ public class AutofillService extends AccessibilityService {
}
}
- @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private void pasteText(final AccessibilityNodeInfo node, final String text) {
// if the user focused on something else, take focus back
// but this will open another dialog...hack to ignore this
@@ -627,4 +587,20 @@ public class AutofillService extends AccessibilityService {
}
node.recycle();
}
+
+ final class Constants {
+ static final String TAG = "Keychain";
+ }
+
+ private class onBoundListener implements OpenPgpServiceConnection.OnBound {
+ @Override
+ public void onBound(IOpenPgpService2 service) {
+ decryptAndVerify();
+ }
+
+ @Override
+ public void onError(Exception e) {
+ e.printStackTrace();
+ }
+ }
}