Search in sources :

Example 46 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Conversations by siacs.

the class DatabaseBackend method onUpgrade.

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    if (oldVersion < 2 && newVersion >= 2) {
        db.execSQL("update " + Account.TABLENAME + " set " + Account.OPTIONS + " = " + Account.OPTIONS + " | 8");
    }
    if (oldVersion < 3 && newVersion >= 3) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.TYPE + " NUMBER");
    }
    if (oldVersion < 5 && newVersion >= 5) {
        db.execSQL("DROP TABLE " + Contact.TABLENAME);
        db.execSQL(CREATE_CONTATCS_STATEMENT);
        db.execSQL("UPDATE " + Account.TABLENAME + " SET " + Account.ROSTERVERSION + " = NULL");
    }
    if (oldVersion < 6 && newVersion >= 6) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.TRUE_COUNTERPART + " TEXT");
    }
    if (oldVersion < 7 && newVersion >= 7) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.REMOTE_MSG_ID + " TEXT");
        db.execSQL("ALTER TABLE " + Contact.TABLENAME + " ADD COLUMN " + Contact.AVATAR + " TEXT");
        db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.AVATAR + " TEXT");
    }
    if (oldVersion < 8 && newVersion >= 8) {
        db.execSQL("ALTER TABLE " + Conversation.TABLENAME + " ADD COLUMN " + Conversation.ATTRIBUTES + " TEXT");
    }
    if (oldVersion < 9 && newVersion >= 9) {
        db.execSQL("ALTER TABLE " + Contact.TABLENAME + " ADD COLUMN " + Contact.LAST_TIME + " NUMBER");
        db.execSQL("ALTER TABLE " + Contact.TABLENAME + " ADD COLUMN " + Contact.LAST_PRESENCE + " TEXT");
    }
    if (oldVersion < 10 && newVersion >= 10) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.RELATIVE_FILE_PATH + " TEXT");
    }
    if (oldVersion < 11 && newVersion >= 11) {
        db.execSQL("ALTER TABLE " + Contact.TABLENAME + " ADD COLUMN " + Contact.GROUPS + " TEXT");
        db.execSQL("delete from " + Contact.TABLENAME);
        db.execSQL("update " + Account.TABLENAME + " set " + Account.ROSTERVERSION + " = NULL");
    }
    if (oldVersion < 12 && newVersion >= 12) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.SERVER_MSG_ID + " TEXT");
    }
    if (oldVersion < 13 && newVersion >= 13) {
        db.execSQL("delete from " + Contact.TABLENAME);
        db.execSQL("update " + Account.TABLENAME + " set " + Account.ROSTERVERSION + " = NULL");
    }
    if (oldVersion < 14 && newVersion >= 14) {
        canonicalizeJids(db);
    }
    if (oldVersion < 15 && newVersion >= 15) {
        recreateAxolotlDb(db);
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.FINGERPRINT + " TEXT");
    }
    if (oldVersion < 16 && newVersion >= 16) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.CARBON + " INTEGER");
    }
    if (oldVersion < 19 && newVersion >= 19) {
        db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.DISPLAY_NAME + " TEXT");
    }
    if (oldVersion < 20 && newVersion >= 20) {
        db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.HOSTNAME + " TEXT");
        db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.PORT + " NUMBER DEFAULT 5222");
    }
    if (oldVersion < 26 && newVersion >= 26) {
        db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.STATUS + " TEXT");
        db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.STATUS_MESSAGE + " TEXT");
    }
    if (oldVersion < 40 && newVersion >= 40) {
        db.execSQL("ALTER TABLE " + Account.TABLENAME + " ADD COLUMN " + Account.RESOURCE + " TEXT");
    }
    /* Any migrations that alter the Account table need to happen BEFORE this migration, as it
         * depends on account de-serialization.
         */
    if (oldVersion < 17 && newVersion >= 17 && newVersion < 31) {
        List<Account> accounts = getAccounts(db);
        for (Account account : accounts) {
            String ownDeviceIdString = account.getKey(SQLiteAxolotlStore.JSONKEY_REGISTRATION_ID);
            if (ownDeviceIdString == null) {
                continue;
            }
            int ownDeviceId = Integer.valueOf(ownDeviceIdString);
            SignalProtocolAddress ownAddress = new SignalProtocolAddress(account.getJid().asBareJid().toString(), ownDeviceId);
            deleteSession(db, account, ownAddress);
            IdentityKeyPair identityKeyPair = loadOwnIdentityKeyPair(db, account);
            if (identityKeyPair != null) {
                String[] selectionArgs = { account.getUuid(), CryptoHelper.bytesToHex(identityKeyPair.getPublicKey().serialize()) };
                ContentValues values = new ContentValues();
                values.put(SQLiteAxolotlStore.TRUSTED, 2);
                db.update(SQLiteAxolotlStore.IDENTITIES_TABLENAME, values, SQLiteAxolotlStore.ACCOUNT + " = ? AND " + SQLiteAxolotlStore.FINGERPRINT + " = ? ", selectionArgs);
            } else {
                Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not load own identity key pair");
            }
        }
    }
    if (oldVersion < 18 && newVersion >= 18) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.READ + " NUMBER DEFAULT 1");
    }
    if (oldVersion < 21 && newVersion >= 21) {
        List<Account> accounts = getAccounts(db);
        for (Account account : accounts) {
            account.unsetPgpSignature();
            db.update(Account.TABLENAME, account.getContentValues(), Account.UUID + "=?", new String[] { account.getUuid() });
        }
    }
    if (oldVersion >= 15 && oldVersion < 22 && newVersion >= 22) {
        db.execSQL("ALTER TABLE " + SQLiteAxolotlStore.IDENTITIES_TABLENAME + " ADD COLUMN " + SQLiteAxolotlStore.CERTIFICATE);
    }
    if (oldVersion < 23 && newVersion >= 23) {
        db.execSQL(CREATE_DISCOVERY_RESULTS_STATEMENT);
    }
    if (oldVersion < 24 && newVersion >= 24) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.EDITED + " TEXT");
    }
    if (oldVersion < 25 && newVersion >= 25) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.OOB + " INTEGER");
    }
    if (oldVersion < 26 && newVersion >= 26) {
        db.execSQL(CREATE_PRESENCE_TEMPLATES_STATEMENT);
    }
    if (oldVersion < 27 && newVersion >= 27) {
        db.execSQL("DELETE FROM " + ServiceDiscoveryResult.TABLENAME);
    }
    if (oldVersion < 28 && newVersion >= 28) {
        canonicalizeJids(db);
    }
    if (oldVersion < 29 && newVersion >= 29) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.ERROR_MESSAGE + " TEXT");
    }
    if (oldVersion >= 15 && oldVersion < 31 && newVersion >= 31) {
        db.execSQL("ALTER TABLE " + SQLiteAxolotlStore.IDENTITIES_TABLENAME + " ADD COLUMN " + SQLiteAxolotlStore.TRUST + " TEXT");
        db.execSQL("ALTER TABLE " + SQLiteAxolotlStore.IDENTITIES_TABLENAME + " ADD COLUMN " + SQLiteAxolotlStore.ACTIVE + " NUMBER");
        HashMap<Integer, ContentValues> migration = new HashMap<>();
        migration.put(0, createFingerprintStatusContentValues(FingerprintStatus.Trust.TRUSTED, true));
        migration.put(1, createFingerprintStatusContentValues(FingerprintStatus.Trust.TRUSTED, true));
        migration.put(2, createFingerprintStatusContentValues(FingerprintStatus.Trust.UNTRUSTED, true));
        migration.put(3, createFingerprintStatusContentValues(FingerprintStatus.Trust.COMPROMISED, false));
        migration.put(4, createFingerprintStatusContentValues(FingerprintStatus.Trust.TRUSTED, false));
        migration.put(5, createFingerprintStatusContentValues(FingerprintStatus.Trust.TRUSTED, false));
        migration.put(6, createFingerprintStatusContentValues(FingerprintStatus.Trust.UNTRUSTED, false));
        migration.put(7, createFingerprintStatusContentValues(FingerprintStatus.Trust.VERIFIED_X509, true));
        migration.put(8, createFingerprintStatusContentValues(FingerprintStatus.Trust.VERIFIED_X509, false));
        for (Map.Entry<Integer, ContentValues> entry : migration.entrySet()) {
            String whereClause = SQLiteAxolotlStore.TRUSTED + "=?";
            String[] where = { String.valueOf(entry.getKey()) };
            db.update(SQLiteAxolotlStore.IDENTITIES_TABLENAME, entry.getValue(), whereClause, where);
        }
    }
    if (oldVersion >= 15 && oldVersion < 32 && newVersion >= 32) {
        db.execSQL("ALTER TABLE " + SQLiteAxolotlStore.IDENTITIES_TABLENAME + " ADD COLUMN " + SQLiteAxolotlStore.LAST_ACTIVATION + " NUMBER");
        ContentValues defaults = new ContentValues();
        defaults.put(SQLiteAxolotlStore.LAST_ACTIVATION, System.currentTimeMillis());
        db.update(SQLiteAxolotlStore.IDENTITIES_TABLENAME, defaults, null, null);
    }
    if (oldVersion >= 15 && oldVersion < 33 && newVersion >= 33) {
        String whereClause = SQLiteAxolotlStore.OWN + "=1";
        db.update(SQLiteAxolotlStore.IDENTITIES_TABLENAME, createFingerprintStatusContentValues(FingerprintStatus.Trust.VERIFIED, true), whereClause, null);
    }
    if (oldVersion < 34 && newVersion >= 34) {
        db.execSQL(CREATE_MESSAGE_TIME_INDEX);
        final File oldPicturesDirectory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/Conversations/");
        final File oldFilesDirectory = new File(Environment.getExternalStorageDirectory() + "/Conversations/");
        final File newFilesDirectory = new File(Environment.getExternalStorageDirectory() + "/Conversations/Media/Conversations Files/");
        final File newVideosDirectory = new File(Environment.getExternalStorageDirectory() + "/Conversations/Media/Conversations Videos/");
        if (oldPicturesDirectory.exists() && oldPicturesDirectory.isDirectory()) {
            final File newPicturesDirectory = new File(Environment.getExternalStorageDirectory() + "/Conversations/Media/Conversations Images/");
            newPicturesDirectory.getParentFile().mkdirs();
            if (oldPicturesDirectory.renameTo(newPicturesDirectory)) {
                Log.d(Config.LOGTAG, "moved " + oldPicturesDirectory.getAbsolutePath() + " to " + newPicturesDirectory.getAbsolutePath());
            }
        }
        if (oldFilesDirectory.exists() && oldFilesDirectory.isDirectory()) {
            newFilesDirectory.mkdirs();
            newVideosDirectory.mkdirs();
            final File[] files = oldFilesDirectory.listFiles();
            if (files == null) {
                return;
            }
            for (File file : files) {
                if (file.getName().equals(".nomedia")) {
                    if (file.delete()) {
                        Log.d(Config.LOGTAG, "deleted nomedia file in " + oldFilesDirectory.getAbsolutePath());
                    }
                } else if (file.isFile()) {
                    final String name = file.getName();
                    boolean isVideo = false;
                    int start = name.lastIndexOf('.') + 1;
                    if (start < name.length()) {
                        String mime = MimeUtils.guessMimeTypeFromExtension(name.substring(start));
                        isVideo = mime != null && mime.startsWith("video/");
                    }
                    File dst = new File((isVideo ? newVideosDirectory : newFilesDirectory).getAbsolutePath() + "/" + file.getName());
                    if (file.renameTo(dst)) {
                        Log.d(Config.LOGTAG, "moved " + file + " to " + dst);
                    }
                }
            }
        }
    }
    if (oldVersion < 35 && newVersion >= 35) {
        db.execSQL(CREATE_MESSAGE_CONVERSATION_INDEX);
    }
    if (oldVersion < 36 && newVersion >= 36) {
        List<Account> accounts = getAccounts(db);
        for (Account account : accounts) {
            account.setOption(Account.OPTION_REQUIRES_ACCESS_MODE_CHANGE, true);
            account.setOption(Account.OPTION_LOGGED_IN_SUCCESSFULLY, false);
            db.update(Account.TABLENAME, account.getContentValues(), Account.UUID + "=?", new String[] { account.getUuid() });
        }
    }
    if (oldVersion < 37 && newVersion >= 37) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.READ_BY_MARKERS + " TEXT");
    }
    if (oldVersion < 38 && newVersion >= 38) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.MARKABLE + " NUMBER DEFAULT 0");
    }
    if (oldVersion < 39 && newVersion >= 39) {
        db.execSQL(CREATE_RESOLVER_RESULTS_TABLE);
    }
    if (QuickConversationsService.isQuicksy() && oldVersion < 43 && newVersion >= 43) {
        List<Account> accounts = getAccounts(db);
        for (Account account : accounts) {
            account.setOption(Account.OPTION_MAGIC_CREATE, true);
            db.update(Account.TABLENAME, account.getContentValues(), Account.UUID + "=?", new String[] { account.getUuid() });
        }
    }
    if (oldVersion < 44 && newVersion >= 44) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.DELETED + " NUMBER DEFAULT 0");
        db.execSQL(CREATE_MESSAGE_DELETED_INDEX);
        db.execSQL(CREATE_MESSAGE_RELATIVE_FILE_PATH_INDEX);
        db.execSQL(CREATE_MESSAGE_TYPE_INDEX);
    }
    if (oldVersion < 45 && newVersion >= 45) {
        db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.BODY_LANGUAGE);
    }
    if (oldVersion < 46 && newVersion >= 46) {
        final long start = SystemClock.elapsedRealtime();
        db.rawQuery("PRAGMA secure_delete = FALSE", null).close();
        db.execSQL("update " + Message.TABLENAME + " set " + Message.EDITED + "=NULL");
        db.rawQuery("PRAGMA secure_delete=ON", null).close();
        final long diff = SystemClock.elapsedRealtime() - start;
        Log.d(Config.LOGTAG, "deleted old edit information in " + diff + "ms");
    }
    if (oldVersion < 47 && newVersion >= 47) {
        db.execSQL("ALTER TABLE " + Contact.TABLENAME + " ADD COLUMN " + Contact.PRESENCE_NAME + " TEXT");
    }
    if (oldVersion < 48 && newVersion >= 48) {
        db.execSQL("ALTER TABLE " + Contact.TABLENAME + " ADD COLUMN " + Contact.RTP_CAPABILITY + " TEXT");
    }
    if (oldVersion < 49 && newVersion >= 49) {
        db.beginTransaction();
        db.execSQL("DROP TRIGGER IF EXISTS after_message_insert;");
        db.execSQL("DROP TRIGGER IF EXISTS after_message_update;");
        db.execSQL("DROP TRIGGER IF EXISTS after_message_delete;");
        db.execSQL("DROP TABLE IF EXISTS messages_index;");
        // a hack that should not be necessary, but
        // there was at least one occurence when SQLite failed at this
        db.execSQL("DROP TABLE IF EXISTS messages_index_docsize;");
        db.execSQL("DROP TABLE IF EXISTS messages_index_segdir;");
        db.execSQL("DROP TABLE IF EXISTS messages_index_segments;");
        db.execSQL("DROP TABLE IF EXISTS messages_index_stat;");
        db.execSQL(CREATE_MESSAGE_INDEX_TABLE);
        db.execSQL(CREATE_MESSAGE_INSERT_TRIGGER);
        db.execSQL(CREATE_MESSAGE_UPDATE_TRIGGER);
        db.execSQL(CREATE_MESSAGE_DELETE_TRIGGER);
        db.setTransactionSuccessful();
        db.endTransaction();
        requiresMessageIndexRebuild = true;
    }
}
Also used : ContentValues(android.content.ContentValues) Account(eu.siacs.conversations.entities.Account) HashMap(java.util.HashMap) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) Map(java.util.Map) HashMap(java.util.HashMap) File(java.io.File) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Example 47 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by WhisperSystems.

