Search in sources :

Example 46 with Message

use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.

the class ExceptionHelper method checkForCrash.

public static boolean checkForCrash(XmppActivity activity) {
    try {
        final XmppConnectionService service = activity == null ? null : activity.xmppConnectionService;
        if (service == null) {
            return false;
        }
        final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
        boolean crashreport = preferences.getBoolean("crashreport", activity.getResources().getBoolean(R.bool.send_crashreport));
        if (!crashreport || 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).isEnabled()) {
                account = accounts.get(i);
                break;
            }
        }
        if (account == null) {
            return false;
        }
        final Account finalAccount = account;
        FileInputStream file = activity.openFileInput(FILENAME);
        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: ").append(packageInfo.versionName).append('\n');
            report.append("Last Update: ").append(DATE_FORMAT.format(new Date(packageInfo.lastUpdateTime))).append('\n');
            Signature[] signatures = packageInfo.signatures;
            if (signatures != null && signatures.length >= 1) {
                report.append("SHA-1: ").append(CryptoHelper.getFingerprintCert(packageInfo.signatures[0].toByteArray())).append('\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(FILENAME);
        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, true);
                } 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("crash_report", false).apply();
            }
        });
        builder.create().show();
        return true;
    } catch (final IOException ignored) {
        return false;
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Account(de.pixart.messenger.entities.Account) Message(de.pixart.messenger.entities.Message) DialogInterface(android.content.DialogInterface) Conversation(de.pixart.messenger.entities.Conversation) XmppConnectionService(de.pixart.messenger.services.XmppConnectionService) PackageManager(android.content.pm.PackageManager) InputStreamReader(java.io.InputStreamReader) SharedPreferences(android.content.SharedPreferences) PackageInfo(android.content.pm.PackageInfo) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Date(java.util.Date) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) IOException(java.io.IOException) Signature(android.content.pm.Signature) BufferedReader(java.io.BufferedReader) OnClickListener(android.content.DialogInterface.OnClickListener)

Example 47 with Message

use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.

the class DatabaseBackend method getMessagesIterable.

public Iterable<Message> getMessagesIterable(final Conversation conversation) {
    return new Iterable<Message>() {

        @Override
        public Iterator<Message> iterator() {
            class MessageIterator implements Iterator<Message> {

                SQLiteDatabase db = getReadableDatabase();

                String[] selectionArgs = { conversation.getUuid() };

                Cursor cursor = db.query(Message.TABLENAME, null, Message.CONVERSATION + "=?", selectionArgs, null, null, Message.TIME_SENT + " ASC", null);

                public MessageIterator() {
                    cursor.moveToFirst();
                }

                @Override
                public boolean hasNext() {
                    return !cursor.isAfterLast();
                }

                @Override
                public Message next() {
                    Message message = Message.fromCursor(cursor, conversation);
                    cursor.moveToNext();
                    return message;
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            }
            return new MessageIterator();
        }
    };
}
Also used : Message(de.pixart.messenger.entities.Message) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Iterator(java.util.Iterator) Cursor(android.database.Cursor)

Aggregations

Message (de.pixart.messenger.entities.Message)47 XmppAxolotlMessage (de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage)16 Conversation (de.pixart.messenger.entities.Conversation)13 EditMessage (de.pixart.messenger.ui.widget.EditMessage)12 SuppressLint (android.annotation.SuppressLint)11 PendingIntent (android.app.PendingIntent)7 SpannableString (android.text.SpannableString)7 Account (de.pixart.messenger.entities.Account)7 Jid (de.pixart.messenger.xmpp.jid.Jid)7 ArrayList (java.util.ArrayList)5 Uri (android.net.Uri)4 Toast (android.widget.Toast)4 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)4 StyleSpan (android.text.style.StyleSpan)3 RelativeLayout (android.widget.RelativeLayout)3 Element (de.pixart.messenger.xml.Element)3 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)3 Date (java.util.Date)3 SharedPreferences (android.content.SharedPreferences)2 PackageManager (android.content.pm.PackageManager)2