From 0ccec2d3bd7c7f890f7b651110ea10a8933eab29 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 25 Nov 2021 12:23:04 +0100 Subject: implement UI, logic and test for prefer UDP preferences --- .../base/fragments/SettingsFragment.java | 19 ++++++++- .../leap/bitmaskclient/base/models/Constants.java | 2 + .../bitmaskclient/base/utils/PreferenceHelper.java | 8 ++++ .../java/se/leap/bitmaskclient/eip/Gateway.java | 3 +- .../leap/bitmaskclient/eip/VpnConfigGenerator.java | 46 ++++++++++++++++------ app/src/main/res/drawable/ic_multiple_stop.xml | 10 +++++ app/src/main/res/layout/f_settings.xml | 3 +- app/src/main/res/values/strings.xml | 3 ++ 8 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 app/src/main/res/drawable/ic_multiple_stop.xml (limited to 'app/src/main') 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..87c64a89 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,18 @@ 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); + }); + } + 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 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 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); + } } } } diff --git a/app/src/main/res/drawable/ic_multiple_stop.xml b/app/src/main/res/drawable/ic_multiple_stop.xml new file mode 100644 index 00000000..c43c84f3 --- /dev/null +++ b/app/src/main/res/drawable/ic_multiple_stop.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/f_settings.xml b/app/src/main/res/layout/f_settings.xml index b625d548..1851fb54 100644 --- a/app/src/main/res/layout/f_settings.xml +++ b/app/src/main/res/layout/f_settings.xml @@ -35,7 +35,7 @@ android:visibility="visible" /> - Use Snowflake Circumvent blocking of the provider\'s configuration server. VPN settings + Use UDP if available + UDP can be faster and better for streaming, but does not work for all networks. + -- cgit v1.2.3 From d71f36119410e5463f76a45ac555d4dd3a510b74 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 25 Nov 2021 12:59:31 +0100 Subject: make settings fragment scrollable --- app/src/main/res/layout/f_settings.xml | 177 +++++++++++++++++---------------- 1 file changed, 91 insertions(+), 86 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/res/layout/f_settings.xml b/app/src/main/res/layout/f_settings.xml index 1851fb54..a4d86fa6 100644 --- a/app/src/main/res/layout/f_settings.xml +++ b/app/src/main/res/layout/f_settings.xml @@ -1,104 +1,109 @@ - - - + android:orientation="vertical"> - + - + - + - - + - + + - + + - - + + + - \ No newline at end of file + + \ No newline at end of file -- cgit v1.2.3 From 5be61773c92ff0bfee8c7b67ca79a0ebb576b644 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 25 Nov 2021 13:06:37 +0100 Subject: restart VPN if user changes UDP settings while VPN is on --- .../java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app/src/main') 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 87c64a89..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 @@ -138,6 +138,10 @@ public class SettingsFragment extends Fragment implements SharedPreferences.OnSh return; } preferUDP(getContext(), isChecked); + if (VpnStatus.isVPNActive()) { + EipCommand.startVPN(getContext(), false); + showVPNFragment(); + } }); } -- cgit v1.2.3 From d939fc28aaa8f9992d296ddf596fa703ffd5ccb0 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 25 Nov 2021 13:54:45 +0100 Subject: use pngs instead of vector graphics to avoid crashes on Android4 --- app/src/main/res/drawable-hdpi/ic_multiple_stop.png | Bin 0 -> 472 bytes app/src/main/res/drawable-ldpi/ic_multiple_stop.png | Bin 0 -> 311 bytes app/src/main/res/drawable-mdpi/ic_multiple_stop.png | Bin 0 -> 311 bytes app/src/main/res/drawable-xhdpi/ic_multiple_stop.png | Bin 0 -> 455 bytes app/src/main/res/drawable-xxhdpi/ic_multiple_stop.png | Bin 0 -> 663 bytes app/src/main/res/drawable-xxxhdpi/ic_multiple_stop.png | Bin 0 -> 837 bytes app/src/main/res/drawable/ic_multiple_stop.xml | 10 ---------- 7 files changed, 10 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_multiple_stop.png create mode 100644 app/src/main/res/drawable-ldpi/ic_multiple_stop.png create mode 100644 app/src/main/res/drawable-mdpi/ic_multiple_stop.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_multiple_stop.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_multiple_stop.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_multiple_stop.png delete mode 100644 app/src/main/res/drawable/ic_multiple_stop.xml (limited to 'app/src/main') diff --git a/app/src/main/res/drawable-hdpi/ic_multiple_stop.png b/app/src/main/res/drawable-hdpi/ic_multiple_stop.png new file mode 100644 index 00000000..cd67c160 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_multiple_stop.png differ diff --git a/app/src/main/res/drawable-ldpi/ic_multiple_stop.png b/app/src/main/res/drawable-ldpi/ic_multiple_stop.png new file mode 100644 index 00000000..fc0a47e1 Binary files /dev/null and b/app/src/main/res/drawable-ldpi/ic_multiple_stop.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_multiple_stop.png b/app/src/main/res/drawable-mdpi/ic_multiple_stop.png new file mode 100644 index 00000000..fc0a47e1 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_multiple_stop.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_multiple_stop.png b/app/src/main/res/drawable-xhdpi/ic_multiple_stop.png new file mode 100644 index 00000000..c16a18c1 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_multiple_stop.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_multiple_stop.png b/app/src/main/res/drawable-xxhdpi/ic_multiple_stop.png new file mode 100644 index 00000000..b6fe22a8 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_multiple_stop.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_multiple_stop.png b/app/src/main/res/drawable-xxxhdpi/ic_multiple_stop.png new file mode 100644 index 00000000..6cf3f58b Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_multiple_stop.png differ diff --git a/app/src/main/res/drawable/ic_multiple_stop.xml b/app/src/main/res/drawable/ic_multiple_stop.xml deleted file mode 100644 index c43c84f3..00000000 --- a/app/src/main/res/drawable/ic_multiple_stop.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - -- cgit v1.2.3