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