mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-09-02 07:15:21 +00:00
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.
This commit is contained in:
committed by
Mohamed Zenadi
parent
4c5edec404
commit
1e658042cf
@@ -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_EDIT = 9916;
|
||||||
public static final int REQUEST_CODE_SELECT_FOLDER = 9917;
|
public static final int REQUEST_CODE_SELECT_FOLDER = 9917;
|
||||||
|
|
||||||
|
private String decodedPassword = "";
|
||||||
|
|
||||||
public final class Constants {
|
public final class Constants {
|
||||||
public static final String TAG = "Keychain";
|
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)
|
if (findViewById(R.id.share_password_as_plaintext) == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
final TextView cryptoPasswordShow = (TextView) findViewById(R.id.crypto_password_show);
|
|
||||||
if (cryptoPasswordShow == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final CharSequence text = cryptoPasswordShow.getText();
|
|
||||||
|
|
||||||
Intent sendIntent = new Intent();
|
Intent sendIntent = new Intent();
|
||||||
sendIntent.setAction(Intent.ACTION_SEND);
|
sendIntent.setAction(Intent.ACTION_SEND);
|
||||||
sendIntent.putExtra(Intent.EXTRA_TEXT, text);
|
sendIntent.putExtra(Intent.EXTRA_TEXT, decodedPassword);
|
||||||
sendIntent.setType("text/plain");
|
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
|
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)
|
if (findViewById(R.id.crypto_password_show) == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
final TextView cryptoPasswordShow = (TextView) findViewById(R.id.crypto_password_show);
|
if (decodedPassword.isEmpty()) {
|
||||||
if (cryptoPasswordShow == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClipData clip = ClipData.newPlainText("pgp_handler_result_pm", cryptoPasswordShow.getText());
|
ClipData clip = ClipData.newPlainText("pgp_handler_result_pm", decodedPassword);
|
||||||
clipboard.setPrimaryClip(clip);
|
clipboard.setPrimaryClip(clip);
|
||||||
try {
|
try {
|
||||||
showToast(this.getResources().getString(R.string.clipboard_beginning_toast_text)
|
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> {
|
public class DelayShow extends AsyncTask<Void, Integer, Boolean> {
|
||||||
ProgressBar pb;
|
ProgressBar pb;
|
||||||
int current, SHOW_TIME;
|
int current, SHOW_TIME;
|
||||||
boolean showPassword;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
@@ -330,23 +324,20 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
|
|||||||
}
|
}
|
||||||
current = 0;
|
current = 0;
|
||||||
|
|
||||||
showPassword = settings.getBoolean("show_password", true);
|
LinearLayout container = (LinearLayout) findViewById(R.id.crypto_container);
|
||||||
if (showPassword) {
|
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)
|
if (extraText.getText().length() != 0)
|
||||||
findViewById(R.id.crypto_extra_show_layout).setVisibility(View.VISIBLE);
|
findViewById(R.id.crypto_extra_show_layout).setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
if (SHOW_TIME == 0) {
|
if (SHOW_TIME == 0) {
|
||||||
// treat 0 as forever, and the user must exit and/or clear clipboard on their own
|
// treat 0 as forever, and the user must exit and/or clear clipboard on their own
|
||||||
cancel(true);
|
cancel(true);
|
||||||
} else {
|
} else {
|
||||||
this.pb = (ProgressBar) findViewById(R.id.pbLoading);
|
this.pb = (ProgressBar) findViewById(R.id.pbLoading);
|
||||||
this.pb.setMax(SHOW_TIME);
|
this.pb.setMax(SHOW_TIME);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,9 +346,7 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
|
|||||||
while (current < SHOW_TIME) {
|
while (current < SHOW_TIME) {
|
||||||
SystemClock.sleep(1000);
|
SystemClock.sleep(1000);
|
||||||
current++;
|
current++;
|
||||||
if (showPassword) {
|
publishProgress(current);
|
||||||
publishProgress(current);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
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
|
// 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_password_show)).setText("");
|
||||||
((TextView) findViewById(R.id.crypto_extra_show)).setText("");
|
((TextView) findViewById(R.id.crypto_extra_show)).setText("");
|
||||||
@@ -388,9 +378,7 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onProgressUpdate(Integer... values) {
|
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);
|
findViewById(R.id.progress_bar_label).setVisibility(View.GONE);
|
||||||
|
|
||||||
boolean showPassword = settings.getBoolean("show_password", true);
|
boolean showPassword = settings.getBoolean("show_password", true);
|
||||||
|
findViewById(R.id.crypto_container).setVisibility(View.VISIBLE);
|
||||||
if (showPassword) {
|
|
||||||
findViewById(R.id.crypto_container).setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
Typeface monoTypeface = Typeface.createFromAsset(getAssets(), "fonts/sourcecodepro.ttf");
|
Typeface monoTypeface = Typeface.createFromAsset(getAssets(), "fonts/sourcecodepro.ttf");
|
||||||
String[] passContent = os.toString("UTF-8").split("\n");
|
String[] passContent = os.toString("UTF-8").split("\n");
|
||||||
((TextView) findViewById(R.id.crypto_password_show))
|
((TextView) findViewById(R.id.crypto_password_show))
|
||||||
.setTypeface(monoTypeface);
|
.setTypeface(monoTypeface);
|
||||||
((TextView) findViewById(R.id.crypto_password_show))
|
((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", "");
|
String extraContent = os.toString("UTF-8").replaceFirst(".*\n", "");
|
||||||
if (extraContent.length() != 0) {
|
if (extraContent.length() != 0) {
|
||||||
@@ -515,11 +501,11 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
|
|||||||
}
|
}
|
||||||
|
|
||||||
new DelayShow().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
new DelayShow().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
if (!showPassword) {
|
/*if (!showPassword) {
|
||||||
// stop here, but still need DelayShow to clear clipboard
|
// stop here, but still need DelayShow to clear clipboard
|
||||||
activity.setResult(RESULT_CANCELED);
|
activity.setResult(RESULT_CANCELED);
|
||||||
activity.finish();
|
activity.finish();
|
||||||
}
|
}*/
|
||||||
} else {
|
} else {
|
||||||
Log.d("PGPHANDLER", "Error message after decrypt : " + os.toString());
|
Log.d("PGPHANDLER", "Error message after decrypt : " + os.toString());
|
||||||
}
|
}
|
||||||
@@ -578,6 +564,7 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
|
|||||||
.setTypeface(monoTypeface);
|
.setTypeface(monoTypeface);
|
||||||
((TextView) findViewById(R.id.crypto_password_show))
|
((TextView) findViewById(R.id.crypto_password_show))
|
||||||
.setText(passContent[0]);
|
.setText(passContent[0]);
|
||||||
|
decodedPassword = passContent[0];
|
||||||
|
|
||||||
String extraContent = os.toString("UTF-8").replaceFirst(".*\n", "");
|
String extraContent = os.toString("UTF-8").replaceFirst(".*\n", "");
|
||||||
if (extraContent.length() != 0) {
|
if (extraContent.length() != 0) {
|
||||||
|
Reference in New Issue
Block a user