Search in sources :

Example 36 with Message

use of eu.siacs.conversations.entities.Message in project Conversations by siacs.

the class JingleConnection method init.

public void init(Account account, JinglePacket packet) {
    this.mJingleStatus = JINGLE_STATUS_INITIATED;
    Conversation conversation = this.mXmppConnectionService.findOrCreateConversation(account, packet.getFrom().toBareJid(), false);
    this.message = new Message(conversation, "", Message.ENCRYPTION_NONE);
    this.message.setStatus(Message.STATUS_RECEIVED);
    this.mStatus = Transferable.STATUS_OFFER;
    this.message.setTransferable(this);
    final Jid from = packet.getFrom();
    this.message.setCounterpart(from);
    this.account = account;
    this.initiator = packet.getFrom();
    this.responder = this.account.getJid();
    this.sessionId = packet.getSessionId();
    Content content = packet.getJingleContent();
    this.contentCreator = content.getAttribute("creator");
    this.contentName = content.getAttribute("name");
    this.transportId = content.getTransportId();
    this.mergeCandidates(JingleCandidate.parse(content.socks5transport().getChildren()));
    this.ftVersion = content.getVersion();
    if (ftVersion == null) {
        this.sendCancel();
        this.fail();
        return;
    }
    this.fileOffer = content.getFileOffer(this.ftVersion);
    mXmppConnectionService.sendIqPacket(account, packet.generateResponse(IqPacket.TYPE.RESULT), null);
    if (fileOffer != null) {
        Element encrypted = fileOffer.findChild("encrypted", AxolotlService.PEP_PREFIX);
        if (encrypted != null) {
            this.mXmppAxolotlMessage = XmppAxolotlMessage.fromElement(encrypted, packet.getFrom().toBareJid());
        }
        Element fileSize = fileOffer.findChild("size");
        Element fileNameElement = fileOffer.findChild("name");
        if (fileNameElement != null) {
            String[] filename = fileNameElement.getContent().toLowerCase(Locale.US).toLowerCase().split("\\.");
            String extension = filename[filename.length - 1];
            if (VALID_IMAGE_EXTENSIONS.contains(extension)) {
                message.setType(Message.TYPE_IMAGE);
                message.setRelativeFilePath(message.getUuid() + "." + extension);
            } else if (VALID_CRYPTO_EXTENSIONS.contains(filename[filename.length - 1])) {
                if (filename.length == 3) {
                    extension = filename[filename.length - 2];
                    if (VALID_IMAGE_EXTENSIONS.contains(extension)) {
                        message.setType(Message.TYPE_IMAGE);
                        message.setRelativeFilePath(message.getUuid() + "." + extension);
                    } else {
                        message.setType(Message.TYPE_FILE);
                    }
                    if (filename[filename.length - 1].equals("otr")) {
                        message.setEncryption(Message.ENCRYPTION_OTR);
                    } else {
                        message.setEncryption(Message.ENCRYPTION_PGP);
                    }
                }
            } else {
                message.setType(Message.TYPE_FILE);
            }
            if (message.getType() == Message.TYPE_FILE) {
                String suffix = "";
                if (!fileNameElement.getContent().isEmpty()) {
                    String[] parts = fileNameElement.getContent().split("/");
                    suffix = parts[parts.length - 1];
                    if (message.getEncryption() == Message.ENCRYPTION_OTR && suffix.endsWith(".otr")) {
                        suffix = suffix.substring(0, suffix.length() - 4);
                    } else if (message.getEncryption() == Message.ENCRYPTION_PGP && (suffix.endsWith(".pgp") || suffix.endsWith(".gpg"))) {
                        suffix = suffix.substring(0, suffix.length() - 4);
                    }
                }
                message.setRelativeFilePath(message.getUuid() + "_" + suffix);
            }
            long size = Long.parseLong(fileSize.getContent());
            message.setBody(Long.toString(size));
            conversation.add(message);
            mJingleConnectionManager.updateConversationUi(true);
            if (mJingleConnectionManager.hasStoragePermission() && size < this.mJingleConnectionManager.getAutoAcceptFileSize() && mXmppConnectionService.isDataSaverDisabled()) {
                Log.d(Config.LOGTAG, "auto accepting file from " + packet.getFrom());
                this.acceptedAutomatically = true;
                this.sendAccept();
            } else {
                message.markUnread();
                Log.d(Config.LOGTAG, "not auto accepting new file offer with size: " + size + " allowed size:" + this.mJingleConnectionManager.getAutoAcceptFileSize());
                this.mXmppConnectionService.getNotificationService().push(message);
            }
            this.file = this.mXmppConnectionService.getFileBackend().getFile(message, false);
            if (mXmppAxolotlMessage != null) {
                XmppAxolotlMessage.XmppAxolotlKeyTransportMessage transportMessage = account.getAxolotlService().processReceivingKeyTransportMessage(mXmppAxolotlMessage);
                if (transportMessage != null) {
                    message.setEncryption(Message.ENCRYPTION_AXOLOTL);
                    this.file.setKey(transportMessage.getKey());
                    this.file.setIv(transportMessage.getIv());
                    message.setFingerprint(transportMessage.getFingerprint());
                } else {
                    Log.d(Config.LOGTAG, "could not process KeyTransportMessage");
                }
            } else if (message.getEncryption() == Message.ENCRYPTION_OTR) {
                byte[] key = conversation.getSymmetricKey();
                if (key == null) {
                    this.sendCancel();
                    this.fail();
                    return;
                } else {
                    this.file.setKeyAndIv(key);
                }
            }
            this.mFileOutputStream = AbstractConnectionManager.createOutputStream(this.file, message.getEncryption() == Message.ENCRYPTION_AXOLOTL);
            if (message.getEncryption() == Message.ENCRYPTION_OTR && Config.REPORT_WRONG_FILESIZE_IN_OTR_JINGLE) {
                this.file.setExpectedSize((size / 16 + 1) * 16);
            } else {
                this.file.setExpectedSize(size);
            }
            Log.d(Config.LOGTAG, "receiving file: expecting size of " + this.file.getExpectedSize());
        } else {
            this.sendCancel();
            this.fail();
        }
    } else {
        this.sendCancel();
        this.fail();
    }
}
Also used : XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) Message(eu.siacs.conversations.entities.Message) Jid(eu.siacs.conversations.xmpp.jid.Jid) Content(eu.siacs.conversations.xmpp.jingle.stanzas.Content) Element(eu.siacs.conversations.xml.Element) Conversation(eu.siacs.conversations.entities.Conversation) XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)

