Search in sources :

Example 21 with WorkerThread

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;
}
Also used : Context(android.content.Context) Context(android.content.Context) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) Base64(org.thoughtcrime.securesms.util.Base64) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) WorkerThread(androidx.annotation.WorkerThread) IOException(java.io.IOException) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ProfileChangeDetails(org.thoughtcrime.securesms.database.model.databaseprotos.ProfileChangeDetails) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) GroupId(org.thoughtcrime.securesms.groups.GroupId) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LinkedList(java.util.LinkedList) Collections(java.util.Collections) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LinkedList(java.util.LinkedList) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 22 with WorkerThread

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);
    }
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 23 with WorkerThread

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());
}
Also used : KbsEnclave(org.thoughtcrime.securesms.KbsEnclave) KeyBackupService(org.whispersystems.signalservice.api.KeyBackupService) MasterKey(org.whispersystems.signalservice.api.kbs.MasterKey) KbsValues(org.thoughtcrime.securesms.keyvalue.KbsValues) KbsPinData(org.whispersystems.signalservice.api.KbsPinData) HashedPin(org.whispersystems.signalservice.api.kbs.HashedPin) WorkerThread(androidx.annotation.WorkerThread)

Example 24 with WorkerThread

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;
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) Uri(android.net.Uri) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 25 with WorkerThread

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);
}
Also used : OutputStream(java.io.OutputStream) ModernEncryptingPartOutputStream(org.thoughtcrime.securesms.crypto.ModernEncryptingPartOutputStream) IOException(java.io.IOException) AttachmentSecret(org.thoughtcrime.securesms.crypto.AttachmentSecret) File(java.io.File) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Aggregations

WorkerThread (androidx.annotation.WorkerThread)204 NonNull (androidx.annotation.NonNull)77 IOException (java.io.IOException)45 Recipient (org.thoughtcrime.securesms.recipients.Recipient)41 Nullable (androidx.annotation.Nullable)26 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)23 Cursor (android.database.Cursor)22 ArrayList (java.util.ArrayList)22 Context (android.content.Context)20 Uri (android.net.Uri)18 LinkedList (java.util.LinkedList)15 List (java.util.List)15 HashMap (java.util.HashMap)14 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)14 Stream (com.annimon.stream.Stream)13 Log (org.signal.core.util.logging.Log)13 HashSet (java.util.HashSet)12 InputStream (java.io.InputStream)11 Bitmap (android.graphics.Bitmap)10 Collections (java.util.Collections)10