Search in sources :

Example 61 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class UsernameUtil method fetchAciForUsername.

@WorkerThread
@NonNull
public static Optional<ServiceId> fetchAciForUsername(@NonNull String username) {
    Optional<RecipientId> localId = SignalDatabase.recipients().getByUsername(username);
    if (localId.isPresent()) {
        Recipient recipient = Recipient.resolved(localId.get());
        if (recipient.getServiceId().isPresent()) {
            Log.i(TAG, "Found username locally -- using associated UUID.");
            return recipient.getServiceId();
        } else {
            Log.w(TAG, "Found username locally, but it had no associated UUID! Clearing it.");
            SignalDatabase.recipients().clearUsernameIfExists(username);
        }
    }
    try {
        Log.d(TAG, "No local user with this username. Searching remotely.");
        SignalServiceProfile profile = ApplicationDependencies.getSignalServiceMessageReceiver().retrieveProfileByUsername(username, Optional.absent(), Locale.getDefault());
        return Optional.fromNullable(profile.getAci());
    } catch (IOException e) {
        return Optional.absent();
    }
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IOException(java.io.IOException) SignalServiceProfile(org.whispersystems.signalservice.api.profiles.SignalServiceProfile) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 62 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class UnreadPaymentsLiveData method getUnreadPayments.

@WorkerThread
@Nullable
private UnreadPayments getUnreadPayments() {
    List<PaymentDatabase.PaymentTransaction> unseenPayments = paymentDatabase.getUnseenPayments();
    int unseenCount = unseenPayments.size();
    switch(unseenCount) {
        case 0:
            return null;
        case 1:
            PaymentDatabase.PaymentTransaction transaction = unseenPayments.get(0);
            Recipient recipient = transaction.getPayee().hasRecipientId() ? Recipient.resolved(transaction.getPayee().requireRecipientId()) : null;
            return UnreadPayments.forSingle(recipient, transaction.getUuid(), transaction.getAmount());
        default:
            return UnreadPayments.forMultiple(unseenCount);
    }
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) PaymentDatabase(org.thoughtcrime.securesms.database.PaymentDatabase) WorkerThread(androidx.annotation.WorkerThread) Nullable(androidx.annotation.Nullable)

Example 63 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class SafetyNumberChangeRepository method trustOrVerifyChangedRecipientsInternal.

@WorkerThread
private TrustAndVerifyResult trustOrVerifyChangedRecipientsInternal(@NonNull List<ChangedRecipient> changedRecipients) {
    SignalIdentityKeyStore identityStore = ApplicationDependencies.getProtocolStore().aci().identities();
    try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
        for (ChangedRecipient changedRecipient : changedRecipients) {
            IdentityRecord identityRecord = changedRecipient.getIdentityRecord();
            if (changedRecipient.isUnverified()) {
                Log.d(TAG, "Setting " + identityRecord.getRecipientId() + " as verified");
                ApplicationDependencies.getProtocolStore().aci().identities().setVerified(identityRecord.getRecipientId(), identityRecord.getIdentityKey(), IdentityDatabase.VerifiedStatus.DEFAULT);
            } else {
                Log.d(TAG, "Setting " + identityRecord.getRecipientId() + " as approved");
                identityStore.setApproval(identityRecord.getRecipientId(), true);
            }
        }
    }
    return TrustAndVerifyResult.trustAndVerify(changedRecipients);
}
Also used : SignalSessionLock(org.whispersystems.signalservice.api.SignalSessionLock) IdentityRecord(org.thoughtcrime.securesms.database.model.IdentityRecord) SignalIdentityKeyStore(org.thoughtcrime.securesms.crypto.storage.SignalIdentityKeyStore) WorkerThread(androidx.annotation.WorkerThread)

Example 64 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class SafetyNumberChangeRepository method processOutgoingMessageRecord.

