Search in sources :

Example 56 with JobManager

use of org.thoughtcrime.securesms.jobmanager.JobManager in project Signal-Android by signalapp.

the class MultiDeviceReadUpdateJob method enqueue.

/**
 * Enqueues all the necessary jobs for read receipts, ensuring that they're all within the
 * maximum size.
 */
public static void enqueue(@NonNull List<SyncMessageId> messageIds) {
    JobManager jobManager = ApplicationDependencies.getJobManager();
    List<List<SyncMessageId>> messageIdChunks = Util.chunk(messageIds, SendReadReceiptJob.MAX_TIMESTAMPS);
    if (messageIdChunks.size() > 1) {
        Log.w(TAG, "Large receipt count! Had to break into multiple chunks. Total count: " + messageIds.size());
    }
    for (List<SyncMessageId> chunk : messageIdChunks) {
        jobManager.add(new MultiDeviceReadUpdateJob(chunk));
    }
}
Also used : LinkedList(java.util.LinkedList) List(java.util.List) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)

Example 57 with JobManager

use of org.thoughtcrime.securesms.jobmanager.JobManager in project Signal-Android by signalapp.

the class GroupV1MigrationJob method enqueueRoutineMigrationsIfNecessary.

public static void enqueueRoutineMigrationsIfNecessary(@NonNull Application application) {
    if (!SignalStore.registrationValues().isRegistrationComplete() || !SignalStore.account().isRegistered() || SignalStore.account().getAci() == null) {
        Log.i(TAG, "Registration not complete. Skipping.");
        return;
    }
    long timeSinceRefresh = System.currentTimeMillis() - SignalStore.misc().getLastGv1RoutineMigrationTime();
    if (timeSinceRefresh < REFRESH_INTERVAL) {
        Log.i(TAG, "Too soon to refresh. Did the last refresh " + timeSinceRefresh + " ms ago.");
        return;
    }
    SignalStore.misc().setLastGv1RoutineMigrationTime(System.currentTimeMillis());
    SignalExecutors.BOUNDED.execute(() -> {
        JobManager jobManager = ApplicationDependencies.getJobManager();
        List<ThreadRecord> threads = SignalDatabase.threads().getRecentV1Groups(ROUTINE_LIMIT);
        Set<RecipientId> needsRefresh = new HashSet<>();
        if (threads.size() > 0) {
            Log.d(TAG, "About to enqueue refreshes for " + threads.size() + " groups.");
        }
        for (ThreadRecord thread : threads) {
            jobManager.add(new GroupV1MigrationJob(thread.getRecipient().getId()));
            needsRefresh.addAll(Stream.of(thread.getRecipient().getParticipants()).filter(r -> r.getGroupsV2Capability() != Recipient.Capability.SUPPORTED || r.getGroupsV1MigrationCapability() != Recipient.Capability.SUPPORTED).map(Recipient::getId).toList());
        }
        if (needsRefresh.size() > 0) {
            Log.w(TAG, "Enqueuing profile refreshes for " + needsRefresh.size() + " GV1 participants.");
            RetrieveProfileJob.enqueue(needsRefresh);
        }
    });
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) GroupsV1MigrationUtil(org.thoughtcrime.securesms.groups.GroupsV1MigrationUtil) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) RetryLaterException(org.thoughtcrime.securesms.transport.RetryLaterException) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) Data(org.thoughtcrime.securesms.jobmanager.Data) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) HashSet(java.util.HashSet) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) NoCredentialForRedemptionTimeException(org.whispersystems.signalservice.api.groupsv2.NoCredentialForRedemptionTimeException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupChangeBusyException(org.thoughtcrime.securesms.groups.GroupChangeBusyException) ThreadRecord(org.thoughtcrime.securesms.database.model.ThreadRecord) SignalExecutors(org.signal.core.util.concurrent.SignalExecutors) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Set(java.util.Set) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) IOException(java.io.IOException) TimeUnit(java.util.concurrent.TimeUnit) Log(org.signal.core.util.logging.Log) List(java.util.List) Application(android.app.Application) Job(org.thoughtcrime.securesms.jobmanager.Job) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ThreadRecord(org.thoughtcrime.securesms.database.model.ThreadRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) HashSet(java.util.HashSet)

Example 58 with JobManager

use of org.thoughtcrime.securesms.jobmanager.JobManager in project Signal-Android by signalapp.

the class LocalBackupJob method enqueue.

public static void enqueue(boolean force) {
    JobManager jobManager = ApplicationDependencies.getJobManager();
    Parameters.Builder parameters = new Parameters.Builder().setQueue(QUEUE).setMaxInstancesForFactory(1).setMaxAttempts(3);
    if (force) {
        jobManager.cancelAllInQueue(QUEUE);
    } else {
        parameters.addConstraint(ChargingConstraint.KEY);
    }
    if (BackupUtil.isUserSelectionRequired(ApplicationDependencies.getApplication())) {
        jobManager.add(new LocalBackupJobApi29(parameters.build()));
    } else {
        jobManager.add(new LocalBackupJob(parameters.build()));
    }
}
Also used : JobManager(org.thoughtcrime.securesms.jobmanager.JobManager)

Aggregations

JobManager (org.thoughtcrime.securesms.jobmanager.JobManager)58 Job (org.thoughtcrime.securesms.jobmanager.Job)18 IOException (java.io.IOException)14 List (java.util.List)14 NonNull (androidx.annotation.NonNull)10 Log (org.signal.core.util.logging.Log)10 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)10 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)10 Recipient (org.thoughtcrime.securesms.recipients.Recipient)10 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)10 WorkerThread (androidx.annotation.WorkerThread)8 TimeUnit (java.util.concurrent.TimeUnit)8 Data (org.thoughtcrime.securesms.jobmanager.Data)8 NetworkConstraint (org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint)8 Application (android.app.Application)6 ArrayList (java.util.ArrayList)6 Collections (java.util.Collections)6 MessageId (org.thoughtcrime.securesms.database.model.MessageId)6 SmsSendJob (org.thoughtcrime.securesms.jobs.SmsSendJob)6 AttachmentCompressionJob (org.thoughtcrime.securesms.jobs.AttachmentCompressionJob)5