From 58664fcddb4933c435d47d1996d80c66224bda4d Mon Sep 17 00:00:00 2001 From: Adrian Chifor Date: Sat, 4 Apr 2015 15:43:17 +0300 Subject: [PATCH] Call changeMasterSecretPassphrase in AsyncTask Fixes #2768 Closes #2893 --- .../securesms/PassphraseChangeActivity.java | 76 ++++++++++++++----- 1 file changed, 55 insertions(+), 21 deletions(-) diff --git a/src/org/thoughtcrime/securesms/PassphraseChangeActivity.java b/src/org/thoughtcrime/securesms/PassphraseChangeActivity.java index 28652be734..891b7328e6 100644 --- a/src/org/thoughtcrime/securesms/PassphraseChangeActivity.java +++ b/src/org/thoughtcrime/securesms/PassphraseChangeActivity.java @@ -16,6 +16,9 @@ */ package org.thoughtcrime.securesms; +import android.os.AsyncTask; +import android.content.Context; +import android.util.Log; import android.os.Bundle; import android.text.Editable; import android.view.View; @@ -88,27 +91,18 @@ public class PassphraseChangeActivity extends PassphraseActivity { original = MasterSecretUtil.UNENCRYPTED_PASSPHRASE; } - try { - if (!passphrase.equals(passphraseRepeat)) { - Toast.makeText(getApplicationContext(), - R.string.PassphraseChangeActivity_passphrases_dont_match_exclamation, - Toast.LENGTH_SHORT).show(); - this.newPassphrase.setText(""); - this.repeatPassphrase.setText(""); - } else if (passphrase.equals("")) { - Toast.makeText(getApplicationContext(), - R.string.PassphraseChangeActivity_enter_new_passphrase_exclamation, - Toast.LENGTH_SHORT).show(); - } else { - MasterSecret masterSecret = MasterSecretUtil.changeMasterSecretPassphrase(this, original, passphrase); - TextSecurePreferences.setPasswordDisabled(this, false); - - setMasterSecret(masterSecret); - } - } catch (InvalidPassphraseException e) { - Toast.makeText(this, R.string.PassphraseChangeActivity_incorrect_old_passphrase_exclamation, - Toast.LENGTH_LONG).show(); - this.originalPassphrase.setText(""); + if (!passphrase.equals(passphraseRepeat)) { + Toast.makeText(getApplicationContext(), + R.string.PassphraseChangeActivity_passphrases_dont_match_exclamation, + Toast.LENGTH_SHORT).show(); + this.newPassphrase.setText(""); + this.repeatPassphrase.setText(""); + } else if (passphrase.equals("")) { + Toast.makeText(getApplicationContext(), + R.string.PassphraseChangeActivity_enter_new_passphrase_exclamation, + Toast.LENGTH_SHORT).show(); + } else { + new ChangePassphraseTask(this).execute(original, passphrase); } } @@ -124,6 +118,46 @@ public class PassphraseChangeActivity extends PassphraseActivity { } } + private class ChangePassphraseTask extends AsyncTask { + private final Context context; + + public ChangePassphraseTask(Context context) { + this.context = context; + } + + @Override + protected void onPreExecute() { + okButton.setEnabled(false); + } + + @Override + protected MasterSecret doInBackground(String... params) { + try { + MasterSecret masterSecret = MasterSecretUtil.changeMasterSecretPassphrase(context, params[0], params[1]); + TextSecurePreferences.setPasswordDisabled(context, false); + + return masterSecret; + + } catch (InvalidPassphraseException e) { + Log.w(PassphraseChangeActivity.class.getSimpleName(), e); + return null; + } + } + + @Override + protected void onPostExecute(MasterSecret masterSecret) { + okButton.setEnabled(true); + + if (masterSecret != null) { + setMasterSecret(masterSecret); + } else { + Toast.makeText(context, R.string.PassphraseChangeActivity_incorrect_old_passphrase_exclamation, + Toast.LENGTH_LONG).show(); + originalPassphrase.setText(""); + } + } + } + @Override protected void cleanup() { this.originalPassphrase = null;