Search in sources :

Example 86 with WorkerThread

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);
    }
}
Also used : JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) IOException(java.io.IOException) WorkerThread(androidx.annotation.WorkerThread)

Example 87 with WorkerThread

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();
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) ComponentName(android.content.ComponentName) Person(androidx.core.app.Person) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat) LocusIdCompat(androidx.core.content.LocusIdCompat) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 88 with WorkerThread

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);
}
Also used : ArrayList(java.util.ArrayList) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat) WorkerThread(androidx.annotation.WorkerThread)

Example 89 with WorkerThread

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);
    }
}
Also used : AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId) NotInCallConstraint(org.thoughtcrime.securesms.jobmanager.impl.NotInCallConstraint) WorkerThread(androidx.annotation.WorkerThread)

Example 90 with WorkerThread

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);
}
Also used : PageLog(com.microsoft.appcenter.analytics.ingestion.models.PageLog) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

WorkerThread (androidx.annotation.WorkerThread)365 NonNull (androidx.annotation.NonNull)151 IOException (java.io.IOException)83 Recipient (org.thoughtcrime.securesms.recipients.Recipient)82 Nullable (androidx.annotation.Nullable)51 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)46 Cursor (android.database.Cursor)41 ArrayList (java.util.ArrayList)41 Context (android.content.Context)39 Uri (android.net.Uri)32 LinkedList (java.util.LinkedList)30 List (java.util.List)30 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)28 Stream (com.annimon.stream.Stream)26 HashMap (java.util.HashMap)26 Log (org.signal.core.util.logging.Log)26 HashSet (java.util.HashSet)24 Map (java.util.Map)21 Collections (java.util.Collections)20 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)20