mirror of
https://github.com/android-password-store/Android-Password-Store.git
synced 2026-04-19 18:20:47 +02:00
Add 'automatically match by default' setting; respect it & per-app settings when creating autofill dialog
This commit is contained in:
parent
d42c526b64
commit
b75190fcd7
|
|
@ -3,6 +3,7 @@ package com.zeapo.pwdstore.autofill;
|
|||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
|
|
@ -39,9 +40,14 @@ public class AutofillFragment extends DialogFragment {
|
|||
String appName = getArguments().getString("appName");
|
||||
|
||||
builder.setTitle(appName);
|
||||
|
||||
// when an app is added for the first time, the radio button selection should reflect
|
||||
// the autofill_default setting: hence, defValue
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(callingActivity);
|
||||
String defValue = settings.getBoolean("autofill_default", true) ? "first" : "never";
|
||||
SharedPreferences prefs
|
||||
= getActivity().getApplicationContext().getSharedPreferences("autofill", Context.MODE_PRIVATE);
|
||||
String preference = prefs.getString(packageName, "first");
|
||||
String preference = prefs.getString(packageName, defValue);
|
||||
switch (preference) {
|
||||
case "first":
|
||||
((RadioButton) view.findViewById(R.id.first)).toggle();
|
||||
|
|
@ -57,7 +63,6 @@ public class AutofillFragment extends DialogFragment {
|
|||
View.OnClickListener matchPassword = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// TODO figure out UI for this
|
||||
Intent intent = new Intent(getActivity(), PasswordStore.class);
|
||||
intent.putExtra("matchWith", true);
|
||||
startActivityForResult(intent, MATCH_WITH);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import android.content.pm.PackageManager;
|
|||
import android.database.Cursor;
|
||||
import android.database.MatrixCursor;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
|
@ -100,6 +101,7 @@ public class AutofillPreferenceActivity extends AppCompatActivity {
|
|||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
// should be a better/faster way to do this?
|
||||
// TODO do this async probably. it lags.
|
||||
MatrixCursor matrixCursor = new MatrixCursor(new String[]{"_id", "package", "label"});
|
||||
for (ApplicationInfo applicationInfo : allApps) {
|
||||
if (applicationInfo.loadLabel(pm).toString().toLowerCase().contains(newText.toLowerCase())) {
|
||||
|
|
@ -147,5 +149,7 @@ public class AutofillPreferenceActivity extends AppCompatActivity {
|
|||
args.putInt("position", recyclerAdapter.getPosition(packageName));
|
||||
df.setArguments(args);
|
||||
df.show(getFragmentManager(), "autofill_dialog");
|
||||
|
||||
// TODO if called from dialog 'Settings' button, should activity finish at OK?
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
|
@ -59,9 +60,13 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecycl
|
|||
public void onBindViewHolder(AutofillRecyclerAdapter.ViewHolder holder, int position) {
|
||||
ApplicationInfo app = apps.get(position);
|
||||
holder.name.setText(pm.getApplicationLabel(app));
|
||||
|
||||
// it shouldn't be possible for prefs.getString to not find the app...use defValue anyway
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
String defValue = settings.getBoolean("autofill_default", true) ? "first" : "never";
|
||||
SharedPreferences prefs
|
||||
= activity.getApplicationContext().getSharedPreferences("autofill", Context.MODE_PRIVATE);
|
||||
String preference = prefs.getString(app.packageName, "first");
|
||||
String preference = prefs.getString(app.packageName, defValue);
|
||||
switch (preference) {
|
||||
case "first":
|
||||
holder.secondary.setText("Automatically match with password");
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ public class AutofillService extends AccessibilityService {
|
|||
dialog.dismiss();
|
||||
}
|
||||
|
||||
// ignore the ACTION_FOCUS from decryptAndVerify
|
||||
// ignore the ACTION_FOCUS from decryptAndVerify otherwise dialog will appear after Fill
|
||||
if (ignoreActionFocus) {
|
||||
ignoreActionFocus = false;
|
||||
return;
|
||||
|
|
@ -124,7 +124,23 @@ public class AutofillService extends AccessibilityService {
|
|||
applicationInfo = null;
|
||||
}
|
||||
final String appName = (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "").toString();
|
||||
items = recursiveFilter(appName, null);
|
||||
|
||||
// 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);
|
||||
String preference = prefs.getString(event.getPackageName().toString(), defValue);
|
||||
switch (preference) {
|
||||
case "first":
|
||||
items = recursiveFilter(appName, null);
|
||||
break;
|
||||
case "never":
|
||||
return;
|
||||
default:
|
||||
String path = PasswordRepository.getWorkTree() + "/" + preference + ".gpg";
|
||||
File file = new File(path);
|
||||
items = new ArrayList<>();
|
||||
items.add(PasswordItem.newPassword(file.getName(), file));
|
||||
}
|
||||
if (items.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,6 +76,11 @@
|
|||
android:key="autofill_apps"
|
||||
android:summary="Customize autofill settings for specific apps."
|
||||
android:title="Per-app settings"/>
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="autofill_default"
|
||||
android:summary="Default to 'Automatically match with password' for apps without custom settings."
|
||||
android:title="Automatically match by default"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="Misc">
|
||||
|
|
|
|||
Loading…
Reference in a new issue