1package eu.siacs.conversations.ui;
2
3import android.app.ActionBar;
4import android.app.AlertDialog;
5import android.app.AlertDialog.Builder;
6import android.app.PendingIntent;
7import android.content.ActivityNotFoundException;
8import android.content.DialogInterface;
9import android.content.Intent;
10import android.content.SharedPreferences;
11import android.graphics.Bitmap;
12import android.net.Uri;
13import android.os.Bundle;
14import android.provider.Settings;
15import android.security.KeyChain;
16import android.security.KeyChainAliasCallback;
17import android.text.Editable;
18import android.text.TextWatcher;
19import android.view.Menu;
20import android.view.MenuItem;
21import android.view.View;
22import android.view.View.OnClickListener;
23import android.widget.AutoCompleteTextView;
24import android.widget.Button;
25import android.widget.CheckBox;
26import android.widget.CompoundButton;
27import android.widget.CompoundButton.OnCheckedChangeListener;
28import android.widget.EditText;
29import android.widget.ImageButton;
30import android.widget.ImageView;
31import android.widget.LinearLayout;
32import android.widget.RelativeLayout;
33import android.widget.TableLayout;
34import android.widget.TableRow;
35import android.widget.TextView;
36import android.widget.Toast;
37
38import java.util.Arrays;
39import java.util.List;
40import java.util.Set;
41import java.util.concurrent.atomic.AtomicInteger;
42
43import eu.siacs.conversations.Config;
44import eu.siacs.conversations.R;
45import eu.siacs.conversations.crypto.axolotl.AxolotlService;
46import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
47import eu.siacs.conversations.entities.Account;
48import eu.siacs.conversations.services.BarcodeProvider;
49import eu.siacs.conversations.services.XmppConnectionService.OnCaptchaRequested;
50import eu.siacs.conversations.services.XmppConnectionService;
51import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
52import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
53import eu.siacs.conversations.utils.CryptoHelper;
54import eu.siacs.conversations.utils.UIHelper;
55import eu.siacs.conversations.utils.XmppUri;
56import eu.siacs.conversations.xml.Element;
57import eu.siacs.conversations.xmpp.OnKeyStatusUpdated;
58import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
59import eu.siacs.conversations.xmpp.XmppConnection;
60import eu.siacs.conversations.xmpp.XmppConnection.Features;
61import eu.siacs.conversations.xmpp.forms.Data;
62import eu.siacs.conversations.xmpp.jid.InvalidJidException;
63import eu.siacs.conversations.xmpp.jid.Jid;
64import eu.siacs.conversations.xmpp.pep.Avatar;
65
66public class EditAccountActivity extends OmemoActivity implements OnAccountUpdate, OnUpdateBlocklist,
67 OnKeyStatusUpdated, OnCaptchaRequested, KeyChainAliasCallback, XmppConnectionService.OnShowErrorToast, XmppConnectionService.OnMamPreferencesFetched {
68
69 private static final int REQUEST_DATA_SAVER = 0x37af244;
70 private AutoCompleteTextView mAccountJid;
71 private EditText mPassword;
72 private EditText mPasswordConfirm;
73 private CheckBox mRegisterNew;
74 private Button mCancelButton;
75 private Button mSaveButton;
76 private Button mDisableOsOptimizationsButton;
77 private TextView mDisableOsOptimizationsHeadline;
78 private TextView getmDisableOsOptimizationsBody;
79 private TableLayout mMoreTable;
80
81 private LinearLayout mStats;
82 private RelativeLayout mOsOptimizations;
83 private TextView mServerInfoSm;
84 private TextView mServerInfoRosterVersion;
85 private TextView mServerInfoCarbons;
86 private TextView mServerInfoMam;
87 private TextView mServerInfoCSI;
88 private TextView mServerInfoBlocking;
89 private TextView mServerInfoPep;
90 private TextView mServerInfoHttpUpload;
91 private TextView mServerInfoPush;
92 private TextView mSessionEst;
93 private TextView mOtrFingerprint;
94 private TextView mAxolotlFingerprint;
95 private TextView mOwnFingerprintDesc;
96 private TextView mAccountJidLabel;
97 private ImageView mAvatar;
98 private RelativeLayout mOtrFingerprintBox;
99 private RelativeLayout mAxolotlFingerprintBox;
100 private ImageButton mOtrFingerprintToClipboardButton;
101 private ImageButton mAxolotlFingerprintToClipboardButton;
102 private LinearLayout keys;
103 private LinearLayout keysCard;
104 private LinearLayout mNamePort;
105 private EditText mHostname;
106 private EditText mPort;
107 private AlertDialog mCaptchaDialog = null;
108
109 private Jid jidToEdit;
110 private boolean mInitMode = false;
111 private boolean mUsernameMode = Config.DOMAIN_LOCK != null;
112 private boolean mShowOptions = false;
113 private Account mAccount;
114 private String messageFingerprint;
115
116 private boolean mFetchingAvatar = false;
117
118 private final OnClickListener mSaveButtonClickListener = new OnClickListener() {
119
120 @Override
121 public void onClick(final View v) {
122 final String password = mPassword.getText().toString();
123 final String passwordConfirm = mPasswordConfirm.getText().toString();
124
125 if (!mInitMode && passwordChangedInMagicCreateMode()) {
126 gotoChangePassword(password);
127 return;
128 }
129 if (mInitMode && mAccount != null) {
130 mAccount.setOption(Account.OPTION_DISABLED, false);
131 }
132 if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED && !accountInfoEdited()) {
133 mAccount.setOption(Account.OPTION_DISABLED, false);
134 if (!xmppConnectionService.updateAccount(mAccount)) {
135 Toast.makeText(EditAccountActivity.this,R.string.unable_to_update_account,Toast.LENGTH_SHORT).show();
136 }
137 return;
138 }
139 final boolean registerNewAccount = mRegisterNew.isChecked() && !Config.DISALLOW_REGISTRATION_IN_UI;
140 if (mUsernameMode && mAccountJid.getText().toString().contains("@")) {
141 mAccountJid.setError(getString(R.string.invalid_username));
142 mAccountJid.requestFocus();
143 return;
144 }
145 final Jid jid;
146 try {
147 if (mUsernameMode) {
148 jid = Jid.fromParts(mAccountJid.getText().toString(), getUserModeDomain(), null);
149 } else {
150 jid = Jid.fromString(mAccountJid.getText().toString());
151 }
152 } catch (final InvalidJidException e) {
153 if (mUsernameMode) {
154 mAccountJid.setError(getString(R.string.invalid_username));
155 } else {
156 mAccountJid.setError(getString(R.string.invalid_jid));
157 }
158 mAccountJid.requestFocus();
159 return;
160 }
161 String hostname = null;
162 int numericPort = 5222;
163 if (mShowOptions) {
164 hostname = mHostname.getText().toString().replaceAll("\\s","");
165 final String port = mPort.getText().toString().replaceAll("\\s","");
166 if (hostname.contains(" ")) {
167 mHostname.setError(getString(R.string.not_valid_hostname));
168 mHostname.requestFocus();
169 return;
170 }
171 try {
172 numericPort = Integer.parseInt(port);
173 if (numericPort < 0 || numericPort > 65535) {
174 mPort.setError(getString(R.string.not_a_valid_port));
175 mPort.requestFocus();
176 return;
177 }
178
179 } catch (NumberFormatException e) {
180 mPort.setError(getString(R.string.not_a_valid_port));
181 mPort.requestFocus();
182 return;
183 }
184 }
185
186 if (jid.isDomainJid()) {
187 if (mUsernameMode) {
188 mAccountJid.setError(getString(R.string.invalid_username));
189 } else {
190 mAccountJid.setError(getString(R.string.invalid_jid));
191 }
192 mAccountJid.requestFocus();
193 return;
194 }
195 if (registerNewAccount) {
196 if (!password.equals(passwordConfirm)) {
197 mPasswordConfirm.setError(getString(R.string.passwords_do_not_match));
198 mPasswordConfirm.requestFocus();
199 return;
200 }
201 }
202 if (mAccount != null) {
203 if (mInitMode && mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE)) {
204 mAccount.setOption(Account.OPTION_MAGIC_CREATE, mAccount.getPassword().contains(password));
205 }
206 mAccount.setJid(jid);
207 mAccount.setPort(numericPort);
208 mAccount.setHostname(hostname);
209 mAccountJid.setError(null);
210 mPasswordConfirm.setError(null);
211 mAccount.setPassword(password);
212 mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
213 if (!xmppConnectionService.updateAccount(mAccount)) {
214 Toast.makeText(EditAccountActivity.this,R.string.unable_to_update_account,Toast.LENGTH_SHORT).show();
215 return;
216 }
217 } else {
218 if (xmppConnectionService.findAccountByJid(jid) != null) {
219 mAccountJid.setError(getString(R.string.account_already_exists));
220 mAccountJid.requestFocus();
221 return;
222 }
223 mAccount = new Account(jid.toBareJid(), password);
224 mAccount.setPort(numericPort);
225 mAccount.setHostname(hostname);
226 mAccount.setOption(Account.OPTION_USETLS, true);
227 mAccount.setOption(Account.OPTION_USECOMPRESSION, true);
228 mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
229 xmppConnectionService.createAccount(mAccount);
230 }
231 mHostname.setError(null);
232 mPort.setError(null);
233 if (!mAccount.isOptionSet(Account.OPTION_DISABLED)
234 && !registerNewAccount
235 && !mInitMode) {
236 finish();
237 } else {
238 updateSaveButton();
239 updateAccountInformation(true);
240 }
241
242 }
243 };
244 private final OnClickListener mCancelButtonClickListener = new OnClickListener() {
245
246 @Override
247 public void onClick(final View v) {
248 deleteMagicCreatedAccountAndReturnIfNecessary();
249 finish();
250 }
251 };
252 private Toast mFetchingMamPrefsToast;
253 private TableRow mPushRow;
254 private String mSavedInstanceAccount;
255 private boolean mSavedInstanceInit = false;
256 private Button mClearDevicesButton;
257
258 public void refreshUiReal() {
259 invalidateOptionsMenu();
260 if (mAccount != null
261 && mAccount.getStatus() != Account.State.ONLINE
262 && mFetchingAvatar) {
263 startActivity(new Intent(getApplicationContext(),
264 ManageAccountActivity.class));
265 finish();
266 } else if (mInitMode && mAccount != null && mAccount.getStatus() == Account.State.ONLINE) {
267 if (!mFetchingAvatar) {
268 mFetchingAvatar = true;
269 xmppConnectionService.checkForAvatar(mAccount, mAvatarFetchCallback);
270 }
271 }
272 if (mAccount != null) {
273 updateAccountInformation(false);
274 }
275 updateSaveButton();
276 }
277
278 @Override
279 public boolean onNavigateUp() {
280 deleteMagicCreatedAccountAndReturnIfNecessary();
281 return super.onNavigateUp();
282 }
283
284 @Override
285 public void onBackPressed() {
286 deleteMagicCreatedAccountAndReturnIfNecessary();
287 super.onBackPressed();
288 }
289
290 private void deleteMagicCreatedAccountAndReturnIfNecessary() {
291 if (Config.MAGIC_CREATE_DOMAIN != null
292 && mAccount != null
293 && mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE)
294 && mAccount.isOptionSet(Account.OPTION_REGISTER)
295 && xmppConnectionService.getAccounts().size() == 1) {
296 xmppConnectionService.deleteAccount(mAccount);
297 startActivity(new Intent(EditAccountActivity.this, WelcomeActivity.class));
298 }
299 }
300
301 @Override
302 public void onAccountUpdate() {
303 refreshUi();
304 }
305
306 private final UiCallback<Avatar> mAvatarFetchCallback = new UiCallback<Avatar>() {
307
308 @Override
309 public void userInputRequried(final PendingIntent pi, final Avatar avatar) {
310 finishInitialSetup(avatar);
311 }
312
313 @Override
314 public void success(final Avatar avatar) {
315 finishInitialSetup(avatar);
316 }
317
318 @Override
319 public void error(final int errorCode, final Avatar avatar) {
320 finishInitialSetup(avatar);
321 }
322 };
323 private final TextWatcher mTextWatcher = new TextWatcher() {
324
325 @Override
326 public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
327 updateSaveButton();
328 }
329
330 @Override
331 public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {
332 }
333
334 @Override
335 public void afterTextChanged(final Editable s) {
336
337 }
338 };
339
340 private final OnClickListener mAvatarClickListener = new OnClickListener() {
341 @Override
342 public void onClick(final View view) {
343 if (mAccount != null) {
344 final Intent intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class);
345 intent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toBareJid().toString());
346 startActivity(intent);
347 }
348 }
349 };
350
351 protected void finishInitialSetup(final Avatar avatar) {
352 runOnUiThread(new Runnable() {
353
354 @Override
355 public void run() {
356 hideKeyboard();
357 final Intent intent;
358 final XmppConnection connection = mAccount.getXmppConnection();
359 final boolean wasFirstAccount = xmppConnectionService != null && xmppConnectionService.getAccounts().size() == 1;
360 if (avatar != null || (connection != null && !connection.getFeatures().pep())) {
361 intent = new Intent(getApplicationContext(), StartConversationActivity.class);
362 if (wasFirstAccount) {
363 intent.putExtra("init", true);
364 }
365 } else {
366 intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class);
367 intent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toBareJid().toString());
368 intent.putExtra("setup", true);
369 }
370 if (wasFirstAccount) {
371 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
372 }
373 startActivity(intent);
374 finish();
375 }
376 });
377 }
378
379 @Override
380 public void onActivityResult(int requestCode, int resultCode, Intent data) {
381 super.onActivityResult(requestCode, resultCode, data);
382 if (requestCode == REQUEST_BATTERY_OP || requestCode == REQUEST_DATA_SAVER) {
383 updateAccountInformation(mAccount == null);
384 }
385 }
386
387 @Override
388 protected void processFingerprintVerification(XmppUri uri) {
389 if (mAccount != null && mAccount.getJid().toBareJid().equals(uri.getJid()) && uri.hasFingerprints()) {
390 if (xmppConnectionService.verifyFingerprints(mAccount,uri.getFingerprints())) {
391 Toast.makeText(this,R.string.verified_fingerprints,Toast.LENGTH_SHORT).show();
392 }
393 } else {
394 Toast.makeText(this,R.string.invalid_barcode,Toast.LENGTH_SHORT).show();
395 }
396 }
397
398 protected void updateSaveButton() {
399 boolean accountInfoEdited = accountInfoEdited();
400
401 if (!mInitMode && passwordChangedInMagicCreateMode()) {
402 this.mSaveButton.setText(R.string.change_password);
403 this.mSaveButton.setEnabled(true);
404 this.mSaveButton.setTextColor(getPrimaryTextColor());
405 } else if (accountInfoEdited && !mInitMode) {
406 this.mSaveButton.setText(R.string.save);
407 this.mSaveButton.setEnabled(true);
408 this.mSaveButton.setTextColor(getPrimaryTextColor());
409 } else if (mAccount != null
410 && (mAccount.getStatus() == Account.State.CONNECTING || mAccount.getStatus() == Account.State.REGISTRATION_SUCCESSFUL|| mFetchingAvatar)) {
411 this.mSaveButton.setEnabled(false);
412 this.mSaveButton.setTextColor(getSecondaryTextColor());
413 this.mSaveButton.setText(R.string.account_status_connecting);
414 } else if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED && !mInitMode) {
415 this.mSaveButton.setEnabled(true);
416 this.mSaveButton.setTextColor(getPrimaryTextColor());
417 this.mSaveButton.setText(R.string.enable);
418 } else {
419 this.mSaveButton.setEnabled(true);
420 this.mSaveButton.setTextColor(getPrimaryTextColor());
421 if (!mInitMode) {
422 if (mAccount != null && mAccount.isOnlineAndConnected()) {
423 this.mSaveButton.setText(R.string.save);
424 if (!accountInfoEdited) {
425 this.mSaveButton.setEnabled(false);
426 this.mSaveButton.setTextColor(getSecondaryTextColor());
427 }
428 } else {
429 this.mSaveButton.setText(R.string.connect);
430 }
431 } else {
432 this.mSaveButton.setText(R.string.next);
433 }
434 }
435 }
436
437 protected boolean accountInfoEdited() {
438 if (this.mAccount == null) {
439 return false;
440 }
441 return jidEdited() ||
442 !this.mAccount.getPassword().equals(this.mPassword.getText().toString()) ||
443 !this.mAccount.getHostname().equals(this.mHostname.getText().toString()) ||
444 !String.valueOf(this.mAccount.getPort()).equals(this.mPort.getText().toString());
445 }
446
447 protected boolean jidEdited() {
448 final String unmodified;
449 if (mUsernameMode) {
450 unmodified = this.mAccount.getJid().getLocalpart();
451 } else {
452 unmodified = this.mAccount.getJid().toBareJid().toString();
453 }
454 return !unmodified.equals(this.mAccountJid.getText().toString());
455 }
456
457 protected boolean passwordChangedInMagicCreateMode() {
458 return mAccount != null
459 && mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE)
460 && !this.mAccount.getPassword().equals(this.mPassword.getText().toString())
461 && !this.jidEdited()
462 && mAccount.isOnlineAndConnected();
463 }
464
465 @Override
466 protected String getShareableUri() {
467 if (mAccount != null) {
468 return mAccount.getShareableUri();
469 } else {
470 return "";
471 }
472 }
473
474 @Override
475 protected void onCreate(final Bundle savedInstanceState) {
476 super.onCreate(savedInstanceState);
477 if (savedInstanceState != null) {
478 this.mSavedInstanceAccount = savedInstanceState.getString("account");
479 this.mSavedInstanceInit = savedInstanceState.getBoolean("initMode", false);
480 }
481 setContentView(R.layout.activity_edit_account);
482 this.mAccountJid = (AutoCompleteTextView) findViewById(R.id.account_jid);
483 this.mAccountJid.addTextChangedListener(this.mTextWatcher);
484 this.mAccountJidLabel = (TextView) findViewById(R.id.account_jid_label);
485 this.mPassword = (EditText) findViewById(R.id.account_password);
486 this.mPassword.addTextChangedListener(this.mTextWatcher);
487 this.mPasswordConfirm = (EditText) findViewById(R.id.account_password_confirm);
488 this.mAvatar = (ImageView) findViewById(R.id.avater);
489 this.mAvatar.setOnClickListener(this.mAvatarClickListener);
490 this.mRegisterNew = (CheckBox) findViewById(R.id.account_register_new);
491 this.mStats = (LinearLayout) findViewById(R.id.stats);
492 this.mOsOptimizations = (RelativeLayout) findViewById(R.id.os_optimization);
493 this.mDisableOsOptimizationsButton = (Button) findViewById(R.id.os_optimization_disable);
494 this.mDisableOsOptimizationsHeadline = (TextView) findViewById(R.id.os_optimization_headline);
495 this.getmDisableOsOptimizationsBody = (TextView) findViewById(R.id.os_optimization_body);
496 this.mSessionEst = (TextView) findViewById(R.id.session_est);
497 this.mServerInfoRosterVersion = (TextView) findViewById(R.id.server_info_roster_version);
498 this.mServerInfoCarbons = (TextView) findViewById(R.id.server_info_carbons);
499 this.mServerInfoMam = (TextView) findViewById(R.id.server_info_mam);
500 this.mServerInfoCSI = (TextView) findViewById(R.id.server_info_csi);
501 this.mServerInfoBlocking = (TextView) findViewById(R.id.server_info_blocking);
502 this.mServerInfoSm = (TextView) findViewById(R.id.server_info_sm);
503 this.mServerInfoPep = (TextView) findViewById(R.id.server_info_pep);
504 this.mServerInfoHttpUpload = (TextView) findViewById(R.id.server_info_http_upload);
505 this.mPushRow = (TableRow) findViewById(R.id.push_row);
506 this.mServerInfoPush = (TextView) findViewById(R.id.server_info_push);
507 this.mOtrFingerprint = (TextView) findViewById(R.id.otr_fingerprint);
508 this.mOtrFingerprintBox = (RelativeLayout) findViewById(R.id.otr_fingerprint_box);
509 this.mOtrFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_to_clipboard);
510 this.mAxolotlFingerprint = (TextView) findViewById(R.id.axolotl_fingerprint);
511 this.mAxolotlFingerprintBox = (RelativeLayout) findViewById(R.id.axolotl_fingerprint_box);
512 this.mAxolotlFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_axolotl_to_clipboard);
513 this.mOwnFingerprintDesc = (TextView) findViewById(R.id.own_fingerprint_desc);
514 this.keysCard = (LinearLayout) findViewById(R.id.other_device_keys_card);
515 this.keys = (LinearLayout) findViewById(R.id.other_device_keys);
516 this.mNamePort = (LinearLayout) findViewById(R.id.name_port);
517 this.mHostname = (EditText) findViewById(R.id.hostname);
518 this.mHostname.addTextChangedListener(mTextWatcher);
519 this.mClearDevicesButton = (Button) findViewById(R.id.clear_devices);
520 this.mClearDevicesButton.setOnClickListener(new OnClickListener() {
521 @Override
522 public void onClick(View v) {
523 showWipePepDialog();
524 }
525 });
526 this.mPort = (EditText) findViewById(R.id.port);
527 this.mPort.setText("5222");
528 this.mPort.addTextChangedListener(mTextWatcher);
529 this.mSaveButton = (Button) findViewById(R.id.save_button);
530 this.mCancelButton = (Button) findViewById(R.id.cancel_button);
531 this.mSaveButton.setOnClickListener(this.mSaveButtonClickListener);
532 this.mCancelButton.setOnClickListener(this.mCancelButtonClickListener);
533 this.mMoreTable = (TableLayout) findViewById(R.id.server_info_more);
534 if (savedInstanceState != null && savedInstanceState.getBoolean("showMoreTable")) {
535 changeMoreTableVisibility(true);
536 }
537 final OnCheckedChangeListener OnCheckedShowConfirmPassword = new OnCheckedChangeListener() {
538 @Override
539 public void onCheckedChanged(final CompoundButton buttonView,
540 final boolean isChecked) {
541 if (isChecked) {
542 mPasswordConfirm.setVisibility(View.VISIBLE);
543 } else {
544 mPasswordConfirm.setVisibility(View.GONE);
545 }
546 updateSaveButton();
547 }
548 };
549 this.mRegisterNew.setOnCheckedChangeListener(OnCheckedShowConfirmPassword);
550 if (Config.DISALLOW_REGISTRATION_IN_UI) {
551 this.mRegisterNew.setVisibility(View.GONE);
552 }
553 }
554
555 @Override
556 public boolean onCreateOptionsMenu(final Menu menu) {
557 super.onCreateOptionsMenu(menu);
558 getMenuInflater().inflate(R.menu.editaccount, menu);
559 final MenuItem showQrCode = menu.findItem(R.id.action_show_qr_code);
560 final MenuItem showBlocklist = menu.findItem(R.id.action_show_block_list);
561 final MenuItem showMoreInfo = menu.findItem(R.id.action_server_info_show_more);
562 final MenuItem changePassword = menu.findItem(R.id.action_change_password_on_server);
563 final MenuItem showPassword = menu.findItem(R.id.action_show_password);
564 final MenuItem renewCertificate = menu.findItem(R.id.action_renew_certificate);
565 final MenuItem mamPrefs = menu.findItem(R.id.action_mam_prefs);
566 final MenuItem changePresence = menu.findItem(R.id.action_change_presence);
567 final MenuItem share = menu.findItem(R.id.action_share);
568 renewCertificate.setVisible(mAccount != null && mAccount.getPrivateKeyAlias() != null);
569
570 share.setVisible(mAccount != null && !mInitMode);
571
572 if (mAccount != null && mAccount.isOnlineAndConnected()) {
573 if (!mAccount.getXmppConnection().getFeatures().blocking()) {
574 showBlocklist.setVisible(false);
575 }
576
577 if (!mAccount.getXmppConnection().getFeatures().register()) {
578 changePassword.setVisible(false);
579 }
580 mamPrefs.setVisible(mAccount.getXmppConnection().getFeatures().mam());
581 changePresence.setVisible(manuallyChangePresence());
582 } else {
583 showQrCode.setVisible(false);
584 showBlocklist.setVisible(false);
585 showMoreInfo.setVisible(false);
586 changePassword.setVisible(false);
587 mamPrefs.setVisible(false);
588 changePresence.setVisible(false);
589 }
590
591 if (mAccount != null) {
592 showPassword.setVisible(mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE)
593 && !mAccount.isOptionSet(Account.OPTION_REGISTER));
594 } else {
595 showPassword.setVisible(false);
596 }
597 return super.onCreateOptionsMenu(menu);
598 }
599
600 @Override
601 public boolean onPrepareOptionsMenu(Menu menu) {
602 final MenuItem showMoreInfo = menu.findItem(R.id.action_server_info_show_more);
603 if (showMoreInfo.isVisible()) {
604 showMoreInfo.setChecked(mMoreTable.getVisibility() == View.VISIBLE);
605 }
606 return super.onPrepareOptionsMenu(menu);
607 }
608
609 @Override
610 protected void onStart() {
611 super.onStart();
612 final int theme = findTheme();
613 if (this.mTheme != theme) {
614 recreate();
615 } else if (getIntent() != null) {
616 try {
617 this.jidToEdit = Jid.fromString(getIntent().getStringExtra("jid"));
618 } catch (final InvalidJidException | NullPointerException ignored) {
619 this.jidToEdit = null;
620 }
621 boolean init = getIntent().getBooleanExtra("init", false);
622 this.mInitMode = init || this.jidToEdit == null;
623 this.messageFingerprint = getIntent().getStringExtra("fingerprint");
624 if (!mInitMode) {
625 this.mRegisterNew.setVisibility(View.GONE);
626 if (getActionBar() != null) {
627 getActionBar().setTitle(getString(R.string.account_details));
628 }
629 } else {
630 this.mAvatar.setVisibility(View.GONE);
631 ActionBar ab = getActionBar();
632 if (ab != null) {
633 if (init && Config.MAGIC_CREATE_DOMAIN == null) {
634 ab.setDisplayShowHomeEnabled(false);
635 ab.setDisplayHomeAsUpEnabled(false);
636 }
637 ab.setTitle(R.string.action_add_account);
638 }
639 }
640 }
641 SharedPreferences preferences = getPreferences();
642 boolean useTor = Config.FORCE_ORBOT || preferences.getBoolean("use_tor", false);
643 this.mShowOptions = useTor || preferences.getBoolean("show_connection_options", false);
644 mHostname.setHint(useTor ? R.string.hostname_or_onion : R.string.hostname_example);
645 this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
646 }
647
648 @Override
649 public void onSaveInstanceState(final Bundle savedInstanceState) {
650 if (mAccount != null) {
651 savedInstanceState.putString("account", mAccount.getJid().toBareJid().toString());
652 savedInstanceState.putBoolean("initMode", mInitMode);
653 savedInstanceState.putBoolean("showMoreTable", mMoreTable.getVisibility() == View.VISIBLE);
654 }
655 super.onSaveInstanceState(savedInstanceState);
656 }
657
658 protected void onBackendConnected() {
659 boolean init = true;
660 if (mSavedInstanceAccount != null) {
661 try {
662 this.mAccount = xmppConnectionService.findAccountByJid(Jid.fromString(mSavedInstanceAccount));
663 this.mInitMode = mSavedInstanceInit;
664 init = false;
665 } catch (InvalidJidException e) {
666 this.mAccount = null;
667 }
668
669 } else if (this.jidToEdit != null) {
670 this.mAccount = xmppConnectionService.findAccountByJid(jidToEdit);
671 }
672
673 if (mAccount != null) {
674 this.mInitMode |= this.mAccount.isOptionSet(Account.OPTION_REGISTER);
675 this.mUsernameMode |= mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) && mAccount.isOptionSet(Account.OPTION_REGISTER);
676 if (this.mAccount.getPrivateKeyAlias() != null) {
677 this.mPassword.setHint(R.string.authenticate_with_certificate);
678 if (this.mInitMode) {
679 this.mPassword.requestFocus();
680 }
681 }
682 if (mPendingFingerprintVerificationUri != null) {
683 processFingerprintVerification(mPendingFingerprintVerificationUri);
684 mPendingFingerprintVerificationUri = null;
685 }
686 updateAccountInformation(init);
687 }
688
689
690 if (Config.MAGIC_CREATE_DOMAIN == null && this.xmppConnectionService.getAccounts().size() == 0) {
691 this.mCancelButton.setEnabled(false);
692 this.mCancelButton.setTextColor(getSecondaryTextColor());
693 }
694 if (mUsernameMode) {
695 this.mAccountJidLabel.setText(R.string.username);
696 this.mAccountJid.setHint(R.string.username_hint);
697 } else {
698 final KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this,
699 R.layout.simple_list_item,
700 xmppConnectionService.getKnownHosts());
701 this.mAccountJid.setAdapter(mKnownHostsAdapter);
702 }
703 updateSaveButton();
704 invalidateOptionsMenu();
705 }
706
707 private String getUserModeDomain() {
708 if (mAccount != null) {
709 return mAccount.getJid().getDomainpart();
710 } else {
711 return Config.DOMAIN_LOCK;
712 }
713 }
714
715 @Override
716 public boolean onOptionsItemSelected(final MenuItem item) {
717 switch (item.getItemId()) {
718 case R.id.action_show_block_list:
719 final Intent showBlocklistIntent = new Intent(this, BlocklistActivity.class);
720 showBlocklistIntent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toString());
721 startActivity(showBlocklistIntent);
722 break;
723 case R.id.action_server_info_show_more:
724 changeMoreTableVisibility(!item.isChecked());
725 break;
726 case R.id.action_share_barcode:
727 shareBarcode();
728 break;
729 case R.id.action_share_http:
730 shareLink(true);
731 break;
732 case R.id.action_share_uri:
733 shareLink(false);
734 break;
735 case R.id.action_change_password_on_server:
736 gotoChangePassword(null);
737 break;
738 case R.id.action_mam_prefs:
739 editMamPrefs();
740 break;
741 case R.id.action_renew_certificate:
742 renewCertificate();
743 break;
744 case R.id.action_change_presence:
745 changePresence();
746 break;
747 case R.id.action_show_password:
748 showPassword();
749 break;
750 }
751 return super.onOptionsItemSelected(item);
752 }
753
754 private void shareLink(boolean http) {
755 Intent intent = new Intent(Intent.ACTION_SEND);
756 intent.setType("text/plain");
757 String text;
758 if (http) {
759 text = mAccount.getShareableLink();
760 } else {
761 text = mAccount.getShareableUri();
762 }
763 intent.putExtra(Intent.EXTRA_TEXT,text);
764 startActivity(Intent.createChooser(intent, getText(R.string.share_with)));
765 }
766
767 private void shareBarcode() {
768 Intent intent = new Intent(Intent.ACTION_SEND);
769 intent.putExtra(Intent.EXTRA_STREAM,BarcodeProvider.getUriForAccount(this,mAccount));
770 intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
771 intent.setType("image/png");
772 startActivity(Intent.createChooser(intent, getText(R.string.share_with)));
773 }
774
775 private void changeMoreTableVisibility(boolean visible) {
776 mMoreTable.setVisibility(visible ? View.VISIBLE : View.GONE);
777 }
778
779 private void gotoChangePassword(String newPassword) {
780 final Intent changePasswordIntent = new Intent(this, ChangePasswordActivity.class);
781 changePasswordIntent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toString());
782 if (newPassword != null) {
783 changePasswordIntent.putExtra("password", newPassword);
784 }
785 startActivity(changePasswordIntent);
786 }
787
788 private void renewCertificate() {
789 KeyChain.choosePrivateKeyAlias(this, this, null, null, null, -1, null);
790 }
791
792 private void changePresence() {
793 Intent intent = new Intent(this, SetPresenceActivity.class);
794 intent.putExtra(SetPresenceActivity.EXTRA_ACCOUNT,mAccount.getJid().toBareJid().toString());
795 startActivity(intent);
796 }
797
798 @Override
799 public void alias(String alias) {
800 if (alias != null) {
801 xmppConnectionService.updateKeyInAccount(mAccount, alias);
802 }
803 }
804
805 private void updateAccountInformation(boolean init) {
806 if (init) {
807 this.mAccountJid.getEditableText().clear();
808 if (mUsernameMode) {
809 this.mAccountJid.getEditableText().append(this.mAccount.getJid().getLocalpart());
810 } else {
811 this.mAccountJid.getEditableText().append(this.mAccount.getJid().toBareJid().toString());
812 }
813 this.mPassword.setText(this.mAccount.getPassword());
814 this.mHostname.setText("");
815 this.mHostname.getEditableText().append(this.mAccount.getHostname());
816 this.mPort.setText("");
817 this.mPort.getEditableText().append(String.valueOf(this.mAccount.getPort()));
818 this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
819
820 }
821
822 if (!mInitMode) {
823 this.mAvatar.setVisibility(View.VISIBLE);
824 this.mAvatar.setImageBitmap(avatarService().get(this.mAccount, getPixel(72)));
825 } else {
826 this.mAvatar.setVisibility(View.GONE);
827 }
828 if (this.mAccount.isOptionSet(Account.OPTION_REGISTER)) {
829 this.mRegisterNew.setVisibility(View.VISIBLE);
830 this.mRegisterNew.setChecked(true);
831 this.mPasswordConfirm.setText(this.mAccount.getPassword());
832 } else {
833 this.mRegisterNew.setVisibility(View.GONE);
834 this.mRegisterNew.setChecked(false);
835 }
836 if (this.mAccount.isOnlineAndConnected() && !this.mFetchingAvatar) {
837 Features features = this.mAccount.getXmppConnection().getFeatures();
838 this.mStats.setVisibility(View.VISIBLE);
839 boolean showBatteryWarning = !xmppConnectionService.getPushManagementService().availableAndUseful(mAccount) && isOptimizingBattery();
840 boolean showDataSaverWarning = isAffectedByDataSaver();
841 showOsOptimizationWarning(showBatteryWarning,showDataSaverWarning);
842 this.mSessionEst.setText(UIHelper.readableTimeDifferenceFull(this, this.mAccount.getXmppConnection()
843 .getLastSessionEstablished()));
844 if (features.rosterVersioning()) {
845 this.mServerInfoRosterVersion.setText(R.string.server_info_available);
846 } else {
847 this.mServerInfoRosterVersion.setText(R.string.server_info_unavailable);
848 }
849 if (features.carbons()) {
850 this.mServerInfoCarbons.setText(R.string.server_info_available);
851 } else {
852 this.mServerInfoCarbons
853 .setText(R.string.server_info_unavailable);
854 }
855 if (features.mam()) {
856 this.mServerInfoMam.setText(R.string.server_info_available);
857 } else {
858 this.mServerInfoMam.setText(R.string.server_info_unavailable);
859 }
860 if (features.csi()) {
861 this.mServerInfoCSI.setText(R.string.server_info_available);
862 } else {
863 this.mServerInfoCSI.setText(R.string.server_info_unavailable);
864 }
865 if (features.blocking()) {
866 this.mServerInfoBlocking.setText(R.string.server_info_available);
867 } else {
868 this.mServerInfoBlocking.setText(R.string.server_info_unavailable);
869 }
870 if (features.sm()) {
871 this.mServerInfoSm.setText(R.string.server_info_available);
872 } else {
873 this.mServerInfoSm.setText(R.string.server_info_unavailable);
874 }
875 if (features.pep()) {
876 AxolotlService axolotlService = this.mAccount.getAxolotlService();
877 if (axolotlService != null && axolotlService.isPepBroken()) {
878 this.mServerInfoPep.setText(R.string.server_info_broken);
879 } else {
880 this.mServerInfoPep.setText(R.string.server_info_available);
881 }
882 } else {
883 this.mServerInfoPep.setText(R.string.server_info_unavailable);
884 }
885 if (features.httpUpload(0)) {
886 this.mServerInfoHttpUpload.setText(R.string.server_info_available);
887 } else {
888 this.mServerInfoHttpUpload.setText(R.string.server_info_unavailable);
889 }
890
891 this.mPushRow.setVisibility(xmppConnectionService.getPushManagementService().isStub() ? View.GONE : View.VISIBLE);
892
893 if (xmppConnectionService.getPushManagementService().available(mAccount)) {
894 this.mServerInfoPush.setText(R.string.server_info_available);
895 } else {
896 this.mServerInfoPush.setText(R.string.server_info_unavailable);
897 }
898 final String otrFingerprint = this.mAccount.getOtrFingerprint();
899 if (otrFingerprint != null && Config.supportOtr()) {
900 this.mOtrFingerprintBox.setVisibility(View.VISIBLE);
901 this.mOtrFingerprint.setText(CryptoHelper.prettifyFingerprint(otrFingerprint));
902 this.mOtrFingerprintToClipboardButton
903 .setVisibility(View.VISIBLE);
904 this.mOtrFingerprintToClipboardButton
905 .setOnClickListener(new View.OnClickListener() {
906
907 @Override
908 public void onClick(final View v) {
909
910 if (copyTextToClipboard(CryptoHelper.prettifyFingerprint(otrFingerprint), R.string.otr_fingerprint)) {
911 Toast.makeText(
912 EditAccountActivity.this,
913 R.string.toast_message_otr_fingerprint,
914 Toast.LENGTH_SHORT).show();
915 }
916 }
917 });
918 } else {
919 this.mOtrFingerprintBox.setVisibility(View.GONE);
920 }
921 final String ownAxolotlFingerprint = this.mAccount.getAxolotlService().getOwnFingerprint();
922 if (ownAxolotlFingerprint != null && Config.supportOmemo()) {
923 this.mAxolotlFingerprintBox.setVisibility(View.VISIBLE);
924 if (ownAxolotlFingerprint.equals(messageFingerprint)) {
925 this.mOwnFingerprintDesc.setTextColor(getResources().getColor(R.color.accent));
926 } else {
927 this.mOwnFingerprintDesc.setTextColor(getSecondaryTextColor());
928 }
929 this.mAxolotlFingerprint.setText(CryptoHelper.prettifyFingerprint(ownAxolotlFingerprint.substring(2)));
930 this.mAxolotlFingerprintToClipboardButton
931 .setVisibility(View.VISIBLE);
932 this.mAxolotlFingerprintToClipboardButton
933 .setOnClickListener(new View.OnClickListener() {
934
935 @Override
936 public void onClick(final View v) {
937 copyOmemoFingerprint(ownAxolotlFingerprint);
938 }
939 });
940 } else {
941 this.mAxolotlFingerprintBox.setVisibility(View.GONE);
942 }
943 boolean hasKeys = false;
944 keys.removeAllViews();
945 for(XmppAxolotlSession session : mAccount.getAxolotlService().findOwnSessions()) {
946 if (!session.getTrust().isCompromised()) {
947 boolean highlight = session.getFingerprint().equals(messageFingerprint);
948 addFingerprintRow(keys,session,highlight);
949 hasKeys = true;
950 }
951 }
952 if (hasKeys && Config.supportOmemo()) {
953 keysCard.setVisibility(View.VISIBLE);
954 Set<Integer> otherDevices = mAccount.getAxolotlService().getOwnDeviceIds();
955 if (otherDevices == null || otherDevices.isEmpty()) {
956 mClearDevicesButton.setVisibility(View.GONE);
957 } else {
958 mClearDevicesButton.setVisibility(View.VISIBLE);
959 }
960 } else {
961 keysCard.setVisibility(View.GONE);
962 }
963 } else {
964 if (this.mAccount.errorStatus()) {
965 final EditText errorTextField;
966 if (this.mAccount.getStatus() == Account.State.UNAUTHORIZED) {
967 errorTextField = this.mPassword;
968 } else if (mShowOptions
969 && this.mAccount.getStatus() == Account.State.SERVER_NOT_FOUND
970 && this.mHostname.getText().length() > 0) {
971 errorTextField = this.mHostname;
972 } else {
973 errorTextField = this.mAccountJid;
974 }
975 errorTextField.setError(getString(this.mAccount.getStatus().getReadableId()));
976 if (init || !accountInfoEdited()) {
977 errorTextField.requestFocus();
978 }
979 } else {
980 this.mAccountJid.setError(null);
981 this.mPassword.setError(null);
982 this.mHostname.setError(null);
983 }
984 this.mStats.setVisibility(View.GONE);
985 }
986 }
987
988 private void showOsOptimizationWarning(boolean showBatteryWarning, boolean showDataSaverWarning) {
989 this.mOsOptimizations.setVisibility(showBatteryWarning || showDataSaverWarning ? View.VISIBLE : View.GONE);
990 if (showDataSaverWarning) {
991 this.mDisableOsOptimizationsHeadline.setText(R.string.data_saver_enabled);
992 this.getmDisableOsOptimizationsBody.setText(R.string.data_saver_enabled_explained);
993 this.mDisableOsOptimizationsButton.setText(R.string.allow);
994 this.mDisableOsOptimizationsButton.setOnClickListener(new OnClickListener() {
995 @Override
996 public void onClick(View v) {
997 Intent intent = new Intent(Settings.ACTION_IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS);
998 Uri uri = Uri.parse("package:"+getPackageName());
999 intent.setData(uri);
1000 try {
1001 startActivityForResult(intent, REQUEST_DATA_SAVER);
1002 } catch (ActivityNotFoundException e) {
1003 Toast.makeText(EditAccountActivity.this, R.string.device_does_not_support_data_saver, Toast.LENGTH_SHORT).show();
1004 }
1005 }
1006 });
1007 } else if (showBatteryWarning) {
1008 this.mDisableOsOptimizationsButton.setText(R.string.disable);
1009 this.mDisableOsOptimizationsHeadline.setText(R.string.battery_optimizations_enabled);
1010 this.getmDisableOsOptimizationsBody.setText(R.string.battery_optimizations_enabled_explained);
1011 this.mDisableOsOptimizationsButton.setOnClickListener(new OnClickListener() {
1012 @Override
1013 public void onClick(View v) {
1014 Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
1015 Uri uri = Uri.parse("package:"+getPackageName());
1016 intent.setData(uri);
1017 try {
1018 startActivityForResult(intent, REQUEST_BATTERY_OP);
1019 } catch (ActivityNotFoundException e) {
1020 Toast.makeText(EditAccountActivity.this, R.string.device_does_not_support_battery_op, Toast.LENGTH_SHORT).show();
1021 }
1022 }
1023 });
1024 }
1025 }
1026
1027 public void showWipePepDialog() {
1028 Builder builder = new Builder(this);
1029 builder.setTitle(getString(R.string.clear_other_devices));
1030 builder.setIconAttribute(android.R.attr.alertDialogIcon);
1031 builder.setMessage(getString(R.string.clear_other_devices_desc));
1032 builder.setNegativeButton(getString(R.string.cancel), null);
1033 builder.setPositiveButton(getString(R.string.accept),
1034 new DialogInterface.OnClickListener() {
1035 @Override
1036 public void onClick(DialogInterface dialog, int which) {
1037 mAccount.getAxolotlService().wipeOtherPepDevices();
1038 }
1039 });
1040 builder.create().show();
1041 }
1042
1043 private void editMamPrefs() {
1044 this.mFetchingMamPrefsToast = Toast.makeText(this, R.string.fetching_mam_prefs, Toast.LENGTH_LONG);
1045 this.mFetchingMamPrefsToast.show();
1046 xmppConnectionService.fetchMamPreferences(mAccount, this);
1047 }
1048
1049 private void showPassword() {
1050 AlertDialog.Builder builder = new AlertDialog.Builder(this);
1051 View view = getLayoutInflater().inflate(R.layout.dialog_show_password, null);
1052 TextView password = (TextView) view.findViewById(R.id.password);
1053 password.setText(mAccount.getPassword());
1054 builder.setTitle(R.string.password);
1055 builder.setView(view);
1056 builder.setPositiveButton(R.string.cancel, null);
1057 builder.create().show();
1058 }
1059
1060 @Override
1061 public void onKeyStatusUpdated(AxolotlService.FetchStatus report) {
1062 refreshUi();
1063 }
1064
1065 @Override
1066 public void onCaptchaRequested(final Account account, final String id, final Data data, final Bitmap captcha) {
1067 runOnUiThread(new Runnable() {
1068 @Override
1069 public void run() {
1070 if ((mCaptchaDialog != null) && mCaptchaDialog.isShowing()) {
1071 mCaptchaDialog.dismiss();
1072 }
1073 final AlertDialog.Builder builder = new AlertDialog.Builder(EditAccountActivity.this);
1074 final View view = getLayoutInflater().inflate(R.layout.captcha, null);
1075 final ImageView imageView = (ImageView) view.findViewById(R.id.captcha);
1076 final EditText input = (EditText) view.findViewById(R.id.input);
1077 imageView.setImageBitmap(captcha);
1078
1079 builder.setTitle(getString(R.string.captcha_required));
1080 builder.setView(view);
1081
1082 builder.setPositiveButton(getString(R.string.ok),
1083 new DialogInterface.OnClickListener() {
1084 @Override
1085 public void onClick(DialogInterface dialog, int which) {
1086 String rc = input.getText().toString();
1087 data.put("username", account.getUsername());
1088 data.put("password", account.getPassword());
1089 data.put("ocr", rc);
1090 data.submit();
1091
1092 if (xmppConnectionServiceBound) {
1093 xmppConnectionService.sendCreateAccountWithCaptchaPacket(
1094 account, id, data);
1095 }
1096 }
1097 });
1098 builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
1099 @Override
1100 public void onClick(DialogInterface dialog, int which) {
1101 if (xmppConnectionService != null) {
1102 xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
1103 }
1104 }
1105 });
1106
1107 builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
1108 @Override
1109 public void onCancel(DialogInterface dialog) {
1110 if (xmppConnectionService != null) {
1111 xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
1112 }
1113 }
1114 });
1115 mCaptchaDialog = builder.create();
1116 mCaptchaDialog.show();
1117 }
1118 });
1119 }
1120
1121 public void onShowErrorToast(final int resId) {
1122 runOnUiThread(new Runnable() {
1123 @Override
1124 public void run() {
1125 Toast.makeText(EditAccountActivity.this, resId, Toast.LENGTH_SHORT).show();
1126 }
1127 });
1128 }
1129
1130 @Override
1131 public void onPreferencesFetched(final Element prefs) {
1132 runOnUiThread(new Runnable() {
1133 @Override
1134 public void run() {
1135 if (mFetchingMamPrefsToast != null) {
1136 mFetchingMamPrefsToast.cancel();
1137 }
1138 AlertDialog.Builder builder = new Builder(EditAccountActivity.this);
1139 builder.setTitle(R.string.server_side_mam_prefs);
1140 String defaultAttr = prefs.getAttribute("default");
1141 final List<String> defaults = Arrays.asList("never", "roster", "always");
1142 final AtomicInteger choice = new AtomicInteger(Math.max(0,defaults.indexOf(defaultAttr)));
1143 builder.setSingleChoiceItems(R.array.mam_prefs, choice.get(), new DialogInterface.OnClickListener() {
1144 @Override
1145 public void onClick(DialogInterface dialog, int which) {
1146 choice.set(which);
1147 }
1148 });
1149 builder.setNegativeButton(R.string.cancel, null);
1150 builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
1151 @Override
1152 public void onClick(DialogInterface dialog, int which) {
1153 prefs.setAttribute("default",defaults.get(choice.get()));
1154 xmppConnectionService.pushMamPreferences(mAccount, prefs);
1155 }
1156 });
1157 builder.create().show();
1158 }
1159 });
1160 }
1161
1162 @Override
1163 public void onPreferencesFetchFailed() {
1164 runOnUiThread(new Runnable() {
1165 @Override
1166 public void run() {
1167 if (mFetchingMamPrefsToast != null) {
1168 mFetchingMamPrefsToast.cancel();
1169 }
1170 Toast.makeText(EditAccountActivity.this,R.string.unable_to_fetch_mam_prefs,Toast.LENGTH_LONG).show();
1171 }
1172 });
1173 }
1174
1175 @Override
1176 public void OnUpdateBlocklist(Status status) {
1177 refreshUi();
1178 }
1179}