aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
diff options
context:
space:
mode:
authorMohamed Zenadi <zeapo@users.noreply.github.com>2015-11-22 14:19:48 +0100
committerMohamed Zenadi <zeapo@users.noreply.github.com>2015-11-22 14:19:48 +0100
commit5b3cc540e413395dc4771d810058fcd467efab4c (patch)
treec6679cd86ad22786a3a977608e6a96eb1cfc485d /app/src/main/java/com/zeapo/pwdstore/UserPreference.java
parent97087ba33e1deaa74e0fa4c51d527f18efa7c754 (diff)
parent6e789a38f10da7c75fde3bed336dbf1d904d8efc (diff)
downloadHardenedPass-5b3cc540e413395dc4771d810058fcd467efab4c.tar.gz
HardenedPass-5b3cc540e413395dc4771d810058fcd467efab4c.zip
Merge pull request #149 from zeapo/fix/external
Add warnings to the user about storing the passwords on the sdcard
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/UserPreference.java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/UserPreference.java82
1 files changed, 57 insertions, 25 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
index d1b3b360..6ffc7abc 100644
--- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
+++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
@@ -1,6 +1,7 @@
package com.zeapo.pwdstore;
import android.accessibilityservice.AccessibilityServiceInfo;
+import android.app.Activity;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
@@ -23,14 +24,12 @@ import android.widget.Toast;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.Iterables;
+import com.nononsenseapps.filepicker.FilePickerActivity;
import com.zeapo.pwdstore.autofill.AutofillPreferenceActivity;
import com.zeapo.pwdstore.crypto.PgpHandler;
import com.zeapo.pwdstore.git.GitActivity;
import com.zeapo.pwdstore.utils.PasswordRepository;
-import net.rdrei.android.dirchooser.DirectoryChooserActivity;
-import net.rdrei.android.dirchooser.DirectoryChooserConfig;
-
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.openintents.openpgp.util.OpenPgpKeyPreference;
@@ -126,7 +125,7 @@ public class UserPreference extends AppCompatActivity {
new AlertDialog.Builder(callingActivity).
setTitle(R.string.pref_dialog_delete_title).
setMessage(getResources().getString(R.string.dialog_delete_msg)
- + " " + PasswordRepository.getWorkTree().toString()).
+ + " \n" + PasswordRepository.getWorkTree().toString()).
setCancelable(false).
setPositiveButton(R.string.dialog_delete, new DialogInterface.OnClickListener() {
@Override
@@ -266,19 +265,32 @@ public class UserPreference extends AppCompatActivity {
}
public void selectExternalGitRepository() {
- Intent intent = new Intent(this, DirectoryChooserActivity.class);
- File dir = new File(Environment.getExternalStorageDirectory() + "/PasswordStore");
- if (!dir.exists()) {
- dir.mkdir();
- }
- DirectoryChooserConfig config = DirectoryChooserConfig.builder()
- .newDirectoryName("PasswordStore")
- .allowNewDirectoryNameModification(true)
- .initialDirectory(Environment.getExternalStorageDirectory() + "/PasswordStore")
- .build();
- intent.putExtra(DirectoryChooserActivity.EXTRA_CONFIG, config);
-
- startActivityForResult(intent, SELECT_GIT_DIRECTORY);
+ final Activity activity = this;
+ new AlertDialog.Builder(this).
+ setTitle("Choose where to store the passwords").
+ setMessage("You must select a directory where to store your passwords. If you want " +
+ "to store your passwords within the hidden storage of the application, " +
+ "cancel this dialog and disable the \"External Repository\" option.").
+ setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ // This always works
+ Intent i = new Intent(activity.getApplicationContext(), FilePickerActivity.class);
+ // This works if you defined the intent filter
+ // Intent i = new Intent(Intent.ACTION_GET_CONTENT);
+
+ // Set these depending on your use case. These are the defaults.
+ i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false);
+ i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true);
+ i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_DIR);
+
+ i.putExtra(FilePickerActivity.EXTRA_START_PATH, Environment.getExternalStorageDirectory().getPath());
+
+ startActivityForResult(i, SELECT_GIT_DIRECTORY);
+ }
+ }).
+ setNegativeButton(R.string.dialog_cancel, null).show();
+
}
@Override
@@ -381,17 +393,37 @@ public class UserPreference extends AppCompatActivity {
}
}
break;
+ case SELECT_GIT_DIRECTORY: {
+ final Uri uri = data.getData();
+
+ if (uri.getPath().equals(Environment.getExternalStorageDirectory().getPath())) {
+ // the user wants to use the root of the sdcard as a store...
+ new AlertDialog.Builder(this).
+ setTitle("SD-Card root selected").
+ setMessage("You have selected the root of your sdcard for the store. " +
+ "This is extremly dangerous and you will lose your data " +
+ "as its content will be deleted").
+ setPositiveButton("Remove everything", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
+ .edit()
+ .putString("git_external_repo", uri.getPath())
+ .apply();
+ }
+ }).
+ setNegativeButton(R.string.dialog_cancel, null).show();
+ } else {
+ PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
+ .edit()
+ .putString("git_external_repo", uri.getPath())
+ .apply();
+ }
+ }
+ break;
default:
break;
}
}
-
- // why do they have to use a different resultCode than OK :/
- if (requestCode == SELECT_GIT_DIRECTORY && resultCode == DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED) {
- PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
- .edit()
- .putString("git_external_repo", data.getStringExtra(DirectoryChooserActivity.RESULT_SELECTED_DIR))
- .apply();
- }
}
}