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