Search in sources :

Example 6 with SmsMessageRecord

use of org.thoughtcrime.securesms.database.model.SmsMessageRecord in project Signal-Android by signalapp.

the class SmsSentJob method handleSentResult.

private void handleSentResult(long messageId, int result) {
    try {
        SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
        SmsMessageRecord record = database.getMessage(messageId);
        switch(result) {
            case Activity.RESULT_OK:
                database.markAsSent(messageId, false);
                break;
            case SmsManager.RESULT_ERROR_NO_SERVICE:
            case SmsManager.RESULT_ERROR_RADIO_OFF:
                Log.w(TAG, "Service connectivity problem, requeuing...");
                ApplicationContext.getInstance(context).getJobManager().add(new SmsSendJob(context, messageId, record.getIndividualRecipient().getAddress().serialize()));
                break;
            default:
                database.markAsSentFailed(messageId);
                MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId());
        }
    } catch (NoSuchMessageException e) {
        Log.w(TAG, e);
    }
}
Also used : NoSuchMessageException(org.thoughtcrime.securesms.database.NoSuchMessageException) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase)

Example 7 with SmsMessageRecord

use of org.thoughtcrime.securesms.database.model.SmsMessageRecord in project Signal-Android by signalapp.

the class SmsDatabase method getMessage.

public SmsMessageRecord getMessage(long messageId) throws NoSuchMessageException {
    SQLiteDatabase db = databaseHelper.getReadableDatabase();
    Cursor cursor = db.query(TABLE_NAME, MESSAGE_PROJECTION, ID_WHERE, new String[] { messageId + "" }, null, null, null);
    Reader reader = new Reader(cursor);
    SmsMessageRecord record = reader.getNext();
    reader.close();
    if (record == null)
        throw new NoSuchMessageException("No message for ID: " + messageId);
    else
        return record;
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) Cursor(android.database.Cursor)

Example 8 with SmsMessageRecord

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

the class SmsSendJob method onSend.

@Override
public void onSend() throws NoSuchMessageException, TooManyRetriesException, UndeliverableMessageException {
    if (runAttempt >= MAX_ATTEMPTS) {
        warn(TAG, "Hit the retry limit. Failing.");
        throw new TooManyRetriesException();
    }
    MessageDatabase database = SignalDatabase.sms();
    SmsMessageRecord record = database.getSmsMessage(messageId);
    if (!record.isPending() && !record.isFailed()) {
        warn(TAG, "Message " + messageId + " was already sent. Ignoring.");
        return;
    }
    if (!record.getRecipient().hasSmsAddress()) {
        throw new UndeliverableMessageException("Recipient didn't have an SMS address! " + record.getRecipient().getId());
    }
    try {
        log(TAG, String.valueOf(record.getDateSent()), "Sending message: " + messageId + " (attempt " + runAttempt + ")");
        deliver(record);
        log(TAG, String.valueOf(record.getDateSent()), "Sent message: " + messageId);
    } catch (UndeliverableMessageException ude) {
        warn(TAG, ude);
        SignalDatabase.sms().markAsSentFailed(record.getId());
        ApplicationDependencies.getMessageNotifier().notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId());
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException)

Example 9 with SmsMessageRecord

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

the class MessageSender method sendLocalTextSelf.

private static void sendLocalTextSelf(Context context, long messageId) {
    try {
        ExpiringMessageManager expirationManager = ApplicationDependencies.getExpiringMessageManager();
        MessageDatabase smsDatabase = SignalDatabase.sms();
        MmsSmsDatabase mmsSmsDatabase = SignalDatabase.mmsSms();
        SmsMessageRecord message = smsDatabase.getSmsMessage(messageId);
        SyncMessageId syncId = new SyncMessageId(Recipient.self().getId(), message.getDateSent());
        smsDatabase.markAsSent(messageId, true);
        smsDatabase.markUnidentified(messageId, true);
        mmsSmsDatabase.incrementDeliveryReceiptCount(syncId, System.currentTimeMillis());
        mmsSmsDatabase.incrementReadReceiptCount(syncId, System.currentTimeMillis());
        if (message.getExpiresIn() > 0) {
            smsDatabase.markExpireStarted(messageId);
            expirationManager.scheduleDeletion(message.getId(), message.isMms(), message.getExpiresIn());
        }
    } catch (NoSuchMessageException e) {
        Log.w(TAG, "Failed to update self-sent message.", e);
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) NoSuchMessageException(org.thoughtcrime.securesms.database.NoSuchMessageException) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) MmsSmsDatabase(org.thoughtcrime.securesms.database.MmsSmsDatabase) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)

Example 10 with SmsMessageRecord

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

the class PushTextSendJob method onPushSend.

