parent
150f8313a0
commit
7cc96e704e
|
@ -207,8 +207,8 @@ public class PgpDecryptionService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final String url = message.getFileParams().url;
|
final String url = message.getFileParams().url;
|
||||||
mXmppConnectionService.getFileBackend().updateFileParams(message, url);
|
|
||||||
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
|
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
|
||||||
|
mXmppConnectionService.getFileBackend().updateFileParams(message, url);
|
||||||
mXmppConnectionService.updateMessage(message);
|
mXmppConnectionService.updateMessage(message);
|
||||||
if (!inputFile.delete()) {
|
if (!inputFile.delete()) {
|
||||||
Log.w(Config.LOGTAG,"unable to delete pgp encrypted source file "+inputFile.getAbsolutePath());
|
Log.w(Config.LOGTAG,"unable to delete pgp encrypted source file "+inputFile.getAbsolutePath());
|
||||||
|
|
|
@ -66,7 +66,6 @@ import eu.siacs.conversations.services.AttachFileToConversationRunnable;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService;
|
import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
import eu.siacs.conversations.ui.adapter.MediaAdapter;
|
import eu.siacs.conversations.ui.adapter.MediaAdapter;
|
||||||
import eu.siacs.conversations.ui.util.Attachment;
|
import eu.siacs.conversations.ui.util.Attachment;
|
||||||
import eu.siacs.conversations.utils.Compatibility;
|
|
||||||
import eu.siacs.conversations.utils.CryptoHelper;
|
import eu.siacs.conversations.utils.CryptoHelper;
|
||||||
import eu.siacs.conversations.utils.FileUtils;
|
import eu.siacs.conversations.utils.FileUtils;
|
||||||
import eu.siacs.conversations.utils.FileWriterException;
|
import eu.siacs.conversations.utils.FileWriterException;
|
||||||
|
@ -400,25 +399,23 @@ public class FileBackend {
|
||||||
|
|
||||||
public static Uri getMediaUri(Context context, File file) {
|
public static Uri getMediaUri(Context context, File file) {
|
||||||
final String filePath = file.getAbsolutePath();
|
final String filePath = file.getAbsolutePath();
|
||||||
final Cursor cursor;
|
try (final Cursor cursor =
|
||||||
try {
|
context.getContentResolver()
|
||||||
cursor =
|
.query(
|
||||||
context.getContentResolver()
|
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
||||||
.query(
|
new String[] {MediaStore.Images.Media._ID},
|
||||||
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
MediaStore.Images.Media.DATA + "=? ",
|
||||||
new String[] {MediaStore.Images.Media._ID},
|
new String[] {filePath},
|
||||||
MediaStore.Images.Media.DATA + "=? ",
|
null)) {
|
||||||
new String[] {filePath},
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
null);
|
final int id =
|
||||||
} catch (SecurityException e) {
|
cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns._ID));
|
||||||
return null;
|
return Uri.withAppendedPath(
|
||||||
}
|
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, String.valueOf(id));
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
} else {
|
||||||
final int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID));
|
return null;
|
||||||
cursor.close();
|
}
|
||||||
return Uri.withAppendedPath(
|
} catch (final Exception e) {
|
||||||
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, String.valueOf(id));
|
|
||||||
} else {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1492,57 +1489,73 @@ public class FileBackend {
|
||||||
updateFileParams(message, null);
|
updateFileParams(message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateFileParams(Message message, String url) {
|
public void updateFileParams(final Message message, final String url) {
|
||||||
DownloadableFile file = getFile(message);
|
final boolean encrypted =
|
||||||
|
message.getEncryption() == Message.ENCRYPTION_PGP
|
||||||
|
|| message.getEncryption() == Message.ENCRYPTION_DECRYPTED;
|
||||||
|
final DownloadableFile file = getFile(message);
|
||||||
final String mime = file.getMimeType();
|
final String mime = file.getMimeType();
|
||||||
final boolean privateMessage = message.isPrivateMessage();
|
|
||||||
final boolean ambiguous = MimeUtils.AMBIGUOUS_CONTAINER_FORMATS.contains(mime);
|
|
||||||
final boolean image =
|
final boolean image =
|
||||||
message.getType() == Message.TYPE_IMAGE
|
message.getType() == Message.TYPE_IMAGE
|
||||||
|| (mime != null && mime.startsWith("image/"));
|
|| (mime != null && mime.startsWith("image/"));
|
||||||
final boolean video = mime != null && mime.startsWith("video/");
|
final boolean privateMessage = message.isPrivateMessage();
|
||||||
final boolean audio = mime != null && mime.startsWith("audio/");
|
|
||||||
final boolean pdf = "application/pdf".equals(mime);
|
|
||||||
final StringBuilder body = new StringBuilder();
|
final StringBuilder body = new StringBuilder();
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
body.append(url);
|
body.append(url);
|
||||||
}
|
}
|
||||||
body.append('|').append(file.getSize());
|
if (encrypted && !file.exists()) {
|
||||||
if (ambiguous) {
|
Log.d(Config.LOGTAG, "skipping updateFileParams because file is encrypted");
|
||||||
try {
|
final DownloadableFile encryptedFile = getFile(message, false);
|
||||||
final Dimensions dimensions = getVideoDimensions(file);
|
body.append('|').append(encryptedFile.getSize());
|
||||||
if (dimensions.valid()) {
|
} else {
|
||||||
Log.d(Config.LOGTAG,"ambiguous file "+mime+" is video");
|
Log.d(Config.LOGTAG, "running updateFileParams");
|
||||||
body.append('|').append(dimensions.width).append('|').append(dimensions.height);
|
final boolean ambiguous = MimeUtils.AMBIGUOUS_CONTAINER_FORMATS.contains(mime);
|
||||||
} else {
|
final boolean video = mime != null && mime.startsWith("video/");
|
||||||
Log.d(Config.LOGTAG,"ambiguous file "+mime+" is audio");
|
final boolean audio = mime != null && mime.startsWith("audio/");
|
||||||
|
final boolean pdf = "application/pdf".equals(mime);
|
||||||
|
body.append('|').append(file.getSize());
|
||||||
|
if (ambiguous) {
|
||||||
|
try {
|
||||||
|
final Dimensions dimensions = getVideoDimensions(file);
|
||||||
|
if (dimensions.valid()) {
|
||||||
|
Log.d(Config.LOGTAG, "ambiguous file " + mime + " is video");
|
||||||
|
body.append('|')
|
||||||
|
.append(dimensions.width)
|
||||||
|
.append('|')
|
||||||
|
.append(dimensions.height);
|
||||||
|
} else {
|
||||||
|
Log.d(Config.LOGTAG, "ambiguous file " + mime + " is audio");
|
||||||
|
body.append("|0|0|").append(getMediaRuntime(file));
|
||||||
|
}
|
||||||
|
} catch (final NotAVideoFile e) {
|
||||||
|
Log.d(Config.LOGTAG, "ambiguous file " + mime + " is audio");
|
||||||
body.append("|0|0|").append(getMediaRuntime(file));
|
body.append("|0|0|").append(getMediaRuntime(file));
|
||||||
}
|
}
|
||||||
} catch (final NotAVideoFile e) {
|
} else if (image || video || pdf) {
|
||||||
Log.d(Config.LOGTAG,"ambiguous file "+mime+" is audio");
|
try {
|
||||||
|
final Dimensions dimensions;
|
||||||
|
if (video) {
|
||||||
|
dimensions = getVideoDimensions(file);
|
||||||
|
} else if (pdf) {
|
||||||
|
dimensions = getPdfDocumentDimensions(file);
|
||||||
|
} else {
|
||||||
|
dimensions = getImageDimensions(file);
|
||||||
|
}
|
||||||
|
if (dimensions.valid()) {
|
||||||
|
body.append('|')
|
||||||
|
.append(dimensions.width)
|
||||||
|
.append('|')
|
||||||
|
.append(dimensions.height);
|
||||||
|
}
|
||||||
|
} catch (NotAVideoFile notAVideoFile) {
|
||||||
|
Log.d(
|
||||||
|
Config.LOGTAG,
|
||||||
|
"file with mime type " + file.getMimeType() + " was not a video file");
|
||||||
|
// fall threw
|
||||||
|
}
|
||||||
|
} else if (audio) {
|
||||||
body.append("|0|0|").append(getMediaRuntime(file));
|
body.append("|0|0|").append(getMediaRuntime(file));
|
||||||
}
|
}
|
||||||
} else if (image || video || pdf) {
|
|
||||||
try {
|
|
||||||
final Dimensions dimensions;
|
|
||||||
if (video) {
|
|
||||||
dimensions = getVideoDimensions(file);
|
|
||||||
} else if (pdf) {
|
|
||||||
dimensions = getPdfDocumentDimensions(file);
|
|
||||||
} else {
|
|
||||||
dimensions = getImageDimensions(file);
|
|
||||||
}
|
|
||||||
if (dimensions.valid()) {
|
|
||||||
body.append('|').append(dimensions.width).append('|').append(dimensions.height);
|
|
||||||
}
|
|
||||||
} catch (NotAVideoFile notAVideoFile) {
|
|
||||||
Log.d(
|
|
||||||
Config.LOGTAG,
|
|
||||||
"file with mime type " + file.getMimeType() + " was not a video file");
|
|
||||||
// fall threw
|
|
||||||
}
|
|
||||||
} else if (audio) {
|
|
||||||
body.append("|0|0|").append(getMediaRuntime(file));
|
|
||||||
}
|
}
|
||||||
message.setBody(body.toString());
|
message.setBody(body.toString());
|
||||||
message.setDeleted(false);
|
message.setDeleted(false);
|
||||||
|
@ -1556,12 +1569,14 @@ public class FileBackend {
|
||||||
try {
|
try {
|
||||||
final MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
|
final MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
|
||||||
mediaMetadataRetriever.setDataSource(file.toString());
|
mediaMetadataRetriever.setDataSource(file.toString());
|
||||||
final String value = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
|
final String value =
|
||||||
|
mediaMetadataRetriever.extractMetadata(
|
||||||
|
MediaMetadataRetriever.METADATA_KEY_DURATION);
|
||||||
if (Strings.isNullOrEmpty(value)) {
|
if (Strings.isNullOrEmpty(value)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return Integer.parseInt(value);
|
return Integer.parseInt(value);
|
||||||
} catch (NumberFormatException e) {
|
} catch (final IllegalArgumentException e) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue