use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class ReviewUtil method getDuplicatedRecipients.
@WorkerThread
@NonNull
public static List<ReviewRecipient> getDuplicatedRecipients(@NonNull GroupId.V2 groupId) {
Context context = ApplicationDependencies.getApplication();
List<MessageRecord> profileChangeRecords = getProfileChangeRecordsForGroup(context, groupId);
if (profileChangeRecords.isEmpty()) {
return Collections.emptyList();
}
List<Recipient> members = SignalDatabase.groups().getGroupMembers(groupId, GroupDatabase.MemberSet.FULL_MEMBERS_INCLUDING_SELF);
List<ReviewRecipient> changed = Stream.of(profileChangeRecords).distinctBy(record -> record.getRecipient().getId()).map(record -> new ReviewRecipient(record.getRecipient().resolve(), getProfileChangeDetails(record))).filter(recipient -> !recipient.getRecipient().isSystemContact()).toList();
List<ReviewRecipient> results = new LinkedList<>();
for (ReviewRecipient recipient : changed) {
if (results.contains(recipient)) {
continue;
}
members.remove(recipient.getRecipient());
for (Recipient member : members) {
if (Objects.equals(member.getDisplayName(context), recipient.getRecipient().getDisplayName(context))) {
results.add(recipient);
results.add(new ReviewRecipient(member));
}
}
}
return results;
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class ReviewUtil method getProfileChangeRecordsForGroup.
@WorkerThread
@NonNull
public static List<MessageRecord> getProfileChangeRecordsForGroup(@NonNull Context context, @NonNull GroupId.V2 groupId) {
RecipientId recipientId = SignalDatabase.recipients().getByGroupId(groupId).get();
Long threadId = SignalDatabase.threads().getThreadIdFor(recipientId);
if (threadId == null) {
return Collections.emptyList();
} else {
return SignalDatabase.sms().getProfileChangeDetailsRecords(threadId, System.currentTimeMillis() - TIMEOUT);
}
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class PinState method onMigrateToRegistrationLockV2.
/**
* Should only be called by {@link org.thoughtcrime.securesms.migrations.RegistrationPinV2MigrationJob}.
*/
@WorkerThread
public static synchronized void onMigrateToRegistrationLockV2(@NonNull Context context, @NonNull String pin) throws IOException, UnauthenticatedResponseException, InvalidKeyException {
Log.i(TAG, "onMigrateToRegistrationLockV2()");
KbsEnclave kbsEnclave = KbsEnclaves.current();
Log.i(TAG, "Enclave: " + kbsEnclave.getEnclaveName());
KbsValues kbsValues = SignalStore.kbsValues();
MasterKey masterKey = kbsValues.getOrCreateMasterKey();
KeyBackupService keyBackupService = ApplicationDependencies.getKeyBackupService(kbsEnclave);
KeyBackupService.PinChangeSession pinChangeSession = keyBackupService.newPinChangeSession();
HashedPin hashedPin = PinHashing.hashPin(pin, pinChangeSession);
KbsPinData kbsData = pinChangeSession.setPin(hashedPin, masterKey);
pinChangeSession.enableRegistrationLock(masterKey);
kbsValues.setKbsMasterKey(kbsData, pin);
TextSecurePreferences.clearRegistrationLockV1(context);
updateState(buildInferredStateFromOtherFields());
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class BlobProvider method writeBlobSpecToDisk.
@WorkerThread
@NonNull
private synchronized Uri writeBlobSpecToDisk(@NonNull Context context, @NonNull BlobSpec blobSpec) throws IOException {
waitUntilInitialized();
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<IOException> exception = new AtomicReference<>(null);
Uri uri = writeBlobSpecToDiskAsync(context, blobSpec, latch::countDown, e -> {
exception.set(e);
latch.countDown();
});
try {
latch.await();
} catch (InterruptedException e) {
throw new IOException(e);
}
if (exception.get() != null) {
throw exception.get();
}
return uri;
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class BlobProvider method writeBlobSpecToDiskAsync.
@WorkerThread
@NonNull
private synchronized Uri writeBlobSpecToDiskAsync(@NonNull Context context, @NonNull BlobSpec blobSpec, @Nullable SuccessListener successListener, @Nullable ErrorListener errorListener) throws IOException {
AttachmentSecret attachmentSecret = AttachmentSecretProvider.getInstance(context).getOrCreateAttachmentSecret();
String directory = getDirectory(blobSpec.getStorageType());
File outputFile = new File(getOrCreateDirectory(context, directory), buildFileName(blobSpec.id));
OutputStream outputStream = ModernEncryptingPartOutputStream.createFor(attachmentSecret, outputFile, true).second;
SignalExecutors.UNBOUNDED.execute(() -> {
try {
StreamUtil.copy(blobSpec.getData(), outputStream);
if (successListener != null) {
successListener.onSuccess();
}
} catch (IOException e) {
Log.w(TAG, "Error during write!", e);
if (errorListener != null) {
errorListener.onError(e);
}
}
});
return buildUri(blobSpec);
}
Aggregations