|
|
@@ -22,7 +22,6 @@ import android.support.v4.app.NavUtils;
|
|
|
import android.support.v4.app.ShareCompat;
|
|
|
import android.support.v4.content.FileProvider;
|
|
|
import android.support.v7.app.ActionBar;
|
|
|
-import android.support.v7.widget.AppCompatTextView;
|
|
|
import android.util.SparseArray;
|
|
|
import android.view.MenuItem;
|
|
|
import android.view.View;
|
|
|
@@ -32,8 +31,10 @@ import java.io.File;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.logging.Level;
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
@@ -48,9 +49,7 @@ import info.knacki.pass.io.GPGUtil;
|
|
|
import info.knacki.pass.io.OnResponseListener;
|
|
|
import info.knacki.pass.settings.SettingsManager;
|
|
|
import info.knacki.pass.ui.GitPullActivity;
|
|
|
-import info.knacki.pass.ui.alertPrompt.AlertPrompt;
|
|
|
import info.knacki.pass.ui.alertPrompt.AlertPromptGenerator;
|
|
|
-import info.knacki.pass.ui.alertPrompt.views.SimpleTextEdit;
|
|
|
import info.knacki.pass.ui.alertPrompt.views.TextView;
|
|
|
import info.knacki.pass.ui.passwordPicker.PasswordPickerFactory;
|
|
|
|
|
|
@@ -163,6 +162,21 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|
|
|
|
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
|
|
public static class EncryptionPreferenceFragment extends PreferenceFragment {
|
|
|
+ String[] fEncryptionMethodNames;
|
|
|
+
|
|
|
+ protected int GetEncryptionMethodNames(SettingsManager.EncryptionType selectedType) {
|
|
|
+ Collection<Map.Entry<SettingsManager.EncryptionType, String>> encMethods = FileInterfaceFactory.GetEncryptionMethodNames(getResources());
|
|
|
+ fEncryptionMethodNames = new String[encMethods.size()];
|
|
|
+ int i =0;
|
|
|
+ int selectedIndex = -1;
|
|
|
+ for (Map.Entry<SettingsManager.EncryptionType, String> method: encMethods) {
|
|
|
+ if (selectedIndex == -1 && method.getKey().equals(selectedType))
|
|
|
+ selectedIndex = i;
|
|
|
+ fEncryptionMethodNames[i++] = method.getValue();
|
|
|
+ }
|
|
|
+ return selectedIndex;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
@@ -170,7 +184,12 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|
|
setHasOptionsMenu(true);
|
|
|
|
|
|
ListPreference encTypePref = (ListPreference) findPreference(getResources().getString(R.string.id_enctype));
|
|
|
- final int encTypeIndex = SettingsManager.GetDefaultEncryptionType(getActivity()).IntValue();
|
|
|
+ final int encTypeIndex = GetEncryptionMethodNames(SettingsManager.GetDefaultEncryptionType(getActivity()));
|
|
|
+ encTypePref.setEntries(fEncryptionMethodNames);
|
|
|
+ String[] encValues = new String[fEncryptionMethodNames.length];
|
|
|
+ for (int i =0; i < fEncryptionMethodNames.length; ++i)
|
|
|
+ encValues[i] = "" +i;
|
|
|
+ encTypePref.setEntryValues(encValues);
|
|
|
encTypePref.setSummary(encTypePref.getEntries()[encTypeIndex]);
|
|
|
encTypePref.setValueIndex(encTypeIndex);
|
|
|
encTypePref.setOnPreferenceChangeListener((preference, o) -> {
|
|
|
@@ -180,7 +199,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|
|
return true;
|
|
|
});
|
|
|
|
|
|
- SwitchPreference fingerPref = (SwitchPreference) findPreference(getString(R.string.pref_enctype_fingerprint));
|
|
|
+ SwitchPreference fingerPref = (SwitchPreference) findPreference(getString(R.string.id_pref_enctype_fingerprint));
|
|
|
fingerPref.setChecked(SettingsManager.IsFingerprintEnabled(getActivity()));
|
|
|
fingerPref.setOnPreferenceChangeListener((preference, o) -> {
|
|
|
SettingsManager.SetFingerprintEnabled(getActivity(), (Boolean) o);
|
|
|
@@ -502,7 +521,9 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|
|
try {
|
|
|
outFile.createNewFile();
|
|
|
FileOutputStream fout = new FileOutputStream(outFile);
|
|
|
- FileUtils.pipe(SettingsManager.GetGPGKeyContent(getActivity()), fout);
|
|
|
+ InputStream keyContent = SettingsManager.GetGPGKeyContent(getActivity());
|
|
|
+ if (keyContent != null)
|
|
|
+ FileUtils.pipe(keyContent, fout);
|
|
|
fout.close();
|
|
|
} catch (IOException e) {
|
|
|
Toast.makeText(getActivity(), "Cannot prepare key for sharing: " + e.getMessage(), Toast.LENGTH_LONG).show();
|
|
|
@@ -538,7 +559,12 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
if (requestCode == ACTIVITY_REQUEST_CODE_BROWSEGPG && resultCode == RESULT_OK) {
|
|
|
try {
|
|
|
- boolean gpgImportStatus = SettingsManager.SetGPGKeyContent(getActivity(), GetFileName(data.getData()), getActivity().getContentResolver().openInputStream(data.getData()));
|
|
|
+ final Uri intentData = data.getData();
|
|
|
+ boolean gpgImportStatus;
|
|
|
+ if (intentData != null)
|
|
|
+ gpgImportStatus = SettingsManager.SetGPGKeyContent(getActivity(), GetFileName(intentData), getActivity().getContentResolver().openInputStream(intentData));
|
|
|
+ else
|
|
|
+ gpgImportStatus = false;
|
|
|
Toast.makeText(getActivity(), getResources().getString(gpgImportStatus ? R.string.gpg_import_ok : R.string.gpg_import_ko), Toast.LENGTH_LONG).show();
|
|
|
} catch (FileNotFoundException e) {
|
|
|
Toast.makeText(getActivity(), getResources().getString(R.string.filenotfound), Toast.LENGTH_LONG).show();
|