Search in sources :

Example 1 with SmsMessageRecord

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

the class PlaintextBackupExporter method exportPlaintext.

private static void exportPlaintext(Context context, MasterSecret masterSecret) throws IOException {
    int count = DatabaseFactory.getSmsDatabase(context).getMessageCount();
    XmlBackup.Writer writer = new XmlBackup.Writer(getPlaintextExportFile().getAbsolutePath(), count);
    SmsMessageRecord record;
    EncryptingSmsDatabase.Reader reader = null;
    int skip = 0;
    int ROW_LIMIT = 500;
    do {
        if (reader != null)
            reader.close();
        reader = DatabaseFactory.getEncryptingSmsDatabase(context).getMessages(masterSecret, skip, ROW_LIMIT);
        while ((record = reader.getNext()) != null) {
            XmlBackup.XmlBackupItem item = new XmlBackup.XmlBackupItem(0, record.getIndividualRecipient().getNumber(), record.getDateReceived(), MmsSmsColumns.Types.translateToSystemBaseType(record.getType()), null, record.getDisplayBody().toString(), null, 1, record.getDeliveryStatus());
            writer.writeItem(item);
        }
        skip += ROW_LIMIT;
    } while (reader.getCount() > 0);
    writer.close();
}
Also used : SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord)

Example 2 with SmsMessageRecord

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

the class SmsDatabase method copyMessageInbox.

public Pair<Long, Long> copyMessageInbox(long messageId) {
    Reader reader = readerFor(getMessage(messageId));
    SmsMessageRecord record = reader.getNext();
    ContentValues contentValues = new ContentValues();
    contentValues.put(TYPE, (record.getType() & ~Types.BASE_TYPE_MASK) | Types.BASE_INBOX_TYPE);
    contentValues.put(ADDRESS, record.getIndividualRecipient().getNumber());
    contentValues.put(ADDRESS_DEVICE_ID, record.getRecipientDeviceId());
    contentValues.put(DATE_RECEIVED, System.currentTimeMillis());
    contentValues.put(DATE_SENT, record.getDateSent());
    contentValues.put(PROTOCOL, 31337);
    contentValues.put(READ, 0);
    contentValues.put(BODY, record.getBody().getBody());
    contentValues.put(THREAD_ID, record.getThreadId());
    contentValues.put(EXPIRES_IN, record.getExpiresIn());
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    long newMessageId = db.insert(TABLE_NAME, null, contentValues);
    DatabaseFactory.getThreadDatabase(context).update(record.getThreadId(), true);
    notifyConversationListeners(record.getThreadId());
    jobManager.add(new TrimThreadJob(context, record.getThreadId()));
    reader.close();
    return new Pair<>(newMessageId, record.getThreadId());
}
Also used : ContentValues(android.content.ContentValues) TrimThreadJob(org.thoughtcrime.securesms.jobs.TrimThreadJob) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) Pair(android.util.Pair)

Example 3 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(MasterSecret masterSecret) throws NoSuchMessageException, RetryLaterException {
    ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
    SmsMessageRecord record = database.getMessage(masterSecret, messageId);
    try {
        Log.w(TAG, "Sending message: " + messageId);
        deliver(record);
        database.markAsSent(messageId, true);
        if (record.getExpiresIn() > 0) {
            database.markExpireStarted(messageId);
            expirationManager.scheduleDeletion(record.getId(), record.isMms(), record.getExpiresIn());
        }
    } catch (InsecureFallbackApprovalException e) {
        Log.w(TAG, e);
        database.markAsPendingInsecureSmsFallback(record.getId());
        MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipients(), record.getThreadId());
        ApplicationContext.getInstance(context).getJobManager().add(new DirectoryRefreshJob(context));
    } catch (UntrustedIdentityException e) {
        Log.w(TAG, e);
        Recipients recipients = RecipientFactory.getRecipientsFromString(context, e.getE164Number(), false);
        long recipientId = recipients.getPrimaryRecipient().getRecipientId();
        database.addMismatchedIdentity(record.getId(), recipientId, e.getIdentityKey());
        database.markAsSentFailed(record.getId());
        database.markAsPush(record.getId());
    }
}
Also used : UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) Recipients(org.thoughtcrime.securesms.recipients.Recipients) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)

Example 4 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(MasterSecret masterSecret) throws NoSuchMessageException {
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
    SmsMessageRecord record = database.getMessage(masterSecret, messageId);
    try {
        Log.w(TAG, "Sending message: " + messageId);
        deliver(record);
    } catch (UndeliverableMessageException ude) {
        Log.w(TAG, ude);
        DatabaseFactory.getSmsDatabase(context).markAsSentFailed(record.getId());
        MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipients(), record.getThreadId());
    }
}
Also used : SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException)

Example 5 with SmsMessageRecord

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

the class SmsSendJob method onSend.

@Override
public void onSend(MasterSecret masterSecret) throws NoSuchMessageException {
    SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
    SmsMessageRecord record = database.getMessage(messageId);
    try {
        Log.w(TAG, "Sending message: " + messageId);
        deliver(record);
    } catch (UndeliverableMessageException ude) {
        Log.w(TAG, ude);
        DatabaseFactory.getSmsDatabase(context).markAsSentFailed(record.getId());
        MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId());
    }
}
Also used : SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase)

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