use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
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 androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class ConversationUtil method buildShortcutInfo.
/**
* Builds the shortcut info object for a given Recipient.
*
* @param context The Context under which we are operating
* @param recipient The Recipient to generate a ShortcutInfo for
* @param rank The rank that should be assigned to this recipient
* @return The new ShortcutInfo
*/
@WorkerThread
@NonNull
private static ShortcutInfoCompat buildShortcutInfo(@NonNull Context context, @NonNull Recipient recipient, int rank) {
Recipient resolved = recipient.resolve();
Person[] persons = buildPersons(context, resolved);
Long threadId = SignalDatabase.threads().getThreadIdFor(resolved.getId());
String shortName = resolved.isSelf() ? context.getString(R.string.note_to_self) : resolved.getShortDisplayName(context);
String longName = resolved.isSelf() ? context.getString(R.string.note_to_self) : resolved.getDisplayName(context);
String shortcutId = getShortcutId(resolved);
return new ShortcutInfoCompat.Builder(context, shortcutId).setLongLived(true).setIntent(ConversationIntents.createBuilder(context, resolved.getId(), threadId != null ? threadId : -1).build()).setShortLabel(shortName).setLongLabel(longName).setIcon(AvatarUtil.getIconCompatForShortcut(context, resolved)).setPersons(persons).setCategories(Collections.singleton(CATEGORY_SHARE_TARGET)).setActivity(new ComponentName(context, "org.thoughtcrime.securesms.RoutingActivity")).setRank(rank).setLocusId(new LocusIdCompat(shortcutId)).build();
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class ConversationUtil method setActiveShortcuts.
/**
* Sets the shortcuts to match the provided recipient list. This call may fail due to getting
* rate-limited.
*
* @param rankedRecipients The recipients in descending priority order. Meaning the most important
* recipient should be first in the list.
* @return True if the update was successful, false if we were rate-limited.
*/
@WorkerThread
public static boolean setActiveShortcuts(@NonNull Context context, @NonNull List<Recipient> rankedRecipients) {
if (ShortcutManagerCompat.isRateLimitingActive(context)) {
return false;
}
int maxShortcuts = ShortcutManagerCompat.getMaxShortcutCountPerActivity(context);
if (rankedRecipients.size() > maxShortcuts) {
Log.w(TAG, "Too many recipients provided! Provided: " + rankedRecipients.size() + ", Max: " + maxShortcuts);
rankedRecipients = rankedRecipients.subList(0, maxShortcuts);
}
List<ShortcutInfoCompat> shortcuts = new ArrayList<>(rankedRecipients.size());
for (int i = 0; i < rankedRecipients.size(); i++) {
ShortcutInfoCompat info = buildShortcutInfo(context, rankedRecipients.get(i), i);
shortcuts.add(info);
}
return ShortcutManagerCompat.setDynamicShortcuts(context, shortcuts);
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class AttachmentUtil method deleteAttachment.
/**
* Deletes the specified attachment. If its the only attachment for its linked message, the entire
* message is deleted.
*/
@WorkerThread
public static void deleteAttachment(@NonNull Context context, @NonNull DatabaseAttachment attachment) {
AttachmentId attachmentId = attachment.getAttachmentId();
long mmsId = attachment.getMmsId();
int attachmentCount = SignalDatabase.attachments().getAttachmentsForMessage(mmsId).size();
if (attachmentCount <= 1) {
SignalDatabase.mms().deleteMessage(mmsId);
} else {
SignalDatabase.attachments().deleteAttachment(attachmentId);
}
}
use of androidx.annotation.WorkerThread in project mobile-center-sdk-android by Microsoft.
the class Analytics method queuePage.
/**
* Enqueue page log now.
*/
@WorkerThread
private void queuePage(String name, Map<String, String> properties) {
PageLog pageLog = new PageLog();
pageLog.setName(name);
pageLog.setProperties(properties);
mChannel.enqueue(pageLog, ANALYTICS_GROUP, Flags.DEFAULTS);
}
Aggregations