Search in sources :

Example 1 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.

the class ContactsCursorLoader method filterNonPushContacts.

@NonNull
private Cursor filterNonPushContacts(@NonNull Cursor cursor) {
    try {
        final long startMillis = System.currentTimeMillis();
        final MatrixCursor matrix = new MatrixCursor(new String[] { ContactsDatabase.ID_COLUMN, ContactsDatabase.NAME_COLUMN, ContactsDatabase.NUMBER_COLUMN, ContactsDatabase.NUMBER_TYPE_COLUMN, ContactsDatabase.LABEL_COLUMN, ContactsDatabase.CONTACT_TYPE_COLUMN });
        while (cursor.moveToNext()) {
            final String number = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NUMBER_COLUMN));
            final Recipients recipients = RecipientFactory.getRecipientsFromString(getContext(), number, true);
            if (DirectoryHelper.getUserCapabilities(getContext(), recipients).getTextCapability() != Capability.SUPPORTED) {
                matrix.addRow(new Object[] { cursor.getLong(cursor.getColumnIndexOrThrow(ContactsDatabase.ID_COLUMN)), cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NAME_COLUMN)), number, cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NUMBER_TYPE_COLUMN)), cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.LABEL_COLUMN)), ContactsDatabase.NORMAL_TYPE });
            }
        }
        Log.w(TAG, "filterNonPushContacts() -> " + (System.currentTimeMillis() - startMillis) + "ms");
        return matrix;
    } finally {
        cursor.close();
    }
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) MatrixCursor(android.database.MatrixCursor) NonNull(android.support.annotation.NonNull)

Example 2 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.

the class PlaintextBackupImporter method importPlaintext.

private static void importPlaintext(Context context, MasterSecret masterSecret) throws IOException {
    Log.w("PlaintextBackupImporter", "importPlaintext()");
    SmsDatabase db = DatabaseFactory.getSmsDatabase(context);
    SQLiteDatabase transaction = db.beginTransaction();
    try {
        ThreadDatabase threads = DatabaseFactory.getThreadDatabase(context);
        XmlBackup backup = new XmlBackup(getPlaintextExportFile().getAbsolutePath());
        MasterCipher masterCipher = new MasterCipher(masterSecret);
        Set<Long> modifiedThreads = new HashSet<Long>();
        XmlBackup.XmlBackupItem item;
        while ((item = backup.getNext()) != null) {
            Recipients recipients = RecipientFactory.getRecipientsFromString(context, item.getAddress(), false);
            long threadId = threads.getThreadIdFor(recipients);
            SQLiteStatement statement = db.createInsertStatement(transaction);
            if (item.getAddress() == null || item.getAddress().equals("null"))
                continue;
            if (!isAppropriateTypeForImport(item.getType()))
                continue;
            addStringToStatement(statement, 1, item.getAddress());
            addNullToStatement(statement, 2);
            addLongToStatement(statement, 3, item.getDate());
            addLongToStatement(statement, 4, item.getDate());
            addLongToStatement(statement, 5, item.getProtocol());
            addLongToStatement(statement, 6, item.getRead());
            addLongToStatement(statement, 7, item.getStatus());
            addTranslatedTypeToStatement(statement, 8, item.getType());
            addNullToStatement(statement, 9);
            addStringToStatement(statement, 10, item.getSubject());
            addEncryptedStingToStatement(masterCipher, statement, 11, item.getBody());
            addStringToStatement(statement, 12, item.getServiceCenter());
            addLongToStatement(statement, 13, threadId);
            modifiedThreads.add(threadId);
            statement.execute();
        }
        for (long threadId : modifiedThreads) {
            threads.update(threadId, true);
        }
        Log.w("PlaintextBackupImporter", "Exited loop");
    } catch (XmlPullParserException e) {
        Log.w("PlaintextBackupImporter", e);
        throw new IOException("XML Parsing error!");
    } finally {
        db.endTransaction(transaction);
    }
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) MasterCipher(org.thoughtcrime.securesms.crypto.MasterCipher) IOException(java.io.IOException) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteStatement(android.database.sqlite.SQLiteStatement) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) HashSet(java.util.HashSet)

Example 3 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.

the class SmsDatabase method insertCallLog.

