summaryrefslogtreecommitdiff
path: root/app/src/main/java/de
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/de')
-rw-r--r--app/src/main/java/de/blinkt/openvpn/VpnProfile.java43
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java1
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/connection/Connection.java3
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/connection/ConnectionAdapter.java35
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/connection/Obfs4Connection.java12
5 files changed, 47 insertions, 47 deletions
diff --git a/app/src/main/java/de/blinkt/openvpn/VpnProfile.java b/app/src/main/java/de/blinkt/openvpn/VpnProfile.java
index 41b5ddb5..f2da0838 100644
--- a/app/src/main/java/de/blinkt/openvpn/VpnProfile.java
+++ b/app/src/main/java/de/blinkt/openvpn/VpnProfile.java
@@ -15,12 +15,14 @@ import android.os.Build;
import android.preference.PreferenceManager;
import android.security.KeyChain;
import android.security.KeyChainException;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
import android.text.TextUtils;
import android.util.Base64;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
import org.spongycastle.util.io.pem.PemObject;
import org.spongycastle.util.io.pem.PemWriter;
@@ -63,8 +65,7 @@ import de.blinkt.openvpn.core.VPNLaunchHelper;
import de.blinkt.openvpn.core.VpnStatus;
import de.blinkt.openvpn.core.X509Utils;
import de.blinkt.openvpn.core.connection.Connection;
-import de.blinkt.openvpn.core.connection.Obfs4Connection;
-import de.blinkt.openvpn.core.connection.OpenvpnConnection;
+import de.blinkt.openvpn.core.connection.ConnectionAdapter;
import se.leap.bitmaskclient.BuildConfig;
import se.leap.bitmaskclient.R;
@@ -303,21 +304,6 @@ public class VpnProfile implements Serializable, Cloneable {
@Deprecated
public void upgradeProfile() {
- if (mProfileVersion < 2) {
- /* default to the behaviour the OS used */
- mAllowLocalLAN = Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT;
- }
-
- if (mProfileVersion < 4) {
- moveOptionsToConnection();
- mAllowedAppsVpnAreDisallowed = true;
- }
- if (mAllowedAppsVpn == null)
- mAllowedAppsVpn = new HashSet<>();
-
- if (mConnections == null)
- mConnections = new Connection[0];
-
if (mProfileVersion < 6) {
if (TextUtils.isEmpty(mProfileCreator))
mUserEditable = true;
@@ -332,20 +318,6 @@ public class VpnProfile implements Serializable, Cloneable {
}
- @Deprecated
- private void moveOptionsToConnection() {
- mConnections = new Connection[1];
- Connection conn = mUsePluggableTransports ? new Obfs4Connection() : new OpenvpnConnection();
-
- conn.setServerName(mServerName);
- conn.setServerPort(mServerPort);
- conn.setUseUdp(mUseUdp);
- conn.setCustomConfiguration("");
-
- mConnections[0] = conn;
-
- }
-
public String getConfigFile(Context context, boolean configForOvpn3) {
File cacheDir = context.getCacheDir();
@@ -1159,8 +1131,9 @@ public class VpnProfile implements Serializable, Cloneable {
public static VpnProfile fromJson(String json) {
try {
- Gson gson = new Gson();
- return gson.fromJson(json, VpnProfile.class);
+ GsonBuilder builder = new GsonBuilder();
+ builder.registerTypeAdapter(Connection.class, new ConnectionAdapter());
+ return builder.create().fromJson(json, VpnProfile.class);
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
index 0d4a8037..2c1a65dc 100644
--- a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
+++ b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
@@ -333,6 +333,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
} else {
/* The intent is null when we are set as always-on or the service has been restarted. */
+ Log.d(TAG, "Starting VPN due to isAlwaysOn system settings or app crash.");
mProfile = VpnStatus.getLastConnectedVpnProfile(this);
VpnStatus.logInfo(R.string.service_restarted);
diff --git a/app/src/main/java/de/blinkt/openvpn/core/connection/Connection.java b/app/src/main/java/de/blinkt/openvpn/core/connection/Connection.java
index a318e55d..4cb9c0c7 100644
--- a/app/src/main/java/de/blinkt/openvpn/core/connection/Connection.java
+++ b/app/src/main/java/de/blinkt/openvpn/core/connection/Connection.java
@@ -7,9 +7,12 @@ package de.blinkt.openvpn.core.connection;
import android.text.TextUtils;
+import com.google.gson.annotations.JsonAdapter;
+
import java.io.Serializable;
import java.util.Locale;
+@JsonAdapter(ConnectionAdapter.class)
public abstract class Connection implements Serializable, Cloneable {
private String mServerName = "openvpn.example.com";
private String mServerPort = "1194";
diff --git a/app/src/main/java/de/blinkt/openvpn/core/connection/ConnectionAdapter.java b/app/src/main/java/de/blinkt/openvpn/core/connection/ConnectionAdapter.java
new file mode 100644
index 00000000..335ef34c
--- /dev/null
+++ b/app/src/main/java/de/blinkt/openvpn/core/connection/ConnectionAdapter.java
@@ -0,0 +1,35 @@
+package de.blinkt.openvpn.core.connection;
+
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+
+import java.lang.reflect.Type;
+
+// Adapter for Gson used to serialize and deserialize abstract Connection class, adds a property about the implemented class
+public class ConnectionAdapter implements JsonSerializer<Connection>, JsonDeserializer<Connection> {
+
+ public final static String META_TYPE = ConnectionAdapter.class.getSimpleName() + ".META_TYPE";
+ @Override
+ public Connection deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
+ JsonObject jsonObject = json.getAsJsonObject();
+ String className = jsonObject.get(META_TYPE).getAsString();
+ try {
+ Class<?> clz = Class.forName(className);
+ return context.deserialize(json, clz);
+ } catch (ClassNotFoundException e) {
+ throw new JsonParseException(e);
+ }
+ }
+
+ @Override
+ public JsonElement serialize(Connection src, Type typeOfSrc, JsonSerializationContext context) {
+ JsonElement json = context.serialize(src, src.getClass());
+ json.getAsJsonObject().addProperty(META_TYPE, src.getClass().getCanonicalName());
+ return json;
+ }
+}
diff --git a/app/src/main/java/de/blinkt/openvpn/core/connection/Obfs4Connection.java b/app/src/main/java/de/blinkt/openvpn/core/connection/Obfs4Connection.java
index a2f86e05..c780f487 100644
--- a/app/src/main/java/de/blinkt/openvpn/core/connection/Obfs4Connection.java
+++ b/app/src/main/java/de/blinkt/openvpn/core/connection/Obfs4Connection.java
@@ -27,18 +27,6 @@ public class Obfs4Connection extends Connection {
this.options = options;
}
- @Deprecated
- public Obfs4Connection() {
- setUseUdp(false);
- setServerName(DISPATCHER_IP);
- setServerPort(DISPATCHER_PORT);
- setProxyName("");
- setProxyPort("");
- setProxyAuthUser(null);
- setProxyAuthPassword(null);
- setProxyType(ProxyType.NONE);
- setUseProxyAuth(false); }
-
@Override
public Connection clone() throws CloneNotSupportedException {
Obfs4Connection connection = (Obfs4Connection) super.clone();