Search in sources :

Example 26 with InvalidJidException

use of eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.

the class ExceptionHelper method checkForCrash.

public static boolean checkForCrash(ConversationActivity activity, final XmppConnectionService service) {
    try {
        final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
        boolean neverSend = preferences.getBoolean("never_send", false);
        if (neverSend || Config.BUG_REPORTS == null) {
            return false;
        }
        List<Account> accounts = service.getAccounts();
        Account account = null;
        for (int i = 0; i < accounts.size(); ++i) {
            if (!accounts.get(i).isOptionSet(Account.OPTION_DISABLED)) {
                account = accounts.get(i);
                break;
            }
        }
        if (account == null) {
            return false;
        }
        final Account finalAccount = account;
        FileInputStream file = activity.openFileInput("stacktrace.txt");
        InputStreamReader inputStreamReader = new InputStreamReader(file);
        BufferedReader stacktrace = new BufferedReader(inputStreamReader);
        final StringBuilder report = new StringBuilder();
        PackageManager pm = activity.getPackageManager();
        PackageInfo packageInfo;
        try {
            packageInfo = pm.getPackageInfo(activity.getPackageName(), PackageManager.GET_SIGNATURES);
            report.append("Version: " + packageInfo.versionName + '\n');
            report.append("Last Update: " + DATE_FORMATs.format(new Date(packageInfo.lastUpdateTime)) + '\n');
            Signature[] signatures = packageInfo.signatures;
            if (signatures != null && signatures.length >= 1) {
                report.append("SHA-1: " + CryptoHelper.getFingerprintCert(packageInfo.signatures[0].toByteArray()) + "\n");
            }
            report.append('\n');
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        String line;
        while ((line = stacktrace.readLine()) != null) {
            report.append(line);
            report.append('\n');
        }
        file.close();
        activity.deleteFile("stacktrace.txt");
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setTitle(activity.getString(R.string.crash_report_title));
        builder.setMessage(activity.getText(R.string.crash_report_message));
        builder.setPositiveButton(activity.getText(R.string.send_now), new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Log.d(Config.LOGTAG, "using account=" + finalAccount.getJid().toBareJid() + " to send in stack trace");
                Conversation conversation = null;
                try {
                    conversation = service.findOrCreateConversation(finalAccount, Jid.fromString(Config.BUG_REPORTS), false);
                } catch (final InvalidJidException ignored) {
                }
                Message message = new Message(conversation, report.toString(), Message.ENCRYPTION_NONE);
                service.sendMessage(message);
            }
        });
        builder.setNegativeButton(activity.getText(R.string.send_never), new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                preferences.edit().putBoolean("never_send", true).apply();
            }
        });
        builder.create().show();
        return true;
    } catch (final IOException ignored) {
        return false;
    }
}
Also used : AlertDialog(android.app.AlertDialog) Account(eu.siacs.conversations.entities.Account) Message(eu.siacs.conversations.entities.Message) DialogInterface(android.content.DialogInterface) Conversation(eu.siacs.conversations.entities.Conversation) PackageManager(android.content.pm.PackageManager) InputStreamReader(java.io.InputStreamReader) SharedPreferences(android.content.SharedPreferences) PackageInfo(android.content.pm.PackageInfo) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Date(java.util.Date) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Signature(android.content.pm.Signature) BufferedReader(java.io.BufferedReader) OnClickListener(android.content.DialogInterface.OnClickListener)

Example 27 with InvalidJidException

use of eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.

the class ManageAccountActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.manage_accounts);
    if (savedInstanceState != null) {
        String jid = savedInstanceState.getString(STATE_SELECTED_ACCOUNT);
        if (jid != null) {
            try {
                this.selectedAccountJid = Jid.fromString(jid);
            } catch (InvalidJidException e) {
                this.selectedAccountJid = null;
            }
        }
    }
    accountListView = (ListView) findViewById(R.id.account_list);
    this.mAccountAdapter = new AccountAdapter(this, accountList);
    accountListView.setAdapter(this.mAccountAdapter);
    accountListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
            switchToAccount(accountList.get(position));
        }
    });
    registerForContextMenu(accountListView);
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) AccountAdapter(eu.siacs.conversations.ui.adapter.AccountAdapter) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Example 28 with InvalidJidException

