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