Search in sources :

Example 1 with MmsException

use of ws.com.google.android.mms.MmsException in project Signal-Android by WhisperSystems.

the class AttachmentDatabase method setAttachmentData.

@NonNull
private Pair<File, Long> setAttachmentData(@NonNull MasterSecret masterSecret, @NonNull InputStream in) throws MmsException {
    try {
        File partsDirectory = context.getDir("parts", Context.MODE_PRIVATE);
        File dataFile = File.createTempFile("part", ".mms", partsDirectory);
        return new Pair<>(dataFile, setAttachmentData(masterSecret, dataFile, in));
    } catch (IOException e) {
        throw new MmsException(e);
    }
}
Also used : MmsException(ws.com.google.android.mms.MmsException) IOException(java.io.IOException) File(java.io.File) Pair(android.util.Pair) NonNull(android.support.annotation.NonNull)

Example 2 with MmsException

use of ws.com.google.android.mms.MmsException in project Signal-Android by WhisperSystems.

the class AttachmentDownloadJob method markFailed.

private void markFailed(long messageId, AttachmentId attachmentId) {
    try {
        AttachmentDatabase database = DatabaseFactory.getAttachmentDatabase(context);
        database.setTransferProgressFailed(attachmentId, messageId);
    } catch (MmsException e) {
        Log.w(TAG, e);
    }
}
Also used : MmsException(ws.com.google.android.mms.MmsException) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase)

Example 3 with MmsException

use of ws.com.google.android.mms.MmsException in project Signal-Android by WhisperSystems.

the class AttachmentDownloadJob method retrieveAttachment.

private void retrieveAttachment(MasterSecret masterSecret, long messageId, final AttachmentId attachmentId, final Attachment attachment) throws IOException {
    AttachmentDatabase database = DatabaseFactory.getAttachmentDatabase(context);
    File attachmentFile = null;
    try {
        attachmentFile = createTempFile();
        SignalServiceAttachmentPointer pointer = createAttachmentPointer(masterSecret, attachment);
        InputStream stream = messageReceiver.retrieveAttachment(pointer, attachmentFile, MAX_ATTACHMENT_SIZE, new ProgressListener() {

            @Override
            public void onAttachmentProgress(long total, long progress) {
                EventBus.getDefault().postSticky(new PartProgressEvent(attachment, total, progress));
            }
        });
        database.insertAttachmentsForPlaceholder(masterSecret, messageId, attachmentId, stream);
    } catch (InvalidPartException | NonSuccessfulResponseCodeException | InvalidMessageException | MmsException e) {
        Log.w(TAG, e);
        markFailed(messageId, attachmentId);
    } finally {
        if (attachmentFile != null)
            attachmentFile.delete();
    }
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) InputStream(java.io.InputStream) SignalServiceAttachmentPointer(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer) NonSuccessfulResponseCodeException(org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException) PartProgressEvent(org.thoughtcrime.securesms.events.PartProgressEvent) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase) MmsException(ws.com.google.android.mms.MmsException) ProgressListener(org.whispersystems.signalservice.api.messages.SignalServiceAttachment.ProgressListener) File(java.io.File)

Example 4 with MmsException

use of ws.com.google.android.mms.MmsException in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleMessage.

