Search in sources :

Example 56 with MmsException

use of org.thoughtcrime.securesms.mms.MmsException in project Signal-Android by signalapp.

the class AttachmentDownloadJob method markFailed.

private void markFailed(long messageId, AttachmentId attachmentId) {
    try {
        AttachmentDatabase database = SignalDatabase.attachments();
        database.setTransferProgressFailed(attachmentId, messageId);
    } catch (MmsException e) {
        Log.w(TAG, e);
    }
}
Also used : MmsException(org.thoughtcrime.securesms.mms.MmsException) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase)

Example 57 with MmsException

use of org.thoughtcrime.securesms.mms.MmsException in project Signal-Android by signalapp.

the class AttachmentDownloadJob method retrieveAttachment.

private void retrieveAttachment(long messageId, final AttachmentId attachmentId, final Attachment attachment) throws IOException, RetryLaterException {
    AttachmentDatabase database = SignalDatabase.attachments();
    File attachmentFile = database.getOrCreateTransferFile(attachmentId);
    try {
        SignalServiceMessageReceiver messageReceiver = ApplicationDependencies.getSignalServiceMessageReceiver();
        SignalServiceAttachmentPointer pointer = createAttachmentPointer(attachment);
        InputStream stream = messageReceiver.retrieveAttachment(pointer, attachmentFile, MAX_ATTACHMENT_SIZE, (total, progress) -> EventBus.getDefault().postSticky(new PartProgressEvent(attachment, PartProgressEvent.Type.NETWORK, total, progress)));
        database.insertAttachmentsForPlaceholder(messageId, attachmentId, stream);
    } catch (RangeException e) {
        Log.w(TAG, "Range exception, file size " + attachmentFile.length(), e);
        if (attachmentFile.delete()) {
            Log.i(TAG, "Deleted temp download file to recover");
            throw new RetryLaterException(e);
        } else {
            throw new IOException("Failed to delete temp download file following range exception");
        }
    } catch (InvalidPartException | NonSuccessfulResponseCodeException | InvalidMessageException | MmsException | MissingConfigurationException e) {
        Log.w(TAG, "Experienced exception while trying to download an attachment.", e);
        markFailed(messageId, attachmentId);
    }
}
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) IOException(java.io.IOException) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase) MmsException(org.thoughtcrime.securesms.mms.MmsException) MissingConfigurationException(org.whispersystems.signalservice.api.push.exceptions.MissingConfigurationException) SignalServiceMessageReceiver(org.whispersystems.signalservice.api.SignalServiceMessageReceiver) RangeException(org.whispersystems.signalservice.api.push.exceptions.RangeException) RetryLaterException(org.thoughtcrime.securesms.transport.RetryLaterException) File(java.io.File)

Example 58 with MmsException

use of org.thoughtcrime.securesms.mms.MmsException in project Signal-Android by signalapp.

the class GroupManagerV2 method sendGroupUpdate.

