Add media constraints for arbitrary file types

Fixes #6573
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2017-04-24 15:52:48 -07:00
parent 03e347bfd9
commit 9bf198bb81
4 changed files with 17 additions and 1 deletions

View File

@ -36,13 +36,15 @@ public abstract class MediaConstraints {
public abstract int getAudioMaxSize(); public abstract int getAudioMaxSize();
public abstract int getDocumentMaxSize();
public boolean isSatisfied(@NonNull Context context, @NonNull MasterSecret masterSecret, @NonNull Attachment attachment) { public boolean isSatisfied(@NonNull Context context, @NonNull MasterSecret masterSecret, @NonNull Attachment attachment) {
try { try {
return (MediaUtil.isGif(attachment) && attachment.getSize() <= getGifMaxSize() && isWithinBounds(context, masterSecret, attachment.getDataUri())) || return (MediaUtil.isGif(attachment) && attachment.getSize() <= getGifMaxSize() && isWithinBounds(context, masterSecret, attachment.getDataUri())) ||
(MediaUtil.isImage(attachment) && attachment.getSize() <= getImageMaxSize() && isWithinBounds(context, masterSecret, attachment.getDataUri())) || (MediaUtil.isImage(attachment) && attachment.getSize() <= getImageMaxSize() && isWithinBounds(context, masterSecret, attachment.getDataUri())) ||
(MediaUtil.isAudio(attachment) && attachment.getSize() <= getAudioMaxSize()) || (MediaUtil.isAudio(attachment) && attachment.getSize() <= getAudioMaxSize()) ||
(MediaUtil.isVideo(attachment) && attachment.getSize() <= getVideoMaxSize()) || (MediaUtil.isVideo(attachment) && attachment.getSize() <= getVideoMaxSize()) ||
(!MediaUtil.isImage(attachment) && !MediaUtil.isAudio(attachment) && !MediaUtil.isVideo(attachment)); (MediaUtil.isFile(attachment) && attachment.getSize() <= getDocumentMaxSize());
} catch (IOException ioe) { } catch (IOException ioe) {
Log.w(TAG, "Failed to determine if media's constraints are satisfied.", ioe); Log.w(TAG, "Failed to determine if media's constraints are satisfied.", ioe);
return false; return false;

View File

@ -38,4 +38,9 @@ public class MmsMediaConstraints extends MediaConstraints {
public int getAudioMaxSize() { public int getAudioMaxSize() {
return MAX_MESSAGE_SIZE; return MAX_MESSAGE_SIZE;
} }
@Override
public int getDocumentMaxSize() {
return MAX_MESSAGE_SIZE;
}
} }

View File

@ -39,4 +39,9 @@ public class PushMediaConstraints extends MediaConstraints {
public int getAudioMaxSize() { public int getAudioMaxSize() {
return 100 * MB; return 100 * MB;
} }
@Override
public int getDocumentMaxSize() {
return 100 * MB;
}
} }

View File

@ -164,6 +164,10 @@ public class MediaUtil {
return !TextUtils.isEmpty(contentType) && contentType.trim().startsWith("video/"); return !TextUtils.isEmpty(contentType) && contentType.trim().startsWith("video/");
} }
public static boolean isFile(Attachment attachment) {
return !isImage(attachment) && !isAudio(attachment) && !isVideo(attachment);
}
public static boolean hasVideoThumbnail(Uri uri) { public static boolean hasVideoThumbnail(Uri uri) {
Log.w(TAG, "Checking: " + uri); Log.w(TAG, "Checking: " + uri);