aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlookshe <github@lookshe.org>2016-04-05 23:24:49 +0200
committerlookshe <github@lookshe.org>2016-04-05 23:24:49 +0200
commitd6a076e11281d4c3fb6b9504fe99d799b04ebbbb (patch)
tree7cbbe209ed0a883bcf29389d91979974444447c1
parentbfb3cb844578d06fad9aade3a7576ee44d785f70 (diff)
parent5eedce91f9d92e5139f13fddb57314570f42b9ad (diff)
Merge tag '1.11.3' into trz/rebase
Diffstat (limited to '')
-rw-r--r--CHANGELOG.md4
-rw-r--r--build.gradle4
-rw-r--r--libs/3rdParty/maven/ShortcutBadger-1.1.3.aarbin16993 -> 0 bytes
-rw-r--r--libs/3rdParty/maven/ShortcutBadger-1.1.4.aarbin0 -> 17561 bytes
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Account.java6
-rw-r--r--src/main/java/eu/siacs/conversations/entities/DownloadableFile.java20
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Message.java4
-rw-r--r--src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java32
-rw-r--r--src/main/java/eu/siacs/conversations/parser/MessageParser.java6
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java16
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java20
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationActivity.java29
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationFragment.java4
-rw-r--r--src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java2
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java12
-rw-r--r--src/main/java/eu/siacs/conversations/ui/XmppActivity.java4
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java2
-rw-r--r--src/main/java/eu/siacs/conversations/utils/FileUtils.java36
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java42
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/forms/Data.java12
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java2
21 files changed, 202 insertions, 55 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b9b3881c..85e7c5ee 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
###Changelog
+####Version 1.11.3
+* check maximum file size when using HTTP Upload
+* properly calculate caps hash
+
####Version 1.11.2
* only add image files to media scanner
* allow to delete files
diff --git a/build.gradle b/build.gradle
index 619a24e5..1e96e154 100644
--- a/build.gradle
+++ b/build.gradle
@@ -36,7 +36,7 @@ dependencies {
compile name: 'bcpkix-jdk15on-1.52'
compile name: 'EnhancedListView-0.3.4', ext: 'aar'
compile name: 'com.nineoldandroids.view.ViewHelper-2.4.0'
- compile name: 'ShortcutBadger-1.1.3', ext: 'aar'
+ compile name: 'ShortcutBadger-1.1.4', ext: 'aar'
compile name: 'swipy-1.2.1', ext: 'aar'
compile name: 'axolotl-android-1.3.4', ext: 'aar'
compile name: 'axolotl-java-1.3.4'
@@ -65,7 +65,7 @@ android {
minSdkVersion 14
targetSdkVersion 23
versionCode 135
- versionName "beta-1"
+ versionName "1.11.3"
archivesBaseName += "-$versionName"
}
diff --git a/libs/3rdParty/maven/ShortcutBadger-1.1.3.aar b/libs/3rdParty/maven/ShortcutBadger-1.1.3.aar
deleted file mode 100644
index fbf939ed..00000000
--- a/libs/3rdParty/maven/ShortcutBadger-1.1.3.aar
+++ /dev/null
Binary files differ
diff --git a/libs/3rdParty/maven/ShortcutBadger-1.1.4.aar b/libs/3rdParty/maven/ShortcutBadger-1.1.4.aar
new file mode 100644
index 00000000..2b69fede
--- /dev/null
+++ b/libs/3rdParty/maven/ShortcutBadger-1.1.4.aar
Binary files differ
diff --git a/src/main/java/eu/siacs/conversations/entities/Account.java b/src/main/java/eu/siacs/conversations/entities/Account.java
index 7aee78b5..4c4a1916 100644
--- a/src/main/java/eu/siacs/conversations/entities/Account.java
+++ b/src/main/java/eu/siacs/conversations/entities/Account.java
@@ -55,8 +55,12 @@ public class Account extends AbstractEntity {
public static final int OPTION_USECOMPRESSION = 3;
public final HashSet<Pair<String, String>> inProgressDiscoFetches = new HashSet<>();
+ public boolean httpUploadAvailable(long filesize) {
+ return xmppConnection != null && xmppConnection.getFeatures().httpUpload(filesize);
+ }
+
public boolean httpUploadAvailable() {
- return xmppConnection != null && xmppConnection.getFeatures().httpUpload();
+ return httpUploadAvailable(0);
}
public void setDisplayName(String displayName) {
diff --git a/src/main/java/eu/siacs/conversations/entities/DownloadableFile.java b/src/main/java/eu/siacs/conversations/entities/DownloadableFile.java
index d35a4b01..4e63a66a 100644
--- a/src/main/java/eu/siacs/conversations/entities/DownloadableFile.java
+++ b/src/main/java/eu/siacs/conversations/entities/DownloadableFile.java
@@ -52,20 +52,16 @@ public class DownloadableFile extends File {
public void setKeyAndIv(byte[] keyIvCombo) {
if (keyIvCombo.length == 48) {
- byte[] secretKey = new byte[32];
- byte[] iv = new byte[16];
- System.arraycopy(keyIvCombo, 0, iv, 0, 16);
- System.arraycopy(keyIvCombo, 16, secretKey, 0, 32);
- this.aeskey = secretKey;
- this.iv = iv;
+ this.aeskey = new byte[32];
+ this.iv = new byte[16];
+ System.arraycopy(keyIvCombo, 0, this.iv, 0, 16);
+ System.arraycopy(keyIvCombo, 16, this.aeskey, 0, 32);
} else if (keyIvCombo.length >= 32) {
- byte[] secretKey = new byte[32];
- System.arraycopy(keyIvCombo, 0, secretKey, 0, 32);
- this.aeskey = secretKey;
+ this.aeskey = new byte[32];
+ System.arraycopy(keyIvCombo, 0, aeskey, 0, 32);
} else if (keyIvCombo.length >= 16) {
- byte[] secretKey = new byte[16];
- System.arraycopy(keyIvCombo, 0, secretKey, 0, 16);
- this.aeskey = secretKey;
+ this.aeskey = new byte[16];
+ System.arraycopy(keyIvCombo, 0, this.aeskey, 0, 16);
}
}
diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java
index 5fafb6c8..7a5be8f8 100644
--- a/src/main/java/eu/siacs/conversations/entities/Message.java
+++ b/src/main/java/eu/siacs/conversations/entities/Message.java
@@ -710,11 +710,11 @@ public class Message extends AbstractEntity {
public int height = 0;
}
- public void setAxolotlFingerprint(String fingerprint) {
+ public void setFingerprint(String fingerprint) {
this.axolotlFingerprint = fingerprint;
}
- public String getAxolotlFingerprint() {
+ public String getFingerprint() {
return axolotlFingerprint;
}
diff --git a/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java b/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java
index 0e041454..a8f60e39 100644
--- a/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java
+++ b/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java
@@ -17,6 +17,7 @@ import org.json.JSONObject;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.forms.Data;
+import eu.siacs.conversations.xmpp.forms.Field;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
public class ServiceDiscoveryResult {
@@ -189,6 +190,19 @@ public class ServiceDiscoveryResult {
return false;
}
+ public String getExtendedDiscoInformation(String formType, String name) {
+ for(Data form : this.forms) {
+ if (formType.equals(form.getFormType())) {
+ for(Field field: form.getFields()) {
+ if (name.equals(field.getFieldName())) {
+ return field.getValue();
+ }
+ }
+ }
+ }
+ return null;
+ }
+
protected byte[] mkCapHash() {
StringBuilder s = new StringBuilder();
@@ -219,8 +233,22 @@ public class ServiceDiscoveryResult {
});
for(Data form : forms) {
- s.append(form.getFormType()+"<");
- //TODO append fields and values
+ s.append(form.getFormType() + "<");
+ List<Field> fields = form.getFields();
+ Collections.sort(fields, new Comparator<Field>() {
+ @Override
+ public int compare(Field lhs, Field rhs) {
+ return lhs.getFieldName().compareTo(rhs.getFieldName());
+ }
+ });
+ for(Field field : fields) {
+ s.append(field.getFieldName()+"<");
+ List<String> values = field.getValues();
+ Collections.sort(values);
+ for(String value : values) {
+ s.append(value+"<");
+ }
+ }
}
MessageDigest md;
diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
index 89d84cb2..3354c2d7 100644
--- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
@@ -16,6 +16,7 @@ import de.thedevstack.android.logcat.Logging;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.utils.AvatarUtil;
import eu.siacs.conversations.Config;
+import eu.siacs.conversations.crypto.OtrService;
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.crypto.axolotl.AxolotlServiceImpl;
@@ -103,8 +104,11 @@ public class MessageParser extends AbstractParser implements
conversation.setSymmetricKey(CryptoHelper.hexToBytes(key));
return null;
}
+ final OtrService otrService = conversation.getAccount().getOtrService();
Message finishedMessage = new Message(conversation, body, Message.ENCRYPTION_OTR, Message.STATUS_RECEIVED);
+ finishedMessage.setFingerprint(otrService.getFingerprint(otrSession.getRemotePublicKey()));
conversation.setLastReceivedOtrMessageId(null);
+
return finishedMessage;
} catch (Exception e) {
conversation.resetOtrSession();
@@ -119,7 +123,7 @@ public class MessageParser extends AbstractParser implements
XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = service.processReceivingPayloadMessage(xmppAxolotlMessage);
if(plaintextMessage != null) {
finishedMessage = new Message(conversation, plaintextMessage.getPlaintext(), Message.ENCRYPTION_AXOLOTL, status);
- finishedMessage.setAxolotlFingerprint(plaintextMessage.getFingerprint());
+ finishedMessage.setFingerprint(plaintextMessage.getFingerprint());
Logging.d(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(finishedMessage.getConversation().getAccount())+" Received Message with session fingerprint: "+plaintextMessage.getFingerprint());
}
diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
index e400095d..e8acd400 100644
--- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
@@ -525,8 +525,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
Cursor cursor = db.query(Conversation.TABLENAME, null,
Conversation.ACCOUNT + "=? AND (" + Conversation.CONTACTJID
+ " like ? OR " + Conversation.CONTACTJID + "=?)", selectionArgs, null, null, null);
- if (cursor.getCount() == 0)
+ if (cursor.getCount() == 0) {
+ cursor.close();
return null;
+ }
cursor.moveToFirst();
Conversation conversation = Conversation.fromCursor(cursor);
cursor.close();
@@ -576,12 +578,15 @@ public class DatabaseBackend extends SQLiteOpenHelper {
try {
cursor.moveToFirst();
int count = cursor.getInt(0);
- cursor.close();
return (count > 0);
} catch (SQLiteCantOpenDatabaseException e) {
return true; // better safe than sorry
} catch (RuntimeException e) {
return true; // better safe than sorry
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
}
@@ -643,11 +648,12 @@ public class DatabaseBackend extends SQLiteOpenHelper {
}
public Pair<Long, String> getLastMessageReceived(Account account) {
+ Cursor cursor = null;
try {
SQLiteDatabase db = this.getReadableDatabase();
String sql = "select messages.timeSent,messages.serverMsgId from accounts join conversations on accounts.uuid=conversations.accountUuid join messages on conversations.uuid=messages.conversationUuid where accounts.uuid=? and (messages.status=0 or messages.carbon=1 or messages.serverMsgId not null) order by messages.timesent desc limit 1";
String[] args = {account.getUuid()};
- Cursor cursor = db.rawQuery(sql, args);
+ cursor = db.rawQuery(sql, args);
if (cursor.getCount() == 0) {
return null;
} else {
@@ -656,6 +662,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
}
} catch (Exception e) {
return null;
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
}
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index f6ab7b72..f1a46f86 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -818,8 +818,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
private void sendFileMessage(final Message message, final boolean delay) {
Logging.d(Config.LOGTAG, "send file message");
final Account account = message.getConversation().getAccount();
- final XmppConnection connection = account.getXmppConnection();
- if (connection != null && connection.getFeatures().httpUpload()) {
+ if (account.httpUploadAvailable(FileBackend.getFile(message,false).getSize())) {
mHttpConnectionManager.createNewUploadConnection(message, delay);
} else {
mJingleConnectionManager.createNewConnection(message);
@@ -856,7 +855,8 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
switch (message.getEncryption()) {
case Message.ENCRYPTION_NONE:
if (message.needsUploading()) {
- if (account.httpUploadAvailable() || message.fixCounterpart()) {
+ if (account.httpUploadAvailable(FileBackend.getFile(message,false).getSize())
+ || message.fixCounterpart()) {
this.sendFileMessage(message, delay);
} else {
break;
@@ -868,7 +868,8 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
case Message.ENCRYPTION_PGP:
case Message.ENCRYPTION_DECRYPTED:
if (message.needsUploading()) {
- if (account.httpUploadAvailable() || message.fixCounterpart()) {
+ if (account.httpUploadAvailable(FileBackend.getFile(message,false).getSize())
+ || message.fixCounterpart()) {
this.sendFileMessage(message, delay);
} else {
break;
@@ -902,9 +903,10 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
break;
case Message.ENCRYPTION_AXOLOTL:
- message.setAxolotlFingerprint(account.getAxolotlService().getOwnFingerprint());
+ message.setFingerprint(account.getAxolotlService().getOwnFingerprint());
if (message.needsUploading()) {
- if (account.httpUploadAvailable() || message.fixCounterpart()) {
+ if (account.httpUploadAvailable(FileBackend.getFile(message,false).getSize())
+ || message.fixCounterpart()) {
this.sendFileMessage(message, delay);
} else {
break;
@@ -948,7 +950,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
break;
case Message.ENCRYPTION_AXOLOTL:
- message.setAxolotlFingerprint(account.getAxolotlService().getOwnFingerprint());
+ message.setFingerprint(account.getAxolotlService().getOwnFingerprint());
break;
}
}
@@ -2564,9 +2566,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
if (unreadCount != count) {
Logging.d(Config.LOGTAG, "update unread count to " + count);
if (count > 0) {
- ShortcutBadger.with(getApplicationContext()).count(count);
+ ShortcutBadger.applyCount(getApplicationContext(), count);
} else {
- ShortcutBadger.with(getApplicationContext()).remove();
+ ShortcutBadger.removeCount(getApplicationContext());
}
unreadCount = count;
}
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
index 02a9cb0f..20c4685f 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
@@ -66,6 +66,7 @@ import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdat
import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
import eu.siacs.conversations.ui.adapter.ConversationAdapter;
import eu.siacs.conversations.utils.ExceptionHelper;
+import eu.siacs.conversations.utils.FileUtils;
import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
@@ -1306,12 +1307,30 @@ public class ConversationActivity extends XmppActivity
}
}
} else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_FILE || requestCode == ATTACHMENT_CHOICE_RECORD_VOICE) {
- mPendingFileUris.clear();
- mPendingFileUris.addAll(extractUriFromIntent(data));
- if (xmppConnectionServiceBound) {
- for (Iterator<Uri> i = mPendingFileUris.iterator(); i.hasNext(); i.remove()) {
- attachFileToConversation(getSelectedConversation(), i.next());
+ final List<Uri> uris = extractUriFromIntent(data);
+ final Conversation c = getSelectedConversation();
+ final long max = c.getAccount()
+ .getXmppConnection()
+ .getFeatures()
+ .getMaxHttpUploadSize();
+ final OnPresenceSelected callback = new OnPresenceSelected() {
+ @Override
+ public void onPresenceSelected() {
+ mPendingFileUris.clear();
+ mPendingFileUris.addAll(uris);
+ if (xmppConnectionServiceBound) {
+ for (Iterator<Uri> i = mPendingFileUris.iterator(); i.hasNext(); i.remove()) {
+ attachFileToConversation(c, i.next());
+ }
+ }
}
+ };
+ if (c.getMode() == Conversation.MODE_MULTI
+ || FileUtils.allFilesUnderSize(this, uris, max)
+ || c.getNextEncryption() == Message.ENCRYPTION_OTR) {
+ callback.onPresenceSelected();
+ } else {
+ selectPresence(c, callback);
}
} else if (requestCode == ATTACHMENT_CHOICE_TAKE_PHOTO) {
if (mPendingImageUris.size() == 1) {
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
index 7a576c01..50002189 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
@@ -472,13 +472,13 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
highlightInConference(user);
}
} else {
- activity.switchToContactDetails(message.getContact(), message.getAxolotlFingerprint());
+ activity.switchToContactDetails(message.getContact(), message.getFingerprint());
}
} else {
Account account = message.getConversation().getAccount();
Intent intent = new Intent(activity, EditAccountActivity.class);
intent.putExtra("jid", account.getJid().toBareJid().toString());
- intent.putExtra("fingerprint", message.getAxolotlFingerprint());
+ intent.putExtra("fingerprint", message.getFingerprint());
startActivity(intent);
}
}
diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
index a01f939c..13fcc9a5 100644
--- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
@@ -692,7 +692,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} else {
this.mServerInfoPep.setText(R.string.server_info_unavailable);
}
- if (features.httpUpload()) {
+ if (features.httpUpload(0)) {
this.mServerInfoHttpUpload.setText(R.string.server_info_available);
} else {
this.mServerInfoHttpUpload.setText(R.string.server_info_unavailable);
diff --git a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java
index 91dd32d9..6ea011f8 100644
--- a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java
@@ -28,8 +28,10 @@ import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
+import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.ui.adapter.ConversationAdapter;
+import eu.siacs.conversations.utils.FileUtils;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
@@ -263,6 +265,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer
}
private void share(final Conversation conversation) {
+ final Account account = conversation.getAccount();
mListView.setEnabled(false);
if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP && !hasPgp()) {
if (share.uuid == null) {
@@ -274,6 +277,9 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer
return;
}
if (share.uris.size() != 0) {
+ final long max = account.getXmppConnection()
+ .getFeatures()
+ .getMaxHttpUploadSize();
OnPresenceSelected callback;
if (this.share.image) {
// TODO: attachementCounter should be set and decremented correctly
@@ -299,7 +305,11 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer
}
};
}
- if (conversation.getAccount().httpUploadAvailable()) {
+ if (account.httpUploadAvailable()
+ && ((share.image && !neverCompressPictures())
+ || conversation.getMode() == Conversation.MODE_MULTI
+ || FileUtils.allFilesUnderSize(this, share.uris, max))
+ && conversation.getNextEncryption() != Message.ENCRYPTION_OTR) {
callback.onPresenceSelected();
} else {
selectPresence(conversation, callback);
diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
index 880641b9..29c9ee0c 100644
--- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
@@ -958,6 +958,10 @@ public abstract class XmppActivity extends Activity {
}
}
+ protected boolean neverCompressPictures() {
+ return getPreferences().getString("picture_compression", "auto").equals("never");
+ }
+
protected void unregisterNdefPushMessageCallback() {
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (nfcAdapter != null && nfcAdapter.isEnabled()) {
diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
index 00554960..9d2917d5 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
@@ -197,7 +197,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
XmppAxolotlSession.Trust trust = message.getConversation()
.getAccount().getAxolotlService().getFingerprintTrust(
- message.getAxolotlFingerprint());
+ message.getFingerprint());
if(trust == null || (!trust.trusted() && !trust.trustedInactive())) {
viewHolder.indicator.setColorFilter(ConversationsPlusColors.warning());
diff --git a/src/main/java/eu/siacs/conversations/utils/FileUtils.java b/src/main/java/eu/siacs/conversations/utils/FileUtils.java
index 7783bcc9..1f2a71ca 100644
--- a/src/main/java/eu/siacs/conversations/utils/FileUtils.java
+++ b/src/main/java/eu/siacs/conversations/utils/FileUtils.java
@@ -10,8 +10,10 @@ import android.os.Build;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
+import android.provider.OpenableColumns;
import java.io.File;
+import java.util.List;
import de.thedevstack.conversationsplus.ConversationsPlusApplication;
@@ -187,6 +189,40 @@ public final class FileUtils {
return secondToLastPart;
}
+ /**
+ * Retrieve file size from given uri
+ * @param context actual Context
+ * @param uri uri to file
+ * @return file size or -1 in case of error
+ */
+ private static long getFileSize(Context context, Uri uri) {
+ Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
+ if (cursor != null && cursor.moveToFirst()) {
+ return cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE));
+ } else {
+ return -1;
+ }
+ }
+
+ /**
+ * Check for given list of uris if corresponding file sizes are all smaller than given maximum
+ * @param context actual Context
+ * @param uris list of uris
+ * @param max maximum file size
+ * @return true if all file sizes are smaller than max, false otherwise
+ */
+ public static boolean allFilesUnderSize(Context context, List<Uri> uris, long max) {
+ if (max <= 0) {
+ return true; //exception to be compatible with HTTP Upload < v0.2
+ }
+ for(Uri uri : uris) {
+ if (getFileSize(context, uri) > max) {
+ return false;
+ }
+ }
+ return true;
+ }
+
private FileUtils() {
// Utility class - do not instantiate
}
diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
index acdf5652..c0b1ff1f 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -1321,12 +1321,12 @@ public class XmppConnection implements Runnable {
this.streamId = null;
}
- public List<Jid> findDiscoItemsByFeature(final String feature) {
+ private List<Entry<Jid, ServiceDiscoveryResult>> findDiscoItemsByFeature(final String feature) {
synchronized (this.disco) {
- final List<Jid> items = new ArrayList<>();
+ final List<Entry<Jid, ServiceDiscoveryResult>> items = new ArrayList<>();
for (final Entry<Jid, ServiceDiscoveryResult> cursor : this.disco.entrySet()) {
if (cursor.getValue().getFeatures().contains(feature)) {
- items.add(cursor.getKey());
+ items.add(cursor);
}
}
return items;
@@ -1334,9 +1334,9 @@ public class XmppConnection implements Runnable {
}
public Jid findDiscoItemByFeature(final String feature) {
- final List<Jid> items = findDiscoItemsByFeature(feature);
+ final List<Entry<Jid, ServiceDiscoveryResult>> items = findDiscoItemsByFeature(feature);
if (items.size() >= 1) {
- return items.get(0);
+ return items.get(0).getKey();
}
return null;
}
@@ -1485,7 +1485,6 @@ public class XmppConnection implements Runnable {
public boolean pep() {
synchronized (XmppConnection.this.disco) {
- final Pair<String, String> needle = new Pair<>("pubsub", "pep");
ServiceDiscoveryResult info = disco.get(account.getServer());
if (info != null && info.hasIdentity("pubsub", "pep")) {
return true;
@@ -1514,8 +1513,35 @@ public class XmppConnection implements Runnable {
this.blockListRequested = value;
}
- public boolean httpUpload() {
- return !Config.DISABLE_HTTP_UPLOAD && findDiscoItemsByFeature(Xmlns.HTTP_UPLOAD).size() > 0;
+ public boolean httpUpload(long filesize) {
+ if (Config.DISABLE_HTTP_UPLOAD) {
+ return false;
+ } else {
+ List<Entry<Jid, ServiceDiscoveryResult>> items = findDiscoItemsByFeature(Xmlns.HTTP_UPLOAD);
+ if (items.size() > 0) {
+ try {
+ long maxsize = Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(Xmlns.HTTP_UPLOAD, "max-file-size"));
+ return filesize <= maxsize;
+ } catch (Exception e) {
+ return true;
+ }
+ } else {
+ return false;
+ }
+ }
+ }
+
+ public long getMaxHttpUploadSize() {
+ List<Entry<Jid, ServiceDiscoveryResult>> items = findDiscoItemsByFeature(Xmlns.HTTP_UPLOAD);
+ if (items.size() > 0) {
+ try {
+ return Long.parseLong(items.get(0).getValue().getExtendedDiscoInformation(Xmlns.HTTP_UPLOAD, "max-file-size"));
+ } catch (Exception e) {
+ return -1;
+ }
+ } else {
+ return -1;
+ }
}
}
diff --git a/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java b/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java
index 380f0280..8dabcb5b 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/forms/Data.java
@@ -9,6 +9,8 @@ import eu.siacs.conversations.xml.Element;
public class Data extends Element {
+ private static final String FORM_TYPE = "FORM_TYPE";
+
public Data() {
super("x");
this.setAttribute("xmlns","jabber:x:data");
@@ -17,7 +19,8 @@ public class Data extends Element {
public List<Field> getFields() {
ArrayList<Field> fields = new ArrayList<Field>();
for(Element child : getChildren()) {
- if (child.getName().equals("field")) {
+ if (child.getName().equals("field")
+ && !FORM_TYPE.equals(child.getAttribute("var"))) {
fields.add(Field.parse(child));
}
}
@@ -26,7 +29,8 @@ public class Data extends Element {
public Field getFieldByName(String needle) {
for(Element child : getChildren()) {
- if (child.getName().equals("field") && needle.equals(child.getAttribute("var"))) {
+ if (child.getName().equals("field")
+ && needle.equals(child.getAttribute("var"))) {
return Field.parse(child);
}
}
@@ -76,11 +80,11 @@ public class Data extends Element {
}
public void setFormType(String formType) {
- this.put("FORM_TYPE", formType);
+ this.put(FORM_TYPE, formType);
}
public String getFormType() {
- String type = getValue("FORM_TYPE");
+ String type = getValue(FORM_TYPE);
return type == null ? "" : type;
}
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 22f5dca9..ecaa9c13 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
@@ -381,7 +381,7 @@ public class JingleConnection implements Transferable {
message.setEncryption(Message.ENCRYPTION_AXOLOTL);
this.file.setKey(transportMessage.getKey());
this.file.setIv(transportMessage.getIv());
- message.setAxolotlFingerprint(transportMessage.getFingerprint());
+ message.setFingerprint(transportMessage.getFingerprint());
} else {
Logging.d(Config.LOGTAG,"could not process KeyTransportMessage");
}