diff options
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java')
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java | 19 |
1 files changed, 14 insertions, 5 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(); |