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;
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,7 +91,6 @@ public class PassphraseChangeActivity extends PassphraseActivity {
original = MasterSecretUtil.UNENCRYPTED_PASSPHRASE;
}
try {
if (!passphrase.equals(passphraseRepeat)) {
Toast.makeText(getApplicationContext(),
R.string.PassphraseChangeActivity_passphrases_dont_match_exclamation,
@ -100,15 +102,7 @@ public class PassphraseChangeActivity extends PassphraseActivity {
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("");
new ChangePassphraseTask(this).execute(original, passphrase);
}
}
@ -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
protected void cleanup() {
this.originalPassphrase = null;