summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2020-07-24 15:41:17 +0200
committercyBerta <cyberta@riseup.net>2020-07-24 15:41:17 +0200
commit501a451b8b932e1f0e001599dbfe53810cb9ead0 (patch)
treef37a16548ad039b8740e5a9fe361ec2acd2f27f8
parentd8b9f60f961e55d0a9204149eb0e8604b9479f55 (diff)
adapt profile selection after perordered gateway list was introduced and use profiles mUsePluggableTransports flag instead of shared preferences to get the requested transport
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java28
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java8
2 files changed, 25 insertions, 11 deletions
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 70d757d4..aa10ffae 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java
@@ -70,7 +70,7 @@ public class GatewaysManager {
Connection.TransportType transportType = getUsePluggableTransports(context) ? OBFS4 : OPENVPN;
if (presortedList.size() > 0) {
- return getGatewayFromPreorderedList(nClosest, transportType);
+ return getGatewayFromPresortedList(nClosest, transportType);
}
return getGatewayFromTimezoneCalculation(nClosest, transportType);
@@ -90,7 +90,7 @@ public class GatewaysManager {
return null;
}
- private Gateway getGatewayFromPreorderedList(int nClosest, Connection.TransportType transportType) {
+ private Gateway getGatewayFromPresortedList(int nClosest, Connection.TransportType transportType) {
while (nClosest < presortedList.size()) {
Gateway gateway = presortedList.get(nClosest);
if (gateway.getProfile(transportType) != null) {
@@ -107,7 +107,29 @@ public class GatewaysManager {
* @return position of the gateway owning to the profile
*/
public int getPosition(VpnProfile profile) {
- Connection.TransportType transportType = getUsePluggableTransports(context) ? OBFS4 : OPENVPN;
+ if (presortedList.size() > 0) {
+ return getPositionFromPresortedList(profile);
+ }
+
+ return getPositionFromTimezoneCalculatedList(profile);
+ }
+
+ private int getPositionFromPresortedList(VpnProfile profile) {
+ Connection.TransportType transportType = profile.mUsePluggableTransports ? OBFS4 : OPENVPN;
+ Gateway gateway;
+ int nClosest = 0;
+ while ((nClosest < presortedList.size())) {
+ gateway = presortedList.get(nClosest);
+ if (profile.equals(gateway.getProfile(transportType))) {
+ return nClosest;
+ }
+ nClosest++;
+ }
+ return -1;
+ }
+
+ private int getPositionFromTimezoneCalculatedList(VpnProfile profile) {
+ Connection.TransportType transportType = profile.mUsePluggableTransports ? OBFS4 : OPENVPN;
GatewaySelector gatewaySelector = new GatewaySelector(new ArrayList<>(gateways.values()));
Gateway gateway;
int nClosest = 0;
diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
index da9e04e4..dd5eb00c 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
@@ -104,8 +104,6 @@ public class GatewaysManagerTest {
JSONObject eipServiceJson = provider.getEipServiceJson();
JSONObject gateway1 = eipServiceJson.getJSONArray(GATEWAYS).getJSONObject(0);
MockHelper.mockProviderObserver(provider);
- mockStatic(PreferenceHelper.class);
- when(PreferenceHelper.getUsePluggableTransports(any(Context.class))).thenReturn(true);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, 3);
@@ -121,8 +119,6 @@ public class GatewaysManagerTest {
JSONObject eipServiceJson = provider.getEipServiceJson();
JSONObject gateway1 = eipServiceJson.getJSONArray(GATEWAYS).getJSONObject(0);
MockHelper.mockProviderObserver(provider);
- mockStatic(PreferenceHelper.class);
- when(PreferenceHelper.getUsePluggableTransports(any(Context.class))).thenReturn(false);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, 3);
@@ -138,8 +134,6 @@ public class GatewaysManagerTest {
JSONObject eipServiceJson = provider.getEipServiceJson();
JSONObject gateway1 = eipServiceJson.getJSONArray(GATEWAYS).getJSONObject(0);
MockHelper.mockProviderObserver(provider);
- mockStatic(PreferenceHelper.class);
- when(PreferenceHelper.getUsePluggableTransports(any(Context.class))).thenReturn(true);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, 3);
@@ -155,8 +149,6 @@ public class GatewaysManagerTest {
JSONObject eipServiceJson = provider.getEipServiceJson();
JSONObject gateway1 = eipServiceJson.getJSONArray(GATEWAYS).getJSONObject(1);
MockHelper.mockProviderObserver(provider);
- mockStatic(PreferenceHelper.class);
- when(PreferenceHelper.getUsePluggableTransports(any(Context.class))).thenReturn(true);
GatewaysManager gatewaysManager = new GatewaysManager(mockContext);
VpnConfigGenerator configGenerator = new VpnConfigGenerator(provider.getDefinition(), secrets, gateway1, 3);