aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/eu/siacs/conversations/Config.java2
-rw-r--r--src/main/java/eu/siacs/conversations/crypto/PgpEngine.java6
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/FileBackend.java37
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java14
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java2
5 files changed, 38 insertions, 23 deletions
diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java
index b1d915d2..a40cff91 100644
--- a/src/main/java/eu/siacs/conversations/Config.java
+++ b/src/main/java/eu/siacs/conversations/Config.java
@@ -19,7 +19,7 @@ public final class Config {
public static final int MESSAGE_MERGE_WINDOW = 20;
public static final boolean PARSE_EMOTICONS = false;
- public static final int PROGRESS_UI_UPDATE_INTERVAL = 750;
+ public static final int PROGRESS_UI_UPDATE_INTERVAL = 750;
private Config() {
diff --git a/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java b/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java
index 3d7cc671..3f84daf6 100644
--- a/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java
+++ b/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java
@@ -80,12 +80,13 @@ public class PgpEngine {
}
}
});
- } else if (message.getType() == Message.TYPE_IMAGE) {
+ } else if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) {
try {
final DownloadableFile inputFile = this.mXmppConnectionService
.getFileBackend().getFile(message, false);
final DownloadableFile outputFile = this.mXmppConnectionService
.getFileBackend().getFile(message, true);
+ outputFile.getParentFile().mkdirs();
outputFile.createNewFile();
InputStream is = new FileInputStream(inputFile);
OutputStream os = new FileOutputStream(outputFile);
@@ -199,12 +200,13 @@ public class PgpEngine {
}
}
});
- } else if (message.getType() == Message.TYPE_IMAGE) {
+ } else if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) {
try {
DownloadableFile inputFile = this.mXmppConnectionService
.getFileBackend().getFile(message, true);
DownloadableFile outputFile = this.mXmppConnectionService
.getFileBackend().getFile(message, false);
+ outputFile.getParentFile().mkdirs();
outputFile.createNewFile();
InputStream is = new FileInputStream(inputFile);
OutputStream os = new FileOutputStream(outputFile);
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
index 7b0ae180..3d771572 100644
--- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
@@ -2,14 +2,12 @@ package eu.siacs.conversations.persistance;
import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
-import java.net.URLConnection;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -17,7 +15,6 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
-import android.content.ContentResolver;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -60,30 +57,36 @@ public class FileBackend {
public DownloadableFile getFile(Message message, boolean decrypted) {
String path = message.getRelativeFilePath();
- if (path != null && !path.isEmpty()) {
+ if (!decrypted && (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED)) {
+ String extension;
+ if (path != null && !path.isEmpty()) {
+ String[] parts = path.split("\\.");
+ extension = "."+parts[parts.length - 1];
+ } else if (message.getType() == Message.TYPE_IMAGE) {
+ extension = ".webp";
+ } else {
+ extension = "";
+ }
+ return new DownloadableFile(getConversationsFileDirectory()+message.getUuid()+extension+".pgp");
+ } else if (path != null && !path.isEmpty()) {
if (path.startsWith("/")) {
return new DownloadableFile(path);
} else {
- return new DownloadableFile(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+"/"+path);
+ return new DownloadableFile(getConversationsFileDirectory()+path);
}
} else {
StringBuilder filename = new StringBuilder();
- filename.append(getConversationsDirectory());
- filename.append(message.getUuid());
- if ((decrypted) || (message.getEncryption() == Message.ENCRYPTION_NONE)) {
- filename.append(".webp");
- } else {
- if (message.getEncryption() == Message.ENCRYPTION_OTR) {
- filename.append(".webp");
- } else {
- filename.append(".webp.pgp");
- }
- }
+ filename.append(getConversationsImageDirectory());
+ filename.append(message.getUuid()+".webp");
return new DownloadableFile(filename.toString());
}
}
- public static String getConversationsDirectory() {
+ public static String getConversationsFileDirectory() {
+ return Environment.getExternalStorageDirectory().getAbsolutePath()+"/Conversations/";
+ }
+
+ public static String getConversationsImageDirectory() {
return Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES).getAbsolutePath()
+ "/Conversations/";
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index babcce26..4565ce30 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -211,7 +211,7 @@ public class XmppConnectionService extends Service {
private Integer rosterChangedListenerCount = 0;
private SecureRandom mRandom;
private FileObserver fileObserver = new FileObserver(
- FileBackend.getConversationsDirectory()) {
+ FileBackend.getConversationsImageDirectory()) {
@Override
public void onEvent(int event, String path) {
@@ -311,7 +311,11 @@ public class XmppConnectionService extends Service {
if (path!=null) {
message.setRelativeFilePath(path);
getFileBackend().updateFileParams(message);
- callback.success(message);
+ if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
+ getPgpEngine().encrypt(message, callback);
+ } else {
+ callback.success(message);
+ }
} else {
new Thread(new Runnable() {
@Override
@@ -319,7 +323,11 @@ public class XmppConnectionService extends Service {
try {
getFileBackend().copyFileToPrivateStorage(message, uri);
getFileBackend().updateFileParams(message);
- callback.success(message);
+ if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
+ getPgpEngine().encrypt(message, callback);
+ } else {
+ callback.success(message);
+ }
} catch (FileBackend.FileCopyException e) {
callback.error(e.getResId(),message);
}
diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
index f42e89a9..793c6c54 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
@@ -306,6 +306,8 @@ public class JingleConnection implements Downloadable {
suffix = parts[parts.length - 1];
if (message.getEncryption() == Message.ENCRYPTION_OTR && suffix.endsWith(".otr")) {
suffix = suffix.substring(0,suffix.length() - 4);
+ } else if (message.getEncryption() == Message.ENCRYPTION_PGP && (suffix.endsWith(".pgp") || suffix.endsWith(".gpg"))) {
+ suffix = suffix.substring(0,suffix.length() - 4);
}
}
message.setRelativeFilePath(message.getUuid()+"_"+suffix);