mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-22 16:07:30 +00:00
Switch passphrase creation to async task.
This commit is contained in:
parent
0e5ff9bdac
commit
84a29df1ee
@ -17,11 +17,9 @@
|
|||||||
package org.thoughtcrime.securesms;
|
package org.thoughtcrime.securesms;
|
||||||
|
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Message;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@ -61,8 +59,19 @@ public class PassphraseCreateActivity extends PassphraseActivity {
|
|||||||
this.okButton = (Button) findViewById(R.id.ok_button);
|
this.okButton = (Button) findViewById(R.id.ok_button);
|
||||||
this.cancelButton = (Button) findViewById(R.id.cancel_button);
|
this.cancelButton = (Button) findViewById(R.id.cancel_button);
|
||||||
|
|
||||||
this.okButton.setOnClickListener(new OkButtonClickListener());
|
this.okButton.setOnClickListener(new View.OnClickListener() {
|
||||||
this.cancelButton.setOnClickListener(new CancelButtonClickListener());
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
verifyAndSavePassphrases();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyAndSavePassphrases() {
|
private void verifyAndSavePassphrases() {
|
||||||
@ -76,28 +85,18 @@ public class PassphraseCreateActivity extends PassphraseActivity {
|
|||||||
this.passphraseEdit.setText("");
|
this.passphraseEdit.setText("");
|
||||||
this.passphraseRepeatEdit.setText("");
|
this.passphraseRepeatEdit.setText("");
|
||||||
} else {
|
} else {
|
||||||
MasterSecret masterSecret = MasterSecretUtil.generateMasterSecret(this, passphrase);
|
// We do this, but the edit boxes are basically impossible to clean up.
|
||||||
MemoryCleaner.clean(passphrase); // We do this, but the edit boxes are basically impossible to clean up.
|
|
||||||
MemoryCleaner.clean(passphraseRepeat);
|
MemoryCleaner.clean(passphraseRepeat);
|
||||||
new AsymmetricSecretGenerator(masterSecret).generate();
|
new SecretGenerator().execute(passphrase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AsymmetricSecretGenerator extends Handler implements Runnable {
|
private class SecretGenerator extends AsyncTask<String, Void, Void> {
|
||||||
private ProgressDialog progressDialog;
|
private ProgressDialog progressDialog;
|
||||||
private MasterSecret masterSecret;
|
private MasterSecret masterSecret;
|
||||||
|
|
||||||
public AsymmetricSecretGenerator(MasterSecret masterSecret) {
|
@Override
|
||||||
this.masterSecret = masterSecret;
|
protected void onPreExecute() {
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
|
||||||
MasterSecretUtil.generateAsymmetricMasterSecret(PassphraseCreateActivity.this, masterSecret);
|
|
||||||
IdentityKeyUtil.generateIdentityKeys(PassphraseCreateActivity.this, masterSecret);
|
|
||||||
this.obtainMessage().sendToTarget();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void generate() {
|
|
||||||
progressDialog = new ProgressDialog(PassphraseCreateActivity.this);
|
progressDialog = new ProgressDialog(PassphraseCreateActivity.this);
|
||||||
progressDialog.setTitle(R.string.PassphraseCreateActivity_generating_keypair);
|
progressDialog.setTitle(R.string.PassphraseCreateActivity_generating_keypair);
|
||||||
progressDialog.setMessage(getString(R.string.PassphraseCreateActivity_generating_a_local_encryption_keypair));
|
progressDialog.setMessage(getString(R.string.PassphraseCreateActivity_generating_a_local_encryption_keypair));
|
||||||
@ -105,28 +104,30 @@ public class PassphraseCreateActivity extends PassphraseActivity {
|
|||||||
progressDialog.setIndeterminate(true);
|
progressDialog.setIndeterminate(true);
|
||||||
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
||||||
progressDialog.show();
|
progressDialog.show();
|
||||||
new Thread(this).start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
protected Void doInBackground(String... params) {
|
||||||
|
String passphrase = params[0];
|
||||||
|
masterSecret = MasterSecretUtil.generateMasterSecret(PassphraseCreateActivity.this,
|
||||||
|
passphrase);
|
||||||
|
|
||||||
|
// We do this, but the edit boxes are basically impossible to clean up.
|
||||||
|
MemoryCleaner.clean(passphrase);
|
||||||
|
|
||||||
|
MasterSecretUtil.generateAsymmetricMasterSecret(PassphraseCreateActivity.this, masterSecret);
|
||||||
|
IdentityKeyUtil.generateIdentityKeys(PassphraseCreateActivity.this, masterSecret);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void param) {
|
||||||
progressDialog.dismiss();
|
progressDialog.dismiss();
|
||||||
setMasterSecret(masterSecret);
|
setMasterSecret(masterSecret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CancelButtonClickListener implements OnClickListener {
|
|
||||||
public void onClick(View v) {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class OkButtonClickListener implements OnClickListener {
|
|
||||||
public void onClick(View v) {
|
|
||||||
verifyAndSavePassphrases();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void cleanup() {
|
protected void cleanup() {
|
||||||
this.passphraseEdit = null;
|
this.passphraseEdit = null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user