/** Disconnect and connect using new network. */ public void forceReconnect() { AccountManager accountManager = AccountManager.getInstance(); for (String account : accountManager.getAccounts()) { accountManager.getAccount(account).forceReconnect(); AccountManager.getInstance().onAccountChanged(account); } }
private void setStatus(StatusMode statusMode, String statusText) { AccountManager accountManager = AccountManager.getInstance(); if (account != null) accountManager.setStatus(account, statusMode, statusText); else { accountManager.setStatus(statusMode, statusText); } }
public void setArchiveMode(String account, ArchiveMode archiveMode) { AccountItem accountItem = AccountManager.getInstance().getAccount(account); AccountManager.getInstance() .updateAccount( account, accountItem.getConnectionSettings().isCustom(), accountItem.getConnectionSettings().getHost(), accountItem.getConnectionSettings().getPort(), accountItem.getConnectionSettings().getServerName(), accountItem.getConnectionSettings().getUserName(), accountItem.isStorePassword(), accountItem.getConnectionSettings().getPassword(), accountItem.getConnectionSettings().getResource(), accountItem.getPriority(), accountItem.isEnabled(), accountItem.getConnectionSettings().isSaslEnabled(), accountItem.getConnectionSettings().getTlsMode(), accountItem.getConnectionSettings().useCompression(), accountItem.getConnectionSettings().getProxyType(), accountItem.getConnectionSettings().getProxyHost(), accountItem.getConnectionSettings().getProxyPort(), accountItem.getConnectionSettings().getProxyUser(), accountItem.getConnectionSettings().getProxyPassword(), accountItem.isSyncable(), archiveMode); }
/** * Update connection state. * * <p>Start connections in waiting states and stop invalidated connections. * * @param userRequest */ public void updateConnections(boolean userRequest) { AccountManager accountManager = AccountManager.getInstance(); for (String account : accountManager.getAccounts()) { if (accountManager.getAccount(account).updateConnection(userRequest)) AccountManager.getInstance().onAccountChanged(account); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (isFinishing()) return; actionWithItem = null; setContentView(R.layout.status_editor); Intent intent = getIntent(); account = StatusEditor.getAccount(intent); if (account == null) setTitle(getString(R.string.status_editor)); else setTitle( getString( R.string.status_editor_for, AccountManager.getInstance().getVerboseName(account))); ListView listView = getListView(); LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); View header = inflater.inflate(R.layout.status_editor_header, listView, false); listView.addHeaderView(header, null, false); listView.setOnItemClickListener(this); registerForContextMenu(listView); setListAdapter(new StatusEditorAdapter(this)); statusTextView = (EditText) header.findViewById(R.id.status_text); statusModeView = (Spinner) header.findViewById(R.id.status_mode); statusModeView.setAdapter(new StatusModeAdapter(this)); ((Button) findViewById(R.id.ok)).setOnClickListener(this); StatusMode statusMode; String statusText; if (savedInstanceState == null) { if (account == null) { statusMode = SettingsManager.statusMode(); statusText = SettingsManager.statusText(); } else { AccountItem accountItem = AccountManager.getInstance().getAccount(account); if (accountItem == null) { Application.getInstance().onError(R.string.NO_SUCH_ACCOUNT); finish(); return; } statusMode = accountItem.getFactualStatusMode(); statusText = accountItem.getStatusText(); } } else { statusMode = StatusMode.valueOf(savedInstanceState.getString(SAVED_MODE)); statusText = savedInstanceState.getString(SAVED_TEXT); } showStatus(statusMode, statusText); }
/** * Open chat with specified contact. * * <p>Show dialog to choose account if necessary. * * @param user * @param text can be <code>null</code>. */ private void openChat(String user, String text) { String bareAddress = Jid.getBareAddress(user); ArrayList<BaseEntity> entities = new ArrayList<>(); for (AbstractChat check : MessageManager.getInstance().getChats()) { if (check.isActive() && check.getUser().equals(bareAddress)) { entities.add(check); } } if (entities.size() == 1) { openChat(entities.get(0), text); return; } entities.clear(); for (RosterContact check : RosterManager.getInstance().getContacts()) { if (check.isEnabled() && check.getUser().equals(bareAddress)) { entities.add(check); } } if (entities.size() == 1) { openChat(entities.get(0), text); return; } Collection<String> accounts = AccountManager.getInstance().getAccounts(); if (accounts.isEmpty()) { return; } if (accounts.size() == 1) { openChat(new BaseEntity(accounts.iterator().next(), bareAddress), text); return; } AccountChooseDialogFragment.newInstance(bareAddress, text) .show(getFragmentManager(), "OPEN_WITH_ACCOUNT"); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (isFinishing()) return; setContentView(R.layout.fingerprint_viewer); integrator = new IntentIntegrator(this); Intent intent = getIntent(); account = getAccount(intent); user = getUser(intent); if (AccountManager.getInstance().getAccount(account) == null || user == null) { Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND); finish(); return; } if (savedInstanceState != null) { remoteFingerprint = savedInstanceState.getString(SAVED_REMOTE_FINGERPRINT); localFingerprint = savedInstanceState.getString(SAVED_LOCAL_FINGERPRINT); } else { remoteFingerprint = OTRManager.getInstance().getRemoteFingerprint(account, user); localFingerprint = OTRManager.getInstance().getLocalFingerprint(account); } verifiedView = (CheckBox) findViewById(R.id.verified); verifiedView.setOnCheckedChangeListener(this); scanView = findViewById(R.id.scan); scanView.setOnClickListener(this); showView = findViewById(R.id.show); showView.setOnClickListener(this); copyView = findViewById(R.id.copy); copyView.setOnClickListener(this); isUpdating = false; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); findViewById(android.R.id.button3).setVisibility(View.GONE); View layout = getLayoutInflater().inflate(R.layout.password_request, null); passwordView = (EditText) layout.findViewById(R.id.account_password); storePasswordView = (CheckBox) layout.findViewById(R.id.store_password); account = getAccount(getIntent()); if (AccountManager.getInstance().getAccount(account) == null) { Application.getInstance().onError(R.string.NO_SUCH_ACCOUNT); finish(); return; } setDialogTitle(AccountManager.getInstance().getVerboseName(account)); setCustomView(layout, true); }
@Override public void onAccept() { super.onAccept(); AccountManager.getInstance() .setPassword(account, storePasswordView.isChecked(), passwordView.getText().toString()); finish(); }
private void onFormReceived( String account, String from, String bareAddress, String session, Feature feature) { OtrMode otrMode = getOtrMode(account, bareAddress, session); boolean cancel = false; Collection<DisclosureValue> disclosureValues = feature.getDisclosureOptions(); DisclosureValue disclosureValue = DisclosureValue.never; if (disclosureValues == null) disclosureValue = null; else if (!disclosureValues.contains(disclosureValue)) cancel = true; Collection<SecurityValue> securityValues = feature.getSecurityOptions(); SecurityValue securityValue; if (AccountManager.getInstance().getAccount(account).getConnectionSettings().getTlsMode() == TLSMode.required) securityValue = SecurityValue.c2s; else securityValue = SecurityValue.none; if (securityValues == null) securityValue = null; else if (!securityValues.contains(securityValue)) cancel = true; Collection<LoggingValue> loggingValues = feature.getLoggingOptions(); LoggingValue loggingValue; if (loggingValues == null) loggingValue = null; else { loggingValue = otrMode.selectLoggingValue(loggingValues); if (loggingValue == null) cancel = true; } if (cancel) { DataForm dataForm = Feature.createDataForm(DataFormType.submit); if (feature.getAcceptValue() != null) { Feature.addAcceptField(dataForm, false); sessionStates.remove(account, session); } else { Feature.addRenegotiateField(dataForm, false); } sendFeature(account, from, session, new Feature(dataForm)); return; } DataForm dataForm = Feature.createDataForm(DataFormType.submit); if (feature.getAcceptValue() != null) Feature.addAcceptField(dataForm, true); else Feature.addRenegotiateField(dataForm, true); if (disclosureValue != null) Feature.addDisclosureField(dataForm, null, disclosureValue); if (securityValue != null) Feature.addSecurityField(dataForm, null, securityValue); if (loggingValue != null) { try { if (loggingValue == LoggingValue.mustnot) MessageArchiveManager.getInstance().setSaveMode(account, from, session, SaveMode.fls); else MessageArchiveManager.getInstance().setSaveMode(account, from, session, SaveMode.body); } catch (NetworkException e) { } Feature.addLoggingField(dataForm, null, loggingValue); } sessionStates.put(account, session, SessionState.active); sendFeature(account, from, session, new Feature(dataForm)); }
@Override protected void onInflate(Bundle savedInstanceState) { setContentView(R.layout.contact_add); ListView listView = getListView(); LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.contact_add_header, listView, false); listView.addHeaderView(view, null, false); accountView = (Spinner) view.findViewById(R.id.contact_account); accountView.setAdapter(new AccountChooseAdapter(this)); accountView.setOnItemSelectedListener(this); userView = (EditText) view.findViewById(R.id.contact_user); nameView = (EditText) view.findViewById(R.id.contact_name); ((Button) view.findViewById(R.id.ok)).setOnClickListener(this); String name; Intent intent = getIntent(); if (savedInstanceState != null) { account = savedInstanceState.getString(SAVED_ACCOUNT); user = savedInstanceState.getString(SAVED_USER); name = savedInstanceState.getString(SAVED_NAME); } else { account = getAccount(intent); user = getUser(intent); if (account == null || user == null) name = null; else { name = RosterManager.getInstance().getName(account, user); if (user.equals(name)) name = null; } } if (account == null) { Collection<String> accounts = AccountManager.getInstance().getAccounts(); if (accounts.size() == 1) account = accounts.iterator().next(); } if (account != null) { for (int position = 0; position < accountView.getCount(); position++) if (account.equals(accountView.getItemAtPosition(position))) { accountView.setSelection(position); break; } } if (user != null) userView.setText(user); if (name != null) nameView.setText(name); if (ACTION_SUBSCRIPTION_REQUEST.equals(intent.getAction())) { subscriptionRequest = PresenceManager.getInstance().getSubscriptionRequest(account, user); if (subscriptionRequest == null) { Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND); finish(); return; } } else { subscriptionRequest = null; } }
/** * @return Group's name to be display. * @see {@link #IS_ROOM}, {@link #ACTIVE_CHATS}, {@link #NO_GROUP}, {@link #IS_ACCOUNT}, {@link * #NO_ACCOUNT}. */ public String getGroupName(String account, String group) { if (group == GroupManager.NO_GROUP) return Application.getInstance().getString(R.string.group_none); else if (group == GroupManager.IS_ROOM) return Application.getInstance().getString(R.string.group_room); else if (group == GroupManager.ACTIVE_CHATS) return Application.getInstance().getString(R.string.group_active_chat); else if (group == GroupManager.IS_ACCOUNT) return AccountManager.getInstance().getVerboseName(account); return group; }
@Override public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item); switch (item.getItemId()) { case OPTION_MENU_CLEAR_STATUSES_ID: AccountManager.getInstance().clearSavedStatuses(); ((UpdatableAdapter) getListAdapter()).onChange(); return true; } return false; }
/** * Sets status for all accounts. * * @param statusMode * @param statusText can be <code>null</code> if value was not changed. */ public void setStatus(StatusMode statusMode, String statusText) { SettingsManager.setStatusMode(statusMode); if (statusText != null) { addSavedStatus(statusMode, statusText); SettingsManager.setStatusText(statusText); } for (AccountItem accountItem : accountItems.values()) { setStatus( accountItem, statusMode, statusText == null ? accountItem.getStatusText() : statusText); } resendPresence(); onAccountsChanged(new ArrayList<String>(AccountManager.getInstance().getAllAccounts())); }
@Override public void onAccept(DialogBuilder dialogBuilder) { switch (dialogBuilder.getDialogId()) { case R.string.cache_clear_warning: AccountManager.getInstance().setStatus(StatusMode.unavailable, null); ((Application) getApplication()).requestToClear(); Application.getInstance().requestToClose(); showDialog(R.string.application_state_closing); break; case R.string.security_clear_certificate_warning: CertificateManager.getInstance().removeCertificates(); ConnectionManager.getInstance().updateConnections(true); break; case R.string.contacts_reset_offline_warning: GroupManager.getInstance().resetShowOfflineModes(); break; } }
@Override public boolean onContextItemSelected(MenuItem item) { super.onContextItemSelected(item); switch (item.getItemId()) { case CONTEXT_MENU_SELECT_STATUS_ID: setStatus(actionWithItem.getStatusMode(), actionWithItem.getStatusText()); finish(); return true; case CONTEXT_MENU_EDIT_STATUS_ID: showStatus(actionWithItem.getStatusMode(), actionWithItem.getStatusText()); return true; case CONTEXT_MENU_REMOVE_STATUS_ID: AccountManager.getInstance().removeSavedStatus(actionWithItem); ((UpdatableAdapter) getListAdapter()).onChange(); return true; } return false; }
private void setUpInputViewButtons() { boolean empty = inputView.getText().toString().trim().isEmpty(); if (empty != isInputEmpty) { isInputEmpty = empty; } if (isInputEmpty) { sendButton.setImageResource(R.drawable.ic_button_send_inactive_24dp); securityButton.setVisibility(View.VISIBLE); if (HttpFileUploadManager.getInstance().isFileUploadSupported(account)) { attachButton.setVisibility(View.VISIBLE); } else { attachButton.setVisibility(View.GONE); } } else { sendButton.setImageResource(R.drawable.ic_button_send); sendButton.setImageLevel(AccountManager.getInstance().getColorLevel(account)); securityButton.setVisibility(View.GONE); attachButton.setVisibility(View.GONE); } }
/** * Requests to join to the room. * * @param account * @param room * @param requested Whether user request to join the room. */ public void joinRoom(final String account, final String room, boolean requested) { final Connection xmppConnection; final RoomChat roomChat; final String nickname; final String password; final Thread thread; roomChat = getRoomChat(account, room); if (roomChat == null) { Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND); return; } RoomState state = roomChat.getState(); if (state == RoomState.available || state == RoomState.occupation) { Application.getInstance().onError(R.string.ALREADY_JOINED); return; } if (state == RoomState.creating || state == RoomState.joining) { Application.getInstance().onError(R.string.ALREADY_IN_PROGRESS); return; } nickname = roomChat.getNickname(); password = roomChat.getPassword(); requestToWriteRoom(account, room, nickname, password, true); ConnectionThread connectionThread = AccountManager.getInstance().getAccount(account).getConnectionThread(); if (connectionThread == null) { Application.getInstance().onError(R.string.NOT_CONNECTED); return; } xmppConnection = connectionThread.getXMPPConnection(); if (xmppConnection == null) { Application.getInstance().onError(R.string.NOT_CONNECTED); return; } final MultiUserChat multiUserChat; try { multiUserChat = new MultiUserChat(xmppConnection, room); } catch (IllegalStateException e) { Application.getInstance().onError(R.string.NOT_CONNECTED); return; } roomChat.setState(RoomState.joining); roomChat.setMultiUserChat(multiUserChat); roomChat.setRequested(requested); thread = new Thread("Join to room " + room + " from " + account) { @Override public void run() { try { if (roomChat.getMultiUserChat() != multiUserChat) return; multiUserChat.join(nickname, password); Application.getInstance() .runOnUiThread( new Runnable() { @Override public void run() { if (roomChat.getMultiUserChat() != multiUserChat) return; if (roomChat.getState() == RoomState.joining) roomChat.setState(RoomState.occupation); removeAuthorizationError(account, room); RosterManager.getInstance().onContactChanged(account, room); } }); return; } catch (final XMPPException e) { Application.getInstance() .runOnUiThread( new Runnable() { @Override public void run() { if (roomChat.getMultiUserChat() != multiUserChat) return; roomChat.setState(RoomState.error); addAuthorizationError(account, room); if (e.getXMPPError() != null && e.getXMPPError().getCode() == 409) Application.getInstance().onError(R.string.NICK_ALREADY_USED); else if (e.getXMPPError() != null && e.getXMPPError().getCode() == 401) Application.getInstance().onError(R.string.AUTHENTICATION_FAILED); else Application.getInstance().onError(R.string.NOT_CONNECTED); RosterManager.getInstance().onContactChanged(account, room); } }); return; } catch (IllegalStateException e) { } catch (RuntimeException e) { LogManager.exception(this, e); } catch (Exception e) { LogManager.exception(this, e); } Application.getInstance() .runOnUiThread( new Runnable() { @Override public void run() { if (roomChat.getMultiUserChat() != multiUserChat) return; roomChat.setState(RoomState.waiting); Application.getInstance().onError(R.string.NOT_CONNECTED); RosterManager.getInstance().onContactChanged(account, room); } }); } }; thread.setDaemon(true); thread.start(); }
@Override public void onDecline() { AccountManager.getInstance().removePasswordRequest(account); finish(); }
@Override protected void onResume() { super.onResume(); barPainter.setDefaultColor(); rebuildAccountToggle(); Application.getInstance().addUIListener(OnAccountChangedListener.class, this); if (action != null) { switch (action) { case ContactList.ACTION_ROOM_INVITE: case Intent.ACTION_SEND: case Intent.ACTION_CREATE_SHORTCUT: if (Intent.ACTION_SEND.equals(action)) { sendText = getIntent().getStringExtra(Intent.EXTRA_TEXT); } Toast.makeText(this, getString(R.string.select_contact), Toast.LENGTH_LONG).show(); break; case Intent.ACTION_VIEW: { action = null; Uri data = getIntent().getData(); if (data != null && "xmpp".equals(data.getScheme())) { XMPPUri xmppUri; try { xmppUri = XMPPUri.parse(data); } catch (IllegalArgumentException e) { xmppUri = null; } if (xmppUri != null && "message".equals(xmppUri.getQueryType())) { ArrayList<String> texts = xmppUri.getValues("body"); String text = null; if (texts != null && !texts.isEmpty()) { text = texts.get(0); } openChat(xmppUri.getPath(), text); } } break; } case Intent.ACTION_SENDTO: { action = null; Uri data = getIntent().getData(); if (data != null) { String path = data.getPath(); if (path != null && path.startsWith("/")) { openChat(path.substring(1), null); } } break; } } } if (Application.getInstance().doNotify()) { if (!SettingsManager.isTranslationSuggested()) { Locale currentLocale = getResources().getConfiguration().locale; if (!currentLocale.getLanguage().equals("en") && !getResources().getBoolean(R.bool.is_translated)) { new TranslationDialog().show(getFragmentManager(), "TRANSLATION_DIALOG"); SettingsManager.setTranslationSuggested(); } } if (SettingsManager.bootCount() > 2 && !SettingsManager.connectionStartAtBoot() && !SettingsManager.startAtBootSuggested()) { StartAtBootDialogFragment.newInstance().show(getFragmentManager(), "START_AT_BOOT"); } if (!SettingsManager.contactIntegrationSuggested() && Application.getInstance().isContactsSupported()) { if (AccountManager.getInstance().getAllAccounts().isEmpty()) { SettingsManager.setContactIntegrationSuggested(); } else { ContactIntegrationDialogFragment.newInstance() .show(getFragmentManager(), "CONTACT_INTEGRATION"); } } } }
@Override public String getText() { return AccountManager.getInstance().getVerboseName(account); }
@Override public void onInitialized() { updateConnections(false); AccountManager.getInstance() .onAccountsChanged(new ArrayList<String>(AccountManager.getInstance().getAllAccounts())); }