mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
Call changeMasterSecretPassphrase in AsyncTask
Fixes #2768 Closes #2893
This commit is contained in:
parent
857135aab1
commit
58664fcddb
@ -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<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;
|
||||
|
Loading…
Reference in New Issue
Block a user