diff options
author | Christian S <christian@pix-art.de> | 2016-05-05 19:30:53 +0200 |
---|---|---|
committer | Christian S <christian@pix-art.de> | 2016-05-05 19:30:53 +0200 |
commit | 27ccf4e08f2547f372196bf381915ed1e6204ad8 (patch) | |
tree | 05749ea85a8421b77daf3c04d316c958895e3601 /src/main | |
parent | 626d0d3260d792843bebf2a8b8a62c1a026dd314 (diff) | |
parent | 6e0ec9b924173bd2afe3b87646e3b1f4e907b7c1 (diff) |
Merge remote-tracking branch 'refs/remotes/siacs/master' into development
Diffstat (limited to 'src/main')
12 files changed, 122 insertions, 60 deletions
diff --git a/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java b/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java index 7ca5bea07..b7d5ac8ca 100644 --- a/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java +++ b/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java @@ -2,6 +2,7 @@ package eu.siacs.conversations.crypto; import android.app.PendingIntent; import android.content.Intent; +import android.util.Log; import org.openintents.openpgp.OpenPgpSignatureResult; import org.openintents.openpgp.util.OpenPgpApi; @@ -16,6 +17,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.URL; +import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; @@ -299,7 +301,7 @@ public class PgpEngine { public void generateSignature(final Account account, String status, final UiCallback<Account> callback) { - if (account.getPgpId() == -1) { + if (account.getPgpId() == 0) { return; } Intent params = new Intent(); @@ -308,6 +310,7 @@ public class PgpEngine { params.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, account.getPgpId()); InputStream is = new ByteArrayInputStream(status.getBytes()); final OutputStream os = new ByteArrayOutputStream(); + Log.d(Config.LOGTAG,account.getJid().toBareJid()+": signing status message \""+status+"\""); api.executeApiAsync(params, is, os, new IOpenPgpCallback() { @Override diff --git a/src/main/java/eu/siacs/conversations/entities/Account.java b/src/main/java/eu/siacs/conversations/entities/Account.java index 2c0ec7ff9..1bcb15c07 100644 --- a/src/main/java/eu/siacs/conversations/entities/Account.java +++ b/src/main/java/eu/siacs/conversations/entities/Account.java @@ -478,10 +478,10 @@ public class Account extends AbstractEntity { try { return keys.getLong(KEY_PGP_ID); } catch (JSONException e) { - return -1; + return 0; } } else { - return -1; + return 0; } } diff --git a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java index d8a0572b6..4962135e3 100644 --- a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java @@ -304,8 +304,10 @@ public class IqGenerator extends AbstractGenerator { register.setTo(account.getServer()); register.setId(id); - register.query("jabber:iq:register").addChild(data); - + Element query = register.query("jabber:iq:register"); + if (data != null) { + query.addChild(data); + } return register; } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 521a0bcf0..5c4a56006 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2997,9 +2997,10 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } public void sendCreateAccountWithCaptchaPacket(Account account, String id, Data data) { - XmppConnection connection = account.getXmppConnection(); + final XmppConnection connection = account.getXmppConnection(); if (connection != null) { - connection.sendCaptchaRegistryRequest(id, data); + IqPacket request = mIqGenerator.generateCreateAccountWithCaptcha(account, id, data); + sendIqPacket(account, request, connection.registrationResponseListener); } } @@ -3252,18 +3253,18 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa return pending; } - public void changeStatus(Account account, Presence.Status status, String statusMessage) { + public void changeStatus(Account account, Presence.Status status, String statusMessage, boolean send) { if (!statusMessage.isEmpty()) { databaseBackend.insertPresenceTemplate(new PresenceTemplate(status, statusMessage)); } - changeStatusReal(account, status, statusMessage); + changeStatusReal(account, status, statusMessage, send); } - private void changeStatusReal(Account account, Presence.Status status, String statusMessage) { + private void changeStatusReal(Account account, Presence.Status status, String statusMessage, boolean send) { account.setPresenceStatus(status); account.setPresenceStatusMessage(statusMessage); databaseBackend.updateAccount(account); - if (!account.isOptionSet(Account.OPTION_DISABLED)) { + if (!account.isOptionSet(Account.OPTION_DISABLED) && send) { sendPresence(account); } } @@ -3273,7 +3274,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa databaseBackend.insertPresenceTemplate(new PresenceTemplate(status, statusMessage)); } for(Account account : getAccounts()) { - changeStatusReal(account, status, statusMessage); + changeStatusReal(account, status, statusMessage, true); } } diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index 11bff7d95..f7cb3d1b8 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -921,7 +921,7 @@ public class ConversationActivity extends XmppActivity conversation.setNextEncryption(Message.ENCRYPTION_PGP); item.setChecked(true); } else { - announcePgp(conversation.getAccount(), conversation); + announcePgp(conversation.getAccount(), conversation, onOpenPGPKeyPublished); } } else { showInstallPgpDialog(); @@ -1363,7 +1363,7 @@ public class ConversationActivity extends XmppActivity // associate selected PGP keyId with the account mSelectedConversation.getAccount().setPgpSignId(data.getExtras().getLong(OpenPgpApi.EXTRA_SIGN_KEY_ID)); // we need to announce the key as described in XEP-027 - announcePgp(mSelectedConversation.getAccount(), null); + announcePgp(mSelectedConversation.getAccount(), null, onOpenPGPKeyPublished); } else { choosePgpSignId(mSelectedConversation.getAccount()); } @@ -1373,7 +1373,7 @@ public class ConversationActivity extends XmppActivity } } else if (requestCode == REQUEST_ANNOUNCE_PGP) { if (xmppConnectionServiceBound) { - announcePgp(mSelectedConversation.getAccount(), mSelectedConversation); + announcePgp(mSelectedConversation.getAccount(), mSelectedConversation, onOpenPGPKeyPublished); this.mPostponedActivityResult = null; } else { this.mPostponedActivityResult = new Pair<>(requestCode, data); diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 091f11a95..aad4467dc 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1199,7 +1199,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa return; } if (conversation.getAccount().getPgpSignature() == null) { - activity.announcePgp(conversation.getAccount(), conversation); + activity.announcePgp(conversation.getAccount(), conversation, activity.onOpenPGPKeyPublished); return; } if (conversation.getMode() == Conversation.MODE_SINGLE) { diff --git a/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java index 7d3c34252..16d8ca716 100644 --- a/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -313,7 +313,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda private void publishOpenPGPPublicKey(Account account) { if (ManageAccountActivity.this.hasPgp()) { - choosePgpSignId(selectedAccount); + announcePgp(selectedAccount, null, onOpenPGPKeyPublished); } else { this.showInstallPgpDialog(); } @@ -345,12 +345,12 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda if (requestCode == REQUEST_CHOOSE_PGP_ID) { if (data.getExtras().containsKey(OpenPgpApi.EXTRA_SIGN_KEY_ID)) { selectedAccount.setPgpSignId(data.getExtras().getLong(OpenPgpApi.EXTRA_SIGN_KEY_ID)); - announcePgp(selectedAccount, null); + announcePgp(selectedAccount, null, onOpenPGPKeyPublished); } else { choosePgpSignId(selectedAccount); } } else if (requestCode == REQUEST_ANNOUNCE_PGP) { - announcePgp(selectedAccount, null); + announcePgp(selectedAccount, null, onOpenPGPKeyPublished); } this.mPostponedActivityResult = null; } else { diff --git a/src/main/java/eu/siacs/conversations/ui/SetPresenceActivity.java b/src/main/java/eu/siacs/conversations/ui/SetPresenceActivity.java index 5fe9c5d8c..effd30bf5 100644 --- a/src/main/java/eu/siacs/conversations/ui/SetPresenceActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/SetPresenceActivity.java @@ -1,7 +1,9 @@ package eu.siacs.conversations.ui; +import android.content.Intent; import android.os.Bundle; import android.os.Handler; +import android.util.Pair; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -18,6 +20,8 @@ import android.widget.TextView; import android.util.Log; +import org.openintents.openpgp.util.OpenPgpApi; + import java.util.List; import java.util.concurrent.RunnableFuture; import java.util.concurrent.atomic.AtomicBoolean; @@ -42,6 +46,14 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis protected Spinner mShowSpinner; protected CheckBox mAllAccounts; protected LinearLayout mTemplatesView; + private Pair<Integer, Intent> mPostponedActivityResult; + + private Runnable onPresenceChanged = new Runnable() { + @Override + public void run() { + finish(); + } + }; protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -83,16 +95,37 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis } } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (resultCode == RESULT_OK) { + if (xmppConnectionServiceBound && mAccount != null) { + if (requestCode == REQUEST_ANNOUNCE_PGP) { + announcePgp(mAccount, null, onPresenceChanged); + } + this.mPostponedActivityResult = null; + } else { + this.mPostponedActivityResult = new Pair<>(requestCode, data); + } + } + } + private void executeChangePresence() { Presence.Status status = getStatusFromSpinner(); boolean allAccounts = mAllAccounts.isChecked(); String statusMessage = mStatusMessage.getText().toString().trim(); - if (allAccounts) { + if (allAccounts && noAccountUsesPgp()) { xmppConnectionService.changeStatus(status, statusMessage); + finish(); } else if (mAccount != null) { - xmppConnectionService.changeStatus(mAccount, status, statusMessage); + if (mAccount.getPgpId() == 0) { + xmppConnectionService.changeStatus(mAccount, status, statusMessage, true); + finish(); + } else { + xmppConnectionService.changeStatus(mAccount, status, statusMessage, false); + announcePgp(mAccount, null, onPresenceChanged); + } } - finish(); } private Presence.Status getStatusFromSpinner() { @@ -145,6 +178,12 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis mStatusMessage.append(message); } mTemplates = xmppConnectionService.databaseBackend.getPresenceTemplates(); + if (this.mPostponedActivityResult != null) { + this.onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second); + } + boolean e = noAccountUsesPgp(); + mAllAccounts.setEnabled(e); + mAllAccounts.setTextColor(e ? getPrimaryTextColor() : getSecondaryTextColor()); } redrawTemplates(); } diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java index a1d4aa103..a7e46f33a 100644 --- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java @@ -185,6 +185,9 @@ public class SettingsActivity extends XmppActivity implements || name.equals("manually_change_presence")) { xmppConnectionService.toggleScreenEventReceiver(); } + if (name.equals("manually_change_presence") && !noAccountUsesPgp()) { + Toast.makeText(this, R.string.republish_pgp_keys, Toast.LENGTH_LONG).show(); + } xmppConnectionService.refreshAllPresences(); } } else if (name.equals("dont_trust_system_cas")) { diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index b236c872d..223e931a0 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -68,6 +68,7 @@ import java.util.ArrayList; import java.util.Hashtable; import java.util.List; import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.RunnableFuture; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; @@ -118,6 +119,13 @@ public abstract class XmppActivity extends Activity { protected int mTheme; protected boolean mUsingEnterKey = false; + protected Runnable onOpenPGPKeyPublished = new Runnable() { + @Override + public void run() { + Toast.makeText(XmppActivity.this,R.string.openpgp_has_been_published, Toast.LENGTH_SHORT).show(); + } + }; + private long mLastUiRefresh = 0; private Handler mRefreshUiHandler = new Handler(); private Runnable mRefreshUiRunnable = new Runnable() { @@ -496,18 +504,23 @@ public abstract class XmppActivity extends Activity { startActivityForResult(intent, REQUEST_INVITE_TO_CONVERSATION); } - protected void announcePgp(Account account, final Conversation conversation) { - if (account.getPgpId() == -1) { + protected void announcePgp(Account account, final Conversation conversation, final Runnable onSuccess) { + if (account.getPgpId() == 0) { choosePgpSignId(account); } else { - xmppConnectionService.getPgpEngine().generateSignature(account, "", new UiCallback<Account>() { + String status = null; + if (manuallyChangePresence()) { + status = account.getPresenceStatusMessage(); + } + if (status == null) { + status = ""; + } + xmppConnectionService.getPgpEngine().generateSignature(account, status, new UiCallback<Account>() { @Override - public void userInputRequried(PendingIntent pi, - Account account) { + public void userInputRequried(PendingIntent pi, Account account) { try { - startIntentSenderForResult(pi.getIntentSender(), - REQUEST_ANNOUNCE_PGP, null, 0, 0, 0); + startIntentSenderForResult(pi.getIntentSender(), REQUEST_ANNOUNCE_PGP, null, 0, 0, 0); } catch (final SendIntentException ignored) { } } @@ -520,6 +533,9 @@ public abstract class XmppActivity extends Activity { conversation.setNextEncryption(Message.ENCRYPTION_PGP); xmppConnectionService.databaseBackend.updateConversation(conversation); } + if (onSuccess != null) { + runOnUiThread(onSuccess); + } } @Override @@ -530,6 +546,15 @@ public abstract class XmppActivity extends Activity { } } + protected boolean noAccountUsesPgp() { + for(Account account : xmppConnectionService.getAccounts()) { + if (account.getPgpId() != 0) { + return false; + } + } + return true; + } + @SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.JELLY_BEAN) protected void setListItemBackgroundOnView(View view) { diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index f48acfe7b..97f204d12 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -177,28 +177,24 @@ public class XmppConnection implements Runnable { }; private Identity mServerIdentity = Identity.UNKNOWN; - private OnIqPacketReceived createPacketReceiveHandler() { - return new OnIqPacketReceived() { - @Override - public void onIqPacketReceived(Account account, IqPacket packet) { - if (packet.getType() == IqPacket.TYPE.RESULT) { - account.setOption(Account.OPTION_REGISTER, - false); - forceCloseSocket(); - changeStatus(Account.State.REGISTRATION_SUCCESSFUL); - } else if (packet.hasChild("error") - && (packet.findChild("error") - .hasChild("conflict"))) { - forceCloseSocket(); - changeStatus(Account.State.REGISTRATION_CONFLICT); - } else { - forceCloseSocket(); - changeStatus(Account.State.REGISTRATION_FAILED); - Log.d(Config.LOGTAG, packet.toString()); - } + public final OnIqPacketReceived registrationResponseListener = new OnIqPacketReceived() { + @Override + public void onIqPacketReceived(Account account, IqPacket packet) { + if (packet.getType() == IqPacket.TYPE.RESULT) { + account.setOption(Account.OPTION_REGISTER, false); + forceCloseSocket(); + changeStatus(Account.State.REGISTRATION_SUCCESSFUL); + } else if (packet.hasChild("error") + && (packet.findChild("error").hasChild("conflict"))) { + forceCloseSocket(); + changeStatus(Account.State.REGISTRATION_CONFLICT); + } else { + forceCloseSocket(); + changeStatus(Account.State.REGISTRATION_FAILED); + Log.d(Config.LOGTAG, packet.toString()); } - }; - } + } + }; public XmppConnection(final Account account, final XmppConnectionService service) { this.account = account; @@ -822,15 +818,6 @@ public class XmppConnection implements Runnable { return mechanisms; } - public void sendCaptchaRegistryRequest(String id, Data data) { - if (data == null) { - setAccountCreationFailed(""); - } else { - IqPacket request = getIqGenerator().generateCreateAccountWithCaptcha(account, id, data); - sendIqPacket(request, createPacketReceiveHandler()); - } - } - private void sendRegistryRequest() { final IqPacket register = new IqPacket(IqPacket.TYPE.GET); register.query("jabber:iq:register"); @@ -848,7 +835,7 @@ public class XmppConnection implements Runnable { final Element password = new Element("password").setContent(account.getPassword()); register.query("jabber:iq:register").addChild(username); register.query().addChild(password); - sendIqPacket(register, createPacketReceiveHandler()); + sendIqPacket(register, registrationResponseListener); } else if (packet.getType() == IqPacket.TYPE.RESULT && (packet.query().hasChild("x", "jabber:x:data"))) { final Data data = Data.parse(packet.query().findChild("x", "jabber:x:data")); diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 9c5f2d3af..136c3983e 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -167,6 +167,8 @@ <string name="mgmt_account_disable">Temporarily disable</string> <string name="mgmt_account_publish_avatar">Publish avatar</string> <string name="mgmt_account_publish_pgp">Publish OpenPGP public key</string> + <string name="openpgp_has_been_published">OpenPGP public key has been published.</string> + <string name="republish_pgp_keys">Remember to republish your OpenPGP public keys!</string> <string name="mgmt_account_enable">Enable account</string> <string name="mgmt_account_are_you_sure">Are you sure?</string> <string name="mgmt_account_delete_confirm_text">If you delete your account your entire conversation history will be lost</string> |