From 7c0eae80591ec6b1562168be3d2a56315afc872a Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 25 Jan 2016 21:17:53 +0100 Subject: expert setting to trigger extended connection options --- .../services/XmppConnectionService.java | 8 ++++-- .../conversations/ui/EditAccountActivity.java | 30 +++++++++++++++++----- .../siacs/conversations/xmpp/XmppConnection.java | 13 ++++++++-- src/main/res/values/strings.xml | 3 +++ src/main/res/xml/preferences.xml | 5 ++++ 5 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index a295b2ce..d4fda1b8 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1969,7 +1969,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } } } - Element form = query.findChild("x","jabber:x:data"); + Element form = query.findChild("x", "jabber:x:data"); if (form != null) { conversation.getMucOptions().updateFormData(Data.parse(form)); } @@ -2378,7 +2378,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa updateConversationUi(); updateRosterUi(); } else { - Conversation conversation = find(account,avatar.owner.toBareJid()); + Conversation conversation = find(account, avatar.owner.toBareJid()); if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) { MucOptions.User user = conversation.getMucOptions().findUser(avatar.owner.getResourcepart()); if (user != null) { @@ -2586,6 +2586,10 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa return Config.FORCE_ORBOT || getPreferences().getBoolean("use_tor", false); } + public boolean showExtendedConnectionOptions() { + return getPreferences().getBoolean("show_connection_options", false); + } + public int unreadCount() { int count = 0; for (Conversation conversation : getConversations()) { diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 24490699..5c783f54 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -5,6 +5,7 @@ import android.app.AlertDialog.Builder; import android.app.PendingIntent; import android.content.DialogInterface; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; @@ -91,7 +92,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate private Jid jidToEdit; private boolean mInitMode = false; - private boolean mUseTor = false; + private boolean mShowOptions = false; private Account mAccount; private String messageFingerprint; @@ -133,7 +134,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate } String hostname = null; int numericPort = 5222; - if (mUseTor) { + if (mShowOptions) { hostname = mHostname.getText().toString(); final String port = mPort.getText().toString(); if (hostname.contains(" ")) { @@ -511,8 +512,11 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate } } } - this.mUseTor = Config.FORCE_ORBOT || getPreferences().getBoolean("use_tor", false); - this.mNamePort.setVisibility(mUseTor ? View.VISIBLE : View.GONE); + SharedPreferences preferences = getPreferences(); + boolean useTor = Config.FORCE_ORBOT || preferences.getBoolean("use_tor", false); + this.mShowOptions = useTor || preferences.getBoolean("show_connection_options", false); + mHostname.setHint(useTor ? R.string.hostname_or_onion : R.string.hostname_example); + this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE); } @Override @@ -598,7 +602,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate this.mHostname.getEditableText().append(this.mAccount.getHostname()); this.mPort.setText(""); this.mPort.getEditableText().append(String.valueOf(this.mAccount.getPort())); - this.mNamePort.setVisibility(mUseTor ? View.VISIBLE : View.GONE); + this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE); } if (!mInitMode) { @@ -740,12 +744,24 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate } } else { if (this.mAccount.errorStatus()) { - this.mAccountJid.setError(getString(this.mAccount.getStatus().getReadableId())); + final EditText errorTextField; + if (this.mAccount.getStatus() == Account.State.UNAUTHORIZED) { + errorTextField = this.mPassword; + } else if (mShowOptions + && this.mAccount.getStatus() == Account.State.SERVER_NOT_FOUND + && this.mHostname.getText().length() > 0) { + errorTextField = this.mHostname; + } else { + errorTextField = this.mAccountJid; + } + errorTextField.setError(getString(this.mAccount.getStatus().getReadableId())); if (init || !accountInfoEdited()) { - this.mAccountJid.requestFocus(); + errorTextField.requestFocus(); } } else { this.mAccountJid.setError(null); + this.mPassword.setError(null); + this.mHostname.setError(null); } this.mStats.setVisibility(View.GONE); } diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index a3dd0644..a39ccc37 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -243,6 +243,7 @@ public class XmppConnection implements Runnable { tagWriter = new TagWriter(); this.changeStatus(Account.State.CONNECTING); final boolean useTor = mXmppConnectionService.useTorToConnect() || account.isOnion(); + final boolean extended = mXmppConnectionService.showExtendedConnectionOptions(); if (useTor) { String destination; if (account.getHostname() == null || account.getHostname().isEmpty()) { @@ -250,8 +251,16 @@ public class XmppConnection implements Runnable { } else { destination = account.getHostname(); } - Log.d(Config.LOGTAG,account.getJid().toBareJid()+": connect to "+destination+" via TOR"); - socket = SocksSocketFactory.createSocketOverTor(destination,account.getPort()); + Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": connect to " + destination + " via TOR"); + socket = SocksSocketFactory.createSocketOverTor(destination, account.getPort()); + startXmpp(); + } else if (extended && account.getHostname() != null && !account.getHostname().isEmpty()) { + socket = new Socket(); + try { + socket.connect(new InetSocketAddress(account.getHostname(), account.getPort()), Config.SOCKET_TIMEOUT * 1000); + } catch (IOException e) { + throw new UnknownHostException(); + } startXmpp(); } else if (DNSHelper.isIp(account.getServer().toString())) { socket = new Socket(); diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 38368383..2034082d 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -529,6 +529,9 @@ Marks your resource as away when the screen is turned off Not available in silent mode Marks your resource as not available when device is in silent mode + Extended connection options + Show hostname and port options when setting up an account + xmpp.example.com Add account with certificate Unable to parse certificate Leave empty to authenticate w/ certificate diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index b3afe0c3..6a5974c0 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -155,6 +155,11 @@ android:key="use_tor" android:summary="@string/pref_use_tor_summary" android:title="@string/pref_use_tor"/> +