private void handleMessage(MasterSecretUnion masterSecret, SignalServiceEnvelope envelope, Optional<Long> smsMessageId) {
    try {
        GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
        SignalProtocolStore axolotlStore = new SignalProtocolStoreImpl(context);
        SignalServiceAddress localAddress = new SignalServiceAddress(TextSecurePreferences.getLocalNumber(context));
        SignalServiceCipher cipher = new SignalServiceCipher(localAddress, axolotlStore);
        SignalServiceContent content = cipher.decrypt(envelope);
        if (content.getDataMessage().isPresent()) {
            SignalServiceDataMessage message = content.getDataMessage().get();
            if (message.isEndSession())
                handleEndSessionMessage(masterSecret, envelope, message, smsMessageId);
            else if (message.isGroupUpdate())
                handleGroupMessage(masterSecret, envelope, message, smsMessageId);
            else if (message.isExpirationUpdate())
                handleExpirationUpdate(masterSecret, envelope, message, smsMessageId);
            else if (message.getAttachments().isPresent())
                handleMediaMessage(masterSecret, envelope, message, smsMessageId);
            else
                handleTextMessage(masterSecret, envelope, message, smsMessageId);
            if (message.getGroupInfo().isPresent() && groupDatabase.isUnknownGroup(message.getGroupInfo().get().getGroupId())) {
                handleUnknownGroupMessage(envelope, message.getGroupInfo().get());
            }
        } else if (content.getSyncMessage().isPresent()) {
            SignalServiceSyncMessage syncMessage = content.getSyncMessage().get();
            if (syncMessage.getSent().isPresent())
                handleSynchronizeSentMessage(masterSecret, envelope, syncMessage.getSent().get(), smsMessageId);
            else if (syncMessage.getRequest().isPresent())
                handleSynchronizeRequestMessage(masterSecret, syncMessage.getRequest().get());
            else if (syncMessage.getRead().isPresent())
                handleSynchronizeReadMessage(masterSecret, syncMessage.getRead().get(), envelope.getTimestamp());
            else
                Log.w(TAG, "Contains no known sync types...");
        } else if (content.getCallMessage().isPresent()) {
            Log.w(TAG, "Got call message...");
            SignalServiceCallMessage message = content.getCallMessage().get();
            if (message.getOfferMessage().isPresent())
                handleCallOfferMessage(envelope, message.getOfferMessage().get(), smsMessageId);
            else if (message.getAnswerMessage().isPresent())
                handleCallAnswerMessage(envelope, message.getAnswerMessage().get());
            else if (message.getIceUpdateMessages().isPresent())
                handleCallIceUpdateMessage(envelope, message.getIceUpdateMessages().get());
            else if (message.getHangupMessage().isPresent())
                handleCallHangupMessage(envelope, message.getHangupMessage().get(), smsMessageId);
        } else {
            Log.w(TAG, "Got unrecognized message...");
        }
        if (envelope.isPreKeySignalMessage()) {
            ApplicationContext.getInstance(context).getJobManager().add(new RefreshPreKeysJob(context));
        }
    } catch (InvalidVersionException e) {
        Log.w(TAG, e);
        handleInvalidVersionMessage(masterSecret, envelope, smsMessageId);
    } catch (InvalidMessageException | InvalidKeyIdException | InvalidKeyException | MmsException e) {
        Log.w(TAG, e);
        handleCorruptMessage(masterSecret, envelope, smsMessageId);
    } catch (NoSessionException e) {
        Log.w(TAG, e);
        handleNoSessionMessage(masterSecret, envelope, smsMessageId);
    } catch (LegacyMessageException e) {
        Log.w(TAG, e);
        handleLegacyMessage(masterSecret, envelope, smsMessageId);
    } catch (DuplicateMessageException e) {
        Log.w(TAG, e);
        handleDuplicateMessage(masterSecret, envelope, smsMessageId);
    } catch (UntrustedIdentityException e) {
        Log.w(TAG, e);
        handleUntrustedIdentityMessage(masterSecret, envelope, smsMessageId);
    }
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) UntrustedIdentityException(org.whispersystems.libsignal.UntrustedIdentityException) SignalServiceCipher(org.whispersystems.signalservice.api.crypto.SignalServiceCipher) InvalidVersionException(org.whispersystems.libsignal.InvalidVersionException) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) SignalServiceSyncMessage(org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage) SignalServiceContent(org.whispersystems.signalservice.api.messages.SignalServiceContent) NoSessionException(org.whispersystems.libsignal.NoSessionException) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) SignalProtocolStore(org.whispersystems.libsignal.state.SignalProtocolStore) MmsException(ws.com.google.android.mms.MmsException) DuplicateMessageException(org.whispersystems.libsignal.DuplicateMessageException) SignalProtocolStoreImpl(org.thoughtcrime.securesms.crypto.storage.SignalProtocolStoreImpl) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) InvalidKeyIdException(org.whispersystems.libsignal.InvalidKeyIdException) LegacyMessageException(org.whispersystems.libsignal.LegacyMessageException)

