1package eu.siacs.conversations.ui;
2
3import android.app.AlertDialog;
4import android.app.AlertDialog.Builder;
5import android.app.PendingIntent;
6import android.content.DialogInterface;
7import android.content.Intent;
8import android.graphics.Bitmap;
9import android.os.Bundle;
10import android.security.KeyChain;
11import android.security.KeyChainAliasCallback;
12import android.text.Editable;
13import android.text.TextWatcher;
14import android.view.Menu;
15import android.view.MenuItem;
16import android.view.View;
17import android.view.View.OnClickListener;
18import android.widget.AutoCompleteTextView;
19import android.widget.Button;
20import android.widget.CheckBox;
21import android.widget.CompoundButton;
22import android.widget.CompoundButton.OnCheckedChangeListener;
23import android.widget.EditText;
24import android.widget.ImageButton;
25import android.widget.ImageView;
26import android.widget.LinearLayout;
27import android.widget.RelativeLayout;
28import android.widget.TableLayout;
29import android.widget.TextView;
30import android.widget.Toast;
31
32import java.util.Set;
33
34import eu.siacs.conversations.Config;
35import eu.siacs.conversations.R;
36import eu.siacs.conversations.crypto.axolotl.AxolotlService;
37import eu.siacs.conversations.entities.Account;
38import eu.siacs.conversations.services.XmppConnectionService.OnCaptchaRequested;
39import eu.siacs.conversations.services.XmppConnectionService;
40import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
41import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
42import eu.siacs.conversations.utils.CryptoHelper;
43import eu.siacs.conversations.utils.UIHelper;
44import eu.siacs.conversations.xmpp.OnKeyStatusUpdated;
45import eu.siacs.conversations.xmpp.XmppConnection.Features;
46import eu.siacs.conversations.xmpp.forms.Data;
47import eu.siacs.conversations.xmpp.jid.InvalidJidException;
48import eu.siacs.conversations.xmpp.jid.Jid;
49import eu.siacs.conversations.xmpp.pep.Avatar;
50
51public class EditAccountActivity extends XmppActivity implements OnAccountUpdate,
52 OnKeyStatusUpdated, OnCaptchaRequested, KeyChainAliasCallback, XmppConnectionService.OnShowErrorToast {
53
54 private AutoCompleteTextView mAccountJid;
55 private EditText mPassword;
56 private EditText mPasswordConfirm;
57 private CheckBox mRegisterNew;
58 private Button mCancelButton;
59 private Button mSaveButton;
60 private TableLayout mMoreTable;
61
62 private LinearLayout mStats;
63 private TextView mServerInfoSm;
64 private TextView mServerInfoRosterVersion;
65 private TextView mServerInfoCarbons;
66 private TextView mServerInfoMam;
67 private TextView mServerInfoCSI;
68 private TextView mServerInfoBlocking;
69 private TextView mServerInfoPep;
70 private TextView mServerInfoHttpUpload;
71 private TextView mSessionEst;
72 private TextView mOtrFingerprint;
73 private TextView mAxolotlFingerprint;
74 private TextView mAccountJidLabel;
75 private ImageView mAvatar;
76 private RelativeLayout mOtrFingerprintBox;
77 private RelativeLayout mAxolotlFingerprintBox;
78 private ImageButton mOtrFingerprintToClipboardButton;
79 private ImageButton mAxolotlFingerprintToClipboardButton;
80 private ImageButton mRegenerateAxolotlKeyButton;
81 private LinearLayout keys;
82 private LinearLayout keysCard;
83 private AlertDialog mCaptchaDialog = null;
84
85 private Jid jidToEdit;
86 private boolean mInitMode = false;
87 private Account mAccount;
88 private String messageFingerprint;
89
90 private boolean mFetchingAvatar = false;
91
92 private final OnClickListener mSaveButtonClickListener = new OnClickListener() {
93
94 @Override
95 public void onClick(final View v) {
96 if (mInitMode && mAccount != null) {
97 mAccount.setOption(Account.OPTION_DISABLED, false);
98 }
99 if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED && !accountInfoEdited()) {
100 mAccount.setOption(Account.OPTION_DISABLED, false);
101 xmppConnectionService.updateAccount(mAccount);
102 return;
103 }
104 final boolean registerNewAccount = mRegisterNew.isChecked() && !Config.DISALLOW_REGISTRATION_IN_UI;
105 if (Config.DOMAIN_LOCK != null && mAccountJid.getText().toString().contains("@")) {
106 mAccountJid.setError(getString(R.string.invalid_username));
107 mAccountJid.requestFocus();
108 return;
109 }
110 final Jid jid;
111 try {
112 if (Config.DOMAIN_LOCK != null) {
113 jid = Jid.fromParts(mAccountJid.getText().toString(), Config.DOMAIN_LOCK, null);
114 } else {
115 jid = Jid.fromString(mAccountJid.getText().toString());
116 }
117 } catch (final InvalidJidException e) {
118 if (Config.DOMAIN_LOCK != null) {
119 mAccountJid.setError(getString(R.string.invalid_username));
120 } else {
121 mAccountJid.setError(getString(R.string.invalid_jid));
122 }
123 mAccountJid.requestFocus();
124 return;
125 }
126 if (jid.isDomainJid()) {
127 if (Config.DOMAIN_LOCK != null) {
128 mAccountJid.setError(getString(R.string.invalid_username));
129 } else {
130 mAccountJid.setError(getString(R.string.invalid_jid));
131 }
132 mAccountJid.requestFocus();
133 return;
134 }
135 final String password = mPassword.getText().toString();
136 final String passwordConfirm = mPasswordConfirm.getText().toString();
137 if (registerNewAccount) {
138 if (!password.equals(passwordConfirm)) {
139 mPasswordConfirm.setError(getString(R.string.passwords_do_not_match));
140 mPasswordConfirm.requestFocus();
141 return;
142 }
143 }
144 if (mAccount != null) {
145 mAccount.setJid(jid);
146 mAccountJid.setError(null);
147 mPasswordConfirm.setError(null);
148 mAccount.setPassword(password);
149 mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
150 xmppConnectionService.updateAccount(mAccount);
151 } else {
152 if (xmppConnectionService.findAccountByJid(jid) != null) {
153 mAccountJid.setError(getString(R.string.account_already_exists));
154 mAccountJid.requestFocus();
155 return;
156 }
157 mAccount = new Account(jid.toBareJid(), password);
158 mAccount.setOption(Account.OPTION_USETLS, true);
159 mAccount.setOption(Account.OPTION_USECOMPRESSION, true);
160 mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
161 xmppConnectionService.createAccount(mAccount);
162 }
163 if (!mAccount.isOptionSet(Account.OPTION_DISABLED)
164 && !registerNewAccount
165 && !mInitMode) {
166 finish();
167 } else {
168 updateSaveButton();
169 updateAccountInformation(true);
170 }
171
172 }
173 };
174 private final OnClickListener mCancelButtonClickListener = new OnClickListener() {
175
176 @Override
177 public void onClick(final View v) {
178 finish();
179 }
180 };
181
182 public void refreshUiReal() {
183 invalidateOptionsMenu();
184 if (mAccount != null
185 && mAccount.getStatus() != Account.State.ONLINE
186 && mFetchingAvatar) {
187 startActivity(new Intent(getApplicationContext(),
188 ManageAccountActivity.class));
189 finish();
190 } else if (mInitMode && mAccount != null && mAccount.getStatus() == Account.State.ONLINE) {
191 if (!mFetchingAvatar) {
192 mFetchingAvatar = true;
193 xmppConnectionService.checkForAvatar(mAccount, mAvatarFetchCallback);
194 }
195 } else {
196 updateSaveButton();
197 }
198 if (mAccount != null) {
199 updateAccountInformation(false);
200 }
201 }
202
203 @Override
204 public void onAccountUpdate() {
205 refreshUi();
206 }
207
208 private final UiCallback<Avatar> mAvatarFetchCallback = new UiCallback<Avatar>() {
209
210 @Override
211 public void userInputRequried(final PendingIntent pi, final Avatar avatar) {
212 finishInitialSetup(avatar);
213 }
214
215 @Override
216 public void success(final Avatar avatar) {
217 finishInitialSetup(avatar);
218 }
219
220 @Override
221 public void error(final int errorCode, final Avatar avatar) {
222 finishInitialSetup(avatar);
223 }
224 };
225 private final TextWatcher mTextWatcher = new TextWatcher() {
226
227 @Override
228 public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
229 updateSaveButton();
230 }
231
232 @Override
233 public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {
234 }
235
236 @Override
237 public void afterTextChanged(final Editable s) {
238
239 }
240 };
241
242 private final OnClickListener mAvatarClickListener = new OnClickListener() {
243 @Override
244 public void onClick(final View view) {
245 if (mAccount != null) {
246 final Intent intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class);
247 intent.putExtra("account", mAccount.getJid().toBareJid().toString());
248 startActivity(intent);
249 }
250 }
251 };
252
253 protected void finishInitialSetup(final Avatar avatar) {
254 runOnUiThread(new Runnable() {
255
256 @Override
257 public void run() {
258 final Intent intent;
259 if (avatar != null) {
260 intent = new Intent(getApplicationContext(),
261 StartConversationActivity.class);
262 if (xmppConnectionService != null && xmppConnectionService.getAccounts().size() == 1) {
263 intent.putExtra("init", true);
264 }
265 } else {
266 intent = new Intent(getApplicationContext(),
267 PublishProfilePictureActivity.class);
268 intent.putExtra("account", mAccount.getJid().toBareJid().toString());
269 intent.putExtra("setup", true);
270 }
271 startActivity(intent);
272 finish();
273 }
274 });
275 }
276
277 protected void updateSaveButton() {
278 if (accountInfoEdited() && !mInitMode) {
279 this.mSaveButton.setText(R.string.save);
280 this.mSaveButton.setEnabled(true);
281 this.mSaveButton.setTextColor(getPrimaryTextColor());
282 } else if (mAccount != null && (mAccount.getStatus() == Account.State.CONNECTING || mFetchingAvatar)) {
283 this.mSaveButton.setEnabled(false);
284 this.mSaveButton.setTextColor(getSecondaryTextColor());
285 this.mSaveButton.setText(R.string.account_status_connecting);
286 } else if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED && !mInitMode) {
287 this.mSaveButton.setEnabled(true);
288 this.mSaveButton.setTextColor(getPrimaryTextColor());
289 this.mSaveButton.setText(R.string.enable);
290 } else {
291 this.mSaveButton.setEnabled(true);
292 this.mSaveButton.setTextColor(getPrimaryTextColor());
293 if (!mInitMode) {
294 if (mAccount != null && mAccount.isOnlineAndConnected()) {
295 this.mSaveButton.setText(R.string.save);
296 if (!accountInfoEdited()) {
297 this.mSaveButton.setEnabled(false);
298 this.mSaveButton.setTextColor(getSecondaryTextColor());
299 }
300 } else {
301 this.mSaveButton.setText(R.string.connect);
302 }
303 } else {
304 this.mSaveButton.setText(R.string.next);
305 }
306 }
307 }
308
309 protected boolean accountInfoEdited() {
310 if (this.mAccount == null) {
311 return false;
312 }
313 final String unmodified;
314 if (Config.DOMAIN_LOCK != null) {
315 unmodified = this.mAccount.getJid().getLocalpart();
316 } else {
317 unmodified = this.mAccount.getJid().toBareJid().toString();
318 }
319 return !unmodified.equals(this.mAccountJid.getText().toString()) ||
320 !this.mAccount.getPassword().equals(this.mPassword.getText().toString());
321 }
322
323 @Override
324 protected String getShareableUri() {
325 if (mAccount != null) {
326 return mAccount.getShareableUri();
327 } else {
328 return "";
329 }
330 }
331
332 @Override
333 protected void onCreate(final Bundle savedInstanceState) {
334 super.onCreate(savedInstanceState);
335 setContentView(R.layout.activity_edit_account);
336 this.mAccountJid = (AutoCompleteTextView) findViewById(R.id.account_jid);
337 this.mAccountJid.addTextChangedListener(this.mTextWatcher);
338 this.mAccountJidLabel = (TextView) findViewById(R.id.account_jid_label);
339 if (Config.DOMAIN_LOCK != null) {
340 this.mAccountJidLabel.setText(R.string.username);
341 this.mAccountJid.setHint(R.string.username_hint);
342 }
343 this.mPassword = (EditText) findViewById(R.id.account_password);
344 this.mPassword.addTextChangedListener(this.mTextWatcher);
345 this.mPasswordConfirm = (EditText) findViewById(R.id.account_password_confirm);
346 this.mAvatar = (ImageView) findViewById(R.id.avater);
347 this.mAvatar.setOnClickListener(this.mAvatarClickListener);
348 this.mRegisterNew = (CheckBox) findViewById(R.id.account_register_new);
349 this.mStats = (LinearLayout) findViewById(R.id.stats);
350 this.mSessionEst = (TextView) findViewById(R.id.session_est);
351 this.mServerInfoRosterVersion = (TextView) findViewById(R.id.server_info_roster_version);
352 this.mServerInfoCarbons = (TextView) findViewById(R.id.server_info_carbons);
353 this.mServerInfoMam = (TextView) findViewById(R.id.server_info_mam);
354 this.mServerInfoCSI = (TextView) findViewById(R.id.server_info_csi);
355 this.mServerInfoBlocking = (TextView) findViewById(R.id.server_info_blocking);
356 this.mServerInfoSm = (TextView) findViewById(R.id.server_info_sm);
357 this.mServerInfoPep = (TextView) findViewById(R.id.server_info_pep);
358 this.mServerInfoHttpUpload = (TextView) findViewById(R.id.server_info_http_upload);
359 this.mOtrFingerprint = (TextView) findViewById(R.id.otr_fingerprint);
360 this.mOtrFingerprintBox = (RelativeLayout) findViewById(R.id.otr_fingerprint_box);
361 this.mOtrFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_to_clipboard);
362 this.mAxolotlFingerprint = (TextView) findViewById(R.id.axolotl_fingerprint);
363 this.mAxolotlFingerprintBox = (RelativeLayout) findViewById(R.id.axolotl_fingerprint_box);
364 this.mAxolotlFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_axolotl_to_clipboard);
365 this.mRegenerateAxolotlKeyButton = (ImageButton) findViewById(R.id.action_regenerate_axolotl_key);
366 this.keysCard = (LinearLayout) findViewById(R.id.other_device_keys_card);
367 this.keys = (LinearLayout) findViewById(R.id.other_device_keys);
368 this.mSaveButton = (Button) findViewById(R.id.save_button);
369 this.mCancelButton = (Button) findViewById(R.id.cancel_button);
370 this.mSaveButton.setOnClickListener(this.mSaveButtonClickListener);
371 this.mCancelButton.setOnClickListener(this.mCancelButtonClickListener);
372 this.mMoreTable = (TableLayout) findViewById(R.id.server_info_more);
373 final OnCheckedChangeListener OnCheckedShowConfirmPassword = new OnCheckedChangeListener() {
374 @Override
375 public void onCheckedChanged(final CompoundButton buttonView,
376 final boolean isChecked) {
377 if (isChecked) {
378 mPasswordConfirm.setVisibility(View.VISIBLE);
379 } else {
380 mPasswordConfirm.setVisibility(View.GONE);
381 }
382 updateSaveButton();
383 }
384 };
385 this.mRegisterNew.setOnCheckedChangeListener(OnCheckedShowConfirmPassword);
386 if (Config.DISALLOW_REGISTRATION_IN_UI) {
387 this.mRegisterNew.setVisibility(View.GONE);
388 }
389 }
390
391 @Override
392 public boolean onCreateOptionsMenu(final Menu menu) {
393 super.onCreateOptionsMenu(menu);
394 getMenuInflater().inflate(R.menu.editaccount, menu);
395 final MenuItem showQrCode = menu.findItem(R.id.action_show_qr_code);
396 final MenuItem showBlocklist = menu.findItem(R.id.action_show_block_list);
397 final MenuItem showMoreInfo = menu.findItem(R.id.action_server_info_show_more);
398 final MenuItem changePassword = menu.findItem(R.id.action_change_password_on_server);
399 final MenuItem clearDevices = menu.findItem(R.id.action_clear_devices);
400 final MenuItem renewCertificate = menu.findItem(R.id.action_renew_certificate);
401
402 renewCertificate.setVisible(mAccount != null && mAccount.getPrivateKeyAlias() != null);
403
404 if (mAccount != null && mAccount.isOnlineAndConnected()) {
405 if (!mAccount.getXmppConnection().getFeatures().blocking()) {
406 showBlocklist.setVisible(false);
407 }
408 if (!mAccount.getXmppConnection().getFeatures().register()) {
409 changePassword.setVisible(false);
410 }
411 Set<Integer> otherDevices = mAccount.getAxolotlService().getOwnDeviceIds();
412 if (otherDevices == null || otherDevices.isEmpty()) {
413 clearDevices.setVisible(false);
414 }
415 } else {
416 showQrCode.setVisible(false);
417 showBlocklist.setVisible(false);
418 showMoreInfo.setVisible(false);
419 changePassword.setVisible(false);
420 clearDevices.setVisible(false);
421 }
422 return true;
423 }
424
425 @Override
426 protected void onStart() {
427 super.onStart();
428 if (getIntent() != null) {
429 try {
430 this.jidToEdit = Jid.fromString(getIntent().getStringExtra("jid"));
431 } catch (final InvalidJidException | NullPointerException ignored) {
432 this.jidToEdit = null;
433 }
434 this.mInitMode = getIntent().getBooleanExtra("init", false) || this.jidToEdit == null;
435 this.messageFingerprint = getIntent().getStringExtra("fingerprint");
436 if (!mInitMode) {
437 this.mRegisterNew.setVisibility(View.GONE);
438 if (getActionBar() != null) {
439 getActionBar().setTitle(getString(R.string.account_details));
440 }
441 } else {
442 this.mAvatar.setVisibility(View.GONE);
443 if (getActionBar() != null) {
444 getActionBar().setTitle(R.string.action_add_account);
445 }
446 }
447 }
448 }
449
450 @Override
451 protected void onBackendConnected() {
452 if (this.jidToEdit != null) {
453 this.mAccount = xmppConnectionService.findAccountByJid(jidToEdit);
454 if (this.mAccount != null) {
455 if (this.mAccount.getPrivateKeyAlias() != null) {
456 this.mPassword.setHint(R.string.authenticate_with_certificate);
457 if (this.mInitMode) {
458 this.mPassword.requestFocus();
459 }
460 }
461 updateAccountInformation(true);
462 }
463 } else if (this.xmppConnectionService.getAccounts().size() == 0) {
464 if (getActionBar() != null) {
465 getActionBar().setDisplayHomeAsUpEnabled(false);
466 getActionBar().setDisplayShowHomeEnabled(false);
467 getActionBar().setHomeButtonEnabled(false);
468 }
469 this.mCancelButton.setEnabled(false);
470 this.mCancelButton.setTextColor(getSecondaryTextColor());
471 }
472 if (Config.DOMAIN_LOCK == null) {
473 final KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this,
474 android.R.layout.simple_list_item_1,
475 xmppConnectionService.getKnownHosts());
476 this.mAccountJid.setAdapter(mKnownHostsAdapter);
477 }
478 updateSaveButton();
479 invalidateOptionsMenu();
480 }
481
482 @Override
483 public boolean onOptionsItemSelected(final MenuItem item) {
484 switch (item.getItemId()) {
485 case R.id.action_show_block_list:
486 final Intent showBlocklistIntent = new Intent(this, BlocklistActivity.class);
487 showBlocklistIntent.putExtra("account", mAccount.getJid().toString());
488 startActivity(showBlocklistIntent);
489 break;
490 case R.id.action_server_info_show_more:
491 mMoreTable.setVisibility(item.isChecked() ? View.GONE : View.VISIBLE);
492 item.setChecked(!item.isChecked());
493 break;
494 case R.id.action_change_password_on_server:
495 final Intent changePasswordIntent = new Intent(this, ChangePasswordActivity.class);
496 changePasswordIntent.putExtra("account", mAccount.getJid().toString());
497 startActivity(changePasswordIntent);
498 break;
499 case R.id.action_clear_devices:
500 showWipePepDialog();
501 break;
502 case R.id.action_renew_certificate:
503 renewCertificate();
504 break;
505 }
506 return super.onOptionsItemSelected(item);
507 }
508
509 private void renewCertificate() {
510 KeyChain.choosePrivateKeyAlias(this, this, null, null, null, -1, null);
511 }
512
513 @Override
514 public void alias(String alias) {
515 if (alias != null) {
516 xmppConnectionService.updateKeyInAccount(mAccount, alias);
517 }
518 }
519
520 private void updateAccountInformation(boolean init) {
521 if (init) {
522 this.mAccountJid.getEditableText().clear();
523 if (Config.DOMAIN_LOCK != null) {
524 this.mAccountJid.getEditableText().append(this.mAccount.getJid().getLocalpart());
525 } else {
526 this.mAccountJid.getEditableText().append(this.mAccount.getJid().toBareJid().toString());
527 }
528 this.mPassword.setText(this.mAccount.getPassword());
529 }
530 if (!mInitMode) {
531 this.mAvatar.setVisibility(View.VISIBLE);
532 this.mAvatar.setImageBitmap(avatarService().get(this.mAccount, getPixel(72)));
533 }
534 if (this.mAccount.isOptionSet(Account.OPTION_REGISTER)) {
535 this.mRegisterNew.setVisibility(View.VISIBLE);
536 this.mRegisterNew.setChecked(true);
537 this.mPasswordConfirm.setText(this.mAccount.getPassword());
538 } else {
539 this.mRegisterNew.setVisibility(View.GONE);
540 this.mRegisterNew.setChecked(false);
541 }
542 if (this.mAccount.isOnlineAndConnected() && !this.mFetchingAvatar) {
543 this.mStats.setVisibility(View.VISIBLE);
544 this.mSessionEst.setText(UIHelper.readableTimeDifferenceFull(this, this.mAccount.getXmppConnection()
545 .getLastSessionEstablished()));
546 Features features = this.mAccount.getXmppConnection().getFeatures();
547 if (features.rosterVersioning()) {
548 this.mServerInfoRosterVersion.setText(R.string.server_info_available);
549 } else {
550 this.mServerInfoRosterVersion.setText(R.string.server_info_unavailable);
551 }
552 if (features.carbons()) {
553 this.mServerInfoCarbons.setText(R.string.server_info_available);
554 } else {
555 this.mServerInfoCarbons
556 .setText(R.string.server_info_unavailable);
557 }
558 if (features.mam()) {
559 this.mServerInfoMam.setText(R.string.server_info_available);
560 } else {
561 this.mServerInfoMam.setText(R.string.server_info_unavailable);
562 }
563 if (features.csi()) {
564 this.mServerInfoCSI.setText(R.string.server_info_available);
565 } else {
566 this.mServerInfoCSI.setText(R.string.server_info_unavailable);
567 }
568 if (features.blocking()) {
569 this.mServerInfoBlocking.setText(R.string.server_info_available);
570 } else {
571 this.mServerInfoBlocking.setText(R.string.server_info_unavailable);
572 }
573 if (features.sm()) {
574 this.mServerInfoSm.setText(R.string.server_info_available);
575 } else {
576 this.mServerInfoSm.setText(R.string.server_info_unavailable);
577 }
578 if (features.pep()) {
579 AxolotlService axolotlService = this.mAccount.getAxolotlService();
580 if (axolotlService != null && axolotlService.isPepBroken()) {
581 this.mServerInfoPep.setText(R.string.server_info_broken);
582 } else {
583 this.mServerInfoPep.setText(R.string.server_info_available);
584 }
585 } else {
586 this.mServerInfoPep.setText(R.string.server_info_unavailable);
587 }
588 if (features.httpUpload()) {
589 this.mServerInfoHttpUpload.setText(R.string.server_info_available);
590 } else {
591 this.mServerInfoHttpUpload.setText(R.string.server_info_unavailable);
592 }
593 final String otrFingerprint = this.mAccount.getOtrFingerprint();
594 if (otrFingerprint != null) {
595 this.mOtrFingerprintBox.setVisibility(View.VISIBLE);
596 this.mOtrFingerprint.setText(CryptoHelper.prettifyFingerprint(otrFingerprint));
597 this.mOtrFingerprintToClipboardButton
598 .setVisibility(View.VISIBLE);
599 this.mOtrFingerprintToClipboardButton
600 .setOnClickListener(new View.OnClickListener() {
601
602 @Override
603 public void onClick(final View v) {
604
605 if (copyTextToClipboard(otrFingerprint, R.string.otr_fingerprint)) {
606 Toast.makeText(
607 EditAccountActivity.this,
608 R.string.toast_message_otr_fingerprint,
609 Toast.LENGTH_SHORT).show();
610 }
611 }
612 });
613 } else {
614 this.mOtrFingerprintBox.setVisibility(View.GONE);
615 }
616 final String axolotlFingerprint = this.mAccount.getAxolotlService().getOwnFingerprint();
617 if (axolotlFingerprint != null) {
618 this.mAxolotlFingerprintBox.setVisibility(View.VISIBLE);
619 this.mAxolotlFingerprint.setText(CryptoHelper.prettifyFingerprint(axolotlFingerprint));
620 this.mAxolotlFingerprintToClipboardButton
621 .setVisibility(View.VISIBLE);
622 this.mAxolotlFingerprintToClipboardButton
623 .setOnClickListener(new View.OnClickListener() {
624
625 @Override
626 public void onClick(final View v) {
627
628 if (copyTextToClipboard(axolotlFingerprint, R.string.omemo_fingerprint)) {
629 Toast.makeText(
630 EditAccountActivity.this,
631 R.string.toast_message_omemo_fingerprint,
632 Toast.LENGTH_SHORT).show();
633 }
634 }
635 });
636 if (Config.SHOW_REGENERATE_AXOLOTL_KEYS_BUTTON) {
637 this.mRegenerateAxolotlKeyButton
638 .setVisibility(View.VISIBLE);
639 this.mRegenerateAxolotlKeyButton
640 .setOnClickListener(new View.OnClickListener() {
641
642 @Override
643 public void onClick(final View v) {
644 showRegenerateAxolotlKeyDialog();
645 }
646 });
647 }
648 } else {
649 this.mAxolotlFingerprintBox.setVisibility(View.GONE);
650 }
651 final String ownFingerprint = mAccount.getAxolotlService().getOwnFingerprint();
652 boolean hasKeys = false;
653 keys.removeAllViews();
654 for (final String fingerprint : mAccount.getAxolotlService().getFingerprintsForOwnSessions()) {
655 if (ownFingerprint.equals(fingerprint)) {
656 continue;
657 }
658 boolean highlight = fingerprint.equals(messageFingerprint);
659 hasKeys |= addFingerprintRow(keys, mAccount, fingerprint, highlight);
660 }
661 if (hasKeys) {
662 keysCard.setVisibility(View.VISIBLE);
663 } else {
664 keysCard.setVisibility(View.GONE);
665 }
666 } else {
667 if (this.mAccount.errorStatus()) {
668 this.mAccountJid.setError(getString(this.mAccount.getStatus().getReadableId()));
669 if (init || !accountInfoEdited()) {
670 this.mAccountJid.requestFocus();
671 }
672 } else {
673 this.mAccountJid.setError(null);
674 }
675 this.mStats.setVisibility(View.GONE);
676 }
677 }
678
679 public void showRegenerateAxolotlKeyDialog() {
680 Builder builder = new Builder(this);
681 builder.setTitle("Regenerate Key");
682 builder.setIconAttribute(android.R.attr.alertDialogIcon);
683 builder.setMessage("Are you sure you want to regenerate your Identity Key? (This will also wipe all established sessions and contact Identity Keys)");
684 builder.setNegativeButton(getString(R.string.cancel), null);
685 builder.setPositiveButton("Yes",
686 new DialogInterface.OnClickListener() {
687 @Override
688 public void onClick(DialogInterface dialog, int which) {
689 mAccount.getAxolotlService().regenerateKeys(false);
690 }
691 });
692 builder.create().show();
693 }
694
695 public void showWipePepDialog() {
696 Builder builder = new Builder(this);
697 builder.setTitle(getString(R.string.clear_other_devices));
698 builder.setIconAttribute(android.R.attr.alertDialogIcon);
699 builder.setMessage(getString(R.string.clear_other_devices_desc));
700 builder.setNegativeButton(getString(R.string.cancel), null);
701 builder.setPositiveButton(getString(R.string.accept),
702 new DialogInterface.OnClickListener() {
703 @Override
704 public void onClick(DialogInterface dialog, int which) {
705 mAccount.getAxolotlService().wipeOtherPepDevices();
706 }
707 });
708 builder.create().show();
709 }
710
711 @Override
712 public void onKeyStatusUpdated(AxolotlService.FetchStatus report) {
713 refreshUi();
714 }
715
716 @Override
717 public void onCaptchaRequested(final Account account, final String id, final Data data,
718 final Bitmap captcha) {
719 final AlertDialog.Builder builder = new AlertDialog.Builder(this);
720 final ImageView view = new ImageView(this);
721 final LinearLayout layout = new LinearLayout(this);
722 final EditText input = new EditText(this);
723
724 view.setImageBitmap(captcha);
725 view.setScaleType(ImageView.ScaleType.FIT_CENTER);
726
727 input.setHint(getString(R.string.captcha_hint));
728
729 layout.setOrientation(LinearLayout.VERTICAL);
730 layout.addView(view);
731 layout.addView(input);
732
733 builder.setTitle(getString(R.string.captcha_required));
734 builder.setView(layout);
735
736 builder.setPositiveButton(getString(R.string.ok),
737 new DialogInterface.OnClickListener() {
738 @Override
739 public void onClick(DialogInterface dialog, int which) {
740 String rc = input.getText().toString();
741 data.put("username", account.getUsername());
742 data.put("password", account.getPassword());
743 data.put("ocr", rc);
744 data.submit();
745
746 if (xmppConnectionServiceBound) {
747 xmppConnectionService.sendCreateAccountWithCaptchaPacket(
748 account, id, data);
749 }
750 }
751 });
752 builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
753 @Override
754 public void onClick(DialogInterface dialog, int which) {
755 if (xmppConnectionService != null) {
756 xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
757 }
758 }
759 });
760
761 builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
762 @Override
763 public void onCancel(DialogInterface dialog) {
764 if (xmppConnectionService != null) {
765 xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
766 }
767 }
768 });
769
770 runOnUiThread(new Runnable() {
771 @Override
772 public void run() {
773 if ((mCaptchaDialog != null) && mCaptchaDialog.isShowing()) {
774 mCaptchaDialog.dismiss();
775 }
776 mCaptchaDialog = builder.create();
777 mCaptchaDialog.show();
778 }
779 });
780 }
781
782 public void onShowErrorToast(final int resId) {
783 runOnUiThread(new Runnable() {
784 @Override
785 public void run() {
786 Toast.makeText(EditAccountActivity.this, resId, Toast.LENGTH_SHORT).show();
787 }
788 });
789 }
790}