Example 37 with Message

use of eu.siacs.conversations.entities.Message in project Conversations by siacs.

the class ConversationAdapter method getView.

@Override
public View getView(int position, View view, ViewGroup parent) {
    if (view == null) {
        LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.conversation_list_row, parent, false);
    }
    Conversation conversation = getItem(position);
    if (this.activity instanceof ConversationActivity) {
        View swipeableItem = view.findViewById(R.id.swipeable_item);
        ConversationActivity a = (ConversationActivity) this.activity;
        int c = a.highlightSelectedConversations() && conversation == a.getSelectedConversation() ? a.getSecondaryBackgroundColor() : a.getPrimaryBackgroundColor();
        swipeableItem.setBackgroundColor(c);
    }
    TextView convName = (TextView) view.findViewById(R.id.conversation_name);
    if (conversation.getMode() == Conversation.MODE_SINGLE || activity.useSubjectToIdentifyConference()) {
        convName.setText(conversation.getName());
    } else {
        convName.setText(conversation.getJid().toBareJid().toString());
    }
    TextView mLastMessage = (TextView) view.findViewById(R.id.conversation_lastmsg);
    TextView mTimestamp = (TextView) view.findViewById(R.id.conversation_lastupdate);
    TextView mSenderName = (TextView) view.findViewById(R.id.sender_name);
    ImageView imagePreview = (ImageView) view.findViewById(R.id.conversation_lastimage);
    ImageView notificationStatus = (ImageView) view.findViewById(R.id.notification_status);
    UnreadCountCustomView unreadCountCustomView = (UnreadCountCustomView) view.findViewById(R.id.unread_count);
    Message message = conversation.getLatestMessage();
    int unreadCount = conversation.unreadCount();
    if (unreadCount > 0) {
        unreadCountCustomView.setVisibility(View.VISIBLE);
        unreadCountCustomView.setUnreadCount(unreadCount);
    } else {
        unreadCountCustomView.setVisibility(View.GONE);
    }
    if (!conversation.isRead()) {
        convName.setTypeface(null, Typeface.BOLD);
    } else {
        convName.setTypeface(null, Typeface.NORMAL);
    }
    if (message.getFileParams().width > 0 && (message.getTransferable() == null || message.getTransferable().getStatus() != Transferable.STATUS_DELETED)) {
        mSenderName.setVisibility(View.GONE);
        mLastMessage.setVisibility(View.GONE);
        imagePreview.setVisibility(View.VISIBLE);
        activity.loadBitmap(message, imagePreview);
    } else {
        Pair<String, Boolean> preview = UIHelper.getMessagePreview(activity, message);
        mLastMessage.setVisibility(View.VISIBLE);
        imagePreview.setVisibility(View.GONE);
        mLastMessage.setText(preview.first);
        if (preview.second) {
            if (conversation.isRead()) {
                mLastMessage.setTypeface(null, Typeface.ITALIC);
                mSenderName.setTypeface(null, Typeface.NORMAL);
            } else {
                mLastMessage.setTypeface(null, Typeface.BOLD_ITALIC);
                mSenderName.setTypeface(null, Typeface.BOLD);
            }
        } else {
            if (conversation.isRead()) {
                mLastMessage.setTypeface(null, Typeface.NORMAL);
                mSenderName.setTypeface(null, Typeface.NORMAL);
            } else {
                mLastMessage.setTypeface(null, Typeface.BOLD);
                mSenderName.setTypeface(null, Typeface.BOLD);
            }
        }
        if (message.getStatus() == Message.STATUS_RECEIVED) {
            if (conversation.getMode() == Conversation.MODE_MULTI) {
                mSenderName.setVisibility(View.VISIBLE);
                mSenderName.setText(UIHelper.getMessageDisplayName(message).split("\\s+")[0] + ':');
            } else {
                mSenderName.setVisibility(View.GONE);
            }
        } else if (message.getType() != Message.TYPE_STATUS) {
            mSenderName.setVisibility(View.VISIBLE);
            mSenderName.setText(activity.getString(R.string.me) + ':');
        } else {
            mSenderName.setVisibility(View.GONE);
        }
    }
    long muted_till = conversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL, 0);
    if (muted_till == Long.MAX_VALUE) {
        notificationStatus.setVisibility(View.VISIBLE);
        int ic_notifications_off = activity.getThemeResource(R.attr.icon_notifications_off, R.drawable.ic_notifications_off_black54_24dp);
        notificationStatus.setImageResource(ic_notifications_off);
    } else if (muted_till >= System.currentTimeMillis()) {
        notificationStatus.setVisibility(View.VISIBLE);
        int ic_notifications_paused = activity.getThemeResource(R.attr.icon_notifications_paused, R.drawable.ic_notifications_paused_black54_24dp);
        notificationStatus.setImageResource(ic_notifications_paused);
    } else if (conversation.alwaysNotify()) {
        notificationStatus.setVisibility(View.GONE);
    } else {
        notificationStatus.setVisibility(View.VISIBLE);
        int ic_notifications_none = activity.getThemeResource(R.attr.icon_notifications_none, R.drawable.ic_notifications_none_black54_24dp);
        notificationStatus.setImageResource(ic_notifications_none);
    }
    mTimestamp.setText(UIHelper.readableTimeDifference(activity, conversation.getLatestMessage().getTimeSent()));
    ImageView profilePicture = (ImageView) view.findViewById(R.id.conversation_image);
    loadAvatar(conversation, profilePicture);
    return view;
}
Also used : ConversationActivity(eu.siacs.conversations.ui.ConversationActivity) UnreadCountCustomView(eu.siacs.conversations.ui.widget.UnreadCountCustomView) Message(eu.siacs.conversations.entities.Message) Conversation(eu.siacs.conversations.entities.Conversation) ImageView(android.widget.ImageView) View(android.view.View) UnreadCountCustomView(eu.siacs.conversations.ui.widget.UnreadCountCustomView) TextView(android.widget.TextView) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 38 with Message

