Search in sources :

Example 91 with Account

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

the class JingleConnection method sendInitRequest.

private void sendInitRequest() {
    JinglePacket packet = this.bootstrapPacket("session-initiate");
    Content content = new Content(this.contentCreator, this.contentName);
    if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) {
        content.setTransportId(this.transportId);
        this.file = this.mXmppConnectionService.getFileBackend().getFile(message, false);
        Pair<InputStream, Integer> pair;
        try {
            if (message.getEncryption() == Message.ENCRYPTION_OTR) {
                Conversation conversation = this.message.getConversation();
                if (!this.mXmppConnectionService.renewSymmetricKey(conversation)) {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not set symmetric key");
                    cancel();
                }
                this.file.setKeyAndIv(conversation.getSymmetricKey());
                pair = AbstractConnectionManager.createInputStream(this.file, false);
                this.file.setExpectedSize(pair.second);
                content.setFileOffer(this.file, true, this.ftVersion);
            } else if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
                this.file.setKey(mXmppAxolotlMessage.getInnerKey());
                this.file.setIv(mXmppAxolotlMessage.getIV());
                pair = AbstractConnectionManager.createInputStream(this.file, true);
                this.file.setExpectedSize(pair.second);
                content.setFileOffer(this.file, false, this.ftVersion).addChild(mXmppAxolotlMessage.toElement());
            } else {
                pair = AbstractConnectionManager.createInputStream(this.file, false);
                this.file.setExpectedSize(pair.second);
                content.setFileOffer(this.file, false, this.ftVersion);
            }
        } catch (FileNotFoundException e) {
            cancel();
            return;
        }
        this.mFileInputStream = pair.first;
        content.setTransportId(this.transportId);
        content.socks5transport().setChildren(getCandidatesAsElements());
        packet.setContent(content);
        this.sendJinglePacket(packet, new OnIqPacketReceived() {

            @Override
            public void onIqPacketReceived(Account account, IqPacket packet) {
                if (packet.getType() == IqPacket.TYPE.RESULT) {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": other party received offer");
                    mJingleStatus = JINGLE_STATUS_INITIATED;
                    mXmppConnectionService.markMessage(message, Message.STATUS_OFFERED);
                } else {
                    fail(IqParser.extractErrorMessage(packet));
                }
            }
        });
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) JinglePacket(eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Content(eu.siacs.conversations.xmpp.jingle.stanzas.Content) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) Conversation(eu.siacs.conversations.entities.Conversation) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 92 with Account

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

the class AccountAdapter method getView.

@Override
public View getView(int position, View view, ViewGroup parent) {
    final Account account = getItem(position);
    if (view == null) {
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.account_row, parent, false);
    }
    TextView jid = (TextView) view.findViewById(R.id.account_jid);
    if (Config.DOMAIN_LOCK != null) {
        jid.setText(account.getJid().getLocalpart());
    } else {
        jid.setText(account.getJid().toBareJid().toString());
    }
    TextView statusView = (TextView) view.findViewById(R.id.account_status);
    ImageView imageView = (ImageView) view.findViewById(R.id.account_image);
    loadAvatar(account, imageView);
    statusView.setText(getContext().getString(account.getStatus().getReadableId()));
    switch(account.getStatus()) {
        case ONLINE:
            statusView.setTextColor(activity.getOnlineColor());
            break;
        case DISABLED:
        case CONNECTING:
            statusView.setTextColor(activity.getSecondaryTextColor());
            break;
        default:
            statusView.setTextColor(activity.getWarningTextColor());
            break;
    }
    final Switch tglAccountState = (Switch) view.findViewById(R.id.tgl_account_status);
    final boolean isDisabled = (account.getStatus() == Account.State.DISABLED);
    tglAccountState.setChecked(!isDisabled, false);
    tglAccountState.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (b == isDisabled && activity instanceof ManageAccountActivity) {
                ((ManageAccountActivity) activity).onClickTglAccountState(account, b);
            }
        }
    });
    return view;
}
Also used : Account(eu.siacs.conversations.entities.Account) Switch(eu.siacs.conversations.ui.widget.Switch) LayoutInflater(android.view.LayoutInflater) ManageAccountActivity(eu.siacs.conversations.ui.ManageAccountActivity) TextView(android.widget.TextView) ImageView(android.widget.ImageView) CompoundButton(android.widget.CompoundButton)

Example 93 with Account

use of eu.siacs.conversations.entities.Account 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 94 with Account

use of eu.siacs.conversations.entities.Account 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 95 with Account

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

the class OmemoActivity method addFingerprintRow.

protected void addFingerprintRow(LinearLayout keys, final XmppAxolotlSession session, boolean highlight) {
    final Account account = session.getAccount();
    final String fingerprint = session.getFingerprint();
    addFingerprintRowWithListeners(keys, session.getAccount(), session.getFingerprint(), highlight, session.getTrust(), true, true, new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            account.getAxolotlService().setFingerprintTrust(fingerprint, FingerprintStatus.createActive(isChecked));
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) CompoundButton(android.widget.CompoundButton)

Aggregations

Account (eu.siacs.conversations.entities.Account)100 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)41 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)33 Jid (eu.siacs.conversations.xmpp.jid.Jid)22 Element (eu.siacs.conversations.xml.Element)21 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)17 Conversation (eu.siacs.conversations.entities.Conversation)16 Contact (eu.siacs.conversations.entities.Contact)9 Message (eu.siacs.conversations.entities.Message)9 ArrayList (java.util.ArrayList)8 PendingIntent (android.app.PendingIntent)7 Intent (android.content.Intent)7 Bookmark (eu.siacs.conversations.entities.Bookmark)7 SuppressLint (android.annotation.SuppressLint)6 AlertDialog (android.app.AlertDialog)6 TextView (android.widget.TextView)6 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)6 FileNotFoundException (java.io.FileNotFoundException)6 DialogInterface (android.content.DialogInterface)5 View (android.view.View)5