From 57876879979a9842d646415139656e3ad5a3d22e Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 4 Apr 2016 20:07:09 +0200 Subject: removed unnecessary wait for disconnect --- .../java/eu/siacs/conversations/services/XmppConnectionService.java | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/services/XmppConnectionService.java') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 28ac4d19..e477046c 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2571,12 +2571,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa if (!account.isOptionSet(Account.OPTION_DISABLED)) { if (!force) { disconnect(account, false); - try { - Log.d(Config.LOGTAG, "wait for disconnect"); - Thread.sleep(500); //sleep wait for disconnect - } catch (InterruptedException e) { - //ignored - } } Thread thread = new Thread(connection); connection.setInteractive(interactive); -- cgit v1.2.3 From ecaf75e5ecf785dbe83a4d1ec5f9a76d22e688ad Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 5 Apr 2016 13:31:03 +0200 Subject: better detect broken pep mark pep as broken when publishing bundle or device list failed reset 'brokenness' when account is getting disabled --- src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main/java/eu/siacs/conversations/services/XmppConnectionService.java') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index e477046c..e9ac3832 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2581,6 +2581,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa disconnect(account, force); account.getRoster().clearPresences(); connection.resetEverything(); + account.getAxolotlService().resetBrokenness(); } } } -- cgit v1.2.3 From 0460702710fd46cac0850224f34a275ceb8e2c1f Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 7 Apr 2016 20:29:40 +0200 Subject: check file owner when attaching files or using them as avatar --- .../eu/siacs/conversations/services/XmppConnectionService.java | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/main/java/eu/siacs/conversations/services/XmppConnectionService.java') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index e9ac3832..2aaf9b62 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -403,6 +403,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa public void attachFileToConversation(final Conversation conversation, final Uri uri, final UiCallback callback) { + if (FileBackend.weOwnFile(uri)) { + Log.d(Config.LOGTAG,"trying to attach file that belonged to us"); + callback.error(R.string.security_error_invalid_file_access, null); + return; + } final Message message; if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) { message = new Message(conversation, "", Message.ENCRYPTION_DECRYPTED); @@ -441,6 +446,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } public void attachImageToConversation(final Conversation conversation, final Uri uri, final UiCallback callback) { + if (FileBackend.weOwnFile(uri)) { + Log.d(Config.LOGTAG,"trying to attach file that belonged to us"); + callback.error(R.string.security_error_invalid_file_access, null); + return; + } final String compressPictures = getCompressPicturesPreference(); if ("never".equals(compressPictures) || ("auto".equals(compressPictures) && getFileBackend().useImageAsIs(uri))) { -- cgit v1.2.3 From 7ff890e513212f1cf03667e4ea7e429431d811c4 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 11 Apr 2016 22:20:32 +0200 Subject: republish avatar if server offers non-persistent pep :-( --- .../services/XmppConnectionService.java | 104 ++++++++++++++++----- 1 file changed, 79 insertions(+), 25 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/services/XmppConnectionService.java') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 2aaf9b62..117ab861 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -840,6 +840,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa connection.setOnBindListener(this.mOnBindListener); connection.setOnMessageAcknowledgeListener(this.mOnMessageAcknowledgedListener); connection.addOnAdvancedStreamFeaturesAvailableListener(this.mMessageArchiveService); + connection.addOnAdvancedStreamFeaturesAvailableListener(this.mAvatarService); AxolotlService axolotlService = account.getAxolotlService(); if (axolotlService != null) { connection.addOnAdvancedStreamFeaturesAvailableListener(axolotlService); @@ -2338,9 +2339,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } } - public void publishAvatar(final Account account, - final Uri image, - final UiCallback callback) { + public void publishAvatar(Account account, Uri image, UiCallback callback) { final Bitmap.CompressFormat format = Config.AVATAR_FORMAT; final int size = Config.AVATAR_SIZE; final Avatar avatar = getFileBackend().getPepAvatar(image, size, format); @@ -2358,40 +2357,96 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa callback.error(R.string.error_saving_avatar, avatar); return; } - final IqPacket packet = this.mIqGenerator.publishAvatar(avatar); - this.sendIqPacket(account, packet, new OnIqPacketReceived() { + publishAvatar(account, avatar, callback); + } else { + callback.error(R.string.error_publish_avatar_converting, null); + } + } - @Override - public void onIqPacketReceived(Account account, IqPacket result) { - if (result.getType() == IqPacket.TYPE.RESULT) { - final IqPacket packet = XmppConnectionService.this.mIqGenerator - .publishAvatarMetadata(avatar); - sendIqPacket(account, packet, new OnIqPacketReceived() { - @Override - public void onIqPacketReceived(Account account, IqPacket result) { - if (result.getType() == IqPacket.TYPE.RESULT) { - if (account.setAvatar(avatar.getFilename())) { - getAvatarService().clear(account); - databaseBackend.updateAccount(account); - } + public void publishAvatar(Account account, final Avatar avatar, final UiCallback callback) { + final IqPacket packet = this.mIqGenerator.publishAvatar(avatar); + this.sendIqPacket(account, packet, new OnIqPacketReceived() { + + @Override + public void onIqPacketReceived(Account account, IqPacket result) { + if (result.getType() == IqPacket.TYPE.RESULT) { + final IqPacket packet = XmppConnectionService.this.mIqGenerator + .publishAvatarMetadata(avatar); + sendIqPacket(account, packet, new OnIqPacketReceived() { + @Override + public void onIqPacketReceived(Account account, IqPacket result) { + if (result.getType() == IqPacket.TYPE.RESULT) { + if (account.setAvatar(avatar.getFilename())) { + getAvatarService().clear(account); + databaseBackend.updateAccount(account); + } + if (callback != null) { callback.success(avatar); } else { + Log.d(Config.LOGTAG,account.getJid().toBareJid()+": published avatar"); + } + } else { + if (callback != null) { callback.error( R.string.error_publish_avatar_server_reject, avatar); } } - }); - } else { + } + }); + } else { + if (callback != null) { callback.error( R.string.error_publish_avatar_server_reject, avatar); } } - }); - } else { - callback.error(R.string.error_publish_avatar_converting, null); + } + }); + } + + public void republishAvatarIfNeeded(Account account) { + if (account.getAxolotlService().isPepBroken()) { + Log.d(Config.LOGTAG,account.getJid().toBareJid()+": skipping republication of avatar because pep is broken"); + return; } + IqPacket packet = this.mIqGenerator.retrieveAvatarMetaData(null); + this.sendIqPacket(account, packet, new OnIqPacketReceived() { + + private Avatar parseAvatar(IqPacket packet) { + Element pubsub = packet.findChild("pubsub", "http://jabber.org/protocol/pubsub"); + if (pubsub != null) { + Element items = pubsub.findChild("items"); + if (items != null) { + return Avatar.parseMetadata(items); + } + } + return null; + } + + private boolean errorIsItemNotFound(IqPacket packet) { + Element error = packet.findChild("error"); + return packet.getType() == IqPacket.TYPE.ERROR + && error != null + && error.hasChild("item-not-found"); + } + + @Override + public void onIqPacketReceived(Account account, IqPacket packet) { + if (packet.getType() == IqPacket.TYPE.RESULT || errorIsItemNotFound(packet)) { + Avatar serverAvatar = parseAvatar(packet); + if (serverAvatar == null && account.getAvatar() != null) { + Avatar avatar = fileBackend.getStoredPepAvatar(account.getAvatar()); + if (avatar != null) { + Log.d(Config.LOGTAG,account.getJid().toBareJid()+": avatar on server was null. republishing"); + publishAvatar(account, fileBackend.getStoredPepAvatar(account.getAvatar()), null); + } else { + Log.e(Config.LOGTAG, account.getJid().toBareJid()+": error rereading avatar"); + } + } + } + } + }); } public void fetchAvatar(Account account, Avatar avatar) { @@ -2526,8 +2581,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa @Override public void onIqPacketReceived(Account account, IqPacket packet) { if (packet.getType() == IqPacket.TYPE.RESULT) { - Element pubsub = packet.findChild("pubsub", - "http://jabber.org/protocol/pubsub"); + Element pubsub = packet.findChild("pubsub","http://jabber.org/protocol/pubsub"); if (pubsub != null) { Element items = pubsub.findChild("items"); if (items != null) { -- cgit v1.2.3 From 7223b5b2746c2250c94965f89d9f636017e447da Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 12 Apr 2016 17:52:58 +0200 Subject: minor code cleanup --- .../java/eu/siacs/conversations/services/XmppConnectionService.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/services/XmppConnectionService.java') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 117ab861..0c4e5f62 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2456,9 +2456,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa public void fetchAvatar(Account account, final Avatar avatar, final UiCallback callback) { final String KEY = generateFetchKey(account, avatar); synchronized (this.mInProgressAvatarFetches) { - if (this.mInProgressAvatarFetches.contains(KEY)) { - return; - } else { + if (!this.mInProgressAvatarFetches.contains(KEY)) { switch (avatar.origin) { case PEP: this.mInProgressAvatarFetches.add(KEY); -- cgit v1.2.3 From 594e65bb2b26d1c99b96c12558bf9d523e68269e Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 13 Apr 2016 11:14:36 +0200 Subject: hacky workaround to determine if uri points to private file on < lolipop --- .../java/eu/siacs/conversations/services/XmppConnectionService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/services/XmppConnectionService.java') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 0c4e5f62..61d78409 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -403,7 +403,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa public void attachFileToConversation(final Conversation conversation, final Uri uri, final UiCallback callback) { - if (FileBackend.weOwnFile(uri)) { + if (FileBackend.weOwnFile(this, uri)) { Log.d(Config.LOGTAG,"trying to attach file that belonged to us"); callback.error(R.string.security_error_invalid_file_access, null); return; @@ -446,7 +446,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } public void attachImageToConversation(final Conversation conversation, final Uri uri, final UiCallback callback) { - if (FileBackend.weOwnFile(uri)) { + if (FileBackend.weOwnFile(this, uri)) { Log.d(Config.LOGTAG,"trying to attach file that belonged to us"); callback.error(R.string.security_error_invalid_file_access, null); return; -- cgit v1.2.3 From 39e717ed94de2800df587395ba77310660c2ea5c Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 14 Apr 2016 00:16:59 +0200 Subject: removed unused call to cancel events --- src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | 1 - 1 file changed, 1 deletion(-) (limited to 'src/main/java/eu/siacs/conversations/services/XmppConnectionService.java') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 61d78409..a975bf4d 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -801,7 +801,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa disconnect(account, false); } }).start(); - cancelWakeUpCall(account.getUuid().hashCode()); } } Log.d(Config.LOGTAG, "good bye"); -- cgit v1.2.3 From eb63cdb9adcf6b0324898fc45d8bdbad964a1892 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 14 Apr 2016 21:45:36 +0200 Subject: removed unnecessary call to stopSelf() after logging out --- .../conversations/services/XmppConnectionService.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/services/XmppConnectionService.java') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index a975bf4d..dbfb818d 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -509,7 +509,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } return START_STICKY; case Intent.ACTION_SHUTDOWN: - logoutAndSave(); + logoutAndSave(true); return START_NOT_STICKY; case ACTION_CLEAR_NOTIFICATION: mNotificationService.clear(); @@ -787,12 +787,16 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa public void onTaskRemoved(final Intent rootIntent) { super.onTaskRemoved(rootIntent); if (!getPreferences().getBoolean("keep_foreground_service", false)) { - this.logoutAndSave(); + this.logoutAndSave(false); } } - private void logoutAndSave() { + private void logoutAndSave(boolean stop) { + int activeAccounts = 0; for (final Account account : accounts) { + if (account.getStatus() != Account.State.DISABLED) { + activeAccounts++; + } databaseBackend.writeRoster(account.getRoster()); if (account.getXmppConnection() != null) { new Thread(new Runnable() { @@ -803,8 +807,10 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa }).start(); } } - Log.d(Config.LOGTAG, "good bye"); - stopSelf(); + if (stop || activeAccounts == 0) { + Log.d(Config.LOGTAG, "good bye"); + stopSelf(); + } } private void cancelWakeUpCall(int requestCode) { -- cgit v1.2.3