@WorkerThread
private void processOutgoingMessageRecord(@NonNull List<ChangedRecipient> changedRecipients, @NonNull MessageRecord messageRecord) {
    Log.d(TAG, "processOutgoingMessageRecord");
    MessageDatabase smsDatabase = SignalDatabase.sms();
    MessageDatabase mmsDatabase = SignalDatabase.mms();
    for (ChangedRecipient changedRecipient : changedRecipients) {
        RecipientId id = changedRecipient.getRecipient().getId();
        IdentityKey identityKey = changedRecipient.getIdentityRecord().getIdentityKey();
        if (messageRecord.isMms()) {
            mmsDatabase.removeMismatchedIdentity(messageRecord.getId(), id, identityKey);
            if (messageRecord.getRecipient().isPushGroup()) {
                MessageSender.resendGroupMessage(context, messageRecord, id);
            } else {
                MessageSender.resend(context, messageRecord);
            }
        } else {
            smsDatabase.removeMismatchedIdentity(messageRecord.getId(), id, identityKey);
            MessageSender.resend(context, messageRecord);
        }
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) IdentityKey(org.whispersystems.libsignal.IdentityKey) WorkerThread(androidx.annotation.WorkerThread)

Example 65 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class SafetyNumberChangeRepository method trustOrVerifyChangedRecipientsAndResendInternal.

@WorkerThread
private TrustAndVerifyResult trustOrVerifyChangedRecipientsAndResendInternal(@NonNull List<ChangedRecipient> changedRecipients, @NonNull MessageRecord messageRecord) {
    if (changedRecipients.isEmpty()) {
        Log.d(TAG, "No changed recipients to process, will still process message record");
    }
    try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
        for (ChangedRecipient changedRecipient : changedRecipients) {
            SignalProtocolAddress mismatchAddress = changedRecipient.getRecipient().requireServiceId().toProtocolAddress(SignalServiceAddress.DEFAULT_DEVICE_ID);
            Log.d(TAG, "Saving identity for: " + changedRecipient.getRecipient().getId() + " " + changedRecipient.getIdentityRecord().getIdentityKey().hashCode());
            SignalIdentityKeyStore.SaveResult result = ApplicationDependencies.getProtocolStore().aci().identities().saveIdentity(mismatchAddress, changedRecipient.getIdentityRecord().getIdentityKey(), true);
            Log.d(TAG, "Saving identity result: " + result);
            if (result == SignalIdentityKeyStore.SaveResult.NO_CHANGE) {
                Log.i(TAG, "Archiving sessions explicitly as they appear to be out of sync.");
                ApplicationDependencies.getProtocolStore().aci().sessions().archiveSession(changedRecipient.getRecipient().getId(), SignalServiceAddress.DEFAULT_DEVICE_ID);
                ApplicationDependencies.getProtocolStore().aci().sessions().archiveSiblingSessions(mismatchAddress);
                SignalDatabase.senderKeyShared().deleteAllFor(changedRecipient.getRecipient().getId());
            }
        }
    }
    if (messageRecord.isOutgoing()) {
        processOutgoingMessageRecord(changedRecipients, messageRecord);
    }
    return TrustAndVerifyResult.trustVerifyAndResend(changedRecipients, messageRecord);
}
Also used : SignalSessionLock(org.whispersystems.signalservice.api.SignalSessionLock) SignalIdentityKeyStore(org.thoughtcrime.securesms.crypto.storage.SignalIdentityKeyStore) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

WorkerThread (androidx.annotation.WorkerThread)365 NonNull (androidx.annotation.NonNull)151 IOException (java.io.IOException)83 Recipient (org.thoughtcrime.securesms.recipients.Recipient)82 Nullable (androidx.annotation.Nullable)51 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)46 Cursor (android.database.Cursor)41 ArrayList (java.util.ArrayList)41 Context (android.content.Context)39 Uri (android.net.Uri)32 LinkedList (java.util.LinkedList)30 List (java.util.List)30 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)28 Stream (com.annimon.stream.Stream)26 HashMap (java.util.HashMap)26 Log (org.signal.core.util.logging.Log)26 HashSet (java.util.HashSet)24 Map (java.util.Map)21 Collections (java.util.Collections)20 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)20