Call changeMasterSecretPassphrase in AsyncTask

Fixes #2768
Closes #2893
This commit is contained in:
Adrian Chifor 2015-04-04 15:43:17 +03:00 committed by Moxie Marlinspike
parent 857135aab1
commit 58664fcddb

View File

@ -16,6 +16,9 @@
*/ */
package org.thoughtcrime.securesms; package org.thoughtcrime.securesms;
import android.os.AsyncTask;
import android.content.Context;
import android.util.Log;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.view.View; import android.view.View;
@ -88,27 +91,18 @@ public class PassphraseChangeActivity extends PassphraseActivity {
original = MasterSecretUtil.UNENCRYPTED_PASSPHRASE; original = MasterSecretUtil.UNENCRYPTED_PASSPHRASE;
} }
try { if (!passphrase.equals(passphraseRepeat)) {
if (!passphrase.equals(passphraseRepeat)) { Toast.makeText(getApplicationContext(),
Toast.makeText(getApplicationContext(), R.string.PassphraseChangeActivity_passphrases_dont_match_exclamation,
R.string.PassphraseChangeActivity_passphrases_dont_match_exclamation, Toast.LENGTH_SHORT).show();
Toast.LENGTH_SHORT).show(); this.newPassphrase.setText("");
this.newPassphrase.setText(""); this.repeatPassphrase.setText("");
this.repeatPassphrase.setText(""); } else if (passphrase.equals("")) {
} else if (passphrase.equals("")) { Toast.makeText(getApplicationContext(),
Toast.makeText(getApplicationContext(), R.string.PassphraseChangeActivity_enter_new_passphrase_exclamation,
R.string.PassphraseChangeActivity_enter_new_passphrase_exclamation, Toast.LENGTH_SHORT).show();
Toast.LENGTH_SHORT).show(); } else {
} else { new ChangePassphraseTask(this).execute(original, passphrase);
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("");
} }
} }
@ -124,6 +118,46 @@ public class PassphraseChangeActivity extends PassphraseActivity {
} }
} }
private class ChangePassphraseTask extends AsyncTask<String, Void, MasterSecret> {
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 @Override
protected void cleanup() { protected void cleanup() {
this.originalPassphrase = null; this.originalPassphrase = null;