Search in sources :

Example 21 with JobManager

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

the class StickerManagementRepository method installStickerPack.

void installStickerPack(@NonNull String packId, @NonNull String packKey, boolean notify) {
    SignalExecutors.SERIAL.execute(() -> {
        JobManager jobManager = ApplicationDependencies.getJobManager();
        if (stickerDatabase.isPackAvailableAsReference(packId)) {
            stickerDatabase.markPackAsInstalled(packId, notify);
        }
        jobManager.add(StickerPackDownloadJob.forInstall(packId, packKey, notify));
        if (TextSecurePreferences.isMultiDevice(context)) {
            jobManager.add(new MultiDeviceStickerPackOperationJob(packId, packKey, MultiDeviceStickerPackOperationJob.Type.INSTALL));
        }
    });
}
Also used : MultiDeviceStickerPackOperationJob(org.thoughtcrime.securesms.jobs.MultiDeviceStickerPackOperationJob) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager)

Example 22 with JobManager

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

the class MmsSendJob method enqueue.

/**
 * Enqueues compression jobs for attachments and finally the MMS send job.
 */
@WorkerThread
public static void enqueue(@NonNull Context context, @NonNull JobManager jobManager, long messageId) {
    MessageDatabase database = SignalDatabase.mms();
    OutgoingMediaMessage message;
    try {
        message = database.getOutgoingMessage(messageId);
    } catch (MmsException | NoSuchMessageException e) {
        throw new AssertionError(e);
    }
    List<Job> compressionJobs = Stream.of(message.getAttachments()).map(a -> (Job) AttachmentCompressionJob.fromAttachment((DatabaseAttachment) a, true, message.getSubscriptionId())).toList();
    MmsSendJob sendJob = new MmsSendJob(messageId);
    jobManager.startChain(compressionJobs).then(sendJob).enqueue();
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) NumberUtil(org.thoughtcrime.securesms.phonenumbers.NumberUtil) Arrays(java.util.Arrays) NonNull(androidx.annotation.NonNull) Data(org.thoughtcrime.securesms.jobmanager.Data) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) PduPart(com.google.android.mms.pdu_alt.PduPart) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException) Utils(com.klinker.android.send_message.Utils) SecureRandom(java.security.SecureRandom) SmilXmlSerializer(com.android.mms.dom.smil.parser.SmilXmlSerializer) Recipient(org.thoughtcrime.securesms.recipients.Recipient) PartAuthority(org.thoughtcrime.securesms.mms.PartAuthority) SendReq(com.google.android.mms.pdu_alt.SendReq) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) Log(org.signal.core.util.logging.Log) List(java.util.List) ContentType(com.google.android.mms.ContentType) SmilHelper(com.google.android.mms.smil.SmilHelper) Job(org.thoughtcrime.securesms.jobmanager.Job) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) NoSuchMessageException(org.thoughtcrime.securesms.database.NoSuchMessageException) Attachment(org.thoughtcrime.securesms.attachments.Attachment) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) Context(android.content.Context) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Stream(com.annimon.stream.Stream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Util(org.thoughtcrime.securesms.util.Util) JobLogger(org.thoughtcrime.securesms.jobmanager.JobLogger) WorkerThread(androidx.annotation.WorkerThread) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) InvalidHeaderValueException(com.google.android.mms.InvalidHeaderValueException) PduHeaders(com.google.android.mms.pdu_alt.PduHeaders) StreamUtil(org.signal.core.util.StreamUtil) MmsException(org.thoughtcrime.securesms.mms.MmsException) EncodedStringValue(com.google.android.mms.pdu_alt.EncodedStringValue) TextUtils(android.text.TextUtils) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) Hex(org.thoughtcrime.securesms.util.Hex) IOException(java.io.IOException) SendConf(com.google.android.mms.pdu_alt.SendConf) MediaConstraints(org.thoughtcrime.securesms.mms.MediaConstraints) CharacterSets(com.google.android.mms.pdu_alt.CharacterSets) PduComposer(com.google.android.mms.pdu_alt.PduComposer) CompatMmsConnection(org.thoughtcrime.securesms.mms.CompatMmsConnection) MmsSendResult(org.thoughtcrime.securesms.mms.MmsSendResult) MimeTypeMap(android.webkit.MimeTypeMap) PduBody(com.google.android.mms.pdu_alt.PduBody) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) MmsException(org.thoughtcrime.securesms.mms.MmsException) NoSuchMessageException(org.thoughtcrime.securesms.database.NoSuchMessageException) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) Job(org.thoughtcrime.securesms.jobmanager.Job) WorkerThread(androidx.annotation.WorkerThread)

Example 23 with JobManager

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

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 24 with JobManager

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

the class MessageContentProcessor method handleSynchronizeStickerPackOperation.

private void handleSynchronizeStickerPackOperation(@NonNull List<StickerPackOperationMessage> stickerPackOperations, long envelopeTimestamp) {
    log(envelopeTimestamp, "Synchronize sticker pack operation.");
    JobManager jobManager = ApplicationDependencies.getJobManager();
    for (StickerPackOperationMessage operation : stickerPackOperations) {
        if (operation.getPackId().isPresent() && operation.getPackKey().isPresent() && operation.getType().isPresent()) {
            String packId = Hex.toStringCondensed(operation.getPackId().get());
            String packKey = Hex.toStringCondensed(operation.getPackKey().get());
            switch(operation.getType().get()) {
                case INSTALL:
                    jobManager.add(StickerPackDownloadJob.forInstall(packId, packKey, false));
                    break;
                case REMOVE:
                    SignalDatabase.stickers().uninstallPack(packId);
                    break;
            }
        } else {
            warn("Received incomplete sticker pack operation sync.");
        }
    }
}
Also used : StickerPackOperationMessage(org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager)

Example 25 with JobManager

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

the class GroupsV2CapabilityChecker method refreshCapabilitiesIfNecessary.

/**
 * @param resolved A collection of resolved recipients.
 * @return True if a recipient needed to be refreshed, otherwise false.
 */
@WorkerThread
public static boolean refreshCapabilitiesIfNecessary(@NonNull Collection<Recipient> resolved) throws IOException {
    Set<RecipientId> needsRefresh = Stream.of(resolved).filter(r -> r.getGroupsV2Capability() != Recipient.Capability.SUPPORTED).map(Recipient::getId).collect(Collectors.toSet());
    if (needsRefresh.size() > 0) {
        Log.d(TAG, "[refreshCapabilitiesIfNecessary] Need to refresh " + needsRefresh.size() + " recipients.");
        List<Job> jobs = RetrieveProfileJob.forRecipients(needsRefresh);
        JobManager jobManager = ApplicationDependencies.getJobManager();
        for (Job job : jobs) {
            if (!jobManager.runSynchronously(job, TimeUnit.SECONDS.toMillis(10)).isPresent()) {
                throw new IOException("Recipient capability was not retrieved in time");
            }
        }
        return true;
    } else {
        return false;
    }
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) IOException(java.io.IOException) RetrieveProfileJob(org.thoughtcrime.securesms.jobs.RetrieveProfileJob) Job(org.thoughtcrime.securesms.jobmanager.Job) WorkerThread(androidx.annotation.WorkerThread)

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