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);
}
}
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());
}
}
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));
}
}
}
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());
}
}
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;
}
}
Aggregations