use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class VoiceNoteMediaItemFactory method buildMediaItem.
/**
* Build out a MediaItem for a given voice note. Expects to be run
* on a background thread.
*
* @param context Context.
* @param messageRecord The MessageRecord of the given voice note.
* @return A MediaItem with all the details the service expects.
*/
@WorkerThread
@Nullable
static MediaItem buildMediaItem(@NonNull Context context, @NonNull MessageRecord messageRecord) {
int startingPosition = SignalDatabase.mmsSms().getMessagePositionInConversation(messageRecord.getThreadId(), messageRecord.getDateReceived());
Recipient threadRecipient = Objects.requireNonNull(SignalDatabase.threads().getRecipientForThreadId(messageRecord.getThreadId()));
Recipient sender = messageRecord.isOutgoing() ? Recipient.self() : messageRecord.getIndividualRecipient();
Recipient avatarRecipient = threadRecipient.isGroup() ? threadRecipient : sender;
AudioSlide audioSlide = ((MmsMessageRecord) messageRecord).getSlideDeck().getAudioSlide();
if (audioSlide == null) {
Log.w(TAG, "Message does not have an audio slide. Can't play this voice note.");
return null;
}
Uri uri = audioSlide.getUri();
if (uri == null) {
Log.w(TAG, "Audio slide does not have a URI. Can't play this voice note.");
return null;
}
return buildMediaItem(context, threadRecipient, avatarRecipient, sender, startingPosition, messageRecord.getThreadId(), messageRecord.getId(), messageRecord.getDateReceived(), uri);
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class GroupsV2CapabilityChecker method allHaveUuidAndSupportGroupsV2.
@WorkerThread
static boolean allHaveUuidAndSupportGroupsV2(@NonNull Collection<RecipientId> recipientIds) throws IOException {
Set<RecipientId> recipientIdsSet = new HashSet<>(recipientIds);
refreshCapabilitiesIfNecessary(Recipient.resolvedList(recipientIdsSet));
boolean noSelfGV2Support = false;
int noGv2Count = 0;
int noUuidCount = 0;
for (RecipientId id : recipientIds) {
Recipient member = Recipient.resolved(id);
Recipient.Capability gv2Capability = member.getGroupsV2Capability();
if (gv2Capability != Recipient.Capability.SUPPORTED) {
Log.w(TAG, "At least one recipient does not support GV2, capability was " + gv2Capability);
noGv2Count++;
if (member.isSelf()) {
noSelfGV2Support = true;
}
}
if (!member.hasServiceId()) {
noUuidCount++;
}
}
if (noGv2Count + noUuidCount > 0) {
if (noUuidCount > 0) {
Log.w(TAG, noUuidCount + " recipient(s) did not have a UUID known to us");
}
if (noGv2Count > 0) {
Log.w(TAG, noGv2Count + " recipient(s) do not support GV2");
if (noSelfGV2Support) {
Log.w(TAG, "Self does not support GV2");
}
}
return false;
}
return true;
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class GroupsV2CapabilityChecker method refreshCapabilitiesIfNecessary.
/**
* @param resolved A collection of resolved recipients.
* @return True if a recipient needed to be refreshed, otherwise false.
*/
@WorkerThread
public static boolean refreshCapabilitiesIfNecessary(@NonNull Collection<Recipient> resolved) throws IOException {
Set<RecipientId> needsRefresh = Stream.of(resolved).filter(r -> r.getGroupsV2Capability() != Recipient.Capability.SUPPORTED).map(Recipient::getId).collect(Collectors.toSet());
if (needsRefresh.size() > 0) {
Log.d(TAG, "[refreshCapabilitiesIfNecessary] Need to refresh " + needsRefresh.size() + " recipients.");
List<Job> jobs = RetrieveProfileJob.forRecipients(needsRefresh);
JobManager jobManager = ApplicationDependencies.getJobManager();
for (Job job : jobs) {
if (!jobManager.runSynchronously(job, TimeUnit.SECONDS.toMillis(10)).isPresent()) {
throw new IOException("Recipient capability was not retrieved in time");
}
}
return true;
} else {
return false;
}
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class CameraContactsRepository method getContacts.
@WorkerThread
@NonNull
private List<Recipient> getContacts(@NonNull String query) {
List<Recipient> recipients = new ArrayList<>();
try (Cursor cursor = contactRepository.querySignalContacts(query)) {
while (cursor.moveToNext()) {
RecipientId id = RecipientId.from(cursor.getLong(cursor.getColumnIndexOrThrow(ContactRepository.ID_COLUMN)));
Recipient recipient = Recipient.resolved(id);
recipients.add(recipient);
}
}
return recipients;
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class ImageEditorModelRenderMediaTransform method transform.
@WorkerThread
@Override
@NonNull
public Media transform(@NonNull Context context, @NonNull Media media) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Bitmap bitmap = modelToRender.render(context, size);
try {
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, outputStream);
Uri uri = BlobProvider.getInstance().forData(outputStream.toByteArray()).withMimeType(MediaUtil.IMAGE_JPEG).createForSingleSessionOnDisk(context);
return new Media(uri, MediaUtil.IMAGE_JPEG, media.getDate(), bitmap.getWidth(), bitmap.getHeight(), outputStream.size(), 0, false, false, media.getBucketId(), media.getCaption(), Optional.absent());
} catch (IOException e) {
Log.w(TAG, "Failed to render image. Using base image.");
return media;
} finally {
bitmap.recycle();
StreamUtil.close(outputStream);
}
}
Aggregations