summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorcyberta <cyberta@riseup.net>2021-11-25 13:00:01 +0000
committercyberta <cyberta@riseup.net>2021-11-25 13:00:01 +0000
commit976843d09cc7455945bf42a3817445649fec7c05 (patch)
tree4a05965b62cdecae5e0630267adb09d51a13f667 /app/src/main/java
parentdcee5f2fa1dc67e5b08223db3441da8bd38e8b20 (diff)
parentd939fc28aaa8f9992d296ddf596fa703ffd5ccb0 (diff)
Merge branch 'UDP_ui' into 'master'
UDP UI See merge request leap/bitmask_android!147
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java23
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java2
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java8
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java3
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java46
5 files changed, 68 insertions, 14 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java
index ed1e8b6d..7157d1cc 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java
@@ -34,10 +34,12 @@ import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT;
import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES;
import static se.leap.bitmaskclient.base.models.Constants.USE_BRIDGES;
import static se.leap.bitmaskclient.base.models.Constants.USE_IPv6_FIREWALL;
+import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getPreferUDP;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getShowAlwaysOnDialog;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseBridges;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseSnowflake;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.hasSnowflakePrefs;
+import static se.leap.bitmaskclient.base.utils.PreferenceHelper.preferUDP;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useBridges;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useSnowflake;
@@ -63,10 +65,11 @@ public class SettingsFragment extends Fragment implements SharedPreferences.OnSh
View view = inflater.inflate(R.layout.f_settings, container, false);
initAlwaysOnVpnEntry(view);
initExcludeAppsEntry(view);
- initFirewallEntry(view);
- initTetheringEntry(view);
+ initPreferUDPEntry(view);
initUseBridgesEntry(view);
initUseSnowflakeEntry(view);
+ initFirewallEntry(view);
+ initTetheringEntry(view);
return view;
}
@@ -126,6 +129,22 @@ public class SettingsFragment extends Fragment implements SharedPreferences.OnSh
}
}
+ private void initPreferUDPEntry(View rootView) {
+ IconSwitchEntry useSnowflake = rootView.findViewById(R.id.prefer_udp);
+ useSnowflake.setVisibility(VISIBLE);
+ useSnowflake.setChecked(getPreferUDP(getContext()));
+ useSnowflake.setOnCheckedChangeListener((buttonView, isChecked) -> {
+ if (!buttonView.isPressed()) {
+ return;
+ }
+ preferUDP(getContext(), isChecked);
+ if (VpnStatus.isVPNActive()) {
+ EipCommand.startVPN(getContext(), false);
+ showVPNFragment();
+ }
+ });
+ }
+
private void initExcludeAppsEntry(View rootView) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
IconTextEntry excludeApps = rootView.findViewById(R.id.exclude_apps);
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java b/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java
index 016a8563..468b1b01 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java
@@ -42,6 +42,7 @@ public interface Constants {
String LAST_UPDATE_CHECK = "last_update_check";
String PREFERRED_CITY = "preferred_city";
String USE_SNOWFLAKE = "use_snowflake";
+ String PREFER_UDP = "prefer_UDP";
//////////////////////////////////////////////
@@ -163,6 +164,7 @@ public interface Constants {
String REMOTE = "remote";
String PORTS = "ports";
String PROTOCOLS = "protocols";
+ String UDP = "udp";
String CAPABILITIES = "capabilities";
String TRANSPORT = "transport";
String TYPE = "type";
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java
index 515ec282..fe9100cb 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java
@@ -29,6 +29,7 @@ import static se.leap.bitmaskclient.base.models.Constants.EXCLUDED_APPS;
import static se.leap.bitmaskclient.base.models.Constants.LAST_UPDATE_CHECK;
import static se.leap.bitmaskclient.base.models.Constants.LAST_USED_PROFILE;
import static se.leap.bitmaskclient.base.models.Constants.PREFERRED_CITY;
+import static se.leap.bitmaskclient.base.models.Constants.PREFER_UDP;
import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_CONFIGURED;
import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_EIP_DEFINITION;
import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_PRIVATE_KEY;
@@ -145,6 +146,13 @@ public class PreferenceHelper {
return getBoolean(context, RESTART_ON_UPDATE, false);
}
+ public static boolean getPreferUDP(Context context) {
+ return getBoolean(context, PREFER_UDP, false);
+ }
+
+ public static void preferUDP(Context context, boolean prefer) {
+ putBoolean(context, PREFER_UDP, prefer);
+ }
public static boolean getUseBridges(SharedPreferences preferences) {
return preferences.getBoolean(USE_BRIDGES, false);
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java
index a3d3abbc..60507363 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java
@@ -174,7 +174,8 @@ public class Gateway {
*/
private @NonNull HashMap<Connection.TransportType, VpnProfile> createVPNProfiles(Context context)
throws ConfigParser.ConfigParseError, IOException, JSONException {
- VpnConfigGenerator vpnConfigurationGenerator = new VpnConfigGenerator(generalConfiguration, secrets, gateway, apiVersion);
+ boolean preferUDP = PreferenceHelper.getPreferUDP(context);
+ VpnConfigGenerator vpnConfigurationGenerator = new VpnConfigGenerator(generalConfiguration, secrets, gateway, apiVersion, preferUDP);
HashMap<Connection.TransportType, VpnProfile> profiles = vpnConfigurationGenerator.generateVpnProfiles();
addProfileInfos(context, profiles);
return profiles;
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java
index d72f0936..303959d0 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java
@@ -48,6 +48,7 @@ import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_VPN_CERTIFICA
import static se.leap.bitmaskclient.base.models.Constants.REMOTE;
import static se.leap.bitmaskclient.base.models.Constants.TRANSPORT;
import static se.leap.bitmaskclient.base.models.Constants.TYPE;
+import static se.leap.bitmaskclient.base.models.Constants.UDP;
import static se.leap.bitmaskclient.pluggableTransports.Dispatcher.DISPATCHER_IP;
import static se.leap.bitmaskclient.pluggableTransports.Dispatcher.DISPATCHER_PORT;
@@ -57,16 +58,18 @@ public class VpnConfigGenerator {
private JSONObject secrets;
private JSONObject obfs4Transport;
private int apiVersion;
+ private boolean preferUDP;
public final static String TAG = VpnConfigGenerator.class.getSimpleName();
private final String newLine = System.getProperty("line.separator"); // Platform new line
- public VpnConfigGenerator(JSONObject generalConfiguration, JSONObject secrets, JSONObject gateway, int apiVersion) throws ConfigParser.ConfigParseError {
+ public VpnConfigGenerator(JSONObject generalConfiguration, JSONObject secrets, JSONObject gateway, int apiVersion, boolean preferUDP) throws ConfigParser.ConfigParseError {
this.generalConfiguration = generalConfiguration;
this.gateway = gateway;
this.secrets = secrets;
this.apiVersion = apiVersion;
+ this.preferUDP = preferUDP;
checkCapabilities();
}
@@ -174,7 +177,7 @@ public class VpnConfigGenerator {
default:
case 1:
case 2:
- ipAddress = gateway.getString(IP_ADDRESS);
+ ipAddress = gateway.getString(IP_ADDRESS);
gatewayConfigApiv1(stringBuilder, ipAddress, capabilities);
break;
case 3:
@@ -213,9 +216,9 @@ public class VpnConfigGenerator {
int port;
String protocol;
JSONArray ports = capabilities.getJSONArray(PORTS);
+ JSONArray protocols = capabilities.getJSONArray(PROTOCOLS);
for (int i = 0; i < ports.length(); i++) {
port = ports.getInt(i);
- JSONArray protocols = capabilities.getJSONArray(PROTOCOLS);
for (int j = 0; j < protocols.length(); j++) {
protocol = protocols.optString(j);
String newRemote = REMOTE + " " + ipAddress + " " + port + " " + protocol + newLine;
@@ -229,14 +232,35 @@ public class VpnConfigGenerator {
String protocol;
JSONObject openvpnTransport = getTransport(transports, OPENVPN);
JSONArray ports = openvpnTransport.getJSONArray(PORTS);
- for (int j = 0; j < ports.length(); j++) {
- port = ports.getString(j);
- JSONArray protocols = openvpnTransport.getJSONArray(PROTOCOLS);
- for (int k = 0; k < protocols.length(); k++) {
- protocol = protocols.optString(k);
- for (String ipAddress : ipAddresses) {
- String newRemote = REMOTE + " " + ipAddress + " " + port + " " + protocol + newLine;
- stringBuilder.append(newRemote);
+ JSONArray protocols = openvpnTransport.getJSONArray(PROTOCOLS);
+ if (preferUDP) {
+ StringBuilder udpRemotes = new StringBuilder();
+ StringBuilder tcpRemotes = new StringBuilder();
+ for (int i = 0; i < protocols.length(); i++) {
+ protocol = protocols.optString(i);
+ for (int j = 0; j < ports.length(); j++) {
+ port = ports.optString(j);
+ for (String ipAddress : ipAddresses) {
+ String newRemote = REMOTE + " " + ipAddress + " " + port + " " + protocol + newLine;
+ if (UDP.equals(protocol)) {
+ udpRemotes.append(newRemote);
+ } else {
+ tcpRemotes.append(newRemote);
+ }
+ }
+ }
+ }
+ stringBuilder.append(udpRemotes.toString());
+ stringBuilder.append(tcpRemotes.toString());
+ } else {
+ for (int j = 0; j < ports.length(); j++) {
+ port = ports.getString(j);
+ for (int k = 0; k < protocols.length(); k++) {
+ protocol = protocols.optString(k);
+ for (String ipAddress : ipAddresses) {
+ String newRemote = REMOTE + " " + ipAddress + " " + port + " " + protocol + newLine;
+ stringBuilder.append(newRemote);
+ }
}
}
}