diff options
Diffstat (limited to 'src/main/java/eu')
7 files changed, 73 insertions, 24 deletions
diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java index 17d911b44..2ce62c9ad 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java @@ -323,14 +323,14 @@ public class AxolotlService { mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket packet) { - if (packet.getType() == IqPacket.TYPE.RESULT) { + if (packet.getType() == IqPacket.TYPE.TIMEOUT) { + Log.d(Config.LOGTAG, getLogprefix(account) + "Timeout received while retrieving own Device Ids."); + } else { Element item = mXmppConnectionService.getIqParser().getItem(packet); Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item); if (!deviceIds.contains(getOwnDeviceId())) { publishOwnDeviceId(deviceIds); } - } else { - Log.d(Config.LOGTAG, getLogprefix(account) + "Error received while retrieving Device Ids" + packet.findChild("error")); } } }); diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index 3b8da6b39..2e13964ed 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -178,7 +178,7 @@ public class NotificationService { } private void setNotificationColor(final Builder mBuilder) { - mBuilder.setColor(mXmppConnectionService.getResources().getColor(R.color.green500)); + mBuilder.setColor(mXmppConnectionService.getResources().getColor(R.color.primary)); } private void updateNotification(final boolean notify) { @@ -559,4 +559,4 @@ public class NotificationService { mBuilder.setContentIntent(resultPendingIntent); mNotificationManager.notify(ERROR_NOTIFICATION_ID, mBuilder.build()); } -}
\ No newline at end of file +} diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 7734dc116..aa5812b6a 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -354,7 +354,7 @@ public abstract class XmppActivity extends Activity { mColorRed = getResources().getColor(R.color.red800); mColorOrange = getResources().getColor(R.color.orange500); mColorGreen = getResources().getColor(R.color.green500); - mPrimaryColor = getResources().getColor(R.color.green500); + mPrimaryColor = getResources().getColor(R.color.primary); mPrimaryBackgroundColor = getResources().getColor(R.color.grey50); mSecondaryBackgroundColor = getResources().getColor(R.color.grey200); this.mTheme = findTheme(); diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 1dbf1b101..461127506 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -323,6 +323,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { } viewHolder.messageBody.setTextColor(this.getMessageTextColor(darkBackground, true)); viewHolder.messageBody.setLinkTextColor(this.getMessageTextColor(darkBackground,true)); + viewHolder.messageBody.setHighlightColor(activity.getResources().getColor(darkBackground ? R.color.grey800 : R.color.grey500)); viewHolder.messageBody.setTypeface(null, Typeface.NORMAL); viewHolder.messageBody.setTextIsSelectable(true); } diff --git a/src/main/java/eu/siacs/conversations/utils/DNSHelper.java b/src/main/java/eu/siacs/conversations/utils/DNSHelper.java index 4d0dd3dab..889206e0b 100644 --- a/src/main/java/eu/siacs/conversations/utils/DNSHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/DNSHelper.java @@ -1,13 +1,21 @@ package eu.siacs.conversations.utils; +import android.annotation.TargetApi; +import android.content.Context; +import android.net.ConnectivityManager; +import android.net.LinkProperties; +import android.net.Network; +import android.os.Build; import android.os.Bundle; import android.util.Log; import java.io.IOException; import java.net.InetAddress; import java.net.SocketTimeoutException; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collections; +import java.util.List; import java.util.Random; import java.util.TreeMap; import java.util.regex.Pattern; @@ -35,17 +43,42 @@ public class DNSHelper { protected static Client client = new Client(); - public static Bundle getSRVRecord(final Jid jid) throws IOException { + public static Bundle getSRVRecord(final Jid jid, Context context) throws IOException { final String host = jid.getDomainpart(); - String dns[] = client.findDNS(); - for (int i = 0; i < dns.length; ++i) { - InetAddress ip = InetAddress.getByName(dns[i]); - Bundle b = queryDNS(host, ip); - if (b.containsKey("values") || i == dns.length - 1) { + final List<InetAddress> servers = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? getDnsServers(context) : getDnsServersPreLolipop(); + Bundle b = null; + for(InetAddress server : servers) { + b = queryDNS(host, server); + if (b.containsKey("values")) { return b; } } - return null; + return b; + } + + @TargetApi(21) + private static List<InetAddress> getDnsServers(Context context) { + List<InetAddress> servers = new ArrayList<>(); + ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + Network[] networks = connectivityManager.getAllNetworks(); + for(int i = 0; i < networks.length; ++i) { + LinkProperties linkProperties = connectivityManager.getLinkProperties(networks[i]); + servers.addAll(linkProperties.getDnsServers()); + } + return servers.size() > 0 ? servers : getDnsServersPreLolipop(); + } + + private static List<InetAddress> getDnsServersPreLolipop() { + List<InetAddress> servers = new ArrayList<>(); + String[] dns = client.findDNS(); + for(int i = 0; i < dns.length; ++i) { + try { + servers.add(InetAddress.getByName(dns[i])); + } catch (UnknownHostException e) { + //ignore + } + } + return servers; } public static Bundle queryDNS(String host, InetAddress dnsServer) { diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index bb0c3987b..64507bd67 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -159,7 +159,7 @@ public class XmppConnection implements Runnable { throw new UnknownHostException(); } } else { - final Bundle result = DNSHelper.getSRVRecord(account.getServer()); + final Bundle result = DNSHelper.getSRVRecord(account.getServer(),mXmppConnectionService); if (result == null) { throw new IOException("unhandled exception in DNS resolver"); } @@ -704,8 +704,11 @@ public class XmppConnection implements Runnable { this.sendUnmodifiedIqPacket(iq, new OnIqPacketReceived() { @Override public void onIqPacketReceived(final Account account, final IqPacket packet) { + if (packet.getType() == IqPacket.TYPE.TIMEOUT) { + return; + } final Element bind = packet.findChild("bind"); - if (bind != null) { + if (bind != null && packet.getType() == IqPacket.TYPE.RESULT) { final Element jid = bind.findChild("jid"); if (jid != null && jid.getContent() != null) { try { @@ -719,11 +722,11 @@ public class XmppConnection implements Runnable { sendPostBindInitialization(); } } else { - Log.d(Config.LOGTAG,account.getJid()+": disconnecting because of bind failure"); + Log.d(Config.LOGTAG, account.getJid() + ": disconnecting because of bind failure"); disconnect(true); } } else { - Log.d(Config.LOGTAG,account.getJid()+": disconnecting because of bind failure"); + Log.d(Config.LOGTAG, account.getJid() + ": disconnecting because of bind failure"); disconnect(true); } } @@ -748,7 +751,7 @@ public class XmppConnection implements Runnable { for(OnIqPacketReceived callback : callbacks) { callback.onIqPacketReceived(account,failurePacket); } - Log.d(Config.LOGTAG,account.getJid().toBareJid()+": done clearing iq callbacks. "+this.packetCallbacks.size()+" left"); + Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": done clearing iq callbacks. " + this.packetCallbacks.size() + " left"); } private void sendStartSession() { @@ -757,7 +760,9 @@ public class XmppConnection implements Runnable { this.sendUnmodifiedIqPacket(startSession, new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket packet) { - if (packet.getType() == IqPacket.TYPE.RESULT) { + if (packet.getType() == IqPacket.TYPE.TIMEOUT) { + return; + } else if (packet.getType() == IqPacket.TYPE.RESULT) { sendPostBindInitialization(); } else { Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not init sessions"); @@ -1031,15 +1036,23 @@ public class XmppConnection implements Runnable { if (tagWriter.isActive()) { tagWriter.finish(); try { - while (!tagWriter.finished() && socket.isConnected()) { - Log.d(Config.LOGTAG, "not yet finished"); - Thread.sleep(100); + int i = 0; + boolean warned = false; + while (!tagWriter.finished() && socket.isConnected() && i <= 10) { + if (!warned) { + Log.d(Config.LOGTAG, account.getJid().toBareJid()+": waiting for tag writer to finish"); + warned = true; + } + Thread.sleep(200); + i++; + } + if (warned) { + Log.d(Config.LOGTAG,account.getJid().toBareJid()+": tag writer has finished"); } tagWriter.writeTag(Tag.end("stream:stream")); socket.close(); } catch (final IOException e) { - Log.d(Config.LOGTAG, - "io exception during disconnect"); + Log.d(Config.LOGTAG,"io exception during disconnect"); } catch (final InterruptedException e) { Log.d(Config.LOGTAG, "interrupted"); } diff --git a/src/main/java/eu/siacs/conversations/xmpp/stanzas/IqPacket.java b/src/main/java/eu/siacs/conversations/xmpp/stanzas/IqPacket.java index 4d16f2e5d..302dc78e8 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/stanzas/IqPacket.java +++ b/src/main/java/eu/siacs/conversations/xmpp/stanzas/IqPacket.java @@ -52,6 +52,8 @@ public class IqPacket extends AbstractAcknowledgeableStanza { return TYPE.SET; case "get": return TYPE.GET; + case "timeout": + return TYPE.TIMEOUT; default: return TYPE.INVALID; } |