Search in sources :

Example 81 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class MediaRepository method getFolders.

@WorkerThread
@NonNull
private List<MediaFolder> getFolders(@NonNull Context context) {
    FolderResult imageFolders = getFolders(context, Images.Media.EXTERNAL_CONTENT_URI);
    FolderResult videoFolders = getFolders(context, Video.Media.EXTERNAL_CONTENT_URI);
    Map<String, FolderData> folders = new HashMap<>(imageFolders.getFolderData());
    for (Map.Entry<String, FolderData> entry : videoFolders.getFolderData().entrySet()) {
        if (folders.containsKey(entry.getKey())) {
            folders.get(entry.getKey()).incrementCount(entry.getValue().getCount());
        } else {
            folders.put(entry.getKey(), entry.getValue());
        }
    }
    String cameraBucketId = imageFolders.getCameraBucketId() != null ? imageFolders.getCameraBucketId() : videoFolders.getCameraBucketId();
    FolderData cameraFolder = cameraBucketId != null ? folders.remove(cameraBucketId) : null;
    List<MediaFolder> mediaFolders = Stream.of(folders.values()).map(folder -> new MediaFolder(folder.getThumbnail(), folder.getTitle(), folder.getCount(), folder.getBucketId(), MediaFolder.FolderType.NORMAL)).filter(folder -> folder.getTitle() != null).sorted((o1, o2) -> o1.getTitle().toLowerCase().compareTo(o2.getTitle().toLowerCase())).toList();
    Uri allMediaThumbnail = imageFolders.getThumbnailTimestamp() > videoFolders.getThumbnailTimestamp() ? imageFolders.getThumbnail() : videoFolders.getThumbnail();
    if (allMediaThumbnail != null) {
        int allMediaCount = Stream.of(mediaFolders).reduce(0, (count, folder) -> count + folder.getItemCount());
        if (cameraFolder != null) {
            allMediaCount += cameraFolder.getCount();
        }
        mediaFolders.add(0, new MediaFolder(allMediaThumbnail, context.getString(R.string.MediaRepository_all_media), allMediaCount, Media.ALL_MEDIA_BUCKET_ID, MediaFolder.FolderType.NORMAL));
    }
    if (cameraFolder != null) {
        mediaFolders.add(0, new MediaFolder(cameraFolder.getThumbnail(), cameraFolder.getTitle(), cameraFolder.getCount(), cameraFolder.getBucketId(), MediaFolder.FolderType.CAMERA));
    }
    return mediaFolders;
}
Also used : MediaUtil(org.thoughtcrime.securesms.util.MediaUtil) Context(android.content.Context) Stream(com.annimon.stream.Stream) Util(org.thoughtcrime.securesms.util.Util) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) Pair(android.util.Pair) WorkerThread(androidx.annotation.WorkerThread) HashMap(java.util.HashMap) R(org.thoughtcrime.securesms.R) Video(android.provider.MediaStore.Video) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SqlUtil(org.thoughtcrime.securesms.util.SqlUtil) MediaStore(android.provider.MediaStore) Map(java.util.Map) PartAuthority(org.thoughtcrime.securesms.mms.PartAuthority) Build(android.os.Build) LinkedList(java.util.LinkedList) TargetApi(android.annotation.TargetApi) Cursor(android.database.Cursor) SignalExecutors(org.signal.core.util.concurrent.SignalExecutors) IOException(java.io.IOException) OpenableColumns(android.provider.OpenableColumns) Collectors(java.util.stream.Collectors) Optional(org.whispersystems.libsignal.util.guava.Optional) Log(org.signal.core.util.logging.Log) Images(android.provider.MediaStore.Images) StorageUtil(org.thoughtcrime.securesms.util.StorageUtil) List(java.util.List) Nullable(androidx.annotation.Nullable) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) VisibleForTesting(androidx.annotation.VisibleForTesting) Collections(java.util.Collections) ContentUris(android.content.ContentUris) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Uri(android.net.Uri) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 82 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class GroupJoinRepository method getGroupDetails.

@WorkerThread
@NonNull
private GroupDetails getGroupDetails() throws VerificationFailedException, IOException, GroupLinkNotActiveException {
    DecryptedGroupJoinInfo joinInfo = GroupManager.getGroupJoinInfoFromServer(context, groupInviteLinkUrl.getGroupMasterKey(), groupInviteLinkUrl.getPassword());
    byte[] avatarBytes = tryGetAvatarBytes(joinInfo);
    return new GroupDetails(joinInfo, avatarBytes);
}
Also used : DecryptedGroupJoinInfo(org.signal.storageservice.protos.groups.local.DecryptedGroupJoinInfo) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 83 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class InviteReminderModel method createReminderInfo.

@WorkerThread
@NonNull
private ReminderInfo createReminderInfo(Recipient recipient) {
    Recipient resolved = recipient.resolve();
    if (resolved.isRegistered() || resolved.isGroup() || resolved.hasSeenSecondInviteReminder()) {
        return new NoReminderInfo();
    }
    ThreadDatabase threadDatabase = SignalDatabase.threads();
    Long threadId = threadDatabase.getThreadIdFor(recipient.getId());
    if (threadId != null) {
        int conversationCount = SignalDatabase.mmsSms().getInsecureSentCount(threadId);
        if (conversationCount >= SECOND_INVITE_REMINDER_MESSAGE_THRESHOLD && !resolved.hasSeenSecondInviteReminder()) {
            return new SecondInviteReminderInfo(context, resolved, repository, repository.getPercentOfInsecureMessages(conversationCount));
        } else if (conversationCount >= FIRST_INVITE_REMINDER_MESSAGE_THRESHOLD && !resolved.hasSeenFirstInviteReminder()) {
            return new FirstInviteReminderInfo(context, resolved, repository, repository.getPercentOfInsecureMessages(conversationCount));
        }
    }
    return new NoReminderInfo();
}
Also used : LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 84 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class JobManager method getDebugInfo.

/**
 * Retrieves a string representing the state of the job queue. Intended for debugging.
 */
@WorkerThread
@NonNull
public String getDebugInfo() {
    AtomicReference<String> result = new AtomicReference<>();
    CountDownLatch latch = new CountDownLatch(1);
    runOnExecutor(() -> {
        result.set(jobController.getDebugInfo());
        latch.countDown();
    });
    try {
        boolean finished = latch.await(10, TimeUnit.SECONDS);
        if (finished) {
            return result.get();
        } else {
            return "Timed out waiting for Job info.";
        }
    } catch (InterruptedException e) {
        Log.w(TAG, "Failed to retrieve Job info.", e);
        return "Failed to retrieve Job info.";
    }
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 85 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class JobManager method flush.

/**
 * Blocks until all pending operations are finished.
 */
@WorkerThread
public void flush() {
    CountDownLatch latch = new CountDownLatch(1);
    runOnExecutor(latch::countDown);
    try {
        latch.await();
        Log.i(TAG, "Successfully flushed.");
    } catch (InterruptedException e) {
        Log.w(TAG, "Failed to finish flushing.", e);
    }
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) 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