use of eu.siacs.conversations.entities.Message in project Conversations by siacs.

the class MessageAdapter method getView.

@Override
public View getView(int position, View view, ViewGroup parent) {
    final Message message = getItem(position);
    final boolean omemoEncryption = message.getEncryption() == Message.ENCRYPTION_AXOLOTL;
    final boolean isInValidSession = message.isValidInSession() && (!omemoEncryption || message.isTrusted());
    final Conversation conversation = message.getConversation();
    final Account account = conversation.getAccount();
    final int type = getItemViewType(position);
    ViewHolder viewHolder;
    if (view == null) {
        viewHolder = new ViewHolder();
        switch(type) {
            case SENT:
                view = activity.getLayoutInflater().inflate(R.layout.message_sent, parent, false);
                viewHolder.message_box = (LinearLayout) view.findViewById(R.id.message_box);
                viewHolder.contact_picture = (ImageView) view.findViewById(R.id.message_photo);
                viewHolder.download_button = (Button) view.findViewById(R.id.download_button);
                viewHolder.indicator = (ImageView) view.findViewById(R.id.security_indicator);
                viewHolder.edit_indicator = (ImageView) view.findViewById(R.id.edit_indicator);
                viewHolder.image = (ImageView) view.findViewById(R.id.message_image);
                viewHolder.messageBody = (CopyTextView) view.findViewById(R.id.message_body);
                viewHolder.time = (TextView) view.findViewById(R.id.message_time);
                viewHolder.indicatorReceived = (ImageView) view.findViewById(R.id.indicator_received);
                break;
            case RECEIVED:
                view = activity.getLayoutInflater().inflate(R.layout.message_received, parent, false);
                viewHolder.message_box = (LinearLayout) view.findViewById(R.id.message_box);
                viewHolder.contact_picture = (ImageView) view.findViewById(R.id.message_photo);
                viewHolder.download_button = (Button) view.findViewById(R.id.download_button);
                viewHolder.indicator = (ImageView) view.findViewById(R.id.security_indicator);
                viewHolder.edit_indicator = (ImageView) view.findViewById(R.id.edit_indicator);
                viewHolder.image = (ImageView) view.findViewById(R.id.message_image);
                viewHolder.messageBody = (CopyTextView) view.findViewById(R.id.message_body);
                viewHolder.time = (TextView) view.findViewById(R.id.message_time);
                viewHolder.indicatorReceived = (ImageView) view.findViewById(R.id.indicator_received);
                viewHolder.encryption = (TextView) view.findViewById(R.id.message_encryption);
                break;
            case STATUS:
                view = activity.getLayoutInflater().inflate(R.layout.message_status, parent, false);
                viewHolder.contact_picture = (ImageView) view.findViewById(R.id.message_photo);
                viewHolder.status_message = (TextView) view.findViewById(R.id.status_message);
                viewHolder.load_more_messages = (Button) view.findViewById(R.id.load_more_messages);
                break;
            default:
                viewHolder = null;
                break;
        }
        if (viewHolder.messageBody != null) {
            listSelectionManager.onCreate(viewHolder.messageBody, new MessageBodyActionModeCallback(viewHolder.messageBody));
            viewHolder.messageBody.setCopyHandler(this);
        }
        view.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) view.getTag();
        if (viewHolder == null) {
            return view;
        }
    }
    boolean darkBackground = type == RECEIVED && (!isInValidSession || mUseGreenBackground) || activity.isDarkTheme();
    if (type == STATUS) {
        if ("LOAD_MORE".equals(message.getBody())) {
            viewHolder.status_message.setVisibility(View.GONE);
            viewHolder.contact_picture.setVisibility(View.GONE);
            viewHolder.load_more_messages.setVisibility(View.VISIBLE);
            viewHolder.load_more_messages.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    loadMoreMessages(message.getConversation());
                }
            });
        } else {
            viewHolder.status_message.setVisibility(View.VISIBLE);
            viewHolder.load_more_messages.setVisibility(View.GONE);
            viewHolder.status_message.setText(message.getBody());
            boolean showAvatar;
            if (conversation.getMode() == Conversation.MODE_SINGLE) {
                showAvatar = true;
                loadAvatar(message, viewHolder.contact_picture, activity.getPixel(32));
            } else if (message.getCounterpart() != null) {
                showAvatar = true;
                loadAvatar(message, viewHolder.contact_picture, activity.getPixel(32));
            } else {
                showAvatar = false;
            }
            if (showAvatar) {
                viewHolder.contact_picture.setAlpha(0.5f);
                viewHolder.contact_picture.setVisibility(View.VISIBLE);
            } else {
                viewHolder.contact_picture.setVisibility(View.GONE);
            }
        }
        return view;
    } else {
        loadAvatar(message, viewHolder.contact_picture, activity.getPixel(48));
    }
    viewHolder.contact_picture.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (MessageAdapter.this.mOnContactPictureClickedListener != null) {
                MessageAdapter.this.mOnContactPictureClickedListener.onContactPictureClicked(message);
            }
        }
    });
    viewHolder.contact_picture.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) {
                MessageAdapter.this.mOnContactPictureLongClickedListener.onContactPictureLongClicked(message);
                return true;
            } else {
                return false;
            }
        }
    });
    final Transferable transferable = message.getTransferable();
    if (transferable != null && transferable.getStatus() != Transferable.STATUS_UPLOADING) {
        if (transferable.getStatus() == Transferable.STATUS_OFFER) {
            displayDownloadableMessage(viewHolder, message, activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, message)));
        } else if (transferable.getStatus() == Transferable.STATUS_OFFER_CHECK_FILESIZE) {
            displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message)));
        } else {
            displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first, darkBackground);
        }
    } else if (message.getType() == Message.TYPE_IMAGE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
        displayImageMessage(viewHolder, message);
    } else if (message.getType() == Message.TYPE_FILE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
        if (message.getFileParams().width > 0) {
            displayImageMessage(viewHolder, message);
        } else {
            displayOpenableMessage(viewHolder, message);
        }
    } else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
        if (account.isPgpDecryptionServiceConnected()) {
            if (!account.hasPendingPgpIntent(conversation)) {
                displayInfoMessage(viewHolder, activity.getString(R.string.message_decrypting), darkBackground);
            } else {
                displayInfoMessage(viewHolder, activity.getString(R.string.pgp_message), darkBackground);
            }
        } else {
            displayInfoMessage(viewHolder, activity.getString(R.string.install_openkeychain), darkBackground);
            if (viewHolder != null) {
                viewHolder.message_box.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        activity.showInstallPgpDialog();
                    }
                });
            }
        }
    } else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
        displayDecryptionFailed(viewHolder, darkBackground);
    } else {
        if (GeoHelper.isGeoUri(message.getBody())) {
            displayLocationMessage(viewHolder, message);
        } else if (message.bodyIsHeart()) {
            displayHeartMessage(viewHolder, message.getBody().trim());
        } else if (message.treatAsDownloadable() == Message.Decision.MUST) {
            try {
                URL url = new URL(message.getBody());
                displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize_on_host, UIHelper.getFileDescriptionString(activity, message), url.getHost()));
            } catch (Exception e) {
                displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message)));
            }
        } else {
            displayTextMessage(viewHolder, message, darkBackground, type);
        }
    }
    if (type == RECEIVED) {
        if (isInValidSession) {
            int bubble;
            if (!mUseGreenBackground) {
                bubble = activity.getThemeResource(R.attr.message_bubble_received_monochrome, R.drawable.message_bubble_received_white);
            } else {
                bubble = activity.getThemeResource(R.attr.message_bubble_received_green, R.drawable.message_bubble_received);
            }
            viewHolder.message_box.setBackgroundResource(bubble);
            viewHolder.encryption.setVisibility(View.GONE);
        } else {
            viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received_warning);
            viewHolder.encryption.setVisibility(View.VISIBLE);
            if (omemoEncryption && !message.isTrusted()) {
                viewHolder.encryption.setText(R.string.not_trusted);
            } else {
                viewHolder.encryption.setText(CryptoHelper.encryptionTypeToText(message.getEncryption()));
            }
        }
    }
    displayStatus(viewHolder, message, type, darkBackground, isInValidSession);
    return view;
}
Also used : Account(eu.siacs.conversations.entities.Account) Message(eu.siacs.conversations.entities.Message) Transferable(eu.siacs.conversations.entities.Transferable) Conversation(eu.siacs.conversations.entities.Conversation) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) CopyTextView(eu.siacs.conversations.ui.widget.CopyTextView) URL(java.net.URL) ActivityNotFoundException(android.content.ActivityNotFoundException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) OnLongClickListener(android.view.View.OnLongClickListener) OnClickListener(android.view.View.OnClickListener)

Example 39 with Message

use of eu.siacs.conversations.entities.Message 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)

Aggregations

Message (eu.siacs.conversations.entities.Message)39 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)16 Conversation (eu.siacs.conversations.entities.Conversation)12 Account (eu.siacs.conversations.entities.Account)9 Jid (eu.siacs.conversations.xmpp.jid.Jid)7 PendingIntent (android.app.PendingIntent)5 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)5 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)5 ArrayList (java.util.ArrayList)5 SuppressLint (android.annotation.SuppressLint)4 SpannableString (android.text.SpannableString)4 NotificationCompat (android.support.v4.app.NotificationCompat)3 StyleSpan (android.text.style.StyleSpan)3 View (android.view.View)3 TextView (android.widget.TextView)3 PgpEngine (eu.siacs.conversations.crypto.PgpEngine)3 Contact (eu.siacs.conversations.entities.Contact)3 Element (eu.siacs.conversations.xml.Element)3 Cursor (android.database.Cursor)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2