expert setting to trigger extended connection options

This commit is contained in:
Daniel Gultsch 2016-01-25 21:17:53 +01:00
parent 31fd425c9a
commit 7c0eae8059
5 changed files with 48 additions and 11 deletions

View file

@ -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) { if (form != null) {
conversation.getMucOptions().updateFormData(Data.parse(form)); conversation.getMucOptions().updateFormData(Data.parse(form));
} }
@ -2378,7 +2378,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
updateConversationUi(); updateConversationUi();
updateRosterUi(); updateRosterUi();
} else { } else {
Conversation conversation = find(account,avatar.owner.toBareJid()); Conversation conversation = find(account, avatar.owner.toBareJid());
if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) { if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) {
MucOptions.User user = conversation.getMucOptions().findUser(avatar.owner.getResourcepart()); MucOptions.User user = conversation.getMucOptions().findUser(avatar.owner.getResourcepart());
if (user != null) { if (user != null) {
@ -2586,6 +2586,10 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
return Config.FORCE_ORBOT || getPreferences().getBoolean("use_tor", false); return Config.FORCE_ORBOT || getPreferences().getBoolean("use_tor", false);
} }
public boolean showExtendedConnectionOptions() {
return getPreferences().getBoolean("show_connection_options", false);
}
public int unreadCount() { public int unreadCount() {
int count = 0; int count = 0;
for (Conversation conversation : getConversations()) { for (Conversation conversation : getConversations()) {

View file

@ -5,6 +5,7 @@ import android.app.AlertDialog.Builder;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -91,7 +92,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
private Jid jidToEdit; private Jid jidToEdit;
private boolean mInitMode = false; private boolean mInitMode = false;
private boolean mUseTor = false; private boolean mShowOptions = false;
private Account mAccount; private Account mAccount;
private String messageFingerprint; private String messageFingerprint;
@ -133,7 +134,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} }
String hostname = null; String hostname = null;
int numericPort = 5222; int numericPort = 5222;
if (mUseTor) { if (mShowOptions) {
hostname = mHostname.getText().toString(); hostname = mHostname.getText().toString();
final String port = mPort.getText().toString(); final String port = mPort.getText().toString();
if (hostname.contains(" ")) { if (hostname.contains(" ")) {
@ -511,8 +512,11 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} }
} }
} }
this.mUseTor = Config.FORCE_ORBOT || getPreferences().getBoolean("use_tor", false); SharedPreferences preferences = getPreferences();
this.mNamePort.setVisibility(mUseTor ? View.VISIBLE : View.GONE); 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 @Override
@ -598,7 +602,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
this.mHostname.getEditableText().append(this.mAccount.getHostname()); this.mHostname.getEditableText().append(this.mAccount.getHostname());
this.mPort.setText(""); this.mPort.setText("");
this.mPort.getEditableText().append(String.valueOf(this.mAccount.getPort())); 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) { if (!mInitMode) {
@ -740,12 +744,24 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} }
} else { } else {
if (this.mAccount.errorStatus()) { 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()) { if (init || !accountInfoEdited()) {
this.mAccountJid.requestFocus(); errorTextField.requestFocus();
} }
} else { } else {
this.mAccountJid.setError(null); this.mAccountJid.setError(null);
this.mPassword.setError(null);
this.mHostname.setError(null);
} }
this.mStats.setVisibility(View.GONE); this.mStats.setVisibility(View.GONE);
} }

View file

@ -243,6 +243,7 @@ public class XmppConnection implements Runnable {
tagWriter = new TagWriter(); tagWriter = new TagWriter();
this.changeStatus(Account.State.CONNECTING); this.changeStatus(Account.State.CONNECTING);
final boolean useTor = mXmppConnectionService.useTorToConnect() || account.isOnion(); final boolean useTor = mXmppConnectionService.useTorToConnect() || account.isOnion();
final boolean extended = mXmppConnectionService.showExtendedConnectionOptions();
if (useTor) { if (useTor) {
String destination; String destination;
if (account.getHostname() == null || account.getHostname().isEmpty()) { if (account.getHostname() == null || account.getHostname().isEmpty()) {
@ -250,8 +251,16 @@ public class XmppConnection implements Runnable {
} else { } else {
destination = account.getHostname(); destination = account.getHostname();
} }
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": connect to "+destination+" via TOR"); Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": connect to " + destination + " via TOR");
socket = SocksSocketFactory.createSocketOverTor(destination,account.getPort()); 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(); startXmpp();
} else if (DNSHelper.isIp(account.getServer().toString())) { } else if (DNSHelper.isIp(account.getServer().toString())) {
socket = new Socket(); socket = new Socket();

View file

@ -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_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">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_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="action_add_account_with_certificate">Add account with certificate</string>
<string name="unable_to_parse_certificate">Unable to parse 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> <string name="authenticate_with_certificate">Leave empty to authenticate w/ certificate</string>

View file

@ -155,6 +155,11 @@
android:key="use_tor" android:key="use_tor"
android:summary="@string/pref_use_tor_summary" android:summary="@string/pref_use_tor_summary"
android:title="@string/pref_use_tor"/> 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>
<PreferenceCategory android:title="@string/pref_input_options"> <PreferenceCategory android:title="@string/pref_input_options">
<CheckBoxPreference <CheckBoxPreference