@NonNull
private RecipientAndThread sendGroupUpdate(@NonNull GroupMasterKey masterKey, @NonNull GroupMutation groupMutation, @Nullable GroupChange signedGroupChange, boolean sendToMembers) {
    GroupId.V2 groupId = GroupId.v2(masterKey);
    Recipient groupRecipient = Recipient.externalGroupExact(context, groupId);
    DecryptedGroupV2Context decryptedGroupV2Context = GroupProtoUtil.createDecryptedGroupV2Context(masterKey, groupMutation, signedGroupChange);
    OutgoingGroupUpdateMessage outgoingMessage = new OutgoingGroupUpdateMessage(groupRecipient, decryptedGroupV2Context, null, System.currentTimeMillis(), 0, false, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    DecryptedGroupChange plainGroupChange = groupMutation.getGroupChange();
    if (plainGroupChange != null && DecryptedGroupUtil.changeIsEmptyExceptForProfileKeyChanges(plainGroupChange)) {
        if (sendToMembers) {
            ApplicationDependencies.getJobManager().add(PushGroupSilentUpdateSendJob.create(context, groupId, groupMutation.getNewGroupState(), outgoingMessage));
        }
        return new RecipientAndThread(groupRecipient, -1);
    } else {
        if (sendToMembers) {
            long threadId = MessageSender.send(context, outgoingMessage, -1, false, null, null);
            return new RecipientAndThread(groupRecipient, threadId);
        } else {
            long threadId = SignalDatabase.threads().getOrCreateValidThreadId(outgoingMessage.getRecipient(), -1, outgoingMessage.getDistributionType());
            try {
                long messageId = SignalDatabase.mms().insertMessageOutbox(outgoingMessage, threadId, false, null);
                SignalDatabase.mms().markAsSent(messageId, true);
                SignalDatabase.threads().update(threadId, true);
            } catch (MmsException e) {
                throw new AssertionError(e);
            }
            return new RecipientAndThread(groupRecipient, threadId);
        }
    }
}
Also used : MmsException(org.thoughtcrime.securesms.mms.MmsException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) OutgoingGroupUpdateMessage(org.thoughtcrime.securesms.mms.OutgoingGroupUpdateMessage) DecryptedGroupV2Context(org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context) NonNull(androidx.annotation.NonNull)

Example 59 with MmsException

use of org.thoughtcrime.securesms.mms.MmsException in project Signal-Android by signalapp.

the class GroupsV1MigrationUtil method handleLeftBehind.

private static void handleLeftBehind(@NonNull Context context, @NonNull GroupId.V1 gv1Id, @NonNull Recipient groupRecipient, long threadId) {
    OutgoingMediaMessage leaveMessage = GroupUtil.createGroupV1LeaveMessage(gv1Id, groupRecipient);
    try {
        long id = SignalDatabase.mms().insertMessageOutbox(leaveMessage, threadId, false, null);
        SignalDatabase.mms().markAsSent(id, true);
    } catch (MmsException e) {
        Log.w(TAG, "Failed to insert group leave message!", e);
    }
    SignalDatabase.groups().setActive(gv1Id, false);
    SignalDatabase.groups().remove(gv1Id, Recipient.self().getId());
}
Also used : MmsException(org.thoughtcrime.securesms.mms.MmsException) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage)

Example 60 with MmsException

use of org.thoughtcrime.securesms.mms.MmsException in project Signal-Android by signalapp.

the class PushGroupSendJob method enqueue.

@WorkerThread
public static void enqueue(@NonNull Context context, @NonNull JobManager jobManager, long messageId, @NonNull RecipientId destination, @Nullable RecipientId filterAddress) {
    try {
        Recipient group = Recipient.resolved(destination);
        if (!group.isPushGroup()) {
            throw new AssertionError("Not a group!");
        }
        MessageDatabase database = SignalDatabase.mms();
        OutgoingMediaMessage message = database.getOutgoingMessage(messageId);
        Set<String> attachmentUploadIds = enqueueCompressingAndUploadAttachmentsChains(jobManager, message);
        if (!SignalDatabase.groups().isActive(group.requireGroupId()) && !isGv2UpdateMessage(message)) {
            throw new MmsException("Inactive group!");
        }
        jobManager.add(new PushGroupSendJob(messageId, destination, filterAddress, !attachmentUploadIds.isEmpty()), attachmentUploadIds, attachmentUploadIds.isEmpty() ? null : destination.toQueueKey());
    } catch (NoSuchMessageException | MmsException e) {
        Log.w(TAG, "Failed to enqueue message.", e);
        SignalDatabase.mms().markAsSentFailed(messageId);
        notifyMediaMessageDeliveryFailed(context, messageId);
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) MmsException(org.thoughtcrime.securesms.mms.MmsException) NoSuchMessageException(org.thoughtcrime.securesms.database.NoSuchMessageException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) ByteString(com.google.protobuf.ByteString) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

MmsException (org.thoughtcrime.securesms.mms.MmsException)61 IOException (java.io.IOException)26 Recipient (org.thoughtcrime.securesms.recipients.Recipient)26 MessageDatabase (org.thoughtcrime.securesms.database.MessageDatabase)24 NonNull (androidx.annotation.NonNull)20 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)20 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)19 Nullable (androidx.annotation.Nullable)18 Attachment (org.thoughtcrime.securesms.attachments.Attachment)18 AttachmentDatabase (org.thoughtcrime.securesms.database.AttachmentDatabase)15 List (java.util.List)14 MessageId (org.thoughtcrime.securesms.database.model.MessageId)14 Context (android.content.Context)12 WorkerThread (androidx.annotation.WorkerThread)12 Stream (com.annimon.stream.Stream)12 LinkedList (java.util.LinkedList)12 Log (org.signal.core.util.logging.Log)12 AttachmentId (org.thoughtcrime.securesms.attachments.AttachmentId)12 NoSuchMessageException (org.thoughtcrime.securesms.database.NoSuchMessageException)12 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)12