use of eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.

the class StartConversationActivity method showJoinConferenceDialog.

@SuppressLint("InflateParams")
protected void showJoinConferenceDialog(final String prefilledJid) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.join_conference);
    final View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null);
    final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account);
    final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView.findViewById(R.id.jid);
    final TextView jabberIdDesc = (TextView) dialogView.findViewById(R.id.jabber_id);
    jabberIdDesc.setText(R.string.conference_address);
    jid.setHint(R.string.conference_address_example);
    jid.setAdapter(new KnownHostsAdapter(this, R.layout.simple_list_item, mKnownConferenceHosts));
    if (prefilledJid != null) {
        jid.append(prefilledJid);
    }
    populateAccountSpinner(this, mActivatedAccounts, spinner);
    final Checkable bookmarkCheckBox = (CheckBox) dialogView.findViewById(R.id.bookmark);
    builder.setView(dialogView);
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.join, null);
    final AlertDialog dialog = builder.create();
    dialog.show();
    mCurrentDialog = dialog;
    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            if (!xmppConnectionServiceBound) {
                return;
            }
            final Account account = getSelectedAccount(spinner);
            if (account == null) {
                return;
            }
            final Jid conferenceJid;
            try {
                conferenceJid = Jid.fromString(jid.getText().toString());
            } catch (final InvalidJidException e) {
                jid.setError(getString(R.string.invalid_jid));
                return;
            }
            if (bookmarkCheckBox.isChecked()) {
                if (account.hasBookmarkFor(conferenceJid)) {
                    jid.setError(getString(R.string.bookmark_already_exists));
                } else {
                    final Bookmark bookmark = new Bookmark(account, conferenceJid.toBareJid());
                    bookmark.setAutojoin(getPreferences().getBoolean("autojoin", true));
                    String nick = conferenceJid.getResourcepart();
                    if (nick != null && !nick.isEmpty()) {
                        bookmark.setNick(nick);
                    }
                    account.getBookmarks().add(bookmark);
                    xmppConnectionService.pushBookmarks(account);
                    final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true);
                    conversation.setBookmark(bookmark);
                    dialog.dismiss();
                    mCurrentDialog = null;
                    switchToConversation(conversation);
                }
            } else {
                final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true);
                dialog.dismiss();
                mCurrentDialog = null;
                switchToConversation(conversation);
            }
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) KnownHostsAdapter(eu.siacs.conversations.ui.adapter.KnownHostsAdapter) Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.jid.Jid) Spinner(android.widget.Spinner) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Conversation(eu.siacs.conversations.entities.Conversation) SpannableString(android.text.SpannableString) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AutoCompleteTextView(android.widget.AutoCompleteTextView) Bookmark(eu.siacs.conversations.entities.Bookmark) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) Checkable(android.widget.Checkable) AutoCompleteTextView(android.widget.AutoCompleteTextView) SuppressLint(android.annotation.SuppressLint)

Example 29 with InvalidJidException

use of eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.

the class XmppActivity method selectPresence.

