use of org.thoughtcrime.securesms.jobmanager.JobManager in project Signal-Android by signalapp.
the class StorageAccountRestoreJob method onRun.
@Override
protected void onRun() throws Exception {
SignalServiceAccountManager accountManager = ApplicationDependencies.getSignalServiceAccountManager();
StorageKey storageServiceKey = SignalStore.storageService().getOrCreateStorageKey();
Log.i(TAG, "Retrieving manifest...");
Optional<SignalStorageManifest> manifest = accountManager.getStorageManifest(storageServiceKey);
if (!manifest.isPresent()) {
Log.w(TAG, "Manifest did not exist or was undecryptable (bad key). Not restoring. Force-pushing.");
ApplicationDependencies.getJobManager().add(new StorageForcePushJob());
return;
}
Log.i(TAG, "Resetting the local manifest to an empty state so that it will sync later.");
SignalStore.storageService().setManifest(SignalStorageManifest.EMPTY);
Optional<StorageId> accountId = manifest.get().getAccountStorageId();
if (!accountId.isPresent()) {
Log.w(TAG, "Manifest had no account record! Not restoring.");
return;
}
Log.i(TAG, "Retrieving account record...");
List<SignalStorageRecord> records = accountManager.readStorageRecords(storageServiceKey, Collections.singletonList(accountId.get()));
SignalStorageRecord record = records.size() > 0 ? records.get(0) : null;
if (record == null) {
Log.w(TAG, "Could not find account record, even though we had an ID! Not restoring.");
return;
}
SignalAccountRecord accountRecord = record.getAccount().orNull();
if (accountRecord == null) {
Log.w(TAG, "The storage record didn't actually have an account on it! Not restoring.");
return;
}
Log.i(TAG, "Applying changes locally...");
SignalDatabase.getRawDatabase().beginTransaction();
try {
StorageSyncHelper.applyAccountStorageSyncUpdates(context, Recipient.self(), accountRecord, false);
SignalDatabase.getRawDatabase().setTransactionSuccessful();
} finally {
SignalDatabase.getRawDatabase().endTransaction();
}
JobManager jobManager = ApplicationDependencies.getJobManager();
if (accountRecord.getAvatarUrlPath().isPresent()) {
Log.i(TAG, "Fetching avatar...");
Optional<JobTracker.JobState> state = jobManager.runSynchronously(new RetrieveProfileAvatarJob(Recipient.self(), accountRecord.getAvatarUrlPath().get()), LIFESPAN / 2);
if (state.isPresent()) {
Log.i(TAG, "Avatar retrieved successfully. " + state.get());
} else {
Log.w(TAG, "Avatar retrieval did not complete in time (or otherwise failed).");
}
} else {
Log.i(TAG, "No avatar present. Not fetching.");
}
Log.i(TAG, "Refreshing attributes...");
Optional<JobTracker.JobState> state = jobManager.runSynchronously(new RefreshAttributesJob(), LIFESPAN / 2);
if (state.isPresent()) {
Log.i(TAG, "Attributes refreshed successfully. " + state.get());
} else {
Log.w(TAG, "Attribute refresh did not complete in time (or otherwise failed).");
}
}
use of org.thoughtcrime.securesms.jobmanager.JobManager in project Signal-Android by signalapp.
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.");
}
}
}
use of org.thoughtcrime.securesms.jobmanager.JobManager in project Signal-Android by signalapp.
the class RestStrategy method execute.
@WorkerThread
@Override
public boolean execute(long timeout) {
long startTime = System.currentTimeMillis();
JobManager jobManager = ApplicationDependencies.getJobManager();
QueueFindingJobListener queueListener = new QueueFindingJobListener();
try (IncomingMessageProcessor.Processor processor = ApplicationDependencies.getIncomingMessageProcessor().acquire()) {
jobManager.addListener(job -> job.getParameters().getQueue() != null && job.getParameters().getQueue().startsWith(PushProcessMessageJob.QUEUE_PREFIX), queueListener);
int jobCount = enqueuePushDecryptJobs(processor, startTime, timeout);
if (jobCount == 0) {
Log.d(TAG, "No PushDecryptMessageJobs were enqueued.");
return true;
} else {
Log.d(TAG, jobCount + " PushDecryptMessageJob(s) were enqueued.");
}
long timeRemainingMs = blockUntilQueueDrained(PushDecryptMessageJob.QUEUE, TimeUnit.SECONDS.toMillis(10));
Set<String> processQueues = queueListener.getQueues();
Log.d(TAG, "Discovered " + processQueues.size() + " queue(s): " + processQueues);
if (timeRemainingMs > 0) {
Iterator<String> iter = processQueues.iterator();
while (iter.hasNext() && timeRemainingMs > 0) {
timeRemainingMs = blockUntilQueueDrained(iter.next(), timeRemainingMs);
}
if (timeRemainingMs <= 0) {
Log.w(TAG, "Ran out of time while waiting for queues to drain.");
}
} else {
Log.w(TAG, "Ran out of time before we could even wait on individual queues!");
}
return true;
} catch (IOException e) {
Log.w(TAG, "Failed to retrieve messages. Resetting the SignalServiceMessageReceiver.", e);
ApplicationDependencies.resetSignalServiceMessageReceiver();
return false;
} finally {
jobManager.removeListener(queueListener);
}
}
use of org.thoughtcrime.securesms.jobmanager.JobManager in project Signal-Android by signalapp.
the class RestStrategy method blockUntilQueueDrained.
private static long blockUntilQueueDrained(@NonNull String queue, long timeoutMs) {
long startTime = System.currentTimeMillis();
final JobManager jobManager = ApplicationDependencies.getJobManager();
final MarkerJob markerJob = new MarkerJob(queue);
Optional<JobTracker.JobState> jobState = jobManager.runSynchronously(markerJob, timeoutMs);
if (!jobState.isPresent()) {
Log.w(TAG, "Timed out waiting for " + queue + " job(s) to finish!");
}
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
Log.d(TAG, "Waited " + duration + " ms for the " + queue + " job(s) to finish.");
return timeoutMs - duration;
}
use of org.thoughtcrime.securesms.jobmanager.JobManager in project Signal-Android by signalapp.
the class MessageRetrievalStrategy method blockUntilQueueDrained.
protected static void blockUntilQueueDrained(@NonNull String tag, @NonNull String queue, long timeoutMs) {
long startTime = System.currentTimeMillis();
final JobManager jobManager = ApplicationDependencies.getJobManager();
final MarkerJob markerJob = new MarkerJob(queue);
Optional<JobTracker.JobState> jobState = jobManager.runSynchronously(markerJob, timeoutMs);
if (!jobState.isPresent()) {
Log.w(tag, "Timed out waiting for " + queue + " job(s) to finish!");
}
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
Log.d(tag, "Waited " + duration + " ms for the " + queue + " job(s) to finish.");
}
Aggregations