From a557d38e4d0bd55442012f7f8a5be62532f7bfe9 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 25 Nov 2015 20:47:02 +0100 Subject: [PATCH] pgp fixes and revert configuration changes --- src/main/AndroidManifest.xml | 5 -- .../java/eu/siacs/conversations/Config.java | 3 +- .../siacs/conversations/crypto/PgpEngine.java | 12 ++- .../siacs/conversations/entities/Message.java | 2 +- .../conversations/entities/MucOptions.java | 27 +------ .../http/HttpDownloadConnection.java | 3 + .../persistance/FileBackend.java | 24 +++--- .../services/XmppConnectionService.java | 76 +++++++++---------- .../ui/ConferenceDetailsActivity.java | 10 --- .../ui/ContactDetailsActivity.java | 9 --- .../ui/ConversationActivity.java | 21 +++-- .../conversations/ui/EditAccountActivity.java | 6 -- .../siacs/conversations/utils/UIHelper.java | 21 ----- .../conversations/xmpp/XmppConnection.java | 2 +- .../xmpp/jingle/JingleConnection.java | 2 + .../xmpp/jingle/JingleConnectionManager.java | 2 +- 16 files changed, 91 insertions(+), 134 deletions(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 325459850..fb5df34d6 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -39,7 +39,6 @@ @@ -91,22 +90,18 @@ android:label="@string/change_password_on_server"/> getStatusCodes(Element x) { @@ -438,10 +423,6 @@ public class MucOptions { this.onRenameListener = listener; } - public void setOnJoinListener(OnJoinListener listener) { - this.onJoinListener = listener; - } - public void setOffline() { this.users.clear(); this.error = 0; diff --git a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java index 792a71e8b..96dee62c7 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java @@ -125,6 +125,9 @@ public class HttpDownloadConnection implements Transferable { mXmppConnectionService.sendBroadcast(intent); message.setTransferable(null); mHttpConnectionManager.finishConnection(this); + if (message.getEncryption() == Message.ENCRYPTION_PGP) { + message.getConversation().getAccount().getPgpDecryptionService().add(message); + } mXmppConnectionService.updateConversationUi(); if (acceptedAutomatically) { mXmppConnectionService.getNotificationService().push(message); diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index edbcd26ee..349e18c70 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -61,22 +61,26 @@ public class FileBackend { final boolean encrypted = !decrypted && (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED); - if (encrypted) { - return new DownloadableFile(getConversationsFileDirectory()+message.getUuid()+".pgp"); + final DownloadableFile file; + String path = message.getRelativeFilePath(); + if (path == null) { + path = message.getUuid(); + } + if (path.startsWith("/")) { + file = new DownloadableFile(path); } else { - String path = message.getRelativeFilePath(); - if (path == null) { - path = message.getUuid(); - } else if (path.startsWith("/")) { - return new DownloadableFile(path); - } String mime = message.getMimeType(); if (mime != null && mime.startsWith("image")) { - return new DownloadableFile(getConversationsImageDirectory() + path); + file = new DownloadableFile(getConversationsImageDirectory() + path); } else { - return new DownloadableFile(getConversationsFileDirectory() + path); + file = new DownloadableFile(getConversationsFileDirectory() + path); } } + if (encrypted) { + return new DownloadableFile(getConversationsFileDirectory() + file.getName() + ".pgp"); + } else { + return file; + } } public static String getConversationsFileDirectory() { diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 27a7eee33..96da50262 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1688,16 +1688,16 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa List conversations = getConversations(); for (Conversation conversation : conversations) { if (conversation.getMode() == Conversation.MODE_MULTI && conversation.getAccount() == account) { - joinMuc(conversation, true); + joinMuc(conversation, true, null); } } } public void joinMuc(Conversation conversation) { - joinMuc(conversation, false); + joinMuc(conversation, false, null); } - private void joinMuc(Conversation conversation, boolean now) { + private void joinMuc(Conversation conversation, boolean now, final OnConferenceJoined onConferenceJoined) { Account account = conversation.getAccount(); account.pendingConferenceJoins.remove(conversation); account.pendingConferenceLeaves.remove(conversation); @@ -1730,11 +1730,13 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } String sig = account.getPgpSignature(); if (sig != null) { - packet.addChild("status").setContent("online"); packet.addChild("x", "jabber:x:signed").setContent(sig); } sendPresencePacket(account, packet); fetchConferenceConfiguration(conversation); + if (onConferenceJoined != null) { + onConferenceJoined.onConferenceJoined(conversation); + } if (!joinJid.equals(conversation.getJid())) { conversation.setContactJid(joinJid); databaseBackend.updateConversation(conversation); @@ -1752,17 +1754,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa @Override public void onFetchFailed(final Conversation conversation, Element error) { - conversation.getMucOptions().setOnJoinListener(new MucOptions.OnJoinListener() { - @Override - public void onSuccess() { - fetchConferenceConfiguration(conversation); - } - - @Override - public void onFailure() { - - } - }); join(conversation); } }); @@ -1889,34 +1880,37 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa String name = new BigInteger(75, getRNG()).toString(32); Jid jid = Jid.fromParts(name, server, null); final Conversation conversation = findOrCreateConversation(account, jid, true); - joinMuc(conversation); - Bundle options = new Bundle(); - options.putString("muc#roomconfig_persistentroom", "1"); - options.putString("muc#roomconfig_membersonly", "1"); - options.putString("muc#roomconfig_publicroom", "0"); - options.putString("muc#roomconfig_whois", "anyone"); - pushConferenceConfiguration(conversation, options, new OnConferenceOptionsPushed() { + joinMuc(conversation, true, new OnConferenceJoined() { @Override - public void onPushSucceeded() { - for (Jid invite : jids) { - invite(conversation, invite); - } - if (account.countPresences() > 1) { - directInvite(conversation, account.getJid().toBareJid()); - } - if (callback != null) { - callback.success(conversation); - } - } + public void onConferenceJoined(final Conversation conversation) { + Bundle options = new Bundle(); + options.putString("muc#roomconfig_persistentroom", "1"); + options.putString("muc#roomconfig_membersonly", "1"); + options.putString("muc#roomconfig_publicroom", "0"); + options.putString("muc#roomconfig_whois", "anyone"); + pushConferenceConfiguration(conversation, options, new OnConferenceOptionsPushed() { + @Override + public void onPushSucceeded() { + for (Jid invite : jids) { + invite(conversation, invite); + } + if (account.countPresences() > 1) { + directInvite(conversation, account.getJid().toBareJid()); + } + if (callback != null) { + callback.success(conversation); + } + } - @Override - public void onPushFailed() { - if (callback != null) { - callback.error(R.string.conference_creation_failed, conversation); - } + @Override + public void onPushFailed() { + if (callback != null) { + callback.error(R.string.conference_creation_failed, conversation); + } + } + }); } }); - } catch (InvalidJidException e) { if (callback != null) { callback.error(R.string.conference_creation_failed, null); @@ -2976,6 +2970,10 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa void onFetchFailed(Conversation conversation, Element error); } + public interface OnConferenceJoined { + void onConferenceJoined(Conversation conversation); + } + public interface OnConferenceOptionsPushed { void onPushSucceeded(); diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index 20195256f..42ce5349a 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -6,7 +6,6 @@ import android.app.PendingIntent; import android.content.Context; import android.content.DialogInterface; import android.content.IntentSender.SendIntentException; -import android.content.res.Configuration; import android.graphics.Bitmap; import android.os.Build; import android.os.Bundle; @@ -42,7 +41,6 @@ import eu.siacs.conversations.entities.MucOptions.User; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate; import eu.siacs.conversations.services.XmppConnectionService.OnMucRosterUpdate; -import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.xmpp.jid.Jid; public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnRoleChanged, XmppConnectionService.OnConferenceOptionsPushed { @@ -55,7 +53,6 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers inviteToConversation(mConversation); } }; - private LinearLayout mMainLayout; private TextView mYourNick; private ImageView mYourPhoto; private ImageButton mEditNickButton; @@ -190,7 +187,6 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_muc_details); - mMainLayout = (LinearLayout) findViewById(R.id.muc_main_layout); mYourNick = (TextView) findViewById(R.id.muc_your_nick); mYourPhoto = (ImageView) findViewById(R.id.your_photo); mEditNickButton = (ImageButton) findViewById(R.id.edit_nick_button); @@ -454,12 +450,6 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers } } - @Override - public void onConfigurationChanged (Configuration newConfig) { - super.onConfigurationChanged(newConfig); - UIHelper.resetChildMargins(mMainLayout); - } - private void updateView() { final MucOptions mucOptions = mConversation.getMucOptions(); final User self = mucOptions.getSelf(); diff --git a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java index ebac6feba..10bdaab16 100644 --- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -7,7 +7,6 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.IntentSender.SendIntentException; import android.content.SharedPreferences; -import android.content.res.Configuration; import android.net.Uri; import android.os.Bundle; import android.preference.PreferenceManager; @@ -100,7 +99,6 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd } } }; - private LinearLayout mainLayout; private Jid accountJid; private Jid contactJid; private TextView contactJidTv; @@ -199,7 +197,6 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd this.messageFingerprint = getIntent().getStringExtra("fingerprint"); setContentView(R.layout.activity_contact_details); - mainLayout = (LinearLayout) findViewById(R.id.details_main_layout); contactJidTv = (TextView) findViewById(R.id.details_contactjid); accountJidTv = (TextView) findViewById(R.id.details_account); lastseen = (TextView) findViewById(R.id.details_lastseen); @@ -300,12 +297,6 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd return true; } - @Override - public void onConfigurationChanged (Configuration newConfig) { - super.onConfigurationChanged(newConfig); - UIHelper.resetChildMargins(mainLayout); - } - private void populateView() { invalidateOptionsMenu(); setTitle(contact.getDisplayName()); diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index 80b054a47..5c7722200 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -17,6 +17,7 @@ import android.provider.MediaStore; import android.support.v4.widget.SlidingPaneLayout; import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener; import android.util.Log; +import android.view.Gravity; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; @@ -510,22 +511,22 @@ public class ConversationActivity extends XmppActivity } final Conversation conversation = getSelectedConversation(); final int encryption = conversation.getNextEncryption(); + final int mode = conversation.getMode(); if (encryption == Message.ENCRYPTION_PGP) { if (hasPgp()) { - if (conversation.getContact().getPgpKeyId() != 0) { + if (mode == Conversation.MODE_SINGLE && conversation.getContact().getPgpKeyId() != 0) { xmppConnectionService.getPgpEngine().hasKey( conversation.getContact(), new UiCallback() { @Override - public void userInputRequried(PendingIntent pi, - Contact contact) { - ConversationActivity.this.runIntent(pi,attachmentChoice); + public void userInputRequried(PendingIntent pi, Contact contact) { + ConversationActivity.this.runIntent(pi, attachmentChoice); } @Override public void success(Contact contact) { - selectPresenceToAttachFile(attachmentChoice,encryption); + selectPresenceToAttachFile(attachmentChoice, encryption); } @Override @@ -533,6 +534,16 @@ public class ConversationActivity extends XmppActivity displayErrorDialog(error); } }); + } else if (mode == Conversation.MODE_MULTI && conversation.getMucOptions().pgpKeysInUse()) { + if (!conversation.getMucOptions().everybodyHasKeys()) { + Toast warning = Toast + .makeText(this, + R.string.missing_public_keys, + Toast.LENGTH_LONG); + warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0); + warning.show(); + } + selectPresenceToAttachFile(attachmentChoice, encryption); } else { final ConversationFragment fragment = (ConversationFragment) getFragmentManager() .findFragmentByTag("conversation"); diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 180fc8b84..5fe5848c0 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -482,12 +482,6 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate invalidateOptionsMenu(); } - @Override - public void onConfigurationChanged (Configuration newConfig) { - super.onConfigurationChanged(newConfig); - UIHelper.resetChildMargins(mMainLayout); - } - @Override public boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java index 8a73d35fb..cac23f077 100644 --- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java @@ -3,11 +3,7 @@ package eu.siacs.conversations.utils; import android.content.Context; import android.text.format.DateFormat; import android.text.format.DateUtils; -import android.util.DisplayMetrics; import android.util.Pair; -import android.view.View; -import android.widget.LinearLayout; -import android.widget.RelativeLayout; import java.util.ArrayList; import java.util.Arrays; @@ -265,21 +261,4 @@ public class UIHelper { body = body.replace("?","").replace("¿",""); return LOCATION_QUESTIONS.contains(body); } - - public static void resetChildMargins(LinearLayout view) { - int childCount = view.getChildCount(); - for (int i = 0; i < childCount; i++) { - UIHelper.resetMargins(view.getChildAt(i)); - } - } - - private static void resetMargins(View view) { - LinearLayout.MarginLayoutParams marginLayoutParams = new LinearLayout.MarginLayoutParams(view.getLayoutParams()); - marginLayoutParams.setMargins(view.getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), - view.getResources().getDimensionPixelSize(R.dimen.activity_vertical_margin), - view.getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), - view.getResources().getDimensionPixelSize(R.dimen.activity_vertical_margin)); - LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(marginLayoutParams); - view.setLayoutParams(layoutParams); - } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 7092aca10..c28ac0394 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -1369,7 +1369,7 @@ public class XmppConnection implements Runnable { } public boolean httpUpload() { - return findDiscoItemsByFeature(Xmlns.HTTP_UPLOAD).size() > 0; + return !Config.DISABLE_HTTP_UPLOAD && findDiscoItemsByFeature(Xmlns.HTTP_UPLOAD).size() > 0; } } 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 388c5dec2..4510bca26 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -114,6 +114,8 @@ public class JingleConnection implements Transferable { Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); intent.setData(Uri.fromFile(file)); mXmppConnectionService.sendBroadcast(intent); + } else { + account.getPgpDecryptionService().add(message); } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java index ab564480c..0f0361cd3 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java @@ -83,7 +83,7 @@ public class JingleConnectionManager extends AbstractConnectionManager { public void getPrimaryCandidate(Account account, final OnPrimaryCandidateFound listener) { - if (Config.NO_PROXY_LOOKUP) { + if (Config.DISABLE_PROXY_LOOKUP) { listener.onPrimaryCandidateFound(false, null); return; }