use of org.thoughtcrime.securesms.util.BitmapDecodingException in project Signal-Android by WhisperSystems.
the class MediaConstraints method isWithinBounds.
private boolean isWithinBounds(Context context, MasterSecret masterSecret, Uri uri) throws IOException {
try {
InputStream is = PartAuthority.getAttachmentStream(context, masterSecret, uri);
Pair<Integer, Integer> dimensions = BitmapUtil.getDimensions(is);
return dimensions.first > 0 && dimensions.first <= getImageMaxWidth(context) && dimensions.second > 0 && dimensions.second <= getImageMaxHeight(context);
} catch (BitmapDecodingException e) {
throw new IOException(e);
}
}
use of org.thoughtcrime.securesms.util.BitmapDecodingException in project Signal-Android by WhisperSystems.
the class AvatarDownloadJob method onRun.
@Override
public void onRun(MasterSecret masterSecret) throws IOException {
GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
GroupDatabase.GroupRecord record = database.getGroup(groupId);
File attachment = null;
try {
if (record != null) {
long avatarId = record.getAvatarId();
String contentType = record.getAvatarContentType();
byte[] key = record.getAvatarKey();
String relay = record.getRelay();
Optional<byte[]> digest = Optional.fromNullable(record.getAvatarDigest());
if (avatarId == -1 || key == null) {
return;
}
if (digest.isPresent()) {
Log.w(TAG, "Downloading group avatar with digest: " + Hex.toString(digest.get()));
}
attachment = File.createTempFile("avatar", "tmp", context.getCacheDir());
attachment.deleteOnExit();
SignalServiceAttachmentPointer pointer = new SignalServiceAttachmentPointer(avatarId, contentType, key, relay, digest);
InputStream inputStream = receiver.retrieveAttachment(pointer, attachment, MAX_AVATAR_SIZE);
Bitmap avatar = BitmapUtil.createScaledBitmap(context, new AttachmentModel(attachment, key), 500, 500);
database.updateAvatar(groupId, avatar);
inputStream.close();
}
} catch (BitmapDecodingException | NonSuccessfulResponseCodeException | InvalidMessageException e) {
Log.w(TAG, e);
} finally {
if (attachment != null)
attachment.delete();
}
}
use of org.thoughtcrime.securesms.util.BitmapDecodingException in project Signal-Android by WhisperSystems.
the class AttachmentDatabaseTest method testThumbnailGenerationTaskRunWhenThumbnailMissing.
public void testThumbnailGenerationTaskRunWhenThumbnailMissing() throws Exception {
final AttachmentId attachmentId = new AttachmentId(ROW_ID, UNIQUE_ID);
DatabaseAttachment mockAttachment = getMockAttachment("image/png");
when(database.getAttachment(attachmentId)).thenReturn(mockAttachment);
doReturn(null).when(database).getDataStream(any(MasterSecret.class), any(AttachmentId.class), eq("thumbnail"));
doNothing().when(database).updateAttachmentThumbnail(any(MasterSecret.class), any(AttachmentId.class), any(InputStream.class), anyFloat());
try {
database.new ThumbnailFetchCallable(mock(MasterSecret.class), attachmentId).call();
throw new AssertionError("Didn't try to generate thumbnail");
} catch (BitmapDecodingException bde) {
if (!(bde.getCause() instanceof FileNotFoundException)) {
throw new AssertionError("Thumbnail generation failed for another reason than a FileNotFoundException: " + bde.getMessage());
}
// else success
}
}
use of org.thoughtcrime.securesms.util.BitmapDecodingException in project Signal-Android by WhisperSystems.
the class EmojiPageBitmap method loadPage.
private Bitmap loadPage() throws IOException {
if (bitmapReference != null && bitmapReference.get() != null)
return bitmapReference.get();
try {
final Bitmap bitmap = BitmapUtil.createScaledBitmap(context, "file:///android_asset/" + model.getSprite(), decodeScale);
bitmapReference = new SoftReference<>(bitmap);
Log.w(TAG, "onPageLoaded(" + model.getSprite() + ")");
return bitmap;
} catch (BitmapDecodingException e) {
Log.w(TAG, e);
throw new IOException(e);
}
}
Aggregations