public void selectPresence(final Conversation conversation, final OnPresenceSelected listener) {
    final Contact contact = conversation.getContact();
    if (conversation.hasValidOtrSession()) {
        SessionID id = conversation.getOtrSession().getSessionID();
        Jid jid;
        try {
            jid = Jid.fromString(id.getAccountID() + "/" + id.getUserID());
        } catch (InvalidJidException e) {
            jid = null;
        }
        conversation.setNextCounterpart(jid);
        listener.onPresenceSelected();
    } else if (!contact.showInRoster()) {
        showAddToRosterDialog(conversation);
    } else {
        final Presences presences = contact.getPresences();
        if (presences.size() == 0) {
            if (!contact.getOption(Contact.Options.TO) && !contact.getOption(Contact.Options.ASKING) && contact.getAccount().getStatus() == Account.State.ONLINE) {
                showAskForPresenceDialog(contact);
            } else if (!contact.getOption(Contact.Options.TO) || !contact.getOption(Contact.Options.FROM)) {
                warnMutalPresenceSubscription(conversation, listener);
            } else {
                conversation.setNextCounterpart(null);
                listener.onPresenceSelected();
            }
        } else if (presences.size() == 1) {
            String presence = presences.toResourceArray()[0];
            try {
                conversation.setNextCounterpart(Jid.fromParts(contact.getJid().getLocalpart(), contact.getJid().getDomainpart(), presence));
            } catch (InvalidJidException e) {
                conversation.setNextCounterpart(null);
            }
            listener.onPresenceSelected();
        } else {
            showPresenceSelectionDialog(presences, conversation, listener);
        }
    }
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) Presences(eu.siacs.conversations.entities.Presences) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) SessionID(net.java.otr4j.session.SessionID) Contact(eu.siacs.conversations.entities.Contact)

Example 30 with InvalidJidException

use of eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.

the class StartConversationActivity method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if ((requestCode & 0xFFFF) == IntentIntegrator.REQUEST_CODE) {
        IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
        if (scanResult != null && scanResult.getFormatName() != null) {
            String data = scanResult.getContents();
            Invite invite = new Invite(data);
            if (xmppConnectionServiceBound) {
                invite.invite();
            } else if (invite.getJid() != null) {
                this.mPendingInvite = invite;
            } else {
                this.mPendingInvite = null;
            }
        }
    } else if (resultCode == RESULT_OK) {
        if (xmppConnectionServiceBound) {
            this.mPostponedActivityResult = null;
            if (requestCode == REQUEST_CREATE_CONFERENCE) {
                Account account = extractAccount(intent);
                final String subject = intent.getStringExtra("subject");
                List<Jid> jids = new ArrayList<>();
                if (intent.getBooleanExtra("multiple", false)) {
                    String[] toAdd = intent.getStringArrayExtra("contacts");
                    for (String item : toAdd) {
                        try {
                            jids.add(Jid.fromString(item));
                        } catch (InvalidJidException e) {
                        //ignored
                        }
                    }
                } else {
                    try {
                        jids.add(Jid.fromString(intent.getStringExtra("contact")));
                    } catch (Exception e) {
                    //ignored
                    }
                }
                if (account != null && jids.size() > 0) {
                    if (xmppConnectionService.createAdhocConference(account, subject, jids, mAdhocConferenceCallback)) {
                        mToast = Toast.makeText(this, R.string.creating_conference, Toast.LENGTH_LONG);
                        mToast.show();
                    }
                }
            }
        } else {
            this.mPostponedActivityResult = new Pair<>(requestCode, intent);
        }
    }
    super.onActivityResult(requestCode, requestCode, intent);
}
Also used : Account(eu.siacs.conversations.entities.Account) IntentResult(com.google.zxing.integration.android.IntentResult) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) List(java.util.List) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) ActivityNotFoundException(android.content.ActivityNotFoundException) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Pair(android.util.Pair)

Aggregations

InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)30 Jid (eu.siacs.conversations.xmpp.jid.Jid)18 Account (eu.siacs.conversations.entities.Account)13 Conversation (eu.siacs.conversations.entities.Conversation)11 AlertDialog (android.app.AlertDialog)4 View (android.view.View)4 Message (eu.siacs.conversations.entities.Message)4 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)4 DialogInterface (android.content.DialogInterface)3 TextView (android.widget.TextView)3 Contact (eu.siacs.conversations.entities.Contact)3 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)3 SuppressLint (android.annotation.SuppressLint)2 OnClickListener (android.content.DialogInterface.OnClickListener)2 Bundle (android.os.Bundle)2 SpannableString (android.text.SpannableString)2 Pair (android.util.Pair)2 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)2