Commit 69093d67 authored by Torsten Grote's avatar Torsten Grote

Merge branch '1636-compression-failure' into 'master'

Fix PNG compression on some phones

Closes #1636

See merge request !1183
parents 120fcf55 5af7bbb2
Pipeline #4036 passed with stage
in 19 minutes and 14 seconds
......@@ -106,4 +106,15 @@ public class AndroidUtils {
public static File getReportDir(Context ctx) {
return ctx.getDir(STORED_REPORTS, MODE_PRIVATE);
}
/**
* Returns an array of supported content types for image attachments.
* GIFs can't be compressed on API < 24 so they're not supported.
* <p>
* TODO: Remove this restriction when large message support is added
*/
public static String[] getSupportedImageContentTypes() {
if (SDK_INT < 24) return new String[] {"image/jpeg", "image/png"};
else return new String[] {"image/jpeg", "image/png", "image/gif"};
}
}
......@@ -135,6 +135,7 @@ dependencies {
testImplementation "org.jmock:jmock-junit4:$jmockVersion"
testImplementation "org.jmock:jmock-legacy:$jmockVersion"
androidTestImplementation project(path: ':bramble-api', configuration: 'testOutput')
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
......
PngSuite
--------
Permission to use, copy, modify and distribute these images for any
purpose and without fee is hereby granted.
(c) Willem van Schaik, 1996, 2011
PNGSUITE
----------------
testset for PNG-(de)coders
created by Willem van Schaik
------------------------------------
This is a collection of graphics images created to test the png applications
like viewers, converters and editors. All (as far as that is possible)
formats supported by the PNG standard are represented.
The suite consists of the following files:
- PngSuite.README - this file
- PngSuite.LICENSE - the PngSuite is freeware
- PngSuite.png - image with PngSuite logo
- PngSuite.tgz - archive of all PNG testfiles
- PngSuite.zip - same in .zip format for PCs
--------
(c) Willem van Schaik
willem@schaik.com
Calgary, April 2011
package org.briarproject.briar.android.attachment;
import android.content.res.AssetManager;
import org.junit.Before;
import java.io.IOException;
import java.io.InputStream;
import static androidx.test.InstrumentationRegistry.getContext;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
abstract class AbstractAttachmentCreationTaskTest {
private final ImageHelper imageHelper = new ImageHelperImpl();
private final ImageSizeCalculator imageSizeCalculator =
new ImageSizeCalculator(imageHelper);
private AttachmentCreationTask task;
@Before
@SuppressWarnings("ConstantConditions") // add real objects when needed
public void setUp() {
task = new AttachmentCreationTask(null,
getApplicationContext().getContentResolver(), null,
imageSizeCalculator, null, null, true);
}
void testCompress(String filename, String contentType)
throws IOException {
InputStream is = getAssetManager().open(filename);
task.compressImage(is, contentType);
}
static AssetManager getAssetManager() {
// pm.getResourcesForApplication(packageName).getAssets() did not work
//noinspection deprecation
return getContext().getAssets();
}
}
package org.briarproject.briar.android.attachment;
import org.junit.Test;
import org.junit.runner.RunWith;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import static android.os.Build.VERSION.SDK_INT;
import static org.junit.Assume.assumeTrue;
@RunWith(AndroidJUnit4.class)
public class AttachmentCreationTaskTest
extends AbstractAttachmentCreationTaskTest {
@Test
public void testCompressSmallPng() throws Exception {
testCompress("red-100x100.png", "image/png");
}
@Test
public void testCompressMediumPng() throws Exception {
testCompress("blue-500x500.png", "image/png");
}
@Test
public void testCompressLargePng() throws Exception {
testCompress("green-1000x2000.png", "image/png");
}
@Test
public void testCompressTransparentPng() throws Exception {
testCompress("transparent-100x100.png", "image/png");
}
@Test
public void testCompressVeryHighJpg() throws Exception {
testCompress("error_high.jpg", "image/jpeg");
}
@Test
public void testCompressVeryWideJpg() throws Exception {
testCompress("error_wide.jpg", "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");
}
@Test
public void testCompressAnimatedGif2() throws Exception {
// TODO: Remove this assumption when we support large messages
assumeTrue(SDK_INT >= 24);
testCompress("animated2.gif", "image/gif");
}
@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");
}
}
package org.briarproject.briar.android.attachment;
import android.content.res.AssetManager;
import org.briarproject.bramble.api.UniqueId;
import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.api.messaging.Attachment;
......@@ -9,14 +7,12 @@ import org.briarproject.briar.api.messaging.AttachmentHeader;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Random;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static androidx.test.InstrumentationRegistry.getContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
......@@ -24,25 +20,6 @@ import static org.junit.Assert.assertTrue;
@RunWith(AndroidJUnit4.class)
public class AttachmentRetrieverIntegrationTest {
private static final String smallKitten =
"https://upload.wikimedia.org/wikipedia/commons/thumb/0/06/Kitten_in_Rizal_Park%2C_Manila.jpg/160px-Kitten_in_Rizal_Park%2C_Manila.jpg";
private static final String originalKitten =