Whitelist supported image formats

pull/156/head
M66B 6 years ago
parent 50690a8544
commit d17dd68f3b

@ -20,6 +20,7 @@ package eu.faircode.email;
*/
import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import androidx.annotation.NonNull;
@ -30,6 +31,8 @@ import androidx.room.PrimaryKey;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@ -54,6 +57,21 @@ public class EntityAttachment {
static final Integer PGP_MESSAGE = 1;
static final Integer PGP_SIGNATURE = 2;
// https://developer.android.com/guide/topics/media/media-formats#image-formats
private static final List<String> IMAGE_TYPES = Collections.unmodifiableList(Arrays.asList(
"image/bmp",
"image/gif",
"image/jpeg",
"image/jpg",
"image/png",
"image/webp"
));
private static final List<String> IMAGE_TYPES8 = Collections.unmodifiableList(Arrays.asList(
"image/heic",
"image/heif"
));
@PrimaryKey(autoGenerate = true)
public Long id;
@NonNull
@ -77,7 +95,11 @@ public class EntityAttachment {
}
boolean isImage() {
return type.startsWith("image/");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
if (IMAGE_TYPES8.contains(type))
return true;
return IMAGE_TYPES.contains(type);
}
File getFile(Context context) {

Loading…
Cancel
Save