@NonNull
private Pair<Long, Long> insertCallLog(@NonNull String number, long type, boolean unread) {
    Recipients recipients = RecipientFactory.getRecipientsFromString(context, number, true);
    long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
    ContentValues values = new ContentValues(6);
    values.put(ADDRESS, number);
    values.put(ADDRESS_DEVICE_ID, 1);
    values.put(DATE_RECEIVED, System.currentTimeMillis());
    values.put(DATE_SENT, System.currentTimeMillis());
    values.put(READ, unread ? 0 : 1);
    values.put(TYPE, type);
    values.put(THREAD_ID, threadId);
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    long messageId = db.insert(TABLE_NAME, null, values);
    DatabaseFactory.getThreadDatabase(context).update(threadId, true);
    notifyConversationListeners(threadId);
    jobManager.add(new TrimThreadJob(context, threadId));
    if (unread) {
        DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
    }
    return new Pair<>(messageId, threadId);
}
Also used : ContentValues(android.content.ContentValues) TrimThreadJob(org.thoughtcrime.securesms.jobs.TrimThreadJob) Recipients(org.thoughtcrime.securesms.recipients.Recipients) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Pair(android.util.Pair) NonNull(android.support.annotation.NonNull)

Example 4 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.

the class SmsMigrator method migrateDatabase.

public static void migrateDatabase(Context context, MasterSecret masterSecret, SmsMigrationProgressListener listener) {
    //    if (context.getSharedPreferences("SecureSMS", Context.MODE_PRIVATE).getBoolean("migrated", false))
    //      return;
    ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
    Cursor cursor = null;
    try {
        Uri threadListUri = Uri.parse("content://mms-sms/conversations?simple=true");
        cursor = context.getContentResolver().query(threadListUri, null, null, null, "date ASC");
        while (cursor != null && cursor.moveToNext()) {
            long theirThreadId = cursor.getLong(cursor.getColumnIndexOrThrow("_id"));
            String theirRecipients = cursor.getString(cursor.getColumnIndexOrThrow("recipient_ids"));
            Recipients ourRecipients = getOurRecipients(context, theirRecipients);
            ProgressDescription progress = new ProgressDescription(cursor.getCount(), cursor.getPosition(), 100, 0);
            if (ourRecipients != null) {
                long ourThreadId = threadDatabase.getThreadIdFor(ourRecipients);
                migrateConversation(context, masterSecret, listener, progress, theirThreadId, ourThreadId);
            }
            progress.incrementPrimaryComplete();
            listener.progressUpdate(progress);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    context.getSharedPreferences("SecureSMS", Context.MODE_PRIVATE).edit().putBoolean("migrated", true).apply();
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) Cursor(android.database.Cursor) Uri(android.net.Uri)

Example 5 with Recipients

use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.

the class MultiDeviceBlockedUpdateJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) throws IOException, UntrustedIdentityException {
    RecipientPreferenceDatabase database = DatabaseFactory.getRecipientPreferenceDatabase(context);
    SignalServiceMessageSender messageSender = messageSenderFactory.create();
    BlockedReader reader = database.readerForBlocked(database.getBlocked());
    List<String> blocked = new LinkedList<>();
    Recipients recipients;
    while ((recipients = reader.getNext()) != null) {
        if (recipients.isSingleRecipient()) {
            try {
                blocked.add(Util.canonicalizeNumber(context, recipients.getPrimaryRecipient().getNumber()));
            } catch (InvalidNumberException e) {
                Log.w(TAG, e);
            }
        }
    }
    messageSender.sendMessage(SignalServiceSyncMessage.forBlocked(new BlockedListMessage(blocked)));
}
Also used : RecipientPreferenceDatabase(org.thoughtcrime.securesms.database.RecipientPreferenceDatabase) Recipients(org.thoughtcrime.securesms.recipients.Recipients) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) BlockedReader(org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.BlockedReader) BlockedListMessage(org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage) LinkedList(java.util.LinkedList)

Aggregations

Recipients (org.thoughtcrime.securesms.recipients.Recipients)45 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)7 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)7 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)6 LinkedList (java.util.LinkedList)5 OutgoingTextMessage (org.thoughtcrime.securesms.sms.OutgoingTextMessage)5 Bundle (android.os.Bundle)4 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)4 ThreadDatabase (org.thoughtcrime.securesms.database.ThreadDatabase)4 RecipientFormattingException (org.thoughtcrime.securesms.recipients.RecipientFormattingException)4 IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)4 Intent (android.content.Intent)3 Cursor (android.database.Cursor)3 NonNull (android.support.annotation.NonNull)3 Attachment (org.thoughtcrime.securesms.attachments.Attachment)3 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)3 OutgoingGroupMediaMessage (org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage)3 Recipient (org.thoughtcrime.securesms.recipients.Recipient)3 MmsException (ws.com.google.android.mms.MmsException)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2