Search in sources :

Example 41 with JobManager

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

the class MediaUploadRepository method cancelUploadInternal.

private void cancelUploadInternal(@NonNull Media media) {
    JobManager jobManager = ApplicationDependencies.getJobManager();
    PreUploadResult result = uploadResults.get(media);
    if (result != null) {
        Stream.of(result.getJobIds()).forEach(jobManager::cancel);
        uploadResults.remove(media);
    }
}
Also used : JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) PreUploadResult(org.thoughtcrime.securesms.sms.MessageSender.PreUploadResult)

Example 42 with JobManager

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

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

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

the class LegacyMigrationJob method scheduleMessagesInPushDatabase.

private static void scheduleMessagesInPushDatabase(@NonNull Context context) {
    PushDatabase pushDatabase = SignalDatabase.push();
    JobManager jobManager = ApplicationDependencies.getJobManager();
    try (PushDatabase.Reader pushReader = pushDatabase.readerFor(pushDatabase.getPending())) {
        SignalServiceEnvelope envelope;
        while ((envelope = pushReader.getNext()) != null) {
            jobManager.add(new PushDecryptMessageJob(context, envelope));
        }
    }
}
Also used : PushDatabase(org.thoughtcrime.securesms.database.PushDatabase) PushDecryptMessageJob(org.thoughtcrime.securesms.jobs.PushDecryptMessageJob) SignalServiceEnvelope(org.whispersystems.signalservice.api.messages.SignalServiceEnvelope) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager)

Example 44 with JobManager

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

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

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

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