the class SenderKeyDistributionSendJob method onRun.

@Override
protected void onRun() throws Exception {
    GroupDatabase groupDatabase = SignalDatabase.groups();
    if (!groupDatabase.isCurrentMember(groupId, recipientId)) {
        Log.w(TAG, recipientId + " is no longer a member of " + groupId + "! Not sending.");
        return;
    }
    Recipient recipient = Recipient.resolved(recipientId);
    if (recipient.getSenderKeyCapability() != Recipient.Capability.SUPPORTED) {
        Log.w(TAG, recipientId + " does not support sender key! Not sending.");
        return;
    }
    if (recipient.isUnregistered()) {
        Log.w(TAG, recipient.getId() + " not registered!");
        return;
    }
    SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
    List<SignalServiceAddress> address = Collections.singletonList(RecipientUtil.toSignalServiceAddress(context, recipient));
    DistributionId distributionId = groupDatabase.getOrCreateDistributionId(groupId);
    SenderKeyDistributionMessage message = messageSender.getOrCreateNewGroupSession(distributionId);
    List<Optional<UnidentifiedAccessPair>> access = UnidentifiedAccessUtil.getAccessFor(context, Collections.singletonList(recipient));
    SendMessageResult result = messageSender.sendSenderKeyDistributionMessage(distributionId, address, access, message, groupId.getDecodedId()).get(0);
    if (result.isSuccess()) {
        List<SignalProtocolAddress> addresses = result.getSuccess().getDevices().stream().map(device -> recipient.requireServiceId().toProtocolAddress(device)).collect(Collectors.toList());
        ApplicationDependencies.getProtocolStore().aci().markSenderKeySharedWith(distributionId, addresses);
    }
}
Also used : SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) NonNull(androidx.annotation.NonNull) Data(org.thoughtcrime.securesms.jobmanager.Data) RecipientUtil(org.thoughtcrime.securesms.recipients.RecipientUtil) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) UnidentifiedAccessPair(org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) Recipient(org.thoughtcrime.securesms.recipients.Recipient) DistributionId(org.whispersystems.signalservice.api.push.DistributionId) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) SenderKeyDistributionMessage(org.whispersystems.libsignal.protocol.SenderKeyDistributionMessage) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) UnidentifiedAccessUtil(org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) Collectors(java.util.stream.Collectors) Optional(org.whispersystems.libsignal.util.guava.Optional) TimeUnit(java.util.concurrent.TimeUnit) Log(org.signal.core.util.logging.Log) List(java.util.List) GroupId(org.thoughtcrime.securesms.groups.GroupId) Job(org.thoughtcrime.securesms.jobmanager.Job) Collections(java.util.Collections) Optional(org.whispersystems.libsignal.util.guava.Optional) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) Recipient(org.thoughtcrime.securesms.recipients.Recipient) DistributionId(org.whispersystems.signalservice.api.push.DistributionId) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) SenderKeyDistributionMessage(org.whispersystems.libsignal.protocol.SenderKeyDistributionMessage) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Example 48 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by WhisperSystems.

