From e83827ab75d070d5743308528a774e7df80c3fc9 Mon Sep 17 00:00:00 2001 From: Geonu Kang Date: Sat, 21 Nov 2015 17:04:19 +0900 Subject: [PATCH] "image/jpg"->"image/jpeg" on MIME type checks and saving Fixes #4602 Closes #4643 --- .../thoughtcrime/securesms/ShareActivity.java | 16 ++++++---------- .../thoughtcrime/securesms/util/MediaUtil.java | 15 ++++++++++++++- .../securesms/util/SaveAttachmentTask.java | 8 ++++---- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ShareActivity.java b/src/org/thoughtcrime/securesms/ShareActivity.java index 68e3af90d3..367c15c489 100644 --- a/src/org/thoughtcrime/securesms/ShareActivity.java +++ b/src/org/thoughtcrime/securesms/ShareActivity.java @@ -29,7 +29,6 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.webkit.MimeTypeMap; import org.thoughtcrime.securesms.crypto.MasterSecret; import org.thoughtcrime.securesms.mms.PartAuthority; @@ -37,6 +36,7 @@ import org.thoughtcrime.securesms.providers.PersistentBlobProvider; import org.thoughtcrime.securesms.recipients.Recipients; import org.thoughtcrime.securesms.util.DynamicLanguage; import org.thoughtcrime.securesms.util.DynamicTheme; +import org.thoughtcrime.securesms.util.MediaUtil; import org.thoughtcrime.securesms.util.ViewUtil; import java.io.IOException; @@ -167,7 +167,8 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity final Intent intent = new Intent(this, target); final String textExtra = getIntent().getStringExtra(Intent.EXTRA_TEXT); final Uri streamExtra = getIntent().getParcelableExtra(Intent.EXTRA_STREAM); - final String type = streamExtra != null ? getMimeType(streamExtra) : getIntent().getType(); + final String type = streamExtra != null ? getMimeType(streamExtra) + : MediaUtil.getCorrectedMimeType(getIntent().getType()); intent.putExtra(ConversationActivity.TEXT_EXTRA, textExtra); if (resolvedExtra != null) intent.setDataAndType(resolvedExtra, type); @@ -175,14 +176,9 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity } private String getMimeType(Uri uri) { - String type = getContentResolver().getType(uri); - - if (type == null) { - String extension = MimeTypeMap.getFileExtensionFromUrl(uri.toString()); - type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); - } - - return type == null ? getIntent().getType() : type; + final String type = MediaUtil.getMimeType(getApplicationContext(), uri); + return type == null ? MediaUtil.getCorrectedMimeType(getIntent().getType()) + : type; } private class ResolveMediaTask extends AsyncTask { diff --git a/src/org/thoughtcrime/securesms/util/MediaUtil.java b/src/org/thoughtcrime/securesms/util/MediaUtil.java index ddd72247af..6caaa83173 100644 --- a/src/org/thoughtcrime/securesms/util/MediaUtil.java +++ b/src/org/thoughtcrime/securesms/util/MediaUtil.java @@ -76,7 +76,20 @@ public class MediaUtil { final String extension = MimeTypeMap.getFileExtensionFromUrl(uri.toString()); type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); } - return type; + return getCorrectedMimeType(type); + } + + public static @Nullable String getCorrectedMimeType(@Nullable String mimeType) { + if (mimeType == null) return null; + + switch(mimeType) { + case "image/jpg": + return MimeTypeMap.getSingleton().hasMimeType(ContentType.IMAGE_JPEG) + ? ContentType.IMAGE_JPEG + : mimeType; + default: + return mimeType; + } } public static long getMediaSize(Context context, MasterSecret masterSecret, Uri uri) throws IOException { diff --git a/src/org/thoughtcrime/securesms/util/SaveAttachmentTask.java b/src/org/thoughtcrime/securesms/util/SaveAttachmentTask.java index 6072414b1f..8c4f287cec 100644 --- a/src/org/thoughtcrime/securesms/util/SaveAttachmentTask.java +++ b/src/org/thoughtcrime/securesms/util/SaveAttachmentTask.java @@ -58,7 +58,8 @@ public class SaveAttachmentTask extends ProgressDialogAsyncTask