diff options
Diffstat (limited to 'main/src/main/java/de')
4 files changed, 59 insertions, 3 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java index 5afb1fe5..01ee3d82 100644 --- a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java +++ b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java @@ -159,8 +159,6 @@ public class VpnProfile implements Serializable, Cloneable { public String mServerPort = "1194"; public boolean mUseUdp = true; - - public VpnProfile(String name) { mUuid = UUID.randomUUID(); mName = name; diff --git a/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java b/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java index 028c8816..6ba80e66 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java +++ b/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java @@ -37,6 +37,8 @@ public class ConfigParser { public void parseConfig(Reader reader) throws IOException, ConfigParseError { + HashMap<String, String> optionAliases = new HashMap<>(); + optionAliases.put("server-poll-timeout", "timeout-connect"); BufferedReader br = new BufferedReader(reader); @@ -76,6 +78,9 @@ public class ConfigParser { checkinlinefile(args, br); String optionname = args.get(0); + if (optionAliases.get(optionname)!=null) + optionname = optionAliases.get(optionname); + if (!options.containsKey(optionname)) { options.put(optionname, new Vector<Vector<String>>()); } @@ -715,8 +720,12 @@ public class ConfigParser { conn.mUseUdp = isUdpProto(proto.get(1)); } + Vector<String> connectTimeout = getOption("connect-timeout", 1, 1); + if (connectTimeout != null) + conn.mConnectTimeout = Integer.parseInt(connectTimeout.get(0)); + - // Parse remote config + // Parse remote config Vector<Vector<String>> remotes = getAllOption("remote", 1, 3); diff --git a/main/src/main/java/de/blinkt/openvpn/core/Connection.java b/main/src/main/java/de/blinkt/openvpn/core/Connection.java index b10664ce..46ee4c36 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/Connection.java +++ b/main/src/main/java/de/blinkt/openvpn/core/Connection.java @@ -16,6 +16,7 @@ public class Connection implements Serializable, Cloneable { public String mCustomConfiguration=""; public boolean mUseCustomConfig=false; public boolean mEnabled=true; + public int mConnectTimeout = 0; private static final long serialVersionUID = 92031902903829089L; @@ -33,6 +34,10 @@ public class Connection implements Serializable, Cloneable { else cfg += " tcp-client\n"; + if (mConnectTimeout!=0) + cfg += String.format(" connect-timeout %d\n" , mConnectTimeout); + + if (!TextUtils.isEmpty(mCustomConfiguration) && mUseCustomConfig) { cfg += mCustomConfiguration; cfg += "\n"; diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/ConnectionsAdapter.java b/main/src/main/java/de/blinkt/openvpn/fragments/ConnectionsAdapter.java index 14c089f5..c0bda8d1 100644 --- a/main/src/main/java/de/blinkt/openvpn/fragments/ConnectionsAdapter.java +++ b/main/src/main/java/de/blinkt/openvpn/fragments/ConnectionsAdapter.java @@ -19,6 +19,7 @@ import android.widget.CompoundButton; import android.widget.EditText; import android.widget.ImageButton; import android.widget.RadioGroup; +import android.widget.SeekBar; import android.widget.Switch; import java.util.Arrays; @@ -55,6 +56,8 @@ public class ConnectionsAdapter extends RecyclerView.Adapter<ConnectionsAdapter. private final CheckBox mCustomOptionCB; private final View mCustomOptionsLayout; private final ImageButton mDeleteButton; + private final EditText mConnectText; + private final SeekBar mConnectSlider; public ConnectionsHolder(View card) { super(card); @@ -66,6 +69,8 @@ public class ConnectionsAdapter extends RecyclerView.Adapter<ConnectionsAdapter. mProtoGroup = (RadioGroup) card.findViewById(R.id.udptcpradiogroup); mCustomOptionsLayout = card.findViewById(R.id.custom_options_layout); mDeleteButton = (ImageButton) card.findViewById(R.id.remove_connection); + mConnectSlider = (SeekBar) card.findViewById(R.id.connect_silder); + mConnectText = (EditText) card.findViewById(R.id.connect_timeout); } } @@ -109,6 +114,13 @@ public class ConnectionsAdapter extends RecyclerView.Adapter<ConnectionsAdapter. cH.mServerNameView.setText(connection.mServerName); cH.mPortNumberView.setText(connection.mServerPort); cH.mRemoteSwitch.setChecked(connection.mEnabled); + if (connection.mConnectTimeout==0) { + cH.mConnectText.setText(""); + } else { + cH.mConnectText.setText(String.valueOf(connection.mConnectTimeout)); + } + cH.mConnectSlider.setProgress(connection.mConnectTimeout); + cH.mRemoteSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { @@ -182,6 +194,38 @@ public class ConnectionsAdapter extends RecyclerView.Adapter<ConnectionsAdapter. } }); + cH.mConnectSlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + if (fromUser) { + cH.mConnectText.setText(String.valueOf(progress)); + connection.mConnectTimeout = progress; + } + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + + } + }); + cH.mConnectText.addTextChangedListener(new OnTextChangedWatcher() { + @Override + public void afterTextChanged(Editable s) { + try { + int t = Integer.valueOf(String.valueOf(s)); + cH.mConnectSlider.setProgress(t); + connection.mConnectTimeout = t; + } catch (Exception ignored) { + + } + } + }); + } private void removeRemote(int idx) { |