the class DirectoryHelper method hasSession.

public static boolean hasSession(@NonNull RecipientId id) {
    Recipient recipient = Recipient.resolved(id);
    if (!recipient.hasServiceId()) {
        return false;
    }
    SignalProtocolAddress protocolAddress = Recipient.resolved(id).requireServiceId().toProtocolAddress(SignalServiceAddress.DEFAULT_DEVICE_ID);
    return ApplicationDependencies.getProtocolStore().aci().containsSession(protocolAddress) || ApplicationDependencies.getProtocolStore().pni().containsSession(protocolAddress);
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Example 49 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by WhisperSystems.

the class PushDecryptMessageJob method handleSenderKeyDistributionMessage.

private void handleSenderKeyDistributionMessage(@NonNull SignalServiceAddress address, int deviceId, @NonNull SenderKeyDistributionMessage message) {
    Log.i(TAG, "Processing SenderKeyDistributionMessage.");
    SignalServiceMessageSender sender = ApplicationDependencies.getSignalServiceMessageSender();
    sender.processSenderKeyDistributionMessage(new SignalProtocolAddress(address.getIdentifier(), deviceId), message);
}
Also used : SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Example 50 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by WhisperSystems.

the class SenderKeySharedDatabase method getSharedWith.

/**
 * Get the set of recipientIds that know about the distributionId in question.
 */
@NonNull
public Set<SignalProtocolAddress> getSharedWith(@NonNull DistributionId distributionId) {
    SQLiteDatabase db = databaseHelper.getSignalReadableDatabase();
    String query = DISTRIBUTION_ID + " = ?";
    String[] args = SqlUtil.buildArgs(distributionId);
    Set<SignalProtocolAddress> addresses = new HashSet<>();
    try (Cursor cursor = db.query(TABLE_NAME, new String[] { ADDRESS, DEVICE }, query, args, null, null, null)) {
        while (cursor.moveToNext()) {
            String address = CursorUtil.requireString(cursor, ADDRESS);
            int device = CursorUtil.requireInt(cursor, DEVICE);
            addresses.add(new SignalProtocolAddress(address, device));
        }
    }
    return addresses;
}
Also used : Cursor(android.database.Cursor) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) HashSet(java.util.HashSet) NonNull(androidx.annotation.NonNull)

Aggregations

SignalProtocolAddress (org.whispersystems.libsignal.SignalProtocolAddress)57 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 PreKeyBundle (org.whispersystems.libsignal.state.PreKeyBundle)7 HashMap (java.util.HashMap)6 Recipient (org.thoughtcrime.securesms.recipients.Recipient)6 IdentityKey (org.whispersystems.libsignal.IdentityKey)6 IOException (java.io.IOException)5 SessionBuilder (org.whispersystems.libsignal.SessionBuilder)5 SessionRecord (org.whispersystems.libsignal.state.SessionRecord)5 Optional (org.whispersystems.libsignal.util.guava.Optional)5 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)5 File (java.io.File)4 List (java.util.List)4 Map (java.util.Map)4 SessionStore (org.whispersystems.libsignal.state.SessionStore)4 DistributionId (org.whispersystems.signalservice.api.push.DistributionId)4 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)4 ByteString (com.google.protobuf.ByteString)3