Search in sources :

Example 41 with WorkerThread

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();
}
Also used : SignalServiceStickerManifest(org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest) InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) IOException(java.io.IOException) SignalServiceStickerManifest(org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest) WorkerThread(androidx.annotation.WorkerThread)

Example 42 with WorkerThread

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;
}
Also used : ArrayList(java.util.ArrayList) StickerDatabase(org.thoughtcrime.securesms.database.StickerDatabase) Cursor(android.database.Cursor) StickerRecord(org.thoughtcrime.securesms.database.model.StickerRecord) WorkerThread(androidx.annotation.WorkerThread)

Example 43 with WorkerThread

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)));
    }
}
Also used : Context(android.content.Context) InputStream(java.io.InputStream) IOException(java.io.IOException) Uri(android.net.Uri) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 44 with WorkerThread

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;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Context(android.content.Context) Lifecycle(androidx.lifecycle.Lifecycle) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Nullable(androidx.annotation.Nullable) AlertDialog(androidx.appcompat.app.AlertDialog) NonNull(androidx.annotation.NonNull) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) WorkerThread(androidx.annotation.WorkerThread) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SimpleTask(org.thoughtcrime.securesms.util.concurrent.SimpleTask) Resources(android.content.res.Resources) Resources(android.content.res.Resources) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) WorkerThread(androidx.annotation.WorkerThread)

Example 45 with WorkerThread

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();
    }
}
Also used : Bitmap(android.graphics.Bitmap) IOException(java.io.IOException) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

WorkerThread (androidx.annotation.WorkerThread)204 NonNull (androidx.annotation.NonNull)77 IOException (java.io.IOException)45 Recipient (org.thoughtcrime.securesms.recipients.Recipient)41 Nullable (androidx.annotation.Nullable)26 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)23 Cursor (android.database.Cursor)22 ArrayList (java.util.ArrayList)22 Context (android.content.Context)20 Uri (android.net.Uri)18 LinkedList (java.util.LinkedList)15 List (java.util.List)15 HashMap (java.util.HashMap)14 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)14 Stream (com.annimon.stream.Stream)13 Log (org.signal.core.util.logging.Log)13 HashSet (java.util.HashSet)12 InputStream (java.io.InputStream)11 Bitmap (android.graphics.Bitmap)10 Collections (java.util.Collections)10