@Override
public void onPushSend() throws IOException, NoSuchMessageException, UndeliverableMessageException, RetryLaterException {
    SignalLocalMetrics.IndividualMessageSend.onJobStarted(messageId);
    ExpiringMessageManager expirationManager = ApplicationDependencies.getExpiringMessageManager();
    MessageDatabase database = SignalDatabase.sms();
    SmsMessageRecord record = database.getSmsMessage(messageId);
    if (!record.isPending() && !record.isFailed()) {
        warn(TAG, String.valueOf(record.getDateSent()), "Message " + messageId + " was already sent. Ignoring.");
        return;
    }
    try {
        log(TAG, String.valueOf(record.getDateSent()), "Sending message: " + messageId + ",  Recipient: " + record.getRecipient().getId() + ", Thread: " + record.getThreadId());
        RecipientUtil.shareProfileIfFirstSecureMessage(context, record.getRecipient());
        Recipient recipient = record.getRecipient().resolve();
        byte[] profileKey = recipient.getProfileKey();
        UnidentifiedAccessMode accessMode = recipient.getUnidentifiedAccessMode();
        boolean unidentified = deliver(record);
        database.markAsSent(messageId, true);
        database.markUnidentified(messageId, unidentified);
        if (recipient.isSelf()) {
            SyncMessageId id = new SyncMessageId(recipient.getId(), record.getDateSent());
            SignalDatabase.mmsSms().incrementDeliveryReceiptCount(id, System.currentTimeMillis());
            SignalDatabase.mmsSms().incrementReadReceiptCount(id, System.currentTimeMillis());
        }
        if (unidentified && accessMode == UnidentifiedAccessMode.UNKNOWN && profileKey == null) {
            log(TAG, String.valueOf(record.getDateSent()), "Marking recipient as UD-unrestricted following a UD send.");
            SignalDatabase.recipients().setUnidentifiedAccessMode(recipient.getId(), UnidentifiedAccessMode.UNRESTRICTED);
        } else if (unidentified && accessMode == UnidentifiedAccessMode.UNKNOWN) {
            log(TAG, String.valueOf(record.getDateSent()), "Marking recipient as UD-enabled following a UD send.");
            SignalDatabase.recipients().setUnidentifiedAccessMode(recipient.getId(), UnidentifiedAccessMode.ENABLED);
        } else if (!unidentified && accessMode != UnidentifiedAccessMode.DISABLED) {
            log(TAG, String.valueOf(record.getDateSent()), "Marking recipient as UD-disabled following a non-UD send.");
            SignalDatabase.recipients().setUnidentifiedAccessMode(recipient.getId(), UnidentifiedAccessMode.DISABLED);
        }
        if (record.getExpiresIn() > 0) {
            database.markExpireStarted(messageId);
            expirationManager.scheduleDeletion(record.getId(), record.isMms(), record.getExpiresIn());
        }
        log(TAG, String.valueOf(record.getDateSent()), "Sent message: " + messageId);
    } catch (InsecureFallbackApprovalException e) {
        warn(TAG, String.valueOf(record.getDateSent()), "Failure", e);
        database.markAsPendingInsecureSmsFallback(record.getId());
        ApplicationDependencies.getMessageNotifier().notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId());
        ApplicationDependencies.getJobManager().add(new DirectoryRefreshJob(false));
    } catch (UntrustedIdentityException e) {
        warn(TAG, String.valueOf(record.getDateSent()), "Failure", e);
        RecipientId recipientId = Recipient.external(context, e.getIdentifier()).getId();
        database.addMismatchedIdentity(record.getId(), recipientId, e.getIdentityKey());
        database.markAsSentFailed(record.getId());
        database.markAsPush(record.getId());
        RetrieveProfileJob.enqueue(recipientId);
    } catch (ProofRequiredException e) {
        handleProofRequiredException(e, record.getRecipient(), record.getThreadId(), messageId, false);
    }
    SignalLocalMetrics.IndividualMessageSend.onJobFinished(messageId);
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ProofRequiredException(org.whispersystems.signalservice.api.push.exceptions.ProofRequiredException) UnidentifiedAccessMode(org.thoughtcrime.securesms.database.RecipientDatabase.UnidentifiedAccessMode) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)

Aggregations

SmsMessageRecord (org.thoughtcrime.securesms.database.model.SmsMessageRecord)17 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)4 MessageDatabase (org.thoughtcrime.securesms.database.MessageDatabase)4 NoSuchMessageException (org.thoughtcrime.securesms.database.NoSuchMessageException)4 SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)4 ExpiringMessageManager (org.thoughtcrime.securesms.service.ExpiringMessageManager)4 Cursor (android.database.Cursor)3 InsecureFallbackApprovalException (org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)3 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)3 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)3 ContentValues (android.content.ContentValues)2 Pair (android.util.Pair)2 SQLiteDatabase (net.sqlcipher.database.SQLiteDatabase)2 SyncMessageId (org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)2 TrimThreadJob (org.thoughtcrime.securesms.jobs.TrimThreadJob)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)1 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)1 MmsSmsDatabase (org.thoughtcrime.securesms.database.MmsSmsDatabase)1 UnidentifiedAccessMode (org.thoughtcrime.securesms.database.RecipientDatabase.UnidentifiedAccessMode)1