use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class StickerPackPreviewRepository method getManifestRemote.
@WorkerThread
private Optional<StickerManifestResult> getManifestRemote(@NonNull String packId, @NonNull String packKey) {
try {
byte[] packIdBytes = Hex.fromStringCondensed(packId);
byte[] packKeyBytes = Hex.fromStringCondensed(packKey);
SignalServiceStickerManifest remoteManifest = receiver.retrieveStickerManifest(packIdBytes, packKeyBytes);
StickerManifest localManifest = new StickerManifest(packId, packKey, remoteManifest.getTitle(), remoteManifest.getAuthor(), toOptionalSticker(packId, packKey, remoteManifest.getCover()), Stream.of(remoteManifest.getStickers()).map(s -> toSticker(packId, packKey, s)).toList());
return Optional.of(new StickerManifestResult(localManifest, false));
} catch (IOException | InvalidMessageException e) {
Log.w(TAG, "Failed to retrieve pack manifest.", e);
}
return Optional.absent();
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class StickerPackPreviewRepository method getStickersFromDatabase.
@WorkerThread
private List<StickerManifest.Sticker> getStickersFromDatabase(@NonNull String packId) {
List<StickerManifest.Sticker> stickers = new ArrayList<>();
try (Cursor cursor = stickerDatabase.getStickersForPack(packId)) {
StickerDatabase.StickerRecordReader reader = new StickerDatabase.StickerRecordReader(cursor);
StickerRecord record;
while ((record = reader.getNext()) != null) {
stickers.add(toSticker(record));
}
}
return stickers;
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class ShareRepository method getResolvedInternal.
@WorkerThread
@NonNull
private ShareData getResolvedInternal(@Nullable Uri uri, @Nullable String mimeType) throws IOException {
Context context = ApplicationDependencies.getApplication();
if (uri == null) {
return ShareData.forPrimitiveTypes();
}
if (!UriUtil.isValidExternalUri(context, uri)) {
throw new IOException("Invalid external URI!");
}
mimeType = getMimeType(context, uri, mimeType);
if (PartAuthority.isLocalUri(uri)) {
return ShareData.forIntentData(uri, mimeType, false, false);
} else {
InputStream stream = null;
try {
stream = context.getContentResolver().openInputStream(uri);
} catch (SecurityException e) {
Log.w(TAG, "Failed to read stream!", e);
}
if (stream == null) {
throw new IOException("Failed to open stream!");
}
long size = getSize(context, uri);
String fileName = getFileName(context, uri);
Uri blobUri;
if (MediaUtil.isImageType(mimeType) || MediaUtil.isVideoType(mimeType)) {
blobUri = BlobProvider.getInstance().forData(stream, size).withMimeType(mimeType).withFileName(fileName).createForSingleSessionOnDisk(context);
} else {
blobUri = BlobProvider.getInstance().forData(stream, size).withMimeType(mimeType).withFileName(fileName).createForSingleSessionOnDisk(context);
// TODO Convert to multi-session after file drafts are fixed.
}
return ShareData.forIntentData(blobUri, mimeType, true, isMmsSupported(context, asUriAttachment(blobUri, mimeType, size)));
}
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class BlockUnblockDialog method buildBlockFor.
@WorkerThread
private static AlertDialog.Builder buildBlockFor(@NonNull Context context, @NonNull Recipient recipient, @NonNull Runnable onBlock, @Nullable Runnable onBlockAndReportSpam) {
recipient = recipient.resolve();
AlertDialog.Builder builder = new MaterialAlertDialogBuilder(context);
Resources resources = context.getResources();
if (recipient.isGroup()) {
if (SignalDatabase.groups().isActive(recipient.requireGroupId())) {
builder.setTitle(resources.getString(R.string.BlockUnblockDialog_block_and_leave_s, recipient.getDisplayName(context)));
builder.setMessage(R.string.BlockUnblockDialog_you_will_no_longer_receive_messages_or_updates);
builder.setPositiveButton(R.string.BlockUnblockDialog_block_and_leave, ((dialog, which) -> onBlock.run()));
builder.setNegativeButton(android.R.string.cancel, null);
} else {
builder.setTitle(resources.getString(R.string.BlockUnblockDialog_block_s, recipient.getDisplayName(context)));
builder.setMessage(R.string.BlockUnblockDialog_group_members_wont_be_able_to_add_you);
builder.setPositiveButton(R.string.RecipientPreferenceActivity_block, ((dialog, which) -> onBlock.run()));
builder.setNegativeButton(android.R.string.cancel, null);
}
} else if (recipient.isReleaseNotes()) {
builder.setTitle(resources.getString(R.string.BlockUnblockDialog_block_s, recipient.getDisplayName(context)));
builder.setMessage(R.string.BlockUnblockDialog_block_getting_signal_updates_and_news);
builder.setPositiveButton(R.string.BlockUnblockDialog_block, ((dialog, which) -> onBlock.run()));
builder.setNegativeButton(android.R.string.cancel, null);
} else {
builder.setTitle(resources.getString(R.string.BlockUnblockDialog_block_s, recipient.getDisplayName(context)));
builder.setMessage(R.string.BlockUnblockDialog_blocked_people_wont_be_able_to_call_you_or_send_you_messages);
if (onBlockAndReportSpam != null) {
builder.setNeutralButton(android.R.string.cancel, null);
builder.setNegativeButton(R.string.BlockUnblockDialog_report_spam_and_block, (d, w) -> onBlockAndReportSpam.run());
builder.setPositiveButton(R.string.BlockUnblockDialog_block, (d, w) -> onBlock.run());
} else {
builder.setPositiveButton(R.string.BlockUnblockDialog_block, ((dialog, which) -> onBlock.run()));
builder.setNegativeButton(android.R.string.cancel, null);
}
}
return builder;
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class FrameSeqDecoder method innerStop.
@WorkerThread
private void innerStop() {
workerHandler.removeCallbacks(renderTask);
frames.clear();
for (Bitmap bitmap : cacheBitmaps) {
if (bitmap != null && !bitmap.isRecycled()) {
bitmap.recycle();
}
}
cacheBitmaps.clear();
if (frameBuffer != null) {
frameBuffer = null;
}
cachedCanvas.clear();
try {
if (mReader != null) {
mReader.close();
mReader = null;
}
if (mWriter != null) {
mWriter.close();
}
} catch (IOException e) {
e.printStackTrace();
}
release();
mState = State.IDLE;
for (RenderListener renderListener : renderListeners) {
renderListener.onEnd();
}
}
Aggregations