diff options
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/eip')
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java | 19 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java | 3 |
2 files changed, 16 insertions, 6 deletions
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 352d6b18..15ee13c2 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java @@ -16,6 +16,8 @@ */ package se.leap.bitmaskclient.eip; +import android.content.Context; + import android.support.annotation.NonNull; import com.google.gson.Gson; @@ -24,10 +26,13 @@ import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; +import java.util.HashSet; +import java.util.Set; import java.util.HashMap; import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.core.ConfigParser; +import se.leap.bitmaskclient.utils.PreferenceHelper; import de.blinkt.openvpn.core.connection.Connection; import static se.leap.bitmaskclient.Constants.IP_ADDRESS; @@ -65,7 +70,7 @@ public class Gateway { * Build a gateway object from a JSON OpenVPN gateway definition in eip-service.json * and create a VpnProfile belonging to it. */ - public Gateway(JSONObject eipDefinition, JSONObject secrets, JSONObject gateway) { + public Gateway(JSONObject eipDefinition, JSONObject secrets, JSONObject gateway, Context context) { this.gateway = gateway; this.secrets = secrets; @@ -74,13 +79,17 @@ public class Gateway { timezone = getTimezone(eipDefinition); name = locationAsName(eipDefinition); apiVersion = getApiVersion(eipDefinition); - vpnProfiles = createVPNProfiles(); + vpnProfiles = createVPNProfiles(context); } - private void addProfileInfos(HashMap<Connection.TransportType, VpnProfile> profiles) { + private void addProfileInfos(Context context, HashMap<Connection.TransportType, VpnProfile> profiles) { + Set<String> excludedAppsVpn = PreferenceHelper.getExcludedApps(context); for (VpnProfile profile : profiles.values()) { profile.mName = name; profile.mGatewayIp = gateway.optString(IP_ADDRESS); + if (excludedAppsVpn != null) { + profile.mAllowedAppsVpn = new HashSet<>(excludedAppsVpn); + } } } @@ -123,12 +132,12 @@ public class Gateway { /** * Create and attach the VpnProfile to our gateway object */ - private @NonNull HashMap<Connection.TransportType, VpnProfile> createVPNProfiles() { + private @NonNull HashMap<Connection.TransportType, VpnProfile> createVPNProfiles(Context context) { HashMap<Connection.TransportType, VpnProfile> profiles = new HashMap<>(); try { VpnConfigGenerator vpnConfigurationGenerator = new VpnConfigGenerator(generalConfiguration, secrets, gateway, apiVersion); profiles = vpnConfigurationGenerator.generateVpnProfiles(); - addProfileInfos(profiles); + addProfileInfos(context, profiles); } catch (ConfigParser.ConfigParseError | IOException | JSONException e) { // FIXME We didn't get a VpnProfile! Error handling! and log level e.printStackTrace(); 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 740df97f..0847a07e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java @@ -44,6 +44,7 @@ public class GatewaysManager { private static final String TAG = GatewaysManager.class.getSimpleName(); + private Context context; private SharedPreferences preferences; private LinkedHashMap<String, Gateway> gateways = new LinkedHashMap<>(); private Type listType = new TypeToken<ArrayList<Gateway>>() {}.getType(); @@ -91,7 +92,7 @@ public class GatewaysManager { for (int i = 0; i < gatewaysDefined.length(); i++) { JSONObject gw = gatewaysDefined.getJSONObject(i); JSONObject secrets = secretsConfiguration(); - Gateway aux = new Gateway(eipDefinition, secrets, gw); + Gateway aux = new Gateway(eipDefinition, secrets, gw, this.context); if (gateways.get(aux.getRemoteIP()) == null) { addGateway(aux); } |