diff --git a/src/conversations/java/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/conversations/java/eu/siacs/conversations/ui/ManageAccountActivity.java index 53841a301..1112e95a6 100644 --- a/src/conversations/java/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/conversations/java/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -369,7 +369,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda } private void deleteAccount(final Account account) { - AlertDialog.Builder builder = new AlertDialog.Builder(this); + final 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)); diff --git a/src/conversations/java/eu/siacs/conversations/ui/WelcomeActivity.java b/src/conversations/java/eu/siacs/conversations/ui/WelcomeActivity.java index 12695b6f7..f6a882ef8 100644 --- a/src/conversations/java/eu/siacs/conversations/ui/WelcomeActivity.java +++ b/src/conversations/java/eu/siacs/conversations/ui/WelcomeActivity.java @@ -1,11 +1,14 @@ package eu.siacs.conversations.ui; import android.Manifest; +import android.content.ActivityNotFoundException; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.databinding.DataBindingUtil; import android.os.Bundle; +import android.security.KeyChain; +import android.security.KeyChainAliasCallback; import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; @@ -21,6 +24,7 @@ import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.databinding.ActivityWelcomeBinding; import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.utils.InstallReferrerUtils; import eu.siacs.conversations.utils.SignupUtils; import eu.siacs.conversations.utils.XmppUri; @@ -29,7 +33,7 @@ import rocks.xmpp.addr.Jid; import static eu.siacs.conversations.utils.PermissionUtils.allGranted; import static eu.siacs.conversations.utils.PermissionUtils.writeGranted; -public class WelcomeActivity extends XmppActivity { +public class WelcomeActivity extends XmppActivity implements XmppConnectionService.OnAccountCreated, KeyChainAliasCallback { private static final int REQUEST_IMPORT_BACKUP = 0x63fb; @@ -154,10 +158,42 @@ public class WelcomeActivity extends XmppActivity { case R.id.action_scan_qr_code: UriHandlerActivity.scan(this); break; + case R.id.action_add_account_with_cert: + addAccountFromKey(); + break; } return super.onOptionsItemSelected(item); } + private void addAccountFromKey() { + try { + KeyChain.choosePrivateKeyAlias(this, this, null, null, null, -1, null); + } catch (ActivityNotFoundException e) { + Toast.makeText(this, R.string.device_does_not_support_certificates, Toast.LENGTH_LONG).show(); + } + } + + @Override + public void alias(final String alias) { + if (alias != null) { + xmppConnectionService.createAccountFromKey(alias, this); + } + } + + @Override + public void onAccountCreated(final Account account) { + final Intent intent = new Intent(this, EditAccountActivity.class); + intent.putExtra("jid", account.getJid().asBareJid().toString()); + intent.putExtra("init", true); + addInviteUri(intent); + startActivity(intent); + } + + @Override + public void informUser(final int r) { + runOnUiThread(() -> Toast.makeText(this, r, Toast.LENGTH_LONG).show()); + } + @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { UriHandlerActivity.onRequestPermissionResult(this, requestCode, grantResults); diff --git a/src/conversations/res/menu/welcome_menu.xml b/src/conversations/res/menu/welcome_menu.xml index ec396f32f..f07a2b91e 100644 --- a/src/conversations/res/menu/welcome_menu.xml +++ b/src/conversations/res/menu/welcome_menu.xml @@ -1,16 +1,22 @@
\ No newline at end of file diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index fc7fb5b37..ab198dbac 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2199,6 +2199,7 @@ public class XmppConnectionService extends Service { final Account account = new Account(info.first, ""); account.setPrivateKeyAlias(alias); account.setOption(Account.OPTION_DISABLED, true); + account.setOption(Account.OPTION_FIXED_USERNAME, true); account.setDisplayName(info.second); createAccount(account); callback.onAccountCreated(account); diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 9e829e041..0e618df46 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -784,12 +784,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat this.mInitMode |= this.mAccount.isOptionSet(Account.OPTION_REGISTER); this.mUsernameMode |= mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) && mAccount.isOptionSet(Account.OPTION_REGISTER); - if (this.mAccount.getPrivateKeyAlias() != null) { - this.binding.accountPassword.setHint(R.string.authenticate_with_certificate); - if (this.mInitMode) { - this.binding.accountPassword.requestFocus(); - } - } if (mPendingFingerprintVerificationUri != null) { processFingerprintVerification(mPendingFingerprintVerificationUri, false); mPendingFingerprintVerificationUri = null;