summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorNorbel AMBANUMBEN <aanorbel@gmail.com>2024-11-13 08:18:09 +0100
committercyBerta <cyberta@riseup.net>2024-11-28 22:53:30 +0100
commit504bb9ae0e84b3d0d1685ad290f914e5199a4c0e (patch)
treebfa219aa19c3b25a8af53532f5c9d48a3b883532 /app
parent12526ef8ff49c9492f5b9e22acdfb762ccd4d514 (diff)
updated settings
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/fragments/CensorshipCircumventionFragment.java14
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java11
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java3
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java28
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java42
5 files changed, 58 insertions, 40 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/CensorshipCircumventionFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/CensorshipCircumventionFragment.java
index 5766fb55..7ca93f2b 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/CensorshipCircumventionFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/CensorshipCircumventionFragment.java
@@ -5,9 +5,8 @@ import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseObfs4Kcp;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUsePortHopping;
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.setUseObfs4;
-import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setUseObfs4Kcp;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setUsePortHopping;
+import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setUseTunnel;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useBridges;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useSnowflake;
import static se.leap.bitmaskclient.base.utils.ViewHelper.setActionBarSubtitle;
@@ -137,16 +136,7 @@ public class CensorshipCircumventionFragment extends Fragment {
binding.tunnelingRadioGroup.setOnCheckedChangeListener((group, checkedId) -> {
useBridges(true);
- if (checkedId == TUNNELING_NONE) {
- setUseObfs4Kcp(false);
- setUseObfs4(false);
- } else if (checkedId == TUNNELING_OBFS4) {
- setUseObfs4Kcp(false);
- setUseObfs4(true);
- } else if (checkedId == TUNNELING_OBFS4_KCP) {
- setUseObfs4Kcp(true);
- setUseObfs4(false);
- }
+ setUseTunnel(checkedId);
tryReconnectVpn();
});
}
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 1167e8a7..99d49ccb 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
@@ -3,6 +3,7 @@ package se.leap.bitmaskclient.base.fragments;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static se.leap.bitmaskclient.R.string.advanced_settings;
+import static se.leap.bitmaskclient.base.fragments.CensorshipCircumventionFragment.TUNNELING_NONE;
import static se.leap.bitmaskclient.base.models.Constants.GATEWAY_PINNING;
import static se.leap.bitmaskclient.base.models.Constants.PREFER_UDP;
import static se.leap.bitmaskclient.base.models.Constants.USE_BRIDGES;
@@ -14,13 +15,11 @@ import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getExcludedApps;
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.preferUDP;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setAllowExperimentalTransports;
-import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setUseObfs4;
-import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setUseObfs4Kcp;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setUseObfuscationPinning;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setUsePortHopping;
+import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setUseTunnel;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useBridges;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useObfuscationPinning;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useSnowflake;
@@ -106,8 +105,7 @@ public class SettingsFragment extends Fragment implements SharedPreferences.OnSh
if (isChecked) {
useSnowflake(false);
- setUseObfs4Kcp(false);
- setUseObfs4(false);
+ setUseTunnel(TUNNELING_NONE);
setUsePortHopping(false);
}
useBridges(isChecked);
@@ -151,8 +149,7 @@ public class SettingsFragment extends Fragment implements SharedPreferences.OnSh
private void resetManualConfig() {
useSnowflake(false);
- setUseObfs4Kcp(false);
- setUseObfs4(false);
+ setUseTunnel(TUNNELING_NONE);
setUsePortHopping(false);
if (VpnStatus.isVPNActive()) {
EipCommand.startVPN(getContext(), false);
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 c24feda5..6c4a71d0 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
@@ -55,8 +55,7 @@ public interface Constants {
String USE_SYSTEM_PROXY = "usesystemproxy";
String CUSTOM_PROVIDER_DOMAINS = "custom_provider_domains";
String USE_PORT_HOPPING = "use_port_hopping";
- String USE_OBSF4 = "use_obsf4";
- String USE_OBSF4_KCP = "use_obsf4_kcp";
+ String USE_TUNNEL = "tunnel";
//////////////////////////////////////////////
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 407976c3..694f2149 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
@@ -1,6 +1,9 @@
package se.leap.bitmaskclient.base.utils;
import static android.content.Context.MODE_PRIVATE;
+import static se.leap.bitmaskclient.base.fragments.CensorshipCircumventionFragment.TUNNELING_NONE;
+import static se.leap.bitmaskclient.base.fragments.CensorshipCircumventionFragment.TUNNELING_OBFS4;
+import static se.leap.bitmaskclient.base.fragments.CensorshipCircumventionFragment.TUNNELING_OBFS4_KCP;
import static se.leap.bitmaskclient.base.models.Constants.ALLOW_EXPERIMENTAL_TRANSPORTS;
import static se.leap.bitmaskclient.base.models.Constants.ALLOW_TETHERING_BLUETOOTH;
import static se.leap.bitmaskclient.base.models.Constants.ALLOW_TETHERING_USB;
@@ -40,11 +43,10 @@ import static se.leap.bitmaskclient.base.models.Constants.SHOW_EXPERIMENTAL;
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.models.Constants.USE_OBFUSCATION_PINNING;
-import static se.leap.bitmaskclient.base.models.Constants.USE_OBSF4;
-import static se.leap.bitmaskclient.base.models.Constants.USE_OBSF4_KCP;
import static se.leap.bitmaskclient.base.models.Constants.USE_PORT_HOPPING;
import static se.leap.bitmaskclient.base.models.Constants.USE_SNOWFLAKE;
import static se.leap.bitmaskclient.base.models.Constants.USE_SYSTEM_PROXY;
+import static se.leap.bitmaskclient.base.models.Constants.USE_TUNNEL;
import android.content.Context;
import android.content.SharedPreferences;
@@ -576,23 +578,27 @@ public class PreferenceHelper {
}
public static boolean getUseObfs4() {
- return getBoolean(USE_OBSF4, false);
+ return getUseTunnel() == TUNNELING_OBFS4;
}
- public static void setUseObfs4(boolean useObsf4) {
- putBoolean(USE_OBSF4, useObsf4);
+ public static boolean getUseObfs4Kcp() {
+ return getUseTunnel() == TUNNELING_OBFS4_KCP;
}
- public static void setUseObfs4Kcp(boolean useObfs4Kcp) {
- putBoolean(USE_OBSF4_KCP, useObfs4Kcp);
+ public static boolean usesManualBridges(){
+ return getUseSnowflake() || usesSpecificTunnel() || getUsePortHopping();
}
- public static boolean getUseObfs4Kcp() {
- return getBoolean(USE_OBSF4_KCP, false);
+ public static boolean usesSpecificTunnel() {
+ return getUseObfs4() || getUseObfs4Kcp();
}
- public static boolean usesManualBridges(){
- return getUseSnowflake() || getUseObfs4() || getUseObfs4Kcp() || getUsePortHopping();
+ public static void setUseTunnel(int tunnel) {
+ putInt(USE_TUNNEL, tunnel);
+ }
+
+ public static int getUseTunnel() {
+ return getInt(USE_TUNNEL, TUNNELING_NONE);
}
public static boolean useIpv6Firewall() {
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java
index cd85f419..5b4fedf2 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java
@@ -32,6 +32,10 @@ import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getObfuscationPi
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getObfuscationPinningPort;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getPreferredCity;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseBridges;
+import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseObfs4;
+import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseObfs4Kcp;
+import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUsePortHopping;
+import static se.leap.bitmaskclient.base.utils.PreferenceHelper.usesSpecificTunnel;
import android.content.Context;
import android.util.Log;
@@ -152,7 +156,7 @@ public class GatewaysManager {
* @return VpnProfile of the n closest Gateway or null if no remaining VpnProfiles available
*/
public @Nullable VpnProfile selectVpnProfile(int nClosestGateway, String city) {
- TransportType[] transportTypes = getUseBridges() ? new TransportType[]{OBFS4, OBFS4_HOP} : new TransportType[]{OPENVPN};
+ TransportType[] transportTypes = determineTransportTypes();
Set<String> obfuscationTransportLayerProtocols = getObfuscationTransportLayerProtocols();
if (presortedList.size() > 0) {
return getVpnProfileFromPresortedList(nClosestGateway, transportTypes, obfuscationTransportLayerProtocols, city);
@@ -160,13 +164,35 @@ public class GatewaysManager {
return getVpnProfileFromTimezoneCalculation(nClosestGateway, transportTypes, obfuscationTransportLayerProtocols, city);
}
+
+ private TransportType[] determineTransportTypes() {
+ if (getUseBridges() && !usesSpecificTunnel()) {
+ return new TransportType[]{OBFS4, OBFS4_HOP};
+ } else if (getUseBridges() && getUseObfs4()) {
+ return new TransportType[]{OBFS4};
+ } else if (getUseBridges() && getUseObfs4Kcp()) {
+ return new TransportType[]{OBFS4_HOP};
+ } else {
+ return new TransportType[]{OPENVPN};
+ }
+ }
+
+
@Nullable
private static Set<String> getObfuscationTransportLayerProtocols() {
- Set<String> obfuscationTransportLayerProtocols = null;
+ Set<String> transportProtocols = null;
+
if (getUseBridges()) {
- obfuscationTransportLayerProtocols = new HashSet<>(Arrays.asList(TCP, KCP));
+ if (getUseObfs4Kcp()) {
+ transportProtocols = Set.of(KCP);
+ } else if (getUseObfs4()) {
+ transportProtocols = Set.of(TCP);
+ } else {
+ transportProtocols = Set.of(TCP, KCP);
+ }
}
- return obfuscationTransportLayerProtocols;
+
+ return transportProtocols;
}
public void updateTransport(TransportType transportType) {
@@ -333,13 +359,13 @@ public class GatewaysManager {
* @return position of the gateway owning to the profile
*/
public int getPosition(VpnProfile profile) {
- if (presortedList.size() > 0) {
+ if (presortedList.size() > 0) {
return getPositionFromPresortedList(profile);
- }
-
+ }
+
return getPositionFromTimezoneCalculatedList(profile);
}
-
+
private int getPositionFromPresortedList(VpnProfile profile) {
int nClosestGateway = 0;
for (Gateway gateway : presortedList) {