diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-01-25 21:17:53 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2016-01-25 21:17:53 +0100 |
commit | 7c0eae80591ec6b1562168be3d2a56315afc872a (patch) | |
tree | 5f944e25d4ca382e113bfa0db09787cfcd6cd547 | |
parent | 31fd425c9a41f1cc70ec92ab5876781464b236d9 (diff) |
expert setting to trigger extended connection options
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 @@ <string name="pref_away_when_screen_off_summary">Marks your resource as away when the screen is turned off</string> <string name="pref_xa_on_silent_mode">Not available in silent mode</string> <string name="pref_xa_on_silent_mode_summary">Marks your resource as not available when device is in silent mode</string> + <string name="pref_show_connection_options">Extended connection options</string> + <string name="pref_show_connection_options_summary">Show hostname and port options when setting up an account</string> + <string name="hostname_example">xmpp.example.com</string> <string name="action_add_account_with_certificate">Add account with certificate</string> <string name="unable_to_parse_certificate">Unable to parse certificate</string> <string name="authenticate_with_certificate">Leave empty to authenticate w/ certificate</string> 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"/> + <CheckBoxPreference + android:defaultValue="false" + android:key="show_connection_options" + android:summary="@string/pref_show_connection_options_summary" + android:title="@string/pref_show_connection_options"/> </PreferenceCategory> <PreferenceCategory android:title="@string/pref_input_options"> <CheckBoxPreference |