Search in sources :

Example 51 with JobManager

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

the class StorageServiceMigrationJob method performMigration.

@Override
public void performMigration() {
    if (SignalStore.account().getAci() == null) {
        Log.w(TAG, "Self not yet available.");
        return;
    }
    SignalDatabase.recipients().markNeedsSync(Recipient.self().getId());
    JobManager jobManager = ApplicationDependencies.getJobManager();
    if (TextSecurePreferences.isMultiDevice(context)) {
        Log.i(TAG, "Multi-device.");
        jobManager.startChain(new StorageSyncJob()).then(new MultiDeviceKeysUpdateJob()).enqueue();
    } else {
        Log.i(TAG, "Single-device.");
        jobManager.add(new StorageSyncJob());
    }
}
Also used : StorageSyncJob(org.thoughtcrime.securesms.jobs.StorageSyncJob) MultiDeviceKeysUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceKeysUpdateJob) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager)

Example 52 with JobManager

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

the class SmsDeliveryListener method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    JobManager jobManager = ApplicationDependencies.getJobManager();
    long messageId = intent.getLongExtra("message_id", -1);
    int runAttempt = intent.getIntExtra("run_attempt", 0);
    boolean isMultipart = intent.getBooleanExtra("is_multipart", true);
    switch(intent.getAction()) {
        case SENT_SMS_ACTION:
            int result = getResultCode();
            jobManager.add(new SmsSentJob(messageId, isMultipart, SENT_SMS_ACTION, result, runAttempt));
            break;
        case DELIVERED_SMS_ACTION:
            byte[] pdu = intent.getByteArrayExtra("pdu");
            if (pdu == null) {
                Log.w(TAG, "No PDU in delivery receipt!");
                break;
            }
            SmsMessage message = SmsMessage.createFromPdu(pdu);
            if (message == null) {
                Log.w(TAG, "Delivery receipt failed to parse!");
                break;
            }
            int status = message.getStatus();
            Log.i(TAG, "Original status: " + status);
            // Note: https://stackoverflow.com/a/33240109
            if ("3gpp2".equals(intent.getStringExtra("format"))) {
                Log.w(TAG, "Correcting for CDMA delivery receipt...");
                if (status >> 24 <= 0)
                    status = SmsDatabase.Status.STATUS_COMPLETE;
                else if (status >> 24 == 2)
                    status = SmsDatabase.Status.STATUS_PENDING;
                else if (status >> 24 == 3)
                    status = SmsDatabase.Status.STATUS_FAILED;
            }
            jobManager.add(new SmsSentJob(messageId, isMultipart, DELIVERED_SMS_ACTION, status, runAttempt));
            break;
        default:
            Log.w(TAG, "Unknown action: " + intent.getAction());
    }
}
Also used : SmsSentJob(org.thoughtcrime.securesms.jobs.SmsSentJob) SmsMessage(android.telephony.SmsMessage) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager)

Example 53 with JobManager

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

the class SendReadReceiptJob method enqueue.

/**
 * Enqueues all the necessary jobs for read receipts, ensuring that they're all within the
 * maximum size.
 */
public static void enqueue(long threadId, @NonNull RecipientId recipientId, List<MarkedMessageInfo> markedMessageInfos) {
    if (recipientId.equals(Recipient.self().getId())) {
        return;
    }
    JobManager jobManager = ApplicationDependencies.getJobManager();
    List<List<MarkedMessageInfo>> messageIdChunks = Util.chunk(markedMessageInfos, MAX_TIMESTAMPS);
    if (messageIdChunks.size() > 1) {
        Log.w(TAG, "Large receipt count! Had to break into multiple chunks. Total count: " + markedMessageInfos.size());
    }
    for (List<MarkedMessageInfo> chunk : messageIdChunks) {
        List<Long> sentTimestamps = chunk.stream().map(info -> info.getSyncMessageId().getTimetamp()).collect(Collectors.toList());
        List<MessageId> messageIds = chunk.stream().map(MarkedMessageInfo::getMessageId).collect(Collectors.toList());
        jobManager.add(new SendReadReceiptJob(threadId, recipientId, sentTimestamps, messageIds));
    }
}
Also used : MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo) ServerRejectedException(org.whispersystems.signalservice.api.push.exceptions.ServerRejectedException) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) ContentHint(org.whispersystems.signalservice.api.crypto.ContentHint) Util(org.thoughtcrime.securesms.util.Util) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult) NonNull(androidx.annotation.NonNull) Data(org.thoughtcrime.securesms.jobmanager.Data) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) RecipientUtil(org.thoughtcrime.securesms.recipients.RecipientUtil) NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) ArrayList(java.util.ArrayList) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) MessageId(org.thoughtcrime.securesms.database.model.MessageId) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) IOException(java.io.IOException) UnidentifiedAccessUtil(org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) Log(org.signal.core.util.logging.Log) List(java.util.List) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) Application(android.app.Application) Job(org.thoughtcrime.securesms.jobmanager.Job) SignalServiceReceiptMessage(org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage) VisibleForTesting(androidx.annotation.VisibleForTesting) Collections(java.util.Collections) ArrayList(java.util.ArrayList) List(java.util.List) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo) MessageId(org.thoughtcrime.securesms.database.model.MessageId)

Example 54 with JobManager

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

the class MultiDeviceViewedUpdateJob 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 MultiDeviceViewedUpdateJob(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 55 with JobManager

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

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)

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