use of java.util.LinkedList in project Signal-Android by WhisperSystems.
the class PreKeyUtil method generatePreKeys.
public static List<PreKeyRecord> generatePreKeys(Context context) {
PreKeyStore preKeyStore = new TextSecurePreKeyStore(context);
List<PreKeyRecord> records = new LinkedList<>();
int preKeyIdOffset = getNextPreKeyId(context);
for (int i = 0; i < BATCH_SIZE; i++) {
int preKeyId = (preKeyIdOffset + i) % Medium.MAX_VALUE;
ECKeyPair keyPair = Curve.generateKeyPair();
PreKeyRecord record = new PreKeyRecord(preKeyId, keyPair);
preKeyStore.storePreKey(preKeyId, record);
records.add(record);
}
setNextPreKeyId(context, (preKeyIdOffset + BATCH_SIZE + 1) % Medium.MAX_VALUE);
return records;
}
use of java.util.LinkedList in project Signal-Android by WhisperSystems.
the class TextSecurePreKeyStore method loadSignedPreKeys.
@Override
public List<SignedPreKeyRecord> loadSignedPreKeys() {
synchronized (FILE_LOCK) {
File directory = getSignedPreKeyDirectory();
List<SignedPreKeyRecord> results = new LinkedList<>();
for (File signedPreKeyFile : directory.listFiles()) {
try {
if (!"index.dat".equals(signedPreKeyFile.getName())) {
results.add(new SignedPreKeyRecord(loadSerializedRecord(signedPreKeyFile)));
}
} catch (IOException | InvalidMessageException e) {
Log.w(TAG, e);
}
}
return results;
}
}
use of java.util.LinkedList in project Signal-Android by WhisperSystems.
the class ContactsDatabase method setRegisteredUsers.
@NonNull
public synchronized List<String> setRegisteredUsers(@NonNull Account account, @NonNull String localNumber, @NonNull List<ContactTokenDetails> registeredContacts, boolean remove) throws RemoteException, OperationApplicationException {
Map<String, ContactTokenDetails> registeredNumbers = new HashMap<>();
List<String> addedNumbers = new LinkedList<>();
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
Map<String, SignalContact> currentContacts = getSignalRawContacts(account, localNumber);
for (ContactTokenDetails registeredContact : registeredContacts) {
String registeredNumber = registeredContact.getNumber();
registeredNumbers.put(registeredNumber, registeredContact);
if (!currentContacts.containsKey(registeredNumber)) {
Optional<SystemContactInfo> systemContactInfo = getSystemContactInfo(registeredNumber, localNumber);
if (systemContactInfo.isPresent()) {
Log.w(TAG, "Adding number: " + registeredNumber);
addedNumbers.add(registeredNumber);
addTextSecureRawContact(operations, account, systemContactInfo.get().number, systemContactInfo.get().name, systemContactInfo.get().id, true);
}
}
}
for (Map.Entry<String, SignalContact> currentContactEntry : currentContacts.entrySet()) {
ContactTokenDetails tokenDetails = registeredNumbers.get(currentContactEntry.getKey());
if (tokenDetails == null) {
if (remove) {
Log.w(TAG, "Removing number: " + currentContactEntry.getKey());
removeTextSecureRawContact(operations, account, currentContactEntry.getValue().getId());
}
} else if (!currentContactEntry.getValue().isVoiceSupported()) {
Log.w(TAG, "Adding voice support: " + currentContactEntry.getKey());
addContactVoiceSupport(operations, currentContactEntry.getKey(), currentContactEntry.getValue().getId());
} else if (!Util.isStringEquals(currentContactEntry.getValue().getRawDisplayName(), currentContactEntry.getValue().getAggregateDisplayName())) {
Log.w(TAG, "Updating display name: " + currentContactEntry.getKey());
updateDisplayName(operations, currentContactEntry.getValue().getAggregateDisplayName(), currentContactEntry.getValue().getId(), currentContactEntry.getValue().getDisplayNameSource());
}
}
if (!operations.isEmpty()) {
context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, operations);
}
return addedNumbers;
}
use of java.util.LinkedList in project Signal-Android by WhisperSystems.
the class DraftDatabase method getDrafts.
public List<Draft> getDrafts(MasterCipher masterCipher, long threadId) {
SQLiteDatabase db = databaseHelper.getReadableDatabase();
List<Draft> results = new LinkedList<Draft>();
Cursor cursor = null;
try {
cursor = db.query(TABLE_NAME, null, THREAD_ID + " = ?", new String[] { threadId + "" }, null, null, null);
while (cursor != null && cursor.moveToNext()) {
try {
String encryptedType = cursor.getString(cursor.getColumnIndexOrThrow(DRAFT_TYPE));
String encryptedValue = cursor.getString(cursor.getColumnIndexOrThrow(DRAFT_VALUE));
results.add(new Draft(masterCipher.decryptBody(encryptedType), masterCipher.decryptBody(encryptedValue)));
} catch (InvalidMessageException ime) {
Log.w("DraftDatabase", ime);
}
}
return results;
} finally {
if (cursor != null)
cursor.close();
}
}
use of java.util.LinkedList 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)));
}
Aggregations