Search in sources :

Example 1 with MmsDatabase

use of org.thoughtcrime.securesms.database.MmsDatabase in project Signal-Android by WhisperSystems.

the class PushMediaSendJob method onPushSend.

@Override
public void onPushSend(MasterSecret masterSecret) throws RetryLaterException, MmsException, NoSuchMessageException, UndeliverableMessageException {
    ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    OutgoingMediaMessage message = database.getOutgoingMessage(masterSecret, messageId);
    try {
        deliver(masterSecret, message);
        database.markAsSent(messageId, true);
        markAttachmentsUploaded(messageId, message.getAttachments());
        if (message.getExpiresIn() > 0 && !message.isExpirationUpdate()) {
            database.markExpireStarted(messageId);
            expirationManager.scheduleDeletion(messageId, true, message.getExpiresIn());
        }
    } catch (InsecureFallbackApprovalException ifae) {
        Log.w(TAG, ifae);
        database.markAsPendingInsecureSmsFallback(messageId);
        notifyMediaMessageDeliveryFailed(context, messageId);
        ApplicationContext.getInstance(context).getJobManager().add(new DirectoryRefreshJob(context));
    } catch (UntrustedIdentityException uie) {
        Log.w(TAG, uie);
        Recipients recipients = RecipientFactory.getRecipientsFromString(context, uie.getE164Number(), false);
        long recipientId = recipients.getPrimaryRecipient().getRecipientId();
        database.addMismatchedIdentity(messageId, recipientId, uie.getIdentityKey());
        database.markAsSentFailed(messageId);
    }
}
Also used : UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) Recipients(org.thoughtcrime.securesms.recipients.Recipients) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 2 with MmsDatabase

use of org.thoughtcrime.securesms.database.MmsDatabase in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleSynchronizeSentExpirationUpdate.

private long handleSynchronizeSentExpirationUpdate(@NonNull MasterSecretUnion masterSecret, @NonNull SentTranscriptMessage message, @NonNull Optional<Long> smsMessageId) throws MmsException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    Recipients recipients = getSyncMessageDestination(message);
    OutgoingExpirationUpdateMessage expirationUpdateMessage = new OutgoingExpirationUpdateMessage(recipients, message.getTimestamp(), message.getMessage().getExpiresInSeconds() * 1000);
    long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
    long messageId = database.insertMessageOutbox(masterSecret, expirationUpdateMessage, threadId, false);
    database.markAsSent(messageId, true);
    DatabaseFactory.getRecipientPreferenceDatabase(context).setExpireMessages(recipients, message.getMessage().getExpiresInSeconds());
    if (smsMessageId.isPresent()) {
        DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
    }
    return threadId;
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) OutgoingExpirationUpdateMessage(org.thoughtcrime.securesms.mms.OutgoingExpirationUpdateMessage) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 3 with MmsDatabase

use of org.thoughtcrime.securesms.database.MmsDatabase in project Signal-Android by WhisperSystems.

the class MmsDownloadJob method onCanceled.

@Override
public void onCanceled() {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    database.markDownloadState(messageId, MmsDatabase.Status.DOWNLOAD_SOFT_FAILURE);
    if (automatic) {
        database.markIncomingNotificationReceived(threadId);
        MessageNotifier.updateNotification(context, null, threadId);
    }
}
Also used : MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 4 with MmsDatabase

use of org.thoughtcrime.securesms.database.MmsDatabase 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)

Example 5 with MmsDatabase

use of org.thoughtcrime.securesms.database.MmsDatabase in project Signal-Android by WhisperSystems.

the class MmsReceiveJob method onRun.

@Override
public void onRun() {
    if (data == null) {
        Log.w(TAG, "Received NULL pdu, ignoring...");
        return;
    }
    PduParser parser = new PduParser(data);
    GenericPdu pdu = null;
    try {
        pdu = parser.parse();
    } catch (RuntimeException e) {
        Log.w(TAG, e);
    }
    if (isNotification(pdu) && !isBlocked(pdu)) {
        MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
        Pair<Long, Long> messageAndThreadId = database.insertMessageInbox((NotificationInd) pdu, subscriptionId);
        Log.w(TAG, "Inserted received MMS notification...");
        ApplicationContext.getInstance(context).getJobManager().add(new MmsDownloadJob(context, messageAndThreadId.first, messageAndThreadId.second, true));
    } else if (isNotification(pdu)) {
        Log.w(TAG, "*** Received blocked MMS, ignoring...");
    }
}
Also used : PduParser(ws.com.google.android.mms.pdu.PduParser) GenericPdu(ws.com.google.android.mms.pdu.GenericPdu) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Aggregations

MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)17 Recipients (org.thoughtcrime.securesms.recipients.Recipients)7 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)4 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)3 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)3 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)3 IncomingMediaMessage (org.thoughtcrime.securesms.mms.IncomingMediaMessage)3 MmsException (ws.com.google.android.mms.MmsException)3 Nullable (android.support.annotation.Nullable)2 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)2 SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)2 CompatMmsConnection (org.thoughtcrime.securesms.mms.CompatMmsConnection)2 ExpiringMessageManager (org.thoughtcrime.securesms.service.ExpiringMessageManager)2 InsecureFallbackApprovalException (org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)2 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)2 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)2 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)2 Uri (android.net.Uri)1