From 905a79fca8c0770276c3ee68f88883c7140c6cf6 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 8 Mar 2014 02:06:00 +0100 Subject: fixed #3 --- .../services/XmppConnectionService.java | 15 +++++++++--- .../conversations/ui/ConversationActivity.java | 13 +++++----- .../siacs/conversations/xmpp/XmppConnection.java | 28 ++++++++-------------- 3 files changed, 29 insertions(+), 27 deletions(-) (limited to 'src/eu') diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index d0a879b4..63f52a8e 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -175,11 +175,12 @@ public class XmppConnectionService extends Service { @Override public void onStatusChanged(Account account) { - Log.d(LOGTAG,account.getJid()+" status switched to " + account.getStatus()); if (accountChangedListener != null) { - Log.d(LOGTAG,"notifiy ui"); accountChangedListener.onAccountListChangedListener(); } + if (account.getXmppConnection().hasFeatureRosterManagment()) { + updateRoster(account, null); + } if (account.getStatus() == Account.STATUS_ONLINE) { databaseBackend.clearPresences(account); connectMultiModeConversations(account); @@ -612,7 +613,12 @@ public class XmppConnectionService extends Service { IqPacket iqPacket = new IqPacket(IqPacket.TYPE_GET); Element query = new Element("query"); query.setAttribute("xmlns", "jabber:iq:roster"); - query.setAttribute("ver", account.getRosterVersion()); + if (!"".equals(account.getRosterVersion())) { + Log.d(LOGTAG,account.getJid()+ ": fetching roster version "+account.getRosterVersion()); + query.setAttribute("ver", account.getRosterVersion()); + } else { + Log.d(LOGTAG,account.getJid()+": fetching roster"); + } iqPacket.addChild(query); account.getXmppConnection().sendIqPacket(iqPacket, new OnIqPacketReceived() { @@ -622,6 +628,7 @@ public class XmppConnectionService extends Service { IqPacket packet) { Element roster = packet.findChild("query"); if (roster != null) { + Log.d(LOGTAG,account.getJid()+": processing roster"); processRosterItems(account, roster); StringBuilder mWhere = new StringBuilder(); mWhere.append("jid NOT IN("); @@ -645,6 +652,8 @@ public class XmppConnectionService extends Service { null); } + } else { + Log.d(LOGTAG,account.getJid()+": empty roster returend"); } mergePhoneContactsWithRoster(new OnPhoneContactsMerged() { diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index 3d39eac7..f8e22dad 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -147,7 +147,12 @@ public class ConversationActivity extends XmppActivity { view = (View) inflater.inflate( R.layout.conversation_list_row, null); } - Conversation conv = getItem(position); + Conversation conv; + if (conversationList.size() > position) { + conv = getItem(position); + } else { + return view; + } if (!spl.isSlideable()) { if (conv==getSelectedConversation()) { view.setBackgroundColor(0xffdddddd); @@ -181,7 +186,7 @@ public class ConversationActivity extends XmppActivity { ((ImageView) view.findViewById(R.id.conversation_image)) - .setImageURI(getItem(position).getProfilePhotoUri()); + .setImageURI(conv.getProfilePhotoUri()); return view; } @@ -417,7 +422,6 @@ public class ConversationActivity extends XmppActivity { xmppConnectionService.setOnConversationListChangedListener(this.onConvChanged); if (conversationList.size()==0) { - conversationList.clear(); conversationList.addAll(xmppConnectionService .getConversations()); @@ -452,12 +456,9 @@ public class ConversationActivity extends XmppActivity { //find currently loaded fragment ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager().findFragmentByTag("conversation"); if (selectedFragment!=null) { - Log.d("gultsch","ConversationActivity. found old fragment."); selectedFragment.onBackendConnected(); } else { - Log.d("gultsch","conversationactivity. no old fragment found. creating new one"); selectedConversation = conversationList.get(0); - Log.d("gultsch","selected conversation is #"+selectedConversation); swapConversationFragment(); } } diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index 24168aef..bf81897c 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -14,13 +14,11 @@ import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.cert.CertPathValidatorException; import java.security.cert.CertificateException; -import java.security.cert.CertificateExpiredException; import java.security.cert.X509Certificate; import java.util.HashSet; import java.util.Hashtable; import java.util.List; -import javax.net.ssl.ManagerFactoryParameters; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; @@ -55,10 +53,6 @@ public class XmppConnection implements Runnable { private XmlReader tagReader; private TagWriter tagWriter; - private boolean isTlsEncrypted = false; - private boolean isAuthenticated = false; - // private boolean shouldUseTLS = false; - private boolean shouldConnect = true; private boolean shouldBind = true; private boolean shouldAuthenticate = true; private Element streamFeatures; @@ -170,9 +164,8 @@ public class XmppConnection implements Runnable { } else if (nextTag.isStart("proceed")) { switchOverToTls(nextTag); } else if (nextTag.isStart("success")) { - isAuthenticated = true; Log.d(LOGTAG, account.getJid() - + ": read success tag in stream. reset again"); + + ": logged in"); tagReader.readTag(); tagReader.reset(); sendStartStream(); @@ -279,14 +272,12 @@ public class XmppConnection implements Runnable { private void sendStartTLS() { Tag startTLS = Tag.empty("starttls"); startTLS.setAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-tls"); - Log.d(LOGTAG, account.getJid() + ": sending starttls"); tagWriter.writeTag(startTLS); } private void switchOverToTls(Tag currentTag) throws XmlPullParserException, IOException { Tag nextTag = tagReader.readTag(); // should be proceed end tag - Log.d(LOGTAG, account.getJid() + ": now switch to ssl"); try { SSLContext sc = SSLContext.getInstance("TLS"); TrustManagerFactory tmf = TrustManagerFactory @@ -352,11 +343,9 @@ public class XmppConnection implements Runnable { socket.getInetAddress().getHostAddress(), socket.getPort(), true); tagReader.setInputStream(sslSocket.getInputStream()); - Log.d(LOGTAG, "reset inputstream"); tagWriter.setOutputStream(sslSocket.getOutputStream()); - Log.d(LOGTAG, "switch over seemed to work"); - isTlsEncrypted = true; sendStartStream(); + Log.d(LOGTAG,account.getJid()+": TLS connection established"); processStream(tagReader.readTag()); sslSocket.close(); } catch (NoSuchAlgorithmException e1) { @@ -375,15 +364,12 @@ public class XmppConnection implements Runnable { auth.setAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl"); auth.setAttribute("mechanism", "PLAIN"); auth.setContent(saslString); - Log.d(LOGTAG, account.getJid() + ": sending sasl " + auth.toString()); tagWriter.writeElement(auth); } private void processStreamFeatures(Tag currentTag) throws XmlPullParserException, IOException { this.streamFeatures = tagReader.readElement(currentTag); - Log.d(LOGTAG, account.getJid() + ": process stream features " - + streamFeatures); if (this.streamFeatures.hasChild("starttls") && account.isOptionSet(Account.OPTION_USETLS)) { sendStartTLS(); @@ -457,7 +443,6 @@ public class XmppConnection implements Runnable { } private void sendEnableCarbons() { - Log.d(LOGTAG, account.getJid() + ": enable carbons"); IqPacket iq = new IqPacket(IqPacket.TYPE_SET); Element enable = new Element("enable"); enable.setAttribute("xmlns", "urn:xmpp:carbons:2"); @@ -558,7 +543,14 @@ public class XmppConnection implements Runnable { } public void disconnect() { - shouldConnect = false; tagWriter.writeTag(Tag.end("stream:stream")); } + + public boolean hasFeatureRosterManagment() { + if (this.streamFeatures==null) { + return false; + } else { + return this.streamFeatures.hasChild("ver"); + } + } } -- cgit v1.2.3