From 287c416dac24dfeb722285cf200a00f918929706 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 29 Apr 2018 15:19:13 +0200 Subject: [PATCH] hard code ogg + audio/ mime type to oga --- .../siacs/conversations/persistance/FileBackend.java | 10 ++++++++++ .../services/AttachFileToConversationRunnable.java | 4 +--- .../java/eu/siacs/conversations/utils/MimeUtils.java | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 5b77e1879..70c38e516 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -332,8 +332,12 @@ public class FileBackend { Log.d(Config.LOGTAG, "copy " + uri.toString() + " to private storage (mime=" + mime + ")"); String extension = MimeUtils.guessExtensionFromMimeType(mime); if (extension == null) { + Log.d(Config.LOGTAG,"extension from mime type was null"); extension = getExtensionFromUri(uri); } + if ("ogg".equals(extension) && type != null && type.startsWith("audio/")) { + extension = "oga"; + } message.setRelativeFilePath(message.getUuid() + "." + extension); copyFileToPrivateStorage(mXmppConnectionService.getFileBackend().getFile(message), uri); } @@ -353,6 +357,12 @@ public class FileBackend { cursor.close(); } } + if (filename == null) { + final List segments = uri.getPathSegments(); + if (segments.size() > 0) { + filename = segments.get(segments.size() -1); + } + } int pos = filename == null ? -1 : filename.lastIndexOf('.'); return pos > 0 ? filename.substring(pos + 1) : null; } diff --git a/src/main/java/eu/siacs/conversations/services/AttachFileToConversationRunnable.java b/src/main/java/eu/siacs/conversations/services/AttachFileToConversationRunnable.java index 3edf19e8f..44f88e27e 100644 --- a/src/main/java/eu/siacs/conversations/services/AttachFileToConversationRunnable.java +++ b/src/main/java/eu/siacs/conversations/services/AttachFileToConversationRunnable.java @@ -45,9 +45,7 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod final String mimeType = type != null ? type : MimeUtils.guessMimeTypeFromUri(mXmppConnectionService, uri); final int autoAcceptFileSize = mXmppConnectionService.getResources().getInteger(R.integer.auto_accept_filesize); this.originalFileSize = FileBackend.getFileSize(mXmppConnectionService,uri); - this.isVideoMessage = (mimeType != null && mimeType.startsWith("video/") - && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) - && originalFileSize > autoAcceptFileSize; + this.isVideoMessage = (mimeType != null && mimeType.startsWith("video/")) && originalFileSize > autoAcceptFileSize; } public boolean isVideoMessage() { diff --git a/src/main/java/eu/siacs/conversations/utils/MimeUtils.java b/src/main/java/eu/siacs/conversations/utils/MimeUtils.java index 8d764cf90..a90fee07a 100644 --- a/src/main/java/eu/siacs/conversations/utils/MimeUtils.java +++ b/src/main/java/eu/siacs/conversations/utils/MimeUtils.java @@ -33,8 +33,8 @@ import eu.siacs.conversations.entities.Transferable; * Used to implement java.net.URLConnection and android.webkit.MimeTypeMap. */ public final class MimeUtils { - private static final Map mimeTypeToExtensionMap = new HashMap(); - private static final Map extensionToMimeTypeMap = new HashMap(); + private static final Map mimeTypeToExtensionMap = new HashMap<>(); + private static final Map extensionToMimeTypeMap = new HashMap<>(); static { // The following table is based on /etc/mime.types data minus // chemical/* MIME types and MIME types that don't map to any