aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java79
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationActivity.java6
-rw-r--r--src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java25
-rw-r--r--src/main/java/de/pixart/messenger/ui/WelcomeActivity.java8
4 files changed, 58 insertions, 60 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index ec077063d..b436d9ec9 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -2018,40 +2018,41 @@ public class XmppConnectionService extends Service {
}
public void createAccountFromKey(final String alias, final OnAccountCreated callback) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- X509Certificate[] chain = KeyChain.getCertificateChain(XmppConnectionService.this, alias);
- Pair<Jid, String> info = CryptoHelper.extractJidAndName(chain[0]);
- if (info == null) {
- callback.informUser(R.string.certificate_does_not_contain_jid);
- return;
- }
- if (findAccountByJid(info.first) == null) {
- Account account = new Account(info.first, "");
- account.setPrivateKeyAlias(alias);
- account.setOption(Account.OPTION_DISABLED, true);
- account.setDisplayName(info.second);
- createAccount(account);
- callback.onAccountCreated(account);
- if (Config.X509_VERIFICATION) {
- try {
- getMemorizingTrustManager().getNonInteractive(account.getJid().getDomainpart()).checkClientTrusted(chain, "RSA");
- } catch (CertificateException e) {
- callback.informUser(R.string.certificate_chain_is_not_trusted);
- }
+ new Thread(() -> {
+ try {
+ final X509Certificate[] chain = KeyChain.getCertificateChain(this, alias);
+ final X509Certificate cert = chain != null && chain.length > 0 ? chain[0] : null;
+ if (cert == null) {
+ callback.informUser(R.string.unable_to_parse_certificate);
+ return;
+ }
+ Pair<Jid, String> info = CryptoHelper.extractJidAndName(cert);
+ if (info == null) {
+ callback.informUser(R.string.certificate_does_not_contain_jid);
+ return;
+ }
+ if (findAccountByJid(info.first) == null) {
+ Account account = new Account(info.first, "");
+ account.setPrivateKeyAlias(alias);
+ account.setOption(Account.OPTION_DISABLED, true);
+ account.setDisplayName(info.second);
+ createAccount(account);
+ callback.onAccountCreated(account);
+ if (Config.X509_VERIFICATION) {
+ try {
+ getMemorizingTrustManager().getNonInteractive(account.getJid().getDomainpart()).checkClientTrusted(chain, "RSA");
+ } catch (CertificateException e) {
+ callback.informUser(R.string.certificate_chain_is_not_trusted);
}
- } else {
- callback.informUser(R.string.account_already_exists);
}
- } catch (Exception e) {
- e.printStackTrace();
- callback.informUser(R.string.unable_to_parse_certificate);
+ } else {
+ callback.informUser(R.string.account_already_exists);
}
+ } catch (Exception e) {
+ e.printStackTrace();
+ callback.informUser(R.string.unable_to_parse_certificate);
}
}).start();
-
}
public void updateKeyInAccount(final Account account, final String alias) {
@@ -2060,6 +2061,10 @@ public class XmppConnectionService extends Service {
X509Certificate[] chain = KeyChain.getCertificateChain(XmppConnectionService.this, alias);
Log.d(Config.LOGTAG, account.getJid().toBareJid() + " loaded certificate chain");
Pair<Jid, String> info = CryptoHelper.extractJidAndName(chain[0]);
+ if (info == null) {
+ showErrorToastInUi(R.string.certificate_does_not_contain_jid);
+ return;
+ }
if (account.getJid().toBareJid().equals(info.first)) {
account.setPrivateKeyAlias(alias);
account.setDisplayName(info.second);
@@ -2126,19 +2131,11 @@ public class XmppConnectionService extends Service {
}
}
if (account.getXmppConnection() != null) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- disconnect(account, true);
- }
- }).start();
+ new Thread(() -> disconnect(account, true)).start();
}
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- if (!databaseBackend.deleteAccount(account)) {
- Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": unable to delete account");
- }
+ final Runnable runnable = () -> {
+ if (!databaseBackend.deleteAccount(account)) {
+ Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": unable to delete account");
}
};
mDatabaseWriterExecutor.execute(runnable);
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
index 78ab0a91f..b461b5d6f 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
@@ -1353,11 +1353,7 @@ public class ConversationActivity extends XmppActivity
startActivity(redirectionIntent);
overridePendingTransition(0, 0);
} else if (Config.MAGIC_CREATE_DOMAIN != null) {
- Log.d(Config.LOGTAG, "First start time: " + FirstStartTime);
- Intent redirectionIntent = new Intent(this, WelcomeActivity.class);
- redirectionIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
- startActivity(redirectionIntent);
- overridePendingTransition(0, 0);
+ WelcomeActivity.launch(this);
} else {
Intent editAccount = new Intent(this, EditAccountActivity.class);
editAccount.putExtra("init", true);
diff --git a/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java b/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java
index 4a17a4fbc..b253d4021 100644
--- a/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java
@@ -338,17 +338,16 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
}
private void deleteAccount(final Account account) {
- AlertDialog.Builder builder = new AlertDialog.Builder(
- ManageAccountActivity.this);
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.mgmt_account_are_you_sure));
builder.setIconAttribute(android.R.attr.alertDialogIcon);
builder.setMessage(getString(R.string.mgmt_account_delete_confirm_text));
builder.setPositiveButton(getString(R.string.delete),
- new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- xmppConnectionService.deleteAccount(account);
- selectedAccount = null;
+ (dialog, which) -> {
+ xmppConnectionService.deleteAccount(account);
+ selectedAccount = null;
+ if (xmppConnectionService.getAccounts().size() == 0 && Config.MAGIC_CREATE_DOMAIN != null) {
+ WelcomeActivity.launch(this);
}
});
builder.setNegativeButton(getString(R.string.cancel), null);
@@ -386,16 +385,14 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
@Override
public void onAccountCreated(Account account) {
- switchToAccount(account, true);
+ Intent intent = new Intent(this, EditAccountActivity.class);
+ intent.putExtra("jid", account.getJid().toBareJid().toString());
+ intent.putExtra("init", true);
+ startActivity(intent);
}
@Override
public void informUser(final int r) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- Toast.makeText(ManageAccountActivity.this, r, Toast.LENGTH_LONG).show();
- }
- });
+ runOnUiThread(() -> Toast.makeText(ManageAccountActivity.this, r, Toast.LENGTH_LONG).show());
}
}
diff --git a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java
index c2b5a49bb..cd2be0161 100644
--- a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java
@@ -2,6 +2,7 @@ package de.pixart.messenger.ui;
import android.Manifest;
import android.app.ActionBar;
+import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
@@ -334,4 +335,11 @@ public class WelcomeActivity extends XmppActivity {
to.putExtra(EXTRA_INVITEE, from.getStringExtra(EXTRA_INVITEE));
}
}
+
+ public static void launch(Activity activity) {
+ Intent intent = new Intent(activity, WelcomeActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
+ activity.startActivity(intent);
+ activity.overridePendingTransition(0, 0);
+ }
} \ No newline at end of file