From 6e789a38f10da7c75fde3bed336dbf1d904d8efc Mon Sep 17 00:00:00 2001 From: zeapo Date: Sun, 22 Nov 2015 14:19:06 +0100 Subject: Add warnings to the user about storing the passwords on the sdcard --- app/src/main/AndroidManifest.xml | 10 ++- .../java/com/zeapo/pwdstore/PasswordStore.java | 66 ++++++++++------- .../java/com/zeapo/pwdstore/UserPreference.java | 82 +++++++++++++++------- app/src/main/res/values/strings.xml | 2 +- app/src/main/res/values/styles.xml | 17 +++++ 5 files changed, 125 insertions(+), 52 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 404a5138..7aa45ca4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -72,7 +72,15 @@ android:value="com.zeapo.pwdstore.PasswordStore" /> - + + + + + + diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java index 83a21266..cca8493b 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java @@ -497,31 +497,7 @@ public class PasswordStore extends AppCompatActivity { new AlertDialog.Builder(this) .setTitle("Repository location") .setMessage("Select where to create or clone your password repository.") - .setPositiveButton("External", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - settings.edit().putBoolean("git_external", true).apply(); - - if (settings.getString("git_external_repo", null) == null) { - Intent intent = new Intent(activity, UserPreference.class); - intent.putExtra("operation", "git_external"); - startActivityForResult(intent, operation); - } else { - switch (operation) { - case NEW_REPO_BUTTON: - initializeRepositoryInfo(); - break; - case CLONE_REPO_BUTTON: - PasswordRepository.initialize(PasswordStore.this); - - Intent intent = new Intent(activity, GitActivity.class); - intent.putExtra("Operation", GitActivity.REQUEST_CLONE); - startActivityForResult(intent, GitActivity.REQUEST_CLONE); - break; - } - } - } - }) - .setNegativeButton("Internal", new DialogInterface.OnClickListener() { + .setPositiveButton("Hidden (preferred)", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { settings.edit().putBoolean("git_external", false).apply(); @@ -539,6 +515,46 @@ public class PasswordStore extends AppCompatActivity { } } }) + .setNegativeButton("SD-Card", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + settings.edit().putBoolean("git_external", true).apply(); + + if (settings.getString("git_external_repo", null) == null) { + Intent intent = new Intent(activity, UserPreference.class); + intent.putExtra("operation", "git_external"); + startActivityForResult(intent, operation); + } else { + new AlertDialog.Builder(activity). + setTitle("Directory already selected"). + setMessage("Do you want to use \"" + settings.getString("git_external_repo", null) + "\"?"). + setPositiveButton("Use", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + switch (operation) { + case NEW_REPO_BUTTON: + initializeRepositoryInfo(); + break; + case CLONE_REPO_BUTTON: + PasswordRepository.initialize(PasswordStore.this); + + Intent intent = new Intent(activity, GitActivity.class); + intent.putExtra("Operation", GitActivity.REQUEST_CLONE); + startActivityForResult(intent, GitActivity.REQUEST_CLONE); + break; + } + } + }). + setNegativeButton("Change", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Intent intent = new Intent(activity, UserPreference.class); + intent.putExtra("operation", "git_external"); + startActivityForResult(intent, operation); + } + }).show(); + } + } + }) .show(); } 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(); - } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4047691f..9cb6ac1b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -9,7 +9,7 @@ Settings Hello world! Directory already exist - Target directory already exist. Current version support only a single store. Do you want to delete the current password store directory? + Target directory already exist. Current version support only a single store. Do you want to delete the current password store directory: Delete directory Cancel Repository information diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 3fffef42..fc592058 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -13,4 +13,21 @@ + + + + + -- cgit v1.2.3