Example 5 with MmsException

use of ws.com.google.android.mms.MmsException in project Signal-Android by WhisperSystems.

the class MmsDownloadJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    Optional<Pair<NotificationInd, Integer>> notification = database.getNotification(messageId);
    if (!notification.isPresent()) {
        Log.w(TAG, "No notification for ID: " + messageId);
        return;
    }
    try {
        if (notification.get().first.getContentLocation() == null) {
            throw new MmsException("Notification content location was null.");
        }
        database.markDownloadState(messageId, MmsDatabase.Status.DOWNLOAD_CONNECTING);
        String contentLocation = new String(notification.get().first.getContentLocation());
        byte[] transactionId = notification.get().first.getTransactionId();
        Log.w(TAG, "Downloading mms at " + Uri.parse(contentLocation).getHost());
        RetrieveConf retrieveConf = new CompatMmsConnection(context).retrieve(contentLocation, transactionId, notification.get().second);
        if (retrieveConf == null) {
            throw new MmsException("RetrieveConf was null");
        }
        storeRetrievedMms(masterSecret, contentLocation, messageId, threadId, retrieveConf, notification.get().second);
    } catch (ApnUnavailableException e) {
        Log.w(TAG, e);
        handleDownloadError(masterSecret, messageId, threadId, MmsDatabase.Status.DOWNLOAD_APN_UNAVAILABLE, automatic);
    } catch (MmsException e) {
        Log.w(TAG, e);
        handleDownloadError(masterSecret, messageId, threadId, MmsDatabase.Status.DOWNLOAD_HARD_FAILURE, automatic);
    } catch (MmsRadioException | IOException e) {
        Log.w(TAG, e);
        handleDownloadError(masterSecret, messageId, threadId, MmsDatabase.Status.DOWNLOAD_SOFT_FAILURE, automatic);
    } catch (DuplicateMessageException e) {
        Log.w(TAG, e);
        database.markAsDecryptDuplicate(messageId, threadId);
    } catch (LegacyMessageException e) {
        Log.w(TAG, e);
        database.markAsLegacyVersion(messageId, threadId);
    } catch (NoSessionException e) {
        Log.w(TAG, e);
        database.markAsNoSession(messageId, threadId);
    } catch (InvalidMessageException e) {
        Log.w(TAG, e);
        database.markAsDecryptFailed(messageId, threadId);
    }
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) IOException(java.io.IOException) NoSessionException(org.whispersystems.libsignal.NoSessionException) CompatMmsConnection(org.thoughtcrime.securesms.mms.CompatMmsConnection) MmsException(ws.com.google.android.mms.MmsException) ApnUnavailableException(org.thoughtcrime.securesms.mms.ApnUnavailableException) DuplicateMessageException(org.whispersystems.libsignal.DuplicateMessageException) MmsRadioException(org.thoughtcrime.securesms.mms.MmsRadioException) LegacyMessageException(org.whispersystems.libsignal.LegacyMessageException) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase) RetrieveConf(ws.com.google.android.mms.pdu.RetrieveConf) Pair(android.util.Pair)

Aggregations

MmsException (ws.com.google.android.mms.MmsException)15 IOException (java.io.IOException)5 Recipients (org.thoughtcrime.securesms.recipients.Recipients)5 ContentValues (android.content.ContentValues)3 File (java.io.File)3 LinkedList (java.util.LinkedList)3 Attachment (org.thoughtcrime.securesms.attachments.Attachment)3 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)3 AttachmentDatabase (org.thoughtcrime.securesms.database.AttachmentDatabase)3 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)3 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)3 NonNull (android.support.annotation.NonNull)2 Nullable (android.support.annotation.Nullable)2 Pair (android.util.Pair)2 MmsNotificationAttachment (org.thoughtcrime.securesms.attachments.MmsNotificationAttachment)2 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)2 OutgoingGroupMediaMessage (org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage)2 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)2 DuplicateMessageException (org.whispersystems.libsignal.DuplicateMessageException)2 LegacyMessageException (org.whispersystems.libsignal.LegacyMessageException)2