aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniƫl van den Berg <danielvandenberg95@gmail.com>2016-09-21 12:57:42 +0200
committerMohamed Zenadi <zeapo@users.noreply.github.com>2016-09-21 12:57:42 +0200
commit1e658042cfb4ce428904a28844339de67d2123ee (patch)
tree775fdf2853f3a0da67830859c3272742f7c191bb
parent4c5edec4040cba4e7a0824f16cc4b41e40b4ef65 (diff)
Allow for manual copying or sharing of the password without showing it. (#222)
* Allow for manual copying or sharing of the password without showing it, see #218. * Cache the password in a variable for copying and sending, instead of using the textview.
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java65
1 files changed, 26 insertions, 39 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java
index c28e6f82..65864879 100644
--- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java
+++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java
@@ -75,6 +75,8 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
public static final int REQUEST_CODE_EDIT = 9916;
public static final int REQUEST_CODE_SELECT_FOLDER = 9917;
+ private String decodedPassword = "";
+
public final class Constants {
public static final String TAG = "Keychain";
}
@@ -233,15 +235,9 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
if (findViewById(R.id.share_password_as_plaintext) == null)
return;
- final TextView cryptoPasswordShow = (TextView) findViewById(R.id.crypto_password_show);
- if (cryptoPasswordShow == null) {
- return;
- }
- final CharSequence text = cryptoPasswordShow.getText();
-
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
- sendIntent.putExtra(Intent.EXTRA_TEXT, text);
+ sendIntent.putExtra(Intent.EXTRA_TEXT, decodedPassword);
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_plaintext_password_to)));//Always show a picker to give the user a chance to cancel
}
@@ -251,12 +247,11 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
if (findViewById(R.id.crypto_password_show) == null)
return;
- final TextView cryptoPasswordShow = (TextView) findViewById(R.id.crypto_password_show);
- if (cryptoPasswordShow == null) {
+ if (decodedPassword.isEmpty()) {
return;
}
- ClipData clip = ClipData.newPlainText("pgp_handler_result_pm", cryptoPasswordShow.getText());
+ ClipData clip = ClipData.newPlainText("pgp_handler_result_pm", decodedPassword);
clipboard.setPrimaryClip(clip);
try {
showToast(this.getResources().getString(R.string.clipboard_beginning_toast_text)
@@ -319,7 +314,6 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
public class DelayShow extends AsyncTask<Void, Integer, Boolean> {
ProgressBar pb;
int current, SHOW_TIME;
- boolean showPassword;
@Override
protected void onPreExecute() {
@@ -330,23 +324,20 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
}
current = 0;
- showPassword = settings.getBoolean("show_password", true);
- if (showPassword) {
- LinearLayout container = (LinearLayout) findViewById(R.id.crypto_container);
- container.setVisibility(View.VISIBLE);
+ LinearLayout container = (LinearLayout) findViewById(R.id.crypto_container);
+ container.setVisibility(View.VISIBLE);
- TextView extraText = (TextView) findViewById(R.id.crypto_extra_show);
+ TextView extraText = (TextView) findViewById(R.id.crypto_extra_show);
- if (extraText.getText().length() != 0)
- findViewById(R.id.crypto_extra_show_layout).setVisibility(View.VISIBLE);
+ if (extraText.getText().length() != 0)
+ findViewById(R.id.crypto_extra_show_layout).setVisibility(View.VISIBLE);
- if (SHOW_TIME == 0) {
- // treat 0 as forever, and the user must exit and/or clear clipboard on their own
- cancel(true);
- } else {
- this.pb = (ProgressBar) findViewById(R.id.pbLoading);
- this.pb.setMax(SHOW_TIME);
- }
+ if (SHOW_TIME == 0) {
+ // treat 0 as forever, and the user must exit and/or clear clipboard on their own
+ cancel(true);
+ } else {
+ this.pb = (ProgressBar) findViewById(R.id.pbLoading);
+ this.pb.setMax(SHOW_TIME);
}
}
@@ -355,9 +346,7 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
while (current < SHOW_TIME) {
SystemClock.sleep(1000);
current++;
- if (showPassword) {
- publishProgress(current);
- }
+ publishProgress(current);
}
return true;
}
@@ -375,7 +364,8 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
}
}
}
- if (showPassword && findViewById(R.id.crypto_password_show) != null) {
+ decodedPassword = "";
+ if (findViewById(R.id.crypto_password_show) != null) {
// clear password; if decrypt changed to encrypt layout via edit button, no need
((TextView) findViewById(R.id.crypto_password_show)).setText("");
((TextView) findViewById(R.id.crypto_extra_show)).setText("");
@@ -388,9 +378,7 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
@Override
protected void onProgressUpdate(Integer... values) {
- if (showPassword) {
- this.pb.setProgress(values[0]);
- }
+ this.pb.setProgress(values[0]);
}
}
@@ -490,17 +478,15 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
findViewById(R.id.progress_bar_label).setVisibility(View.GONE);
boolean showPassword = settings.getBoolean("show_password", true);
-
- if (showPassword) {
- findViewById(R.id.crypto_container).setVisibility(View.VISIBLE);
- }
+ findViewById(R.id.crypto_container).setVisibility(View.VISIBLE);
Typeface monoTypeface = Typeface.createFromAsset(getAssets(), "fonts/sourcecodepro.ttf");
String[] passContent = os.toString("UTF-8").split("\n");
((TextView) findViewById(R.id.crypto_password_show))
.setTypeface(monoTypeface);
((TextView) findViewById(R.id.crypto_password_show))
- .setText(passContent[0]);
+ .setText(showPassword?passContent[0]:"********");
+ decodedPassword = passContent[0];
String extraContent = os.toString("UTF-8").replaceFirst(".*\n", "");
if (extraContent.length() != 0) {
@@ -515,11 +501,11 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
}
new DelayShow().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
- if (!showPassword) {
+ /*if (!showPassword) {
// stop here, but still need DelayShow to clear clipboard
activity.setResult(RESULT_CANCELED);
activity.finish();
- }
+ }*/
} else {
Log.d("PGPHANDLER", "Error message after decrypt : " + os.toString());
}
@@ -578,6 +564,7 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
.setTypeface(monoTypeface);
((TextView) findViewById(R.id.crypto_password_show))
.setText(passContent[0]);
+ decodedPassword = passContent[0];
String extraContent = os.toString("UTF-8").replaceFirst(".*\n", "");
if (extraContent.length() != 0) {