Search in sources :

Example 66 with LinkedList

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;
}
Also used : TextSecurePreKeyStore(org.thoughtcrime.securesms.crypto.storage.TextSecurePreKeyStore) ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair) PreKeyRecord(org.whispersystems.libsignal.state.PreKeyRecord) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) PreKeyStore(org.whispersystems.libsignal.state.PreKeyStore) TextSecurePreKeyStore(org.thoughtcrime.securesms.crypto.storage.TextSecurePreKeyStore) SignedPreKeyStore(org.whispersystems.libsignal.state.SignedPreKeyStore) LinkedList(java.util.LinkedList)

Example 67 with LinkedList

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;
    }
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) LinkedList(java.util.LinkedList)

Example 68 with LinkedList

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;
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) HashMap(java.util.HashMap) ContactTokenDetails(org.whispersystems.signalservice.api.push.ContactTokenDetails) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map) NonNull(android.support.annotation.NonNull)

Example 69 with LinkedList

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();
    }
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) LinkedList(java.util.LinkedList)

Example 70 with LinkedList

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)));
}
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

LinkedList (java.util.LinkedList)10512 Test (org.junit.Test)1487 List (java.util.List)1463 HashMap (java.util.HashMap)1371 ArrayList (java.util.ArrayList)1313 Map (java.util.Map)871 IOException (java.io.IOException)800 File (java.io.File)695 HashSet (java.util.HashSet)605 LinkedHashMap (java.util.LinkedHashMap)382 GenericValue (org.apache.ofbiz.entity.GenericValue)296 Iterator (java.util.Iterator)277 Set (java.util.Set)255 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)232 Date (java.util.Date)222 Collection (java.util.Collection)201 Delegator (org.apache.ofbiz.entity.Delegator)162 Locale (java.util.Locale)158 URL (java.net.URL)154 BufferedReader (java.io.BufferedReader)146