mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Remove support for GIF attachments on API < 24.
This commit is contained in:
@@ -11,9 +11,11 @@ import java.util.logging.Logger;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import static android.os.Build.VERSION.SDK_INT;
|
||||
import static androidx.test.InstrumentationRegistry.getContext;
|
||||
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class AttachmentCreationTaskTest {
|
||||
@@ -30,30 +32,55 @@ public class AttachmentCreationTaskTest {
|
||||
imageSizeCalculator, null, null, true);
|
||||
|
||||
@Test
|
||||
public void testCompress() throws Exception {
|
||||
InputStream is = getAssetInputStream("animated.gif");
|
||||
task.compressImage(is, "image/gif");
|
||||
public void testCompress100x100Png() throws Exception {
|
||||
testCompress("red-100x100.png", "image/png");
|
||||
}
|
||||
|
||||
is = getAssetInputStream("animated2.gif");
|
||||
task.compressImage(is, "image/gif");
|
||||
@Test
|
||||
public void testCompress500x500Png() throws Exception {
|
||||
testCompress("blue-500x500.png", "image/png");
|
||||
}
|
||||
|
||||
is = getAssetInputStream("blue-500x500.png");
|
||||
task.compressImage(is, "image/png");
|
||||
@Test
|
||||
public void testCompress1000x2000Png() throws Exception {
|
||||
testCompress("green-1000x2000.png", "image/png");
|
||||
}
|
||||
|
||||
is = getAssetInputStream("error_high.jpg");
|
||||
task.compressImage(is, "image/jpeg");
|
||||
@Test
|
||||
public void testCompressVeryHighJpg() throws Exception {
|
||||
testCompress("error_high.jpg", "image/jpeg");
|
||||
}
|
||||
|
||||
is = getAssetInputStream("error_large.gif");
|
||||
task.compressImage(is, "image/gif");
|
||||
@Test
|
||||
public void testCompressVeryWideJpg() throws Exception {
|
||||
testCompress("error_wide.jpg", "image/jpeg");
|
||||
}
|
||||
|
||||
is = getAssetInputStream("error_wide.jpg");
|
||||
task.compressImage(is, "image/jpeg");
|
||||
@Test
|
||||
public void testCompressAnimatedGif1() throws Exception {
|
||||
// TODO: Remove this assumption when we support large messages
|
||||
assumeTrue(SDK_INT >= 24);
|
||||
testCompress("animated.gif", "image/gif");
|
||||
}
|
||||
|
||||
is = getAssetInputStream("green-1000x2000.png");
|
||||
task.compressImage(is, "image/png");
|
||||
@Test
|
||||
public void testCompressAnimatedGif2() throws Exception {
|
||||
// TODO: Remove this assumption when we support large messages
|
||||
assumeTrue(SDK_INT >= 24);
|
||||
testCompress("animated2.gif", "image/gif");
|
||||
}
|
||||
|
||||
is = getAssetInputStream("red-100x100.png");
|
||||
task.compressImage(is, "image/png");
|
||||
@Test
|
||||
public void testCompressVeryLargeGif() throws Exception {
|
||||
// TODO: Remove this assumption when we support large messages
|
||||
assumeTrue(SDK_INT >= 24);
|
||||
testCompress("error_large.gif", "image/gif");
|
||||
}
|
||||
|
||||
private void testCompress(String filename, String contentType)
|
||||
throws Exception {
|
||||
InputStream is = getAssetInputStream(filename);
|
||||
task.compressImage(is, contentType);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -26,14 +26,15 @@ import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import static android.graphics.Bitmap.CompressFormat.JPEG;
|
||||
import static android.graphics.BitmapFactory.decodeStream;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.AndroidUtils.getSupportedImageContentTypes;
|
||||
import static org.briarproject.bramble.util.IoUtils.tryToClose;
|
||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.LogUtils.now;
|
||||
import static org.briarproject.briar.api.messaging.MessagingConstants.IMAGE_MIME_TYPES;
|
||||
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_IMAGE_SIZE;
|
||||
|
||||
@NotNullByDefault
|
||||
@@ -108,7 +109,7 @@ class AttachmentCreationTask {
|
||||
long start = now();
|
||||
String contentType = contentResolver.getType(uri);
|
||||
if (contentType == null) throw new IOException("null content type");
|
||||
if (!isValidMimeType(contentType)) {
|
||||
if (!asList(getSupportedImageContentTypes()).contains(contentType)) {
|
||||
String uriString = uri.toString();
|
||||
throw new UnsupportedMimeTypeException("", contentType, uriString);
|
||||
}
|
||||
@@ -124,13 +125,6 @@ class AttachmentCreationTask {
|
||||
return h;
|
||||
}
|
||||
|
||||
private boolean isValidMimeType(String mimeType) {
|
||||
for (String supportedType : IMAGE_MIME_TYPES) {
|
||||
if (supportedType.equals(mimeType)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
InputStream compressImage(InputStream is, String contentType)
|
||||
throws IOException {
|
||||
|
||||
@@ -40,8 +40,8 @@ import static android.widget.Toast.LENGTH_LONG;
|
||||
import static androidx.core.content.ContextCompat.getColor;
|
||||
import static androidx.customview.view.AbsSavedState.EMPTY_STATE;
|
||||
import static androidx.lifecycle.Lifecycle.State.DESTROYED;
|
||||
import static org.briarproject.bramble.util.AndroidUtils.getSupportedImageContentTypes;
|
||||
import static org.briarproject.briar.android.util.UiUtils.resolveColorAttribute;
|
||||
import static org.briarproject.briar.api.messaging.MessagingConstants.IMAGE_MIME_TYPES;
|
||||
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_ATTACHMENTS_PER_MESSAGE;
|
||||
|
||||
@UiThread
|
||||
@@ -131,7 +131,8 @@ public class TextAttachmentController extends TextSendController
|
||||
ACTION_OPEN_DOCUMENT : ACTION_GET_CONTENT);
|
||||
intent.setType("image/*");
|
||||
intent.addCategory(CATEGORY_OPENABLE);
|
||||
if (SDK_INT >= 19) intent.putExtra(EXTRA_MIME_TYPES, IMAGE_MIME_TYPES);
|
||||
if (SDK_INT >= 19)
|
||||
intent.putExtra(EXTRA_MIME_TYPES, getSupportedImageContentTypes());
|
||||
if (SDK_INT >= 18) intent.putExtra(EXTRA_ALLOW_MULTIPLE, true);